diff --git a/README.md b/README.md index d20f8fc0..1739eca0 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ int main() { bot.getApi().sendMessage(message->chat->id, "Your message is: " + message->text); }); try { - printf("Bot username: %s\n", bot.getApi().getMe()->username.c_str()); + printf("Bot name: %s\n", bot.getApi().getMe()->firstName.c_str()); TgBot::TgLongPoll longPoll(bot); while (true) { printf("Long poll started\n"); diff --git a/include/tgbot/Optional.h b/include/tgbot/Optional.h index b3563d48..a1b5abdd 100644 --- a/include/tgbot/Optional.h +++ b/include/tgbot/Optional.h @@ -5,16 +5,16 @@ namespace TgBot { +// Optional via boost::optional template - using Optional = boost::optional; + using Optional = boost::optional; -// use for: OptionalPtr> -// for pointers, we assume optional value == nullptr (or not owned, etc) +// Optional is nullptr (for std::shared/unique_ptr<> etc) template - using OptionalPtr = T; + using OptionalNullPtr = T; template - using Required = T; + using Required = T; } diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 850c41f6..eba210c9 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -899,7 +899,7 @@ class TGBOT_API TgTypeParser { private: inline void removeLastComma(std::string& input) const { - if (!input.empty() && input.back() == ',') input.erase(input.length() - 1); + if (!input.empty() && input.back() == ',') input.pop_back(); } template @@ -907,11 +907,7 @@ class TGBOT_API TgTypeParser { if (!value) { return; } - json += '"'; - json += varName; - json += R"(":)"; - json += *value; - json += ','; + appendToJson(json, varName, *value); } template diff --git a/include/tgbot/types/InlineKeyboardButton.h b/include/tgbot/types/InlineKeyboardButton.h index 35bad3f1..925493d6 100644 --- a/include/tgbot/types/InlineKeyboardButton.h +++ b/include/tgbot/types/InlineKeyboardButton.h @@ -47,14 +47,14 @@ class InlineKeyboardButton { * The Web App will be able to send an arbitrary message on behalf of the user using the method Api::answerWebAppQuery. * Available only in private chats between a user and the bot. */ - OptionalPtr webApp; + OptionalNullPtr webApp; /** * @brief Optional. An HTTPS URL used to automatically authorize the user. * * Can be used as a replacement for the [Telegram Login Widget](https://core.telegram.org/widgets/login). */ - OptionalPtr loginUrl; + OptionalNullPtr loginUrl; /** * @brief Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field. @@ -74,14 +74,14 @@ class InlineKeyboardButton { /** * @brief Optional. If set, pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot's username and the specified inline query in the input field */ - OptionalPtr switchInlineQueryChosenChat; + OptionalNullPtr switchInlineQueryChosenChat; /** * @brief Optional. Description of the game that will be launched when the user presses the button. * * NOTE: This type of button must always be the first button in the first row. */ - OptionalPtr callbackGame; + OptionalNullPtr callbackGame; /** * @brief Optional. Specify True, to send a [Pay button](https://core.telegram.org/bots/api#payments). diff --git a/include/tgbot/types/MessageEntity.h b/include/tgbot/types/MessageEntity.h index 12da9d40..de07ee80 100644 --- a/include/tgbot/types/MessageEntity.h +++ b/include/tgbot/types/MessageEntity.h @@ -55,7 +55,7 @@ class MessageEntity { /** * @brief Optional. For Type::TextMention only, the mentioned user */ - OptionalPtr user; + OptionalNullPtr user; /** * @brief Optional. For Type::Pre only, the programming language of the entity text diff --git a/samples/echobot-curl-client/src/main.cpp b/samples/echobot-curl-client/src/main.cpp index d845bbd7..0aee5e2f 100644 --- a/samples/echobot-curl-client/src/main.cpp +++ b/samples/echobot-curl-client/src/main.cpp @@ -33,7 +33,7 @@ int main() { }); try { - printf("Bot username: %s\n", bot.getApi().getMe()->username->c_str()); + printf("Bot name: %s\n", bot.getApi().getMe()->firstName.c_str()); bot.getApi().deleteWebhook(); TgLongPoll longPoll(bot); diff --git a/samples/echobot-setmycommands/src/main.cpp b/samples/echobot-setmycommands/src/main.cpp index 7b0ef606..16d6d5f9 100644 --- a/samples/echobot-setmycommands/src/main.cpp +++ b/samples/echobot-setmycommands/src/main.cpp @@ -59,7 +59,7 @@ int main() { }); try { - printf("Bot username: %s\n", bot.getApi().getMe()->username->c_str()); + printf("Bot name: %s\n", bot.getApi().getMe()->firstName.c_str()); bot.getApi().deleteWebhook(); TgLongPoll longPoll(bot); diff --git a/samples/echobot-submodule/src/main.cpp b/samples/echobot-submodule/src/main.cpp index b12631a0..aa15aee8 100644 --- a/samples/echobot-submodule/src/main.cpp +++ b/samples/echobot-submodule/src/main.cpp @@ -31,7 +31,7 @@ int main() { }); try { - printf("Bot username: %s\n", bot.getApi().getMe()->username->c_str()); + printf("Bot name: %s\n", bot.getApi().getMe()->firstName.c_str()); bot.getApi().deleteWebhook(); TgLongPoll longPoll(bot); diff --git a/samples/echobot-webhook-server/src/main.cpp b/samples/echobot-webhook-server/src/main.cpp index 0e48ddc0..afc4e077 100644 --- a/samples/echobot-webhook-server/src/main.cpp +++ b/samples/echobot-webhook-server/src/main.cpp @@ -33,7 +33,7 @@ int main() { }); try { - printf("Bot username: %s\n", bot.getApi().getMe()->username->c_str()); + printf("Bot name: %s\n", bot.getApi().getMe()->firstName.c_str()); TgWebhookTcpServer webhookServer(8080, bot); diff --git a/samples/echobot/src/main.cpp b/samples/echobot/src/main.cpp index 7ea3abba..9aa6a8ee 100644 --- a/samples/echobot/src/main.cpp +++ b/samples/echobot/src/main.cpp @@ -31,7 +31,10 @@ int main() { }); try { - printf("Bot username: %s\n", bot.getApi().getMe()->username.value_or(string{"unknown"}).c_str()); + auto user = bot.getApi().getMe(); + printf("Bot name: %s, username: %s\n", + user->firstName.c_str(), + user->username.value_or(string{"unknown"}).c_str()); bot.getApi().deleteWebhook(); TgLongPoll longPoll(bot); diff --git a/samples/inline-keyboard/src/main.cpp b/samples/inline-keyboard/src/main.cpp index 6dd4a3f3..94359d4c 100644 --- a/samples/inline-keyboard/src/main.cpp +++ b/samples/inline-keyboard/src/main.cpp @@ -44,7 +44,7 @@ int main() { }); try { - printf("Bot username: %s\n", bot.getApi().getMe()->username->c_str()); + printf("Bot name: %s\n", bot.getApi().getMe()->firstName.c_str()); bot.getApi().deleteWebhook(); TgLongPoll longPoll(bot); diff --git a/samples/photo/src/main.cpp b/samples/photo/src/main.cpp index 08322756..6ba74ea4 100644 --- a/samples/photo/src/main.cpp +++ b/samples/photo/src/main.cpp @@ -30,7 +30,7 @@ int main() { }); try { - printf("Bot username: %s\n", bot.getApi().getMe()->username->c_str()); + printf("Bot name: %s\n", bot.getApi().getMe()->firstName.c_str()); bot.getApi().deleteWebhook(); TgLongPoll longPoll(bot); diff --git a/samples/receive-file/src/main.cpp b/samples/receive-file/src/main.cpp index a17da66d..5d29c616 100644 --- a/samples/receive-file/src/main.cpp +++ b/samples/receive-file/src/main.cpp @@ -36,7 +36,7 @@ int main() { }); try { - printf("Bot username: %s\n", bot.getApi().getMe()->username->c_str()); + printf("Bot name: %s\n", bot.getApi().getMe()->firstName.c_str()); bot.getApi().deleteWebhook(); TgLongPoll longPoll(bot); diff --git a/samples/received-text-processing/src/main.cpp b/samples/received-text-processing/src/main.cpp index 9cf4887a..97a203e4 100644 --- a/samples/received-text-processing/src/main.cpp +++ b/samples/received-text-processing/src/main.cpp @@ -46,7 +46,7 @@ int main() { }); try { - printf("Bot username: %s\n", bot.getApi().getMe()->username->c_str()); + printf("Bot name: %s\n", bot.getApi().getMe()->firstName.c_str()); bot.getApi().deleteWebhook(); while (true) { diff --git a/samples/reply-keyboard/src/main.cpp b/samples/reply-keyboard/src/main.cpp index cf716900..fb4d122a 100644 --- a/samples/reply-keyboard/src/main.cpp +++ b/samples/reply-keyboard/src/main.cpp @@ -73,7 +73,7 @@ int main() { }); try { - printf("Bot username: %s\n", bot.getApi().getMe()->username->c_str()); + printf("Bot name: %s\n", bot.getApi().getMe()->firstName.c_str()); bot.getApi().deleteWebhook(); TgLongPoll longPoll(bot);