From 4c804e926d42ce953bd198bb53caa7593df1974f Mon Sep 17 00:00:00 2001 From: Soo-Hwan Na Date: Sat, 1 Jun 2024 11:08:18 +0900 Subject: [PATCH 01/19] tgbot-cpp: Use explicit alias target for curl --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 627af9c0..fa0d232e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,7 +89,7 @@ set(LIB_LIST ) if (CURL_FOUND) - set(LIB_LIST ${LIB_LIST} ${CURL_LIBRARIES}) + set(LIB_LIST ${LIB_LIST} CURL::libcurl) endif() if (WIN32) From 7497688fa9ee1e8d5b5f0ae072926e682f6fb8e5 Mon Sep 17 00:00:00 2001 From: royna2544 Date: Fri, 13 Sep 2024 18:08:22 +0900 Subject: [PATCH 02/19] StringTools: Use boost replacements if possible --- src/tools/StringTools.cpp | 42 +++++---------------------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/src/tools/StringTools.cpp b/src/tools/StringTools.cpp index cc5436f6..fc06af71 100644 --- a/src/tools/StringTools.cpp +++ b/src/tools/StringTools.cpp @@ -1,5 +1,7 @@ #include "tgbot/tools/StringTools.h" +#include +#include #include #include #include @@ -10,49 +12,15 @@ using namespace std; namespace StringTools { bool startsWith(const string& str1, const string& str2) { - if (str1.length() < str2.length()) { - return false; - } - string::const_iterator it1(str1.begin()); - string::const_iterator end1(str1.end()); - string::const_iterator it2(str2.begin()); - string::const_iterator end2(str2.end()); - while (it1 != end1 && it2 != end2) { - if (*it1 != *it2) { - return false; - } - ++it1; - ++it2; - } - return true; + return boost::starts_with(str1, str2); } bool endsWith(const string& str1, const string& str2) { - if (str1.length() < str2.length()) { - return false; - } - string::const_iterator it1(str1.end()); - string::const_iterator begin1(str1.begin()); - string::const_iterator it2(str2.end()); - string::const_iterator begin2(str2.begin()); - --begin1; - --begin2; - while (it1 != begin1 && it2 != begin2) { - if (*it1 != *it2) { - return false; - } - --it1; - --it2; - } - return true; + return boost::ends_with(str1, str2); } void split(const string& str, char delimiter, vector& dest) { - istringstream stream(str); - string s; - while (getline(stream, s, delimiter)) { - dest.push_back(s); - } + boost::split(dest, str, [delimiter](char c) { return c == delimiter; }); } string generateRandomString(std::size_t length) { From ccd42beee6df5dfb0e52fdb2960e2c09877ed310 Mon Sep 17 00:00:00 2001 From: roynatech2544 Date: Mon, 12 Aug 2024 21:53:40 +0900 Subject: [PATCH 03/19] TgTypeParser: Migrate to boost::ptree - The current method of manually appending string and commas are too lame and bug-prone, migrate to template-specialization based boost.PropertyTree for universal JSON fix --- include/tgbot/Api.h | 1 - include/tgbot/TgTypeParser.h | 1358 ++-- include/tgbot/net/TgWebhookServer.h | 60 +- src/Api.cpp | 4822 ++++++------ src/TgTypeParser.cpp | 10218 ++++++++++++-------------- 5 files changed, 7626 insertions(+), 8833 deletions(-) diff --git a/include/tgbot/Api.h b/include/tgbot/Api.h index 2288f5c0..0872cbcd 100644 --- a/include/tgbot/Api.h +++ b/include/tgbot/Api.h @@ -2244,7 +2244,6 @@ friend class Bot; boost::property_tree::ptree sendRequest(const std::string& method, const std::vector& args = std::vector()) const; const std::string _token; - const TgTypeParser _tgTypeParser; const std::string _url; }; } diff --git a/include/tgbot/TgTypeParser.h b/include/tgbot/TgTypeParser.h index 661930e0..5b5061da 100644 --- a/include/tgbot/TgTypeParser.h +++ b/include/tgbot/TgTypeParser.h @@ -2,195 +2,195 @@ #define TGBOT_TGTYPEPARSER_H #include "tgbot/export.h" -#include "tgbot/types/Update.h" -#include "tgbot/types/WebhookInfo.h" -#include "tgbot/types/User.h" -#include "tgbot/types/Chat.h" -#include "tgbot/types/Message.h" -#include "tgbot/types/MessageId.h" -#include "tgbot/types/InaccessibleMessage.h" -#include "tgbot/types/MessageEntity.h" -#include "tgbot/types/TextQuote.h" -#include "tgbot/types/ExternalReplyInfo.h" -#include "tgbot/types/ReplyParameters.h" -#include "tgbot/types/MessageOrigin.h" -#include "tgbot/types/MessageOriginUser.h" -#include "tgbot/types/MessageOriginHiddenUser.h" -#include "tgbot/types/MessageOriginChat.h" -#include "tgbot/types/MessageOriginChannel.h" -#include "tgbot/types/PhotoSize.h" #include "tgbot/types/Animation.h" #include "tgbot/types/Audio.h" -#include "tgbot/types/Document.h" -#include "tgbot/types/Story.h" -#include "tgbot/types/Video.h" -#include "tgbot/types/VideoNote.h" -#include "tgbot/types/Voice.h" -#include "tgbot/types/Contact.h" -#include "tgbot/types/Dice.h" -#include "tgbot/types/PollOption.h" -#include "tgbot/types/PollAnswer.h" -#include "tgbot/types/Poll.h" -#include "tgbot/types/Location.h" -#include "tgbot/types/Venue.h" -#include "tgbot/types/WebAppData.h" -#include "tgbot/types/ProximityAlertTriggered.h" -#include "tgbot/types/MessageAutoDeleteTimerChanged.h" -#include "tgbot/types/ChatBoostAdded.h" -#include "tgbot/types/ForumTopicCreated.h" -#include "tgbot/types/ForumTopicClosed.h" -#include "tgbot/types/ForumTopicEdited.h" -#include "tgbot/types/ForumTopicReopened.h" -#include "tgbot/types/GeneralForumTopicHidden.h" -#include "tgbot/types/GeneralForumTopicUnhidden.h" -#include "tgbot/types/SharedUser.h" -#include "tgbot/types/UsersShared.h" -#include "tgbot/types/ChatShared.h" -#include "tgbot/types/WriteAccessAllowed.h" -#include "tgbot/types/VideoChatScheduled.h" -#include "tgbot/types/VideoChatStarted.h" -#include "tgbot/types/VideoChatEnded.h" -#include "tgbot/types/VideoChatParticipantsInvited.h" -#include "tgbot/types/GiveawayCreated.h" -#include "tgbot/types/Giveaway.h" -#include "tgbot/types/GiveawayWinners.h" -#include "tgbot/types/GiveawayCompleted.h" -#include "tgbot/types/LinkPreviewOptions.h" -#include "tgbot/types/UserProfilePhotos.h" -#include "tgbot/types/File.h" -#include "tgbot/types/WebAppInfo.h" -#include "tgbot/types/ReplyKeyboardMarkup.h" -#include "tgbot/types/KeyboardButton.h" -#include "tgbot/types/KeyboardButtonRequestUsers.h" -#include "tgbot/types/KeyboardButtonRequestChat.h" -#include "tgbot/types/KeyboardButtonPollType.h" -#include "tgbot/types/ReplyKeyboardRemove.h" -#include "tgbot/types/InlineKeyboardMarkup.h" -#include "tgbot/types/InlineKeyboardButton.h" -#include "tgbot/types/LoginUrl.h" -#include "tgbot/types/SwitchInlineQueryChosenChat.h" -#include "tgbot/types/CallbackQuery.h" -#include "tgbot/types/ForceReply.h" -#include "tgbot/types/ChatPhoto.h" -#include "tgbot/types/ChatInviteLink.h" -#include "tgbot/types/ChatAdministratorRights.h" -#include "tgbot/types/ChatMemberUpdated.h" -#include "tgbot/types/ChatMember.h" -#include "tgbot/types/ChatMemberOwner.h" -#include "tgbot/types/ChatMemberAdministrator.h" -#include "tgbot/types/ChatMemberMember.h" -#include "tgbot/types/ChatMemberRestricted.h" -#include "tgbot/types/ChatMemberLeft.h" -#include "tgbot/types/ChatMemberBanned.h" -#include "tgbot/types/ChatJoinRequest.h" -#include "tgbot/types/ChatPermissions.h" #include "tgbot/types/Birthdate.h" -#include "tgbot/types/BusinessIntro.h" -#include "tgbot/types/BusinessLocation.h" -#include "tgbot/types/BusinessOpeningHoursInterval.h" -#include "tgbot/types/BusinessOpeningHours.h" -#include "tgbot/types/ChatLocation.h" -#include "tgbot/types/ReactionType.h" -#include "tgbot/types/ReactionTypeEmoji.h" -#include "tgbot/types/ReactionTypeCustomEmoji.h" -#include "tgbot/types/ReactionCount.h" -#include "tgbot/types/MessageReactionUpdated.h" -#include "tgbot/types/MessageReactionCountUpdated.h" -#include "tgbot/types/ForumTopic.h" #include "tgbot/types/BotCommand.h" #include "tgbot/types/BotCommandScope.h" -#include "tgbot/types/BotCommandScopeDefault.h" -#include "tgbot/types/BotCommandScopeAllPrivateChats.h" -#include "tgbot/types/BotCommandScopeAllGroupChats.h" #include "tgbot/types/BotCommandScopeAllChatAdministrators.h" +#include "tgbot/types/BotCommandScopeAllGroupChats.h" +#include "tgbot/types/BotCommandScopeAllPrivateChats.h" #include "tgbot/types/BotCommandScopeChat.h" #include "tgbot/types/BotCommandScopeChatAdministrators.h" #include "tgbot/types/BotCommandScopeChatMember.h" -#include "tgbot/types/BotName.h" +#include "tgbot/types/BotCommandScopeDefault.h" #include "tgbot/types/BotDescription.h" +#include "tgbot/types/BotName.h" #include "tgbot/types/BotShortDescription.h" -#include "tgbot/types/MenuButton.h" -#include "tgbot/types/MenuButtonCommands.h" -#include "tgbot/types/MenuButtonWebApp.h" -#include "tgbot/types/MenuButtonDefault.h" +#include "tgbot/types/BusinessConnection.h" +#include "tgbot/types/BusinessIntro.h" +#include "tgbot/types/BusinessLocation.h" +#include "tgbot/types/BusinessMessagesDeleted.h" +#include "tgbot/types/BusinessOpeningHours.h" +#include "tgbot/types/BusinessOpeningHoursInterval.h" +#include "tgbot/types/CallbackGame.h" +#include "tgbot/types/CallbackQuery.h" +#include "tgbot/types/Chat.h" +#include "tgbot/types/ChatAdministratorRights.h" +#include "tgbot/types/ChatBoost.h" +#include "tgbot/types/ChatBoostAdded.h" +#include "tgbot/types/ChatBoostRemoved.h" #include "tgbot/types/ChatBoostSource.h" -#include "tgbot/types/ChatBoostSourcePremium.h" #include "tgbot/types/ChatBoostSourceGiftCode.h" #include "tgbot/types/ChatBoostSourceGiveaway.h" -#include "tgbot/types/ChatBoost.h" +#include "tgbot/types/ChatBoostSourcePremium.h" #include "tgbot/types/ChatBoostUpdated.h" -#include "tgbot/types/ChatBoostRemoved.h" -#include "tgbot/types/UserChatBoosts.h" -#include "tgbot/types/BusinessConnection.h" -#include "tgbot/types/BusinessMessagesDeleted.h" -#include "tgbot/types/ResponseParameters.h" -#include "tgbot/types/InputMedia.h" -#include "tgbot/types/InputMediaPhoto.h" -#include "tgbot/types/InputMediaVideo.h" -#include "tgbot/types/InputMediaAnimation.h" -#include "tgbot/types/InputMediaAudio.h" -#include "tgbot/types/InputMediaDocument.h" -#include "tgbot/types/Sticker.h" -#include "tgbot/types/StickerSet.h" -#include "tgbot/types/MaskPosition.h" -#include "tgbot/types/InputSticker.h" +#include "tgbot/types/ChatInviteLink.h" +#include "tgbot/types/ChatJoinRequest.h" +#include "tgbot/types/ChatLocation.h" +#include "tgbot/types/ChatMember.h" +#include "tgbot/types/ChatMemberAdministrator.h" +#include "tgbot/types/ChatMemberBanned.h" +#include "tgbot/types/ChatMemberLeft.h" +#include "tgbot/types/ChatMemberMember.h" +#include "tgbot/types/ChatMemberOwner.h" +#include "tgbot/types/ChatMemberRestricted.h" +#include "tgbot/types/ChatMemberUpdated.h" +#include "tgbot/types/ChatPermissions.h" +#include "tgbot/types/ChatPhoto.h" +#include "tgbot/types/ChatShared.h" +#include "tgbot/types/ChosenInlineResult.h" +#include "tgbot/types/Contact.h" +#include "tgbot/types/Dice.h" +#include "tgbot/types/Document.h" +#include "tgbot/types/EncryptedCredentials.h" +#include "tgbot/types/EncryptedPassportElement.h" +#include "tgbot/types/ExternalReplyInfo.h" +#include "tgbot/types/File.h" +#include "tgbot/types/ForceReply.h" +#include "tgbot/types/ForumTopic.h" +#include "tgbot/types/ForumTopicClosed.h" +#include "tgbot/types/ForumTopicCreated.h" +#include "tgbot/types/ForumTopicEdited.h" +#include "tgbot/types/ForumTopicReopened.h" +#include "tgbot/types/Game.h" +#include "tgbot/types/GameHighScore.h" +#include "tgbot/types/GeneralForumTopicHidden.h" +#include "tgbot/types/GeneralForumTopicUnhidden.h" +#include "tgbot/types/GenericReply.h" +#include "tgbot/types/Giveaway.h" +#include "tgbot/types/GiveawayCompleted.h" +#include "tgbot/types/GiveawayCreated.h" +#include "tgbot/types/GiveawayWinners.h" +#include "tgbot/types/InaccessibleMessage.h" +#include "tgbot/types/InlineKeyboardButton.h" +#include "tgbot/types/InlineKeyboardMarkup.h" #include "tgbot/types/InlineQuery.h" -#include "tgbot/types/InlineQueryResultsButton.h" #include "tgbot/types/InlineQueryResult.h" #include "tgbot/types/InlineQueryResultArticle.h" -#include "tgbot/types/InlineQueryResultPhoto.h" -#include "tgbot/types/InlineQueryResultGif.h" -#include "tgbot/types/InlineQueryResultMpeg4Gif.h" -#include "tgbot/types/InlineQueryResultVideo.h" #include "tgbot/types/InlineQueryResultAudio.h" -#include "tgbot/types/InlineQueryResultVoice.h" -#include "tgbot/types/InlineQueryResultDocument.h" -#include "tgbot/types/InlineQueryResultLocation.h" -#include "tgbot/types/InlineQueryResultVenue.h" -#include "tgbot/types/InlineQueryResultContact.h" -#include "tgbot/types/InlineQueryResultGame.h" -#include "tgbot/types/InlineQueryResultCachedPhoto.h" +#include "tgbot/types/InlineQueryResultCachedAudio.h" +#include "tgbot/types/InlineQueryResultCachedDocument.h" #include "tgbot/types/InlineQueryResultCachedGif.h" #include "tgbot/types/InlineQueryResultCachedMpeg4Gif.h" +#include "tgbot/types/InlineQueryResultCachedPhoto.h" #include "tgbot/types/InlineQueryResultCachedSticker.h" -#include "tgbot/types/InlineQueryResultCachedDocument.h" #include "tgbot/types/InlineQueryResultCachedVideo.h" #include "tgbot/types/InlineQueryResultCachedVoice.h" -#include "tgbot/types/InlineQueryResultCachedAudio.h" +#include "tgbot/types/InlineQueryResultContact.h" +#include "tgbot/types/InlineQueryResultDocument.h" +#include "tgbot/types/InlineQueryResultGame.h" +#include "tgbot/types/InlineQueryResultGif.h" +#include "tgbot/types/InlineQueryResultLocation.h" +#include "tgbot/types/InlineQueryResultMpeg4Gif.h" +#include "tgbot/types/InlineQueryResultPhoto.h" +#include "tgbot/types/InlineQueryResultVenue.h" +#include "tgbot/types/InlineQueryResultVideo.h" +#include "tgbot/types/InlineQueryResultVoice.h" +#include "tgbot/types/InlineQueryResultsButton.h" +#include "tgbot/types/InputContactMessageContent.h" +#include "tgbot/types/InputInvoiceMessageContent.h" +#include "tgbot/types/InputLocationMessageContent.h" +#include "tgbot/types/InputMedia.h" +#include "tgbot/types/InputMediaAnimation.h" +#include "tgbot/types/InputMediaAudio.h" +#include "tgbot/types/InputMediaDocument.h" +#include "tgbot/types/InputMediaPhoto.h" +#include "tgbot/types/InputMediaVideo.h" #include "tgbot/types/InputMessageContent.h" +#include "tgbot/types/InputSticker.h" #include "tgbot/types/InputTextMessageContent.h" -#include "tgbot/types/InputLocationMessageContent.h" #include "tgbot/types/InputVenueMessageContent.h" -#include "tgbot/types/InputContactMessageContent.h" -#include "tgbot/types/InputInvoiceMessageContent.h" -#include "tgbot/types/ChosenInlineResult.h" -#include "tgbot/types/SentWebAppMessage.h" -#include "tgbot/types/LabeledPrice.h" #include "tgbot/types/Invoice.h" -#include "tgbot/types/ShippingAddress.h" +#include "tgbot/types/KeyboardButton.h" +#include "tgbot/types/KeyboardButtonPollType.h" +#include "tgbot/types/KeyboardButtonRequestChat.h" +#include "tgbot/types/KeyboardButtonRequestUsers.h" +#include "tgbot/types/LabeledPrice.h" +#include "tgbot/types/LinkPreviewOptions.h" +#include "tgbot/types/Location.h" +#include "tgbot/types/LoginUrl.h" +#include "tgbot/types/MaskPosition.h" +#include "tgbot/types/MenuButton.h" +#include "tgbot/types/MenuButtonCommands.h" +#include "tgbot/types/MenuButtonDefault.h" +#include "tgbot/types/MenuButtonWebApp.h" +#include "tgbot/types/Message.h" +#include "tgbot/types/MessageAutoDeleteTimerChanged.h" +#include "tgbot/types/MessageEntity.h" +#include "tgbot/types/MessageId.h" +#include "tgbot/types/MessageOrigin.h" +#include "tgbot/types/MessageOriginChannel.h" +#include "tgbot/types/MessageOriginChat.h" +#include "tgbot/types/MessageOriginHiddenUser.h" +#include "tgbot/types/MessageOriginUser.h" +#include "tgbot/types/MessageReactionCountUpdated.h" +#include "tgbot/types/MessageReactionUpdated.h" #include "tgbot/types/OrderInfo.h" -#include "tgbot/types/ShippingOption.h" -#include "tgbot/types/SuccessfulPayment.h" -#include "tgbot/types/ShippingQuery.h" -#include "tgbot/types/PreCheckoutQuery.h" #include "tgbot/types/PassportData.h" -#include "tgbot/types/PassportFile.h" -#include "tgbot/types/EncryptedPassportElement.h" -#include "tgbot/types/EncryptedCredentials.h" #include "tgbot/types/PassportElementError.h" #include "tgbot/types/PassportElementErrorDataField.h" +#include "tgbot/types/PassportElementErrorFile.h" +#include "tgbot/types/PassportElementErrorFiles.h" #include "tgbot/types/PassportElementErrorFrontSide.h" #include "tgbot/types/PassportElementErrorReverseSide.h" #include "tgbot/types/PassportElementErrorSelfie.h" -#include "tgbot/types/PassportElementErrorFile.h" -#include "tgbot/types/PassportElementErrorFiles.h" #include "tgbot/types/PassportElementErrorTranslationFile.h" #include "tgbot/types/PassportElementErrorTranslationFiles.h" #include "tgbot/types/PassportElementErrorUnspecified.h" -#include "tgbot/types/Game.h" -#include "tgbot/types/CallbackGame.h" -#include "tgbot/types/GameHighScore.h" -#include "tgbot/types/GenericReply.h" +#include "tgbot/types/PassportFile.h" +#include "tgbot/types/PhotoSize.h" +#include "tgbot/types/Poll.h" +#include "tgbot/types/PollAnswer.h" +#include "tgbot/types/PollOption.h" +#include "tgbot/types/PreCheckoutQuery.h" +#include "tgbot/types/ProximityAlertTriggered.h" +#include "tgbot/types/ReactionCount.h" +#include "tgbot/types/ReactionType.h" +#include "tgbot/types/ReactionTypeCustomEmoji.h" +#include "tgbot/types/ReactionTypeEmoji.h" +#include "tgbot/types/ReplyKeyboardMarkup.h" +#include "tgbot/types/ReplyKeyboardRemove.h" +#include "tgbot/types/ReplyParameters.h" +#include "tgbot/types/ResponseParameters.h" +#include "tgbot/types/SentWebAppMessage.h" +#include "tgbot/types/SharedUser.h" +#include "tgbot/types/ShippingAddress.h" +#include "tgbot/types/ShippingOption.h" +#include "tgbot/types/ShippingQuery.h" +#include "tgbot/types/Sticker.h" +#include "tgbot/types/StickerSet.h" +#include "tgbot/types/Story.h" +#include "tgbot/types/SuccessfulPayment.h" +#include "tgbot/types/SwitchInlineQueryChosenChat.h" +#include "tgbot/types/TextQuote.h" +#include "tgbot/types/Update.h" +#include "tgbot/types/User.h" +#include "tgbot/types/UserChatBoosts.h" +#include "tgbot/types/UserProfilePhotos.h" +#include "tgbot/types/UsersShared.h" +#include "tgbot/types/Venue.h" +#include "tgbot/types/Video.h" +#include "tgbot/types/VideoChatEnded.h" +#include "tgbot/types/VideoChatParticipantsInvited.h" +#include "tgbot/types/VideoChatScheduled.h" +#include "tgbot/types/VideoChatStarted.h" +#include "tgbot/types/VideoNote.h" +#include "tgbot/types/Voice.h" +#include "tgbot/types/WebAppData.h" +#include "tgbot/types/WebAppInfo.h" +#include "tgbot/types/WebhookInfo.h" +#include "tgbot/types/WriteAccessAllowed.h" #include #include @@ -198,766 +198,352 @@ #include #include #include +#include #include #include namespace TgBot { -class TGBOT_API TgTypeParser { - -public: - template - using JsonToTgTypeFunc = std::shared_ptr (TgTypeParser::*)(const boost::property_tree::ptree&) const; - - template - using TgTypeToJsonFunc = std::string (TgTypeParser::*)(const std::shared_ptr&) const; - - Update::Ptr parseJsonAndGetUpdate(const boost::property_tree::ptree& data) const; - std::string parseUpdate(const Update::Ptr& object) const; - - WebhookInfo::Ptr parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const; - std::string parseWebhookInfo(const WebhookInfo::Ptr& object) const; - - User::Ptr parseJsonAndGetUser(const boost::property_tree::ptree& data) const; - std::string parseUser(const User::Ptr& object) const; - - Chat::Ptr parseJsonAndGetChat(const boost::property_tree::ptree& data) const; - std::string parseChat(const Chat::Ptr& object) const; - - Message::Ptr parseJsonAndGetMessage(const boost::property_tree::ptree& data) const; - std::string parseMessage(const Message::Ptr& object) const; - - MessageId::Ptr parseJsonAndGetMessageId(const boost::property_tree::ptree& data) const; - std::string parseMessageId(const MessageId::Ptr& object) const; - - InaccessibleMessage::Ptr parseJsonAndGetInaccessibleMessage(const boost::property_tree::ptree& data) const; - std::string parseInaccessibleMessage(const InaccessibleMessage::Ptr& object) const; - - MessageEntity::Ptr parseJsonAndGetMessageEntity(const boost::property_tree::ptree& data) const; - std::string parseMessageEntity(const MessageEntity::Ptr& object) const; - - TextQuote::Ptr parseJsonAndGetTextQuote(const boost::property_tree::ptree& data) const; - std::string parseTextQuote(const TextQuote::Ptr& object) const; - - ExternalReplyInfo::Ptr parseJsonAndGetExternalReplyInfo(const boost::property_tree::ptree& data) const; - std::string parseExternalReplyInfo(const ExternalReplyInfo::Ptr& object) const; - - ReplyParameters::Ptr parseJsonAndGetReplyParameters(const boost::property_tree::ptree& data) const; - std::string parseReplyParameters(const ReplyParameters::Ptr& object) const; - - MessageOrigin::Ptr parseJsonAndGetMessageOrigin(const boost::property_tree::ptree& data) const; - std::string parseMessageOrigin(const MessageOrigin::Ptr& object) const; - - MessageOriginUser::Ptr parseJsonAndGetMessageOriginUser(const boost::property_tree::ptree& data) const; - std::string parseMessageOriginUser(const MessageOriginUser::Ptr& object) const; - - MessageOriginHiddenUser::Ptr parseJsonAndGetMessageOriginHiddenUser(const boost::property_tree::ptree& data) const; - std::string parseMessageOriginHiddenUser(const MessageOriginHiddenUser::Ptr& object) const; - - MessageOriginChat::Ptr parseJsonAndGetMessageOriginChat(const boost::property_tree::ptree& data) const; - std::string parseMessageOriginChat(const MessageOriginChat::Ptr& object) const; - - MessageOriginChannel::Ptr parseJsonAndGetMessageOriginChannel(const boost::property_tree::ptree& data) const; - std::string parseMessageOriginChannel(const MessageOriginChannel::Ptr& object) const; - - PhotoSize::Ptr parseJsonAndGetPhotoSize(const boost::property_tree::ptree& data) const; - std::string parsePhotoSize(const PhotoSize::Ptr& object) const; - - Animation::Ptr parseJsonAndGetAnimation(const boost::property_tree::ptree& data) const; - std::string parseAnimation(const Animation::Ptr& object) const; - - Audio::Ptr parseJsonAndGetAudio(const boost::property_tree::ptree& data) const; - std::string parseAudio(const Audio::Ptr& object) const; - - Document::Ptr parseJsonAndGetDocument(const boost::property_tree::ptree& data) const; - std::string parseDocument(const Document::Ptr& object) const; - - Story::Ptr parseJsonAndGetStory(const boost::property_tree::ptree& data) const; - std::string parseStory(const Story::Ptr& object) const; - - Video::Ptr parseJsonAndGetVideo(const boost::property_tree::ptree& data) const; - std::string parseVideo(const Video::Ptr& object) const; - - VideoNote::Ptr parseJsonAndGetVideoNote(const boost::property_tree::ptree& data) const; - std::string parseVideoNote(const VideoNote::Ptr& object) const; - - Voice::Ptr parseJsonAndGetVoice(const boost::property_tree::ptree& data) const; - std::string parseVoice(const Voice::Ptr& object) const; - - Contact::Ptr parseJsonAndGetContact(const boost::property_tree::ptree& data) const; - std::string parseContact(const Contact::Ptr& object) const; - - Dice::Ptr parseJsonAndGetDice(const boost::property_tree::ptree& data) const; - std::string parseDice(const Dice::Ptr& object) const; - - PollOption::Ptr parseJsonAndGetPollOption(const boost::property_tree::ptree& data) const; - std::string parsePollOption(const PollOption::Ptr& object) const; - - PollAnswer::Ptr parseJsonAndGetPollAnswer(const boost::property_tree::ptree& data) const; - std::string parsePollAnswer(const PollAnswer::Ptr& object) const; - - Poll::Ptr parseJsonAndGetPoll(const boost::property_tree::ptree& data) const; - std::string parsePoll(const Poll::Ptr& object) const; - - Location::Ptr parseJsonAndGetLocation(const boost::property_tree::ptree& data) const; - std::string parseLocation(const Location::Ptr& object) const; - - Venue::Ptr parseJsonAndGetVenue(const boost::property_tree::ptree& data) const; - std::string parseVenue(const Venue::Ptr& object) const; - - WebAppData::Ptr parseJsonAndGetWebAppData(const boost::property_tree::ptree& data) const; - std::string parseWebAppData(const WebAppData::Ptr& object) const; - - ProximityAlertTriggered::Ptr parseJsonAndGetProximityAlertTriggered(const boost::property_tree::ptree& data) const; - std::string parseProximityAlertTriggered(const ProximityAlertTriggered::Ptr& object) const; - - MessageAutoDeleteTimerChanged::Ptr parseJsonAndGetMessageAutoDeleteTimerChanged(const boost::property_tree::ptree& data) const; - std::string parseMessageAutoDeleteTimerChanged(const MessageAutoDeleteTimerChanged::Ptr& object) const; - - ChatBoostAdded::Ptr parseJsonAndGetChatBoostAdded(const boost::property_tree::ptree& data) const; - std::string parseChatBoostAdded(const ChatBoostAdded::Ptr& object) const; - - ForumTopicCreated::Ptr parseJsonAndGetForumTopicCreated(const boost::property_tree::ptree& data) const; - std::string parseForumTopicCreated(const ForumTopicCreated::Ptr& object) const; - - ForumTopicClosed::Ptr parseJsonAndGetForumTopicClosed(const boost::property_tree::ptree& data) const; - std::string parseForumTopicClosed(const ForumTopicClosed::Ptr& object) const; - - ForumTopicEdited::Ptr parseJsonAndGetForumTopicEdited(const boost::property_tree::ptree& data) const; - std::string parseForumTopicEdited(const ForumTopicEdited::Ptr& object) const; - - ForumTopicReopened::Ptr parseJsonAndGetForumTopicReopened(const boost::property_tree::ptree& data) const; - std::string parseForumTopicReopened(const ForumTopicReopened::Ptr& object) const; - - GeneralForumTopicHidden::Ptr parseJsonAndGetGeneralForumTopicHidden(const boost::property_tree::ptree& data) const; - std::string parseGeneralForumTopicHidden(const GeneralForumTopicHidden::Ptr& object) const; - - GeneralForumTopicUnhidden::Ptr parseJsonAndGetGeneralForumTopicUnhidden(const boost::property_tree::ptree& data) const; - std::string parseGeneralForumTopicUnhidden(const GeneralForumTopicUnhidden::Ptr& object) const; - - SharedUser::Ptr parseJsonAndGetSharedUser(const boost::property_tree::ptree& data) const; - std::string parseSharedUser(const SharedUser::Ptr& object) const; - - UsersShared::Ptr parseJsonAndGetUsersShared(const boost::property_tree::ptree& data) const; - std::string parseUsersShared(const UsersShared::Ptr& object) const; - - ChatShared::Ptr parseJsonAndGetChatShared(const boost::property_tree::ptree& data) const; - std::string parseChatShared(const ChatShared::Ptr& object) const; - - WriteAccessAllowed::Ptr parseJsonAndGetWriteAccessAllowed(const boost::property_tree::ptree& data) const; - std::string parseWriteAccessAllowed(const WriteAccessAllowed::Ptr& object) const; - - VideoChatScheduled::Ptr parseJsonAndGetVideoChatScheduled(const boost::property_tree::ptree& data) const; - std::string parseVideoChatScheduled(const VideoChatScheduled::Ptr& object) const; - - VideoChatStarted::Ptr parseJsonAndGetVideoChatStarted(const boost::property_tree::ptree& data) const; - std::string parseVideoChatStarted(const VideoChatStarted::Ptr& object) const; - - VideoChatEnded::Ptr parseJsonAndGetVideoChatEnded(const boost::property_tree::ptree& data) const; - std::string parseVideoChatEnded(const VideoChatEnded::Ptr& object) const; - - VideoChatParticipantsInvited::Ptr parseJsonAndGetVideoChatParticipantsInvited(const boost::property_tree::ptree& data) const; - std::string parseVideoChatParticipantsInvited(const VideoChatParticipantsInvited::Ptr& object) const; - - GiveawayCreated::Ptr parseJsonAndGetGiveawayCreated(const boost::property_tree::ptree& data) const; - std::string parseGiveawayCreated(const GiveawayCreated::Ptr& object) const; - - Giveaway::Ptr parseJsonAndGetGiveaway(const boost::property_tree::ptree& data) const; - std::string parseGiveaway(const Giveaway::Ptr& object) const; - - GiveawayWinners::Ptr parseJsonAndGetGiveawayWinners(const boost::property_tree::ptree& data) const; - std::string parseGiveawayWinners(const GiveawayWinners::Ptr& object) const; - - GiveawayCompleted::Ptr parseJsonAndGetGiveawayCompleted(const boost::property_tree::ptree& data) const; - std::string parseGiveawayCompleted(const GiveawayCompleted::Ptr& object) const; - - LinkPreviewOptions::Ptr parseJsonAndGetLinkPreviewOptions(const boost::property_tree::ptree& data) const; - std::string parseLinkPreviewOptions(const LinkPreviewOptions::Ptr& object) const; - - UserProfilePhotos::Ptr parseJsonAndGetUserProfilePhotos(const boost::property_tree::ptree& data) const; - std::string parseUserProfilePhotos(const UserProfilePhotos::Ptr& object) const; - - File::Ptr parseJsonAndGetFile(const boost::property_tree::ptree& data) const; - std::string parseFile(const File::Ptr& object) const; - - WebAppInfo::Ptr parseJsonAndGetWebAppInfo(const boost::property_tree::ptree& data) const; - std::string parseWebAppInfo(const WebAppInfo::Ptr& object) const; - - ReplyKeyboardMarkup::Ptr parseJsonAndGetReplyKeyboardMarkup(const boost::property_tree::ptree& data) const; - std::string parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Ptr& object) const; - - KeyboardButton::Ptr parseJsonAndGetKeyboardButton(const boost::property_tree::ptree& data) const; - std::string parseKeyboardButton(const KeyboardButton::Ptr& object) const; - - KeyboardButtonRequestUsers::Ptr parseJsonAndGetKeyboardButtonRequestUsers(const boost::property_tree::ptree& data) const; - std::string parseKeyboardButtonRequestUsers(const KeyboardButtonRequestUsers::Ptr& object) const; - - KeyboardButtonRequestChat::Ptr parseJsonAndGetKeyboardButtonRequestChat(const boost::property_tree::ptree& data) const; - std::string parseKeyboardButtonRequestChat(const KeyboardButtonRequestChat::Ptr& object) const; - - KeyboardButtonPollType::Ptr parseJsonAndGetKeyboardButtonPollType(const boost::property_tree::ptree& data) const; - std::string parseKeyboardButtonPollType(const KeyboardButtonPollType::Ptr& object) const; - - ReplyKeyboardRemove::Ptr parseJsonAndGetReplyKeyboardRemove(const boost::property_tree::ptree& data) const; - std::string parseReplyKeyboardRemove(const ReplyKeyboardRemove::Ptr& object) const; - - InlineKeyboardMarkup::Ptr parseJsonAndGetInlineKeyboardMarkup(const boost::property_tree::ptree& data) const; - std::string parseInlineKeyboardMarkup(const InlineKeyboardMarkup::Ptr& object) const; - - InlineKeyboardButton::Ptr parseJsonAndGetInlineKeyboardButton(const boost::property_tree::ptree& data) const; - std::string parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const; - - LoginUrl::Ptr parseJsonAndGetLoginUrl(const boost::property_tree::ptree& data) const; - std::string parseLoginUrl(const LoginUrl::Ptr& object) const; - - SwitchInlineQueryChosenChat::Ptr parseJsonAndGetSwitchInlineQueryChosenChat(const boost::property_tree::ptree& data) const; - std::string parseSwitchInlineQueryChosenChat(const SwitchInlineQueryChosenChat::Ptr& object) const; - - CallbackQuery::Ptr parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const; - std::string parseCallbackQuery(const CallbackQuery::Ptr& object) const; - - ForceReply::Ptr parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const; - std::string parseForceReply(const ForceReply::Ptr& object) const; - - ChatPhoto::Ptr parseJsonAndGetChatPhoto(const boost::property_tree::ptree& data) const; - std::string parseChatPhoto(const ChatPhoto::Ptr& object) const; - - ChatInviteLink::Ptr parseJsonAndGetChatInviteLink(const boost::property_tree::ptree& data) const; - std::string parseChatInviteLink(const ChatInviteLink::Ptr& object) const; - - ChatAdministratorRights::Ptr parseJsonAndGetChatAdministratorRights(const boost::property_tree::ptree& data) const; - std::string parseChatAdministratorRights(const ChatAdministratorRights::Ptr& object) const; - - ChatMemberUpdated::Ptr parseJsonAndGetChatMemberUpdated(const boost::property_tree::ptree& data) const; - std::string parseChatMemberUpdated(const ChatMemberUpdated::Ptr& object) const; - - ChatMember::Ptr parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const; - std::string parseChatMember(const ChatMember::Ptr& object) const; - - ChatMemberOwner::Ptr parseJsonAndGetChatMemberOwner(const boost::property_tree::ptree& data) const; - std::string parseChatMemberOwner(const ChatMemberOwner::Ptr& object) const; - - ChatMemberAdministrator::Ptr parseJsonAndGetChatMemberAdministrator(const boost::property_tree::ptree& data) const; - std::string parseChatMemberAdministrator(const ChatMemberAdministrator::Ptr& object) const; - - ChatMemberMember::Ptr parseJsonAndGetChatMemberMember(const boost::property_tree::ptree& data) const; - std::string parseChatMemberMember(const ChatMemberMember::Ptr& object) const; - - ChatMemberRestricted::Ptr parseJsonAndGetChatMemberRestricted(const boost::property_tree::ptree& data) const; - std::string parseChatMemberRestricted(const ChatMemberRestricted::Ptr& object) const; - - ChatMemberLeft::Ptr parseJsonAndGetChatMemberLeft(const boost::property_tree::ptree& data) const; - std::string parseChatMemberLeft(const ChatMemberLeft::Ptr& object) const; - - ChatMemberBanned::Ptr parseJsonAndGetChatMemberBanned(const boost::property_tree::ptree& data) const; - std::string parseChatMemberBanned(const ChatMemberBanned::Ptr& object) const; - - ChatJoinRequest::Ptr parseJsonAndGetChatJoinRequest(const boost::property_tree::ptree& data) const; - std::string parseChatJoinRequest(const ChatJoinRequest::Ptr& object) const; - - ChatPermissions::Ptr parseJsonAndGetChatPermissions(const boost::property_tree::ptree& data) const; - std::string parseChatPermissions(const ChatPermissions::Ptr& object) const; +template using Matrix = std::vector>; +namespace detail { // shared_ptr +template struct is_shared_ptr : std::false_type {}; - Birthdate::Ptr parseJsonAndGetBirthdate(const boost::property_tree::ptree& data) const; - std::string parseBirthdate(const Birthdate::Ptr& object) const; - - BusinessIntro::Ptr parseJsonAndGetBusinessIntro(const boost::property_tree::ptree& data) const; - std::string parseBusinessIntro(const BusinessIntro::Ptr& object) const; - - BusinessLocation::Ptr parseJsonAndGetBusinessLocation(const boost::property_tree::ptree& data) const; - std::string parseBusinessLocation(const BusinessLocation::Ptr& object) const; - - BusinessOpeningHoursInterval::Ptr parseJsonAndGetBusinessOpeningHoursInterval(const boost::property_tree::ptree& data) const; - std::string parseBusinessOpeningHoursInterval(const BusinessOpeningHoursInterval::Ptr& object) const; - - BusinessOpeningHours::Ptr parseJsonAndGetBusinessOpeningHours(const boost::property_tree::ptree& data) const; - std::string parseBusinessOpeningHours(const BusinessOpeningHours::Ptr& object) const; - - ChatLocation::Ptr parseJsonAndGetChatLocation(const boost::property_tree::ptree& data) const; - std::string parseChatLocation(const ChatLocation::Ptr& object) const; - - ReactionType::Ptr parseJsonAndGetReactionType(const boost::property_tree::ptree& data) const; - std::string parseReactionType(const ReactionType::Ptr& object) const; - - ReactionTypeEmoji::Ptr parseJsonAndGetReactionTypeEmoji(const boost::property_tree::ptree& data) const; - std::string parseReactionTypeEmoji(const ReactionTypeEmoji::Ptr& object) const; - - ReactionTypeCustomEmoji::Ptr parseJsonAndGetReactionTypeCustomEmoji(const boost::property_tree::ptree& data) const; - std::string parseReactionTypeCustomEmoji(const ReactionTypeCustomEmoji::Ptr& object) const; - - ReactionCount::Ptr parseJsonAndGetReactionCount(const boost::property_tree::ptree& data) const; - std::string parseReactionCount(const ReactionCount::Ptr& object) const; - - MessageReactionUpdated::Ptr parseJsonAndGetMessageReactionUpdated(const boost::property_tree::ptree& data) const; - std::string parseMessageReactionUpdated(const MessageReactionUpdated::Ptr& object) const; - - MessageReactionCountUpdated::Ptr parseJsonAndGetMessageReactionCountUpdated(const boost::property_tree::ptree& data) const; - std::string parseMessageReactionCountUpdated(const MessageReactionCountUpdated::Ptr& object) const; - - ForumTopic::Ptr parseJsonAndGetForumTopic(const boost::property_tree::ptree& data) const; - std::string parseForumTopic(const ForumTopic::Ptr& object) const; - - BotCommand::Ptr parseJsonAndGetBotCommand(const boost::property_tree::ptree& data) const; - std::string parseBotCommand(const BotCommand::Ptr& object) const; - - BotCommandScope::Ptr parseJsonAndGetBotCommandScope(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScope(const BotCommandScope::Ptr& object) const; - - BotCommandScopeDefault::Ptr parseJsonAndGetBotCommandScopeDefault(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeDefault(const BotCommandScopeDefault::Ptr& object) const; - - BotCommandScopeAllPrivateChats::Ptr parseJsonAndGetBotCommandScopeAllPrivateChats(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeAllPrivateChats(const BotCommandScopeAllPrivateChats::Ptr& object) const; - - BotCommandScopeAllGroupChats::Ptr parseJsonAndGetBotCommandScopeAllGroupChats(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeAllGroupChats(const BotCommandScopeAllGroupChats::Ptr& object) const; - - BotCommandScopeAllChatAdministrators::Ptr parseJsonAndGetBotCommandScopeAllChatAdministrators(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeAllChatAdministrators(const BotCommandScopeAllChatAdministrators::Ptr& object) const; - - BotCommandScopeChat::Ptr parseJsonAndGetBotCommandScopeChat(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeChat(const BotCommandScopeChat::Ptr& object) const; - - BotCommandScopeChatAdministrators::Ptr parseJsonAndGetBotCommandScopeChatAdministrators(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeChatAdministrators(const BotCommandScopeChatAdministrators::Ptr& object) const; - - BotCommandScopeChatMember::Ptr parseJsonAndGetBotCommandScopeChatMember(const boost::property_tree::ptree& data) const; - std::string parseBotCommandScopeChatMember(const BotCommandScopeChatMember::Ptr& object) const; - - BotName::Ptr parseJsonAndGetBotName(const boost::property_tree::ptree& data) const; - std::string parseBotName(const BotName::Ptr& object) const; - - BotDescription::Ptr parseJsonAndGetBotDescription(const boost::property_tree::ptree& data) const; - std::string parseBotDescription(const BotDescription::Ptr& object) const; - - BotShortDescription::Ptr parseJsonAndGetBotShortDescription(const boost::property_tree::ptree& data) const; - std::string parseBotShortDescription(const BotShortDescription::Ptr& object) const; - - MenuButton::Ptr parseJsonAndGetMenuButton(const boost::property_tree::ptree& data) const; - std::string parseMenuButton(const MenuButton::Ptr& object) const; - - MenuButtonCommands::Ptr parseJsonAndGetMenuButtonCommands(const boost::property_tree::ptree& data) const; - std::string parseMenuButtonCommands(const MenuButtonCommands::Ptr& object) const; - - MenuButtonWebApp::Ptr parseJsonAndGetMenuButtonWebApp(const boost::property_tree::ptree& data) const; - std::string parseMenuButtonWebApp(const MenuButtonWebApp::Ptr& object) const; - - MenuButtonDefault::Ptr parseJsonAndGetMenuButtonDefault(const boost::property_tree::ptree& data) const; - std::string parseMenuButtonDefault(const MenuButtonDefault::Ptr& object) const; - - ChatBoostSource::Ptr parseJsonAndGetChatBoostSource(const boost::property_tree::ptree& data) const; - std::string parseChatBoostSource(const ChatBoostSource::Ptr& object) const; - - ChatBoostSourcePremium::Ptr parseJsonAndGetChatBoostSourcePremium(const boost::property_tree::ptree& data) const; - std::string parseChatBoostSourcePremium(const ChatBoostSourcePremium::Ptr& object) const; - - ChatBoostSourceGiftCode::Ptr parseJsonAndGetChatBoostSourceGiftCode(const boost::property_tree::ptree& data) const; - std::string parseChatBoostSourceGiftCode(const ChatBoostSourceGiftCode::Ptr& object) const; - - ChatBoostSourceGiveaway::Ptr parseJsonAndGetChatBoostSourceGiveaway(const boost::property_tree::ptree& data) const; - std::string parseChatBoostSourceGiveaway(const ChatBoostSourceGiveaway::Ptr& object) const; - - ChatBoost::Ptr parseJsonAndGetChatBoost(const boost::property_tree::ptree& data) const; - std::string parseChatBoost(const ChatBoost::Ptr& object) const; - - ChatBoostUpdated::Ptr parseJsonAndGetChatBoostUpdated(const boost::property_tree::ptree& data) const; - std::string parseChatBoostUpdated(const ChatBoostUpdated::Ptr& object) const; - - ChatBoostRemoved::Ptr parseJsonAndGetChatBoostRemoved(const boost::property_tree::ptree& data) const; - std::string parseChatBoostRemoved(const ChatBoostRemoved::Ptr& object) const; - - UserChatBoosts::Ptr parseJsonAndGetUserChatBoosts(const boost::property_tree::ptree& data) const; - std::string parseUserChatBoosts(const UserChatBoosts::Ptr& object) const; - - BusinessConnection::Ptr parseJsonAndGetBusinessConnection(const boost::property_tree::ptree& data) const; - std::string parseBusinessConnection(const BusinessConnection::Ptr& object) const; - - BusinessMessagesDeleted::Ptr parseJsonAndGetBusinessMessagesDeleted(const boost::property_tree::ptree& data) const; - std::string parseBusinessMessagesDeleted(const BusinessMessagesDeleted::Ptr& object) const; - - ResponseParameters::Ptr parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const; - std::string parseResponseParameters(const ResponseParameters::Ptr& object) const; - - InputMedia::Ptr parseJsonAndGetInputMedia(const boost::property_tree::ptree& data) const; - std::string parseInputMedia(const InputMedia::Ptr& object) const; - - InputMediaPhoto::Ptr parseJsonAndGetInputMediaPhoto(const boost::property_tree::ptree& data) const; - std::string parseInputMediaPhoto(const InputMediaPhoto::Ptr& object) const; - - InputMediaVideo::Ptr parseJsonAndGetInputMediaVideo(const boost::property_tree::ptree& data) const; - std::string parseInputMediaVideo(const InputMediaVideo::Ptr& object) const; - - InputMediaAnimation::Ptr parseJsonAndGetInputMediaAnimation(const boost::property_tree::ptree& data) const; - std::string parseInputMediaAnimation(const InputMediaAnimation::Ptr& object) const; - - InputMediaAudio::Ptr parseJsonAndGetInputMediaAudio(const boost::property_tree::ptree& data) const; - std::string parseInputMediaAudio(const InputMediaAudio::Ptr& object) const; - - InputMediaDocument::Ptr parseJsonAndGetInputMediaDocument(const boost::property_tree::ptree& data) const; - std::string parseInputMediaDocument(const InputMediaDocument::Ptr& object) const; - - Sticker::Ptr parseJsonAndGetSticker(const boost::property_tree::ptree& data) const; - std::string parseSticker(const Sticker::Ptr& object) const; - - StickerSet::Ptr parseJsonAndGetStickerSet(const boost::property_tree::ptree& data) const; - std::string parseStickerSet(const StickerSet::Ptr& object) const; - - MaskPosition::Ptr parseJsonAndGetMaskPosition(const boost::property_tree::ptree& data) const; - std::string parseMaskPosition(const MaskPosition::Ptr& object) const; - - InputSticker::Ptr parseJsonAndGetInputSticker(const boost::property_tree::ptree& data) const; - std::string parseInputSticker(const InputSticker::Ptr& object) const; - - InlineQuery::Ptr parseJsonAndGetInlineQuery(const boost::property_tree::ptree& data) const; - std::string parseInlineQuery(const InlineQuery::Ptr& object) const; - - InlineQueryResultsButton::Ptr parseJsonAndGetInlineQueryResultsButton(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultsButton(const InlineQueryResultsButton::Ptr& object) const; - - InlineQueryResult::Ptr parseJsonAndGetInlineQueryResult(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResult(const InlineQueryResult::Ptr& object) const; - - InlineQueryResultArticle::Ptr parseJsonAndGetInlineQueryResultArticle(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultArticle(const InlineQueryResultArticle::Ptr& object) const; - - InlineQueryResultPhoto::Ptr parseJsonAndGetInlineQueryResultPhoto(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultPhoto(const InlineQueryResultPhoto::Ptr& object) const; - - InlineQueryResultGif::Ptr parseJsonAndGetInlineQueryResultGif(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultGif(const InlineQueryResultGif::Ptr& object) const; - - InlineQueryResultMpeg4Gif::Ptr parseJsonAndGetInlineQueryResultMpeg4Gif(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultMpeg4Gif(const InlineQueryResultMpeg4Gif::Ptr& object) const; - - InlineQueryResultVideo::Ptr parseJsonAndGetInlineQueryResultVideo(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultVideo(const InlineQueryResultVideo::Ptr& object) const; - - InlineQueryResultAudio::Ptr parseJsonAndGetInlineQueryResultAudio(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultAudio(const InlineQueryResultAudio::Ptr& object) const; - - InlineQueryResultVoice::Ptr parseJsonAndGetInlineQueryResultVoice(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultVoice(const InlineQueryResultVoice::Ptr& object) const; - - InlineQueryResultDocument::Ptr parseJsonAndGetInlineQueryResultDocument(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultDocument(const InlineQueryResultDocument::Ptr& object) const; - - InlineQueryResultLocation::Ptr parseJsonAndGetInlineQueryResultLocation(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultLocation(const InlineQueryResultLocation::Ptr& object) const; - - InlineQueryResultVenue::Ptr parseJsonAndGetInlineQueryResultVenue(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultVenue(const InlineQueryResultVenue::Ptr& object) const; - - InlineQueryResultContact::Ptr parseJsonAndGetInlineQueryResultContact(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultContact(const InlineQueryResultContact::Ptr& object) const; - - InlineQueryResultGame::Ptr parseJsonAndGetInlineQueryResultGame(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultGame(const InlineQueryResultGame::Ptr& object) const; - - InlineQueryResultCachedPhoto::Ptr parseJsonAndGetInlineQueryResultCachedPhoto(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedPhoto(const InlineQueryResultCachedPhoto::Ptr& object) const; - - InlineQueryResultCachedGif::Ptr parseJsonAndGetInlineQueryResultCachedGif(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedGif(const InlineQueryResultCachedGif::Ptr& object) const; - - InlineQueryResultCachedMpeg4Gif::Ptr parseJsonAndGetInlineQueryResultCachedMpeg4Gif(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedMpeg4Gif(const InlineQueryResultCachedMpeg4Gif::Ptr& object) const; - - InlineQueryResultCachedSticker::Ptr parseJsonAndGetInlineQueryResultCachedSticker(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedSticker(const InlineQueryResultCachedSticker::Ptr& object) const; - - InlineQueryResultCachedDocument::Ptr parseJsonAndGetInlineQueryResultCachedDocument(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedDocument(const InlineQueryResultCachedDocument::Ptr& object) const; - - InlineQueryResultCachedVideo::Ptr parseJsonAndGetInlineQueryResultCachedVideo(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedVideo(const InlineQueryResultCachedVideo::Ptr& object) const; - - InlineQueryResultCachedVoice::Ptr parseJsonAndGetInlineQueryResultCachedVoice(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedVoice(const InlineQueryResultCachedVoice::Ptr& object) const; - - InlineQueryResultCachedAudio::Ptr parseJsonAndGetInlineQueryResultCachedAudio(const boost::property_tree::ptree& data) const; - std::string parseInlineQueryResultCachedAudio(const InlineQueryResultCachedAudio::Ptr& object) const; - - InputMessageContent::Ptr parseJsonAndGetInputMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputMessageContent(const InputMessageContent::Ptr& object) const; - - InputTextMessageContent::Ptr parseJsonAndGetInputTextMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputTextMessageContent(const InputTextMessageContent::Ptr& object) const; - - InputLocationMessageContent::Ptr parseJsonAndGetInputLocationMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputLocationMessageContent(const InputLocationMessageContent::Ptr& object) const; - - InputVenueMessageContent::Ptr parseJsonAndGetInputVenueMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputVenueMessageContent(const InputVenueMessageContent::Ptr& object) const; - - InputContactMessageContent::Ptr parseJsonAndGetInputContactMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputContactMessageContent(const InputContactMessageContent::Ptr& object) const; - - InputInvoiceMessageContent::Ptr parseJsonAndGetInputInvoiceMessageContent(const boost::property_tree::ptree& data) const; - std::string parseInputInvoiceMessageContent(const InputInvoiceMessageContent::Ptr& object) const; - - ChosenInlineResult::Ptr parseJsonAndGetChosenInlineResult(const boost::property_tree::ptree& data) const; - std::string parseChosenInlineResult(const ChosenInlineResult::Ptr& object) const; - - SentWebAppMessage::Ptr parseJsonAndGetSentWebAppMessage(const boost::property_tree::ptree& data) const; - std::string parseSentWebAppMessage(const SentWebAppMessage::Ptr& object) const; - - LabeledPrice::Ptr parseJsonAndGetLabeledPrice(const boost::property_tree::ptree& data) const; - std::string parseLabeledPrice(const LabeledPrice::Ptr& object) const; - - Invoice::Ptr parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const; - std::string parseInvoice(const Invoice::Ptr& object) const; - - ShippingAddress::Ptr parseJsonAndGetShippingAddress(const boost::property_tree::ptree& data) const; - std::string parseShippingAddress(const ShippingAddress::Ptr& object) const; - - OrderInfo::Ptr parseJsonAndGetOrderInfo(const boost::property_tree::ptree& data) const; - std::string parseOrderInfo(const OrderInfo::Ptr& object) const; - - ShippingOption::Ptr parseJsonAndGetShippingOption(const boost::property_tree::ptree& data) const; - std::string parseShippingOption(const ShippingOption::Ptr& object) const; - - SuccessfulPayment::Ptr parseJsonAndGetSuccessfulPayment(const boost::property_tree::ptree& data) const; - std::string parseSuccessfulPayment(const SuccessfulPayment::Ptr& object) const; - - ShippingQuery::Ptr parseJsonAndGetShippingQuery(const boost::property_tree::ptree& data) const; - std::string parseShippingQuery(const ShippingQuery::Ptr& object) const; - - PreCheckoutQuery::Ptr parseJsonAndGetPreCheckoutQuery(const boost::property_tree::ptree& data) const; - std::string parsePreCheckoutQuery(const PreCheckoutQuery::Ptr& object) const; - - PassportData::Ptr parseJsonAndGetPassportData(const boost::property_tree::ptree& data) const; - std::string parsePassportData(const PassportData::Ptr& object) const; - - PassportFile::Ptr parseJsonAndGetPassportFile(const boost::property_tree::ptree& data) const; - std::string parsePassportFile(const PassportFile::Ptr& object) const; - - EncryptedPassportElement::Ptr parseJsonAndGetEncryptedPassportElement(const boost::property_tree::ptree& data) const; - std::string parseEncryptedPassportElement(const EncryptedPassportElement::Ptr& object) const; - - EncryptedCredentials::Ptr parseJsonAndGetEncryptedCredentials(const boost::property_tree::ptree& data) const; - std::string parseEncryptedCredentials(const EncryptedCredentials::Ptr& object) const; - - PassportElementError::Ptr parseJsonAndGetPassportElementError(const boost::property_tree::ptree& data) const; - std::string parsePassportElementError(const PassportElementError::Ptr& object) const; - - PassportElementErrorDataField::Ptr parseJsonAndGetPassportElementErrorDataField(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorDataField(const PassportElementErrorDataField::Ptr& object) const; - - PassportElementErrorFrontSide::Ptr parseJsonAndGetPassportElementErrorFrontSide(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorFrontSide(const PassportElementErrorFrontSide::Ptr& object) const; - - PassportElementErrorReverseSide::Ptr parseJsonAndGetPassportElementErrorReverseSide(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorReverseSide(const PassportElementErrorReverseSide::Ptr& object) const; - - PassportElementErrorSelfie::Ptr parseJsonAndGetPassportElementErrorSelfie(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorSelfie(const PassportElementErrorSelfie::Ptr& object) const; - - PassportElementErrorFile::Ptr parseJsonAndGetPassportElementErrorFile(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorFile(const PassportElementErrorFile::Ptr& object) const; - - PassportElementErrorFiles::Ptr parseJsonAndGetPassportElementErrorFiles(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorFiles(const PassportElementErrorFiles::Ptr& object) const; - - PassportElementErrorTranslationFile::Ptr parseJsonAndGetPassportElementErrorTranslationFile(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorTranslationFile(const PassportElementErrorTranslationFile::Ptr& object) const; - - PassportElementErrorTranslationFiles::Ptr parseJsonAndGetPassportElementErrorTranslationFiles(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorTranslationFiles(const PassportElementErrorTranslationFiles::Ptr& object) const; - - PassportElementErrorUnspecified::Ptr parseJsonAndGetPassportElementErrorUnspecified(const boost::property_tree::ptree& data) const; - std::string parsePassportElementErrorUnspecified(const PassportElementErrorUnspecified::Ptr& object) const; - - Game::Ptr parseJsonAndGetGame(const boost::property_tree::ptree& data) const; - std::string parseGame(const Game::Ptr& object) const; - - CallbackGame::Ptr parseJsonAndGetCallbackGame(const boost::property_tree::ptree& data) const; - std::string parseCallbackGame(const CallbackGame::Ptr& object) const; +template +struct is_shared_ptr> : std::true_type { + using type = T; +}; - GameHighScore::Ptr parseJsonAndGetGameHighScore(const boost::property_tree::ptree& data) const; - std::string parseGameHighScore(const GameHighScore::Ptr& object) const; +template constexpr bool is_shared_ptr_v = is_shared_ptr::value; - GenericReply::Ptr parseJsonAndGetGenericReply(const boost::property_tree::ptree& data) const; - std::string parseGenericReply(const GenericReply::Ptr& object) const; +// vector +template struct is_vector : std::false_type {}; +template struct is_vector> : std::true_type { + using type = T; +}; +template constexpr bool is_vector_v = is_vector::value; - inline boost::property_tree::ptree parseJson(const std::string& json) const { - boost::property_tree::ptree tree; - std::istringstream input(json); - boost::property_tree::read_json(input, tree); - return tree; - } +// primitive +template struct is_primitive : std::false_type {}; +template <> struct is_primitive : std::true_type {}; +template <> struct is_primitive : std::true_type {}; +template <> struct is_primitive : std::true_type {}; - template - std::shared_ptr tryParseJson(JsonToTgTypeFunc parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return std::shared_ptr(); - } - return (this->*parseFunc)(treeItem->second); - } +template constexpr bool is_primitive_v = is_primitive::value; - template - std::vector> parseJsonAndGetArray(JsonToTgTypeFunc parseFunc, const boost::property_tree::ptree& data) const { - std::vector> result; - result.reserve(data.size()); - for (const std::pair& innerTreeItem : data) { - result.push_back((this->*parseFunc)(innerTreeItem.second)); - } - return result; - } +// Matrix +template struct is_matrix : std::false_type {}; +template struct is_matrix> : std::true_type { + using type = T; +}; +template constexpr bool is_matrix_v = is_matrix::value; - template - std::vector parseJsonAndGetArray(std::function parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { - std::vector result; - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return result; - } - result.reserve(treeItem->second.size()); - for (const std::pair& innerTreeItem : treeItem->second) { - result.push_back(parseFunc(innerTreeItem.second)); - } - return result; - } +} // namespace detail - template - std::vector> parseJsonAndGetArray(JsonToTgTypeFunc parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { - std::vector> result; - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return result; - } - result.reserve(treeItem->second.size()); - for (const std::pair& innerTreeItem : treeItem->second) { - result.push_back((this->*parseFunc)(innerTreeItem.second)); - } - return result; - } +template +std::shared_ptr parse(const boost::property_tree::ptree &data) = delete; - template - std::vector>> parseJsonAndGet2DArray(JsonToTgTypeFunc parseFunc, const boost::property_tree::ptree& data, const std::string& keyName) const { - std::vector>> result; - auto treeItem = data.find(keyName); - if (treeItem == data.not_found()) { - return result; - } - result.reserve(treeItem->second.size()); - for (const std::pair& innerTreeItem : treeItem->second) { - std::vector> innerResult; - for (const std::pair& innerInnerTreeItem : innerTreeItem.second) { - innerResult.push_back((this->*parseFunc)(innerInnerTreeItem.second)); - } - result.push_back(innerResult); - } - return result; - } +#define DECLARE_PARSER_FROM_PTREE(TYPE) \ + template <> TYPE::Ptr parse(const boost::property_tree::ptree &data) - template - std::string parseArray(TgTypeToJsonFunc parseFunc, const std::vector>& objects) const { - if (objects.empty()) - return ""; - std::string result; - result += '['; - for (const std::shared_ptr& item : objects) { - result += (this->*parseFunc)(item); - result += ','; - } - result.erase(result.length() - 1); - result += ']'; - return result; - } +// Grab array of T from this specific node. +template +std::vector> +parseArray(const boost::property_tree::ptree &data) { + std::vector> result; + for (const auto &item : data) { + result.emplace_back(parse(item.second)); + } + return result; +} - template - std::string parseArray(std::function parseFunc, const std::vector& objects) const { - if (objects.empty()) - return ""; - std::string result; - result += '['; - for (const T& item : objects) { - result += parseFunc(item); - result += ','; - } - result.erase(result.length() - 1); - result += ']'; - return result; - } +// T should be instance of std::shared_ptr. +// Grab array of T with a given key. +template +std::vector> +parseArray(const boost::property_tree::ptree &data, const std::string &key) { + if (data.empty() || data.find(key) == data.not_found()) { + return {}; + } + return parseArray(data.find(key)->second); +} - template - std::string parse2DArray(TgTypeToJsonFunc parseFunc, const std::vector>>& objects) const { - if (objects.empty()) - return ""; - std::string result; - result += '['; - for (const std::vector>& item : objects) { - result += parseArray(parseFunc, item); - result += ','; - } - result.erase(result.length() - 1); - result += ']'; - return result; - } +// T should be instance of std::shared_ptr. +// Grab 2D array of T from this specific node. +template +Matrix> +parseMatrix(const boost::property_tree::ptree &data) { + std::vector>> result; + for (const auto &item : data) { + result.emplace_back(parseArray(item.second)); + } + return result; +} -private: - inline void removeLastComma(std::string& input) const { - input.erase(input.length() - 1); - } +template +Matrix> parseMatrix(const boost::property_tree::ptree &data, + const std::string &key) { + if (data.empty() || data.find(key) == data.not_found()) { + return {}; + } + return parseMatrix(data.find(key)->second); +} - template - inline void appendToJson(std::string& json, const std::string& varName, const std::shared_ptr& value) const { - if (value == nullptr) { - return; - } - json += '"'; - json += varName; - json += R"(":)"; - json += value; - json += ','; - } +// T should be int, bool, std::string, etc where boost::property_tree::ptree +// supports it. +template +std::vector parsePrimitiveArray(const boost::property_tree::ptree &data, + const std::string &key) { + if (data.empty() || data.find(key) == data.not_found()) { + return {}; + } + std::vector result; + for (const auto &item : data.find(key)->second) { + result.emplace_back(item.second.get("")); + } + return result; +} - template - inline void appendToJson(std::string& json, const std::string& varName, const T& value) const { - json += '"'; - json += varName; - json += R"(":)"; - json += value; - json += ','; - } +// This is for processing objects to JSON string. +template boost::property_tree::ptree put(const T &value) = delete; - template - inline void appendToJsonNumber(std::string& json, const std::string& varName, const T& value) const { - json += '"'; - json += varName; - json += R"(":)"; - json += std::to_string(value); - json += ','; - } +#define DECLARE_PARSER_TO_PTREE(TYPE) \ + template <> boost::property_tree::ptree put(const TYPE ::Ptr &object) - inline void appendToJson(std::string &json, const std::string &varName, const int &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const long &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const long long &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const unsigned &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const unsigned long &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const unsigned long long &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const float &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const double &value) const { appendToJsonNumber(json, varName, value); } - inline void appendToJson(std::string &json, const std::string &varName, const long double &value) const { appendToJsonNumber(json, varName, value); } +// Helper to put base class shared_ptr to derived T. +template && + !std::is_same_v && + std::is_base_of_v, + bool> = true> +boost::property_tree::ptree put(const V &data) { + return put(std::static_pointer_cast(data)); +} - inline void appendToJson(std::string& json, const std::string& varName, const bool& value) const { - json += '"'; - json += varName; - json += R"(":)"; - json += (value ? "true" : "false"); - json += ','; +template , bool> = true> +boost::property_tree::ptree put(const std::vector &vector) { + boost::property_tree::ptree dataArray; + for (const auto &item : vector) { + boost::property_tree::ptree dataNode; + if constexpr (detail::is_primitive_v) { + dataNode.put("", item); + } else { + dataNode.add_child("", put(item)); } + dataArray.push_back(std::make_pair("", dataNode)); + } + return dataArray; +} - inline void appendToJson(std::string& json, const std::string& varName, const char* value) const { - if (value != nullptr){ - std::string strValue(value); - appendToJson(json, varName, strValue); - } - } +// Put 2D array of T to JSON string. +template boost::property_tree::ptree put(const Matrix &matrix) { + boost::property_tree::ptree dataMatrix; + for (const auto &row : matrix) { + boost::property_tree::ptree dataRow; + dataRow.push_back(std::make_pair("", put(row))); + dataMatrix.push_back(std::make_pair("", dataRow)); + } + return dataMatrix; +} - void appendToJson(std::string& json, const std::string& varName, const std::string& value) const; -}; +template std::string putJSON(const T &object) { + std::ostringstream ss; + boost::property_tree::write_json(ss, put(object), false); + return ss.str(); } -#endif //TGBOT_TGTYPEPARSER_H +#define IMPLEMENT_PARSERS(type) \ + DECLARE_PARSER_FROM_PTREE(type); \ + DECLARE_PARSER_TO_PTREE(type) +IMPLEMENT_PARSERS(Animation); +IMPLEMENT_PARSERS(Audio); +IMPLEMENT_PARSERS(Birthdate); +IMPLEMENT_PARSERS(BotCommand); +IMPLEMENT_PARSERS(BotCommandScope); +IMPLEMENT_PARSERS(BotCommandScopeAllChatAdministrators); +IMPLEMENT_PARSERS(BotCommandScopeAllGroupChats); +IMPLEMENT_PARSERS(BotCommandScopeAllPrivateChats); +IMPLEMENT_PARSERS(BotCommandScopeChat); +IMPLEMENT_PARSERS(BotCommandScopeChatAdministrators); +IMPLEMENT_PARSERS(BotCommandScopeChatMember); +IMPLEMENT_PARSERS(BotCommandScopeDefault); +IMPLEMENT_PARSERS(BotDescription); +IMPLEMENT_PARSERS(BotName); +IMPLEMENT_PARSERS(BotShortDescription); +IMPLEMENT_PARSERS(BusinessConnection); +IMPLEMENT_PARSERS(BusinessIntro); +IMPLEMENT_PARSERS(BusinessLocation); +IMPLEMENT_PARSERS(BusinessMessagesDeleted); +IMPLEMENT_PARSERS(BusinessOpeningHours); +IMPLEMENT_PARSERS(BusinessOpeningHoursInterval); +IMPLEMENT_PARSERS(CallbackGame); +IMPLEMENT_PARSERS(CallbackQuery); +IMPLEMENT_PARSERS(Chat); +IMPLEMENT_PARSERS(ChatAdministratorRights); +IMPLEMENT_PARSERS(ChatBoost); +IMPLEMENT_PARSERS(ChatBoostAdded); +IMPLEMENT_PARSERS(ChatBoostRemoved); +IMPLEMENT_PARSERS(ChatBoostSource); +IMPLEMENT_PARSERS(ChatBoostSourceGiftCode); +IMPLEMENT_PARSERS(ChatBoostSourceGiveaway); +IMPLEMENT_PARSERS(ChatBoostSourcePremium); +IMPLEMENT_PARSERS(ChatBoostUpdated); +IMPLEMENT_PARSERS(ChatInviteLink); +IMPLEMENT_PARSERS(ChatJoinRequest); +IMPLEMENT_PARSERS(ChatLocation); +IMPLEMENT_PARSERS(ChatMember); +IMPLEMENT_PARSERS(ChatMemberAdministrator); +IMPLEMENT_PARSERS(ChatMemberBanned); +IMPLEMENT_PARSERS(ChatMemberLeft); +IMPLEMENT_PARSERS(ChatMemberMember); +IMPLEMENT_PARSERS(ChatMemberOwner); +IMPLEMENT_PARSERS(ChatMemberRestricted); +IMPLEMENT_PARSERS(ChatMemberUpdated); +IMPLEMENT_PARSERS(ChatPermissions); +IMPLEMENT_PARSERS(ChatPhoto); +IMPLEMENT_PARSERS(ChatShared); +IMPLEMENT_PARSERS(ChosenInlineResult); +IMPLEMENT_PARSERS(Contact); +IMPLEMENT_PARSERS(Dice); +IMPLEMENT_PARSERS(Document); +IMPLEMENT_PARSERS(EncryptedCredentials); +IMPLEMENT_PARSERS(EncryptedPassportElement); +IMPLEMENT_PARSERS(ExternalReplyInfo); +IMPLEMENT_PARSERS(File); +IMPLEMENT_PARSERS(ForceReply); +IMPLEMENT_PARSERS(ForumTopic); +IMPLEMENT_PARSERS(ForumTopicClosed); +IMPLEMENT_PARSERS(ForumTopicCreated); +IMPLEMENT_PARSERS(ForumTopicEdited); +IMPLEMENT_PARSERS(ForumTopicReopened); +IMPLEMENT_PARSERS(Game); +IMPLEMENT_PARSERS(GameHighScore); +IMPLEMENT_PARSERS(GeneralForumTopicHidden); +IMPLEMENT_PARSERS(GeneralForumTopicUnhidden); +IMPLEMENT_PARSERS(GenericReply); +IMPLEMENT_PARSERS(Giveaway); +IMPLEMENT_PARSERS(GiveawayCompleted); +IMPLEMENT_PARSERS(GiveawayCreated); +IMPLEMENT_PARSERS(GiveawayWinners); +IMPLEMENT_PARSERS(InaccessibleMessage); +IMPLEMENT_PARSERS(InlineKeyboardButton); +IMPLEMENT_PARSERS(InlineKeyboardMarkup); +IMPLEMENT_PARSERS(InlineQuery); +IMPLEMENT_PARSERS(InlineQueryResult); +IMPLEMENT_PARSERS(InlineQueryResultArticle); +IMPLEMENT_PARSERS(InlineQueryResultAudio); +IMPLEMENT_PARSERS(InlineQueryResultCachedAudio); +IMPLEMENT_PARSERS(InlineQueryResultCachedDocument); +IMPLEMENT_PARSERS(InlineQueryResultCachedGif); +IMPLEMENT_PARSERS(InlineQueryResultCachedMpeg4Gif); +IMPLEMENT_PARSERS(InlineQueryResultCachedPhoto); +IMPLEMENT_PARSERS(InlineQueryResultCachedSticker); +IMPLEMENT_PARSERS(InlineQueryResultCachedVideo); +IMPLEMENT_PARSERS(InlineQueryResultCachedVoice); +IMPLEMENT_PARSERS(InlineQueryResultContact); +IMPLEMENT_PARSERS(InlineQueryResultDocument); +IMPLEMENT_PARSERS(InlineQueryResultGame); +IMPLEMENT_PARSERS(InlineQueryResultGif); +IMPLEMENT_PARSERS(InlineQueryResultLocation); +IMPLEMENT_PARSERS(InlineQueryResultMpeg4Gif); +IMPLEMENT_PARSERS(InlineQueryResultPhoto); +IMPLEMENT_PARSERS(InlineQueryResultVenue); +IMPLEMENT_PARSERS(InlineQueryResultVideo); +IMPLEMENT_PARSERS(InlineQueryResultVoice); +IMPLEMENT_PARSERS(InlineQueryResultsButton); +IMPLEMENT_PARSERS(InputContactMessageContent); +IMPLEMENT_PARSERS(InputInvoiceMessageContent); +IMPLEMENT_PARSERS(InputLocationMessageContent); +IMPLEMENT_PARSERS(InputMedia); +IMPLEMENT_PARSERS(InputMediaAnimation); +IMPLEMENT_PARSERS(InputMediaAudio); +IMPLEMENT_PARSERS(InputMediaDocument); +IMPLEMENT_PARSERS(InputMediaPhoto); +IMPLEMENT_PARSERS(InputMediaVideo); +IMPLEMENT_PARSERS(InputMessageContent); +IMPLEMENT_PARSERS(InputSticker); +IMPLEMENT_PARSERS(InputTextMessageContent); +IMPLEMENT_PARSERS(InputVenueMessageContent); +IMPLEMENT_PARSERS(Invoice); +IMPLEMENT_PARSERS(KeyboardButton); +IMPLEMENT_PARSERS(KeyboardButtonPollType); +IMPLEMENT_PARSERS(KeyboardButtonRequestChat); +IMPLEMENT_PARSERS(KeyboardButtonRequestUsers); +IMPLEMENT_PARSERS(LabeledPrice); +IMPLEMENT_PARSERS(LinkPreviewOptions); +IMPLEMENT_PARSERS(Location); +IMPLEMENT_PARSERS(LoginUrl); +IMPLEMENT_PARSERS(MaskPosition); +IMPLEMENT_PARSERS(MenuButton); +IMPLEMENT_PARSERS(MenuButtonCommands); +IMPLEMENT_PARSERS(MenuButtonDefault); +IMPLEMENT_PARSERS(MenuButtonWebApp); +IMPLEMENT_PARSERS(Message); +IMPLEMENT_PARSERS(MessageAutoDeleteTimerChanged); +IMPLEMENT_PARSERS(MessageEntity); +IMPLEMENT_PARSERS(MessageId); +IMPLEMENT_PARSERS(MessageOrigin); +IMPLEMENT_PARSERS(MessageOriginChannel); +IMPLEMENT_PARSERS(MessageOriginChat); +IMPLEMENT_PARSERS(MessageOriginHiddenUser); +IMPLEMENT_PARSERS(MessageOriginUser); +IMPLEMENT_PARSERS(MessageReactionCountUpdated); +IMPLEMENT_PARSERS(MessageReactionUpdated); +IMPLEMENT_PARSERS(OrderInfo); +IMPLEMENT_PARSERS(PassportData); +IMPLEMENT_PARSERS(PassportElementError); +IMPLEMENT_PARSERS(PassportElementErrorDataField); +IMPLEMENT_PARSERS(PassportElementErrorFile); +IMPLEMENT_PARSERS(PassportElementErrorFiles); +IMPLEMENT_PARSERS(PassportElementErrorFrontSide); +IMPLEMENT_PARSERS(PassportElementErrorReverseSide); +IMPLEMENT_PARSERS(PassportElementErrorSelfie); +IMPLEMENT_PARSERS(PassportElementErrorTranslationFile); +IMPLEMENT_PARSERS(PassportElementErrorTranslationFiles); +IMPLEMENT_PARSERS(PassportElementErrorUnspecified); +IMPLEMENT_PARSERS(PassportFile); +IMPLEMENT_PARSERS(PhotoSize); +IMPLEMENT_PARSERS(Poll); +IMPLEMENT_PARSERS(PollAnswer); +IMPLEMENT_PARSERS(PollOption); +IMPLEMENT_PARSERS(PreCheckoutQuery); +IMPLEMENT_PARSERS(ProximityAlertTriggered); +IMPLEMENT_PARSERS(ReactionCount); +IMPLEMENT_PARSERS(ReactionType); +IMPLEMENT_PARSERS(ReactionTypeCustomEmoji); +IMPLEMENT_PARSERS(ReactionTypeEmoji); +IMPLEMENT_PARSERS(ReplyKeyboardMarkup); +IMPLEMENT_PARSERS(ReplyKeyboardRemove); +IMPLEMENT_PARSERS(ReplyParameters); +IMPLEMENT_PARSERS(ResponseParameters); +IMPLEMENT_PARSERS(SentWebAppMessage); +IMPLEMENT_PARSERS(SharedUser); +IMPLEMENT_PARSERS(ShippingAddress); +IMPLEMENT_PARSERS(ShippingOption); +IMPLEMENT_PARSERS(ShippingQuery); +IMPLEMENT_PARSERS(Sticker); +IMPLEMENT_PARSERS(StickerSet); +IMPLEMENT_PARSERS(Story); +IMPLEMENT_PARSERS(SuccessfulPayment); +IMPLEMENT_PARSERS(SwitchInlineQueryChosenChat); +IMPLEMENT_PARSERS(TextQuote); +IMPLEMENT_PARSERS(Update); +IMPLEMENT_PARSERS(User); +IMPLEMENT_PARSERS(UserChatBoosts); +IMPLEMENT_PARSERS(UserProfilePhotos); +IMPLEMENT_PARSERS(UsersShared); +IMPLEMENT_PARSERS(Venue); +IMPLEMENT_PARSERS(Video); +IMPLEMENT_PARSERS(VideoChatEnded); +IMPLEMENT_PARSERS(VideoChatParticipantsInvited); +IMPLEMENT_PARSERS(VideoChatScheduled); +IMPLEMENT_PARSERS(VideoChatStarted); +IMPLEMENT_PARSERS(VideoNote); +IMPLEMENT_PARSERS(Voice); +IMPLEMENT_PARSERS(WebAppData); +IMPLEMENT_PARSERS(WebAppInfo); +IMPLEMENT_PARSERS(WebhookInfo); +IMPLEMENT_PARSERS(WriteAccessAllowed); + +} // namespace TgBot + +#endif // TGBOT_TGTYPEPARSER_H diff --git a/include/tgbot/net/TgWebhookServer.h b/include/tgbot/net/TgWebhookServer.h index f7eb9497..0b4133f2 100644 --- a/include/tgbot/net/TgWebhookServer.h +++ b/include/tgbot/net/TgWebhookServer.h @@ -6,43 +6,59 @@ #include "tgbot/TgTypeParser.h" #include "tgbot/net/HttpServer.h" +#include #include #include #include namespace TgBot { -template +template class TgWebhookServer : public HttpServer { public: - TgWebhookServer(const typename boost::asio::basic_socket_acceptor::endpoint_type& endpoint, const typename HttpServer::ServerHandler& handler) = delete; + TgWebhookServer( + const typename boost::asio::basic_socket_acceptor::endpoint_type + &endpoint, + const typename HttpServer::ServerHandler &handler) = delete; - TgWebhookServer(const typename boost::asio::basic_socket_acceptor::endpoint_type& endpoint, std::string path, const EventHandler& eventHandler) - : HttpServer(endpoint, - [this](const std::string& _1, const std::unordered_map& _2) { return _handle(_1, _2); }), - _path(std::move(path)), _eventHandler(eventHandler), _tgTypeParser() - { - } + TgWebhookServer( + const typename boost::asio::basic_socket_acceptor::endpoint_type + &endpoint, + std::string path, const EventHandler &eventHandler) + : HttpServer( + endpoint, + [this](const std::string &_1, + const std::unordered_map &_2) { + return _handle(_1, _2); + }), + _path(std::move(path)), _eventHandler(eventHandler) {} - TgWebhookServer(const typename boost::asio::basic_socket_acceptor::endpoint_type& endpoint, const Bot& bot) - : TgWebhookServer(endpoint, "/" + bot.getToken(), bot.getEventHandler()) - { - } + TgWebhookServer( + const typename boost::asio::basic_socket_acceptor::endpoint_type + &endpoint, + const Bot &bot) + : TgWebhookServer(endpoint, "/" + bot.getToken(), bot.getEventHandler()) { + } private: - std::string _handle(const std::string& data, const std::unordered_map& headers) { - if (headers.at("_method") == "POST" && headers.at("_path") == _path) { - _eventHandler.handleUpdate(_tgTypeParser.parseJsonAndGetUpdate(_tgTypeParser.parseJson(data))); - } - return HttpServer::_httpParser.generateResponse("", "text/plain", 200, "OK", false); + std::string + _handle(const std::string &data, + const std::unordered_map &headers) { + if (headers.at("_method") == "POST" && headers.at("_path") == _path) { + std::istringstream iss(data); + boost::property_tree::ptree pt; + boost::property_tree::read_json(iss, pt); + _eventHandler.handleUpdate(parse(pt)); } + return HttpServer::_httpParser.generateResponse("", "text/plain", + 200, "OK", false); + } - const std::string _path; - const EventHandler& _eventHandler; - const TgTypeParser _tgTypeParser; + const std::string _path; + const EventHandler &_eventHandler; }; -} +} // namespace TgBot -#endif //TGBOT_TGHTTPSERVER_H +#endif // TGBOT_TGHTTPSERVER_H diff --git a/src/Api.cpp b/src/Api.cpp index 2c4b82aa..67782a76 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1,1240 +1,1186 @@ #include "tgbot/Api.h" +#include "tgbot/TgTypeParser.h" +#include "tgbot/types/Message.h" +#include "tgbot/types/MessageId.h" #include #include +namespace { +std::vector +escapeJSONStringVec(const std::vector &vec) { + std::vector newVec = vec; + for (auto i = newVec.begin(); i != newVec.end(); ++i) { + std::stringstream ss; + ss << std::quoted(StringTools::escapeJsonString(*i)); + *i = ss.str(); + } + return newVec; +} +} // namespace namespace TgBot { -Api::Api(std::string token, const HttpClient& httpClient, const std::string& url) - : _httpClient(httpClient), _token(std::move(token)), _tgTypeParser(), _url(url) { -} - -std::vector Api::getUpdates(std::int32_t offset, - std::int32_t limit, - std::int32_t timeout, - const StringArrayPtr& allowedUpdates) const { - std::vector args; - args.reserve(4); - - if (offset != 0) { - args.emplace_back("offset", offset); - } - if (limit != 100) { - args.emplace_back("limit", std::max(1, std::min(100, limit))); - } - if (timeout != 0) { - args.emplace_back("timeout", timeout); - } - if (allowedUpdates != nullptr) { - std::string allowedUpdatesJson = _tgTypeParser.parseArray( - [] (const std::string& s)->std::string { - return s; - }, *allowedUpdates); - args.emplace_back("allowed_updates", allowedUpdatesJson); - } - - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetUpdate, sendRequest("getUpdates", args)); -} - -bool Api::setWebhook(const std::string& url, - InputFile::Ptr certificate, +Api::Api(std::string token, const HttpClient &httpClient, + const std::string &url) + : _httpClient(httpClient), _token(std::move(token)), _url(url) {} + +std::vector +Api::getUpdates(std::int32_t offset, std::int32_t limit, std::int32_t timeout, + const StringArrayPtr &allowedUpdates) const { + std::vector args; + args.reserve(4); + + if (offset != 0) { + args.emplace_back("offset", offset); + } + if (limit != 100) { + args.emplace_back("limit", std::max(1, std::min(100, limit))); + } + if (timeout != 0) { + args.emplace_back("timeout", timeout); + } + if (allowedUpdates != nullptr) { + std::string allowedUpdatesJson = putJSON(*allowedUpdates); + args.emplace_back("allowed_updates", allowedUpdatesJson); + } + + return parseArray(sendRequest("getUpdates", args)); +} + +bool Api::setWebhook(const std::string &url, InputFile::Ptr certificate, std::int32_t maxConnections, - const StringArrayPtr& allowedUpdates, - const std::string& ipAddress, - bool dropPendingUpdates, - const std::string& secretToken) const { - std::vector args; - args.reserve(7); - - args.emplace_back("url", url); - if (certificate != nullptr) { - args.emplace_back("certificate", certificate->data, true, certificate->mimeType, certificate->fileName); - } - if (!ipAddress.empty()) { - args.emplace_back("ip_address", ipAddress); - } - if (maxConnections != 40) { - args.emplace_back("max_connections", std::max(1, std::min(100, maxConnections))); - } - if (allowedUpdates != nullptr) { - auto allowedUpdatesJson = _tgTypeParser.parseArray( - [] (const std::string& s)->std::string { - return s; - }, *allowedUpdates); - args.emplace_back("allowed_updates", allowedUpdatesJson); - } - if (dropPendingUpdates) { - args.emplace_back("drop_pending_updates", dropPendingUpdates); - } - if (!secretToken.empty()) { - args.emplace_back("secret_token", secretToken); - } - - return sendRequest("setWebhook", args).get("", false); + const StringArrayPtr &allowedUpdates, + const std::string &ipAddress, bool dropPendingUpdates, + const std::string &secretToken) const { + std::vector args; + args.reserve(7); + + args.emplace_back("url", url); + if (certificate != nullptr) { + args.emplace_back("certificate", certificate->data, true, + certificate->mimeType, certificate->fileName); + } + if (!ipAddress.empty()) { + args.emplace_back("ip_address", ipAddress); + } + if (maxConnections != 40) { + args.emplace_back("max_connections", + std::max(1, std::min(100, maxConnections))); + } + if (allowedUpdates != nullptr) { + auto allowedUpdatesJson = putJSON(*allowedUpdates); + args.emplace_back("allowed_updates", allowedUpdatesJson); + } + if (dropPendingUpdates) { + args.emplace_back("drop_pending_updates", dropPendingUpdates); + } + if (!secretToken.empty()) { + args.emplace_back("secret_token", secretToken); + } + + return sendRequest("setWebhook", args).get("", false); } bool Api::deleteWebhook(bool dropPendingUpdates) const { - std::vector args; - args.reserve(1); + std::vector args; + args.reserve(1); - if (dropPendingUpdates) { - args.emplace_back("drop_pending_updates", dropPendingUpdates); - } + if (dropPendingUpdates) { + args.emplace_back("drop_pending_updates", dropPendingUpdates); + } - return sendRequest("deleteWebhook", args).get("", false); + return sendRequest("deleteWebhook", args).get("", false); } WebhookInfo::Ptr Api::getWebhookInfo() const { - boost::property_tree::ptree p = sendRequest("getWebhookInfo"); + boost::property_tree::ptree p = sendRequest("getWebhookInfo"); - if (!p.get_child_optional("url")) { - return nullptr; - } + if (!p.get_child_optional("url")) { + return nullptr; + } - if (p.get("url", "") != std::string("")) { - return _tgTypeParser.parseJsonAndGetWebhookInfo(p); - } else { - return nullptr; - } + if (p.get("url", "") != std::string("")) { + return parse(p); + } else { + return nullptr; + } } -User::Ptr Api::getMe() const { - return _tgTypeParser.parseJsonAndGetUser(sendRequest("getMe")); -} +User::Ptr Api::getMe() const { return parse(sendRequest("getMe")); } -bool Api::logOut() const { - return sendRequest("logOut").get("", false); -} +bool Api::logOut() const { return sendRequest("logOut").get("", false); } -bool Api::close() const { - return sendRequest("close").get("", false); -} +bool Api::close() const { return sendRequest("close").get("", false); } Message::Ptr Api::sendMessage(boost::variant chatId, - const std::string& text, + const std::string &text, LinkPreviewOptions::Ptr linkPreviewOptions, ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, - const std::string& parseMode, + const std::string &parseMode, bool disableNotification, - const std::vector& entities, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(11); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("text", text); - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!entities.empty()) { - args.emplace_back("entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, entities)); - } - if (linkPreviewOptions != nullptr) { - args.emplace_back("link_preview_options", _tgTypeParser.parseLinkPreviewOptions(linkPreviewOptions)); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendMessage", args)); -} + const std::vector &entities, + std::int32_t messageThreadId, bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(11); -Message::Ptr Api::forwardMessage(boost::variant chatId, - boost::variant fromChatId, - std::int32_t messageId, - bool disableNotification, - bool protectContent, - std::int32_t messageThreadId) const { - std::vector args; - args.reserve(6); - - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("from_chat_id", fromChatId); - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("text", text); + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!entities.empty()) { + args.emplace_back("entities", putJSON(entities)); + } + if (linkPreviewOptions != nullptr) { + args.emplace_back("link_preview_options", putJSON(linkPreviewOptions)); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendMessage", args)); +} + +Message::Ptr +Api::forwardMessage(boost::variant chatId, + boost::variant fromChatId, + std::int32_t messageId, bool disableNotification, + bool protectContent, std::int32_t messageThreadId) const { + std::vector args; + args.reserve(6); + + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("from_chat_id", fromChatId); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + args.emplace_back("message_id", messageId); + + return parse(sendRequest("forwardMessage", args)); +} + +std::vector +Api::forwardMessages(boost::variant chatId, + boost::variant fromChatId, + const std::vector &messageIds, + std::int32_t messageThreadId, bool disableNotification, + bool protectContent) const { + std::vector args; + args.reserve(6); + + args.emplace_back("chat_id", chatId); + args.emplace_back("from_chat_id", fromChatId); + if (!messageIds.empty()) { + args.emplace_back("message_ids", putJSON(messageIds)); + } + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + + return parseArray(sendRequest("forwardMessages", args)); +} + +MessageId::Ptr +Api::copyMessage(boost::variant chatId, + boost::variant fromChatId, + std::int32_t messageId, const std::string &caption, + const std::string &parseMode, + const std::vector &captionEntities, + bool disableNotification, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, bool protectContent, + std::int32_t messageThreadId) const { + std::vector args; + args.reserve(11); + + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("from_chat_id", fromChatId); + args.emplace_back("message_id", messageId); + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("copyMessage", args)); +} + +std::vector +Api::copyMessages(boost::variant chatId, + boost::variant fromChatId, + const std::vector &messageIds, + std::int32_t messageThreadId, bool disableNotification, + bool protectContent, bool removeCaption) const { + std::vector args; + args.reserve(7); + + args.emplace_back("chat_id", chatId); + args.emplace_back("from_chat_id", fromChatId); + + if (!messageIds.empty()) { + args.emplace_back("message_ids", putJSON(messageIds)); + } + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (removeCaption) { + args.emplace_back("remove_caption", removeCaption); + } + + return parseArray(sendRequest("copyMessages", args)); +} + +Message::Ptr +Api::sendPhoto(boost::variant chatId, + boost::variant photo, + const std::string &caption, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + bool disableNotification, + const std::vector &captionEntities, + std::int32_t messageThreadId, bool protectContent, + bool hasSpoiler, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(12); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (photo.which() == 0) { // InputFile::Ptr + auto file = boost::get(photo); + args.emplace_back("photo", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("photo", boost::get(photo)); + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (hasSpoiler) { + args.emplace_back("has_spoiler", hasSpoiler); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup != nullptr) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendPhoto", args)); +} + +Message::Ptr +Api::sendAudio(boost::variant chatId, + boost::variant audio, + const std::string &caption, std::int32_t duration, + const std::string &performer, const std::string &title, + boost::variant thumbnail, + ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + bool disableNotification, + const std::vector &captionEntities, + std::int32_t messageThreadId, bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(15); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (audio.which() == 0) { // InputFile::Ptr + auto file = boost::get(audio); + args.emplace_back("audio", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("audio", boost::get(audio)); + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (duration) { + args.emplace_back("duration", duration); + } + if (!performer.empty()) { + args.emplace_back("performer", performer); + } + if (!title.empty()) { + args.emplace_back("title", title); + } + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); + } + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendAudio", args)); +} + +Message::Ptr Api::sendDocument( + boost::variant chatId, + boost::variant document, + boost::variant thumbnail, + const std::string &caption, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + bool disableNotification, + const std::vector &captionEntities, + bool disableContentTypeDetection, std::int32_t messageThreadId, + bool protectContent, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(13); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (document.which() == 0) { // InputFile::Ptr + auto file = boost::get(document); + args.emplace_back("document", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("document", boost::get(document)); + } + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); + } + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (disableContentTypeDetection) { + args.emplace_back("disable_content_type_detection", + disableContentTypeDetection); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendDocument", args)); +} + +Message::Ptr +Api::sendVideo(boost::variant chatId, + boost::variant video, + bool supportsStreaming, std::int32_t duration, + std::int32_t width, std::int32_t height, + boost::variant thumbnail, + const std::string &caption, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + bool disableNotification, + const std::vector &captionEntities, + std::int32_t messageThreadId, bool protectContent, + bool hasSpoiler, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(17); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (video.which() == 0) { // InputFile::Ptr + auto file = boost::get(video); + args.emplace_back("video", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("video", boost::get(video)); + } + if (duration != 0) { + args.emplace_back("duration", duration); + } + if (width != 0) { + args.emplace_back("width", width); + } + if (height != 0) { + args.emplace_back("height", height); + } + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); + } + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (hasSpoiler) { + args.emplace_back("has_spoiler", hasSpoiler); + } + if (supportsStreaming) { + args.emplace_back("supports_streaming", supportsStreaming); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup != nullptr) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendVideo", args)); +} + +Message::Ptr Api::sendAnimation( + boost::variant chatId, + boost::variant animation, + std::int32_t duration, std::int32_t width, std::int32_t height, + boost::variant thumbnail, + const std::string &caption, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + bool disableNotification, + const std::vector &captionEntities, + std::int32_t messageThreadId, bool protectContent, bool hasSpoiler, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(16); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (animation.which() == 0) { // InputFile::Ptr + auto file = boost::get(animation); + args.emplace_back("animation", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("animation", boost::get(animation)); + } + if (duration != 0) { + args.emplace_back("duration", duration); + } + if (width != 0) { + args.emplace_back("width", width); + } + if (height != 0) { + args.emplace_back("height", height); + } + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); + } + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (hasSpoiler) { + args.emplace_back("has_spoiler", hasSpoiler); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup != nullptr) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendAnimation", args)); +} + +Message::Ptr +Api::sendVoice(boost::variant chatId, + boost::variant voice, + const std::string &caption, std::int32_t duration, + ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + bool disableNotification, + const std::vector &captionEntities, + std::int32_t messageThreadId, bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(12); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (voice.which() == 0) { // InputFile::Ptr + auto file = boost::get(voice); + args.emplace_back("voice", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("voice", boost::get(voice)); + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (duration) { + args.emplace_back("duration", duration); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendVoice", args)); +} + +Message::Ptr Api::sendVideoNote( + boost::variant chatId, + boost::variant videoNote, + ReplyParameters::Ptr replyParameters, bool disableNotification, + std::int32_t duration, std::int32_t length, + boost::variant thumbnail, + GenericReply::Ptr replyMarkup, std::int32_t messageThreadId, + bool protectContent, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(11); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (videoNote.which() == 0) { // InputFile::Ptr + auto file = boost::get(videoNote); + args.emplace_back("video_note", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("video_note", boost::get(videoNote)); + } + if (duration) { + args.emplace_back("duration", duration); + } + if (length) { + args.emplace_back("length", length); + } + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); + } + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendVideoNote", args)); +} + +std::vector Api::sendMediaGroup( + boost::variant chatId, + const std::vector &media, bool disableNotification, + ReplyParameters::Ptr replyParameters, std::int32_t messageThreadId, + bool protectContent, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(7); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("media", putJSON(media)); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + + return parseArray(sendRequest("sendMediaGroup", args)); +} + +Message::Ptr Api::sendLocation( + boost::variant chatId, float latitude, + float longitude, std::int32_t livePeriod, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, + bool disableNotification, float horizontalAccuracy, std::int32_t heading, + std::int32_t proximityAlertRadius, std::int32_t messageThreadId, + bool protectContent, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(13); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("latitude", latitude); + args.emplace_back("longitude", longitude); + if (horizontalAccuracy) { + args.emplace_back("horizontal_accuracy", horizontalAccuracy); + } + if (livePeriod) { + args.emplace_back("live_period", std::max(60, std::min(86400, livePeriod))); + } + if (heading) { + args.emplace_back("heading", std::max(1, std::min(360, heading))); + } + if (proximityAlertRadius) { + args.emplace_back("proximity_alert_radius", + std::max(1, std::min(100000, proximityAlertRadius))); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendLocation", args)); +} + +Message::Ptr Api::editMessageLiveLocation( + float latitude, float longitude, + boost::variant chatId, std::int32_t messageId, + const std::string &inlineMessageId, InlineKeyboardMarkup::Ptr replyMarkup, + float horizontalAccuracy, std::int32_t heading, + std::int32_t proximityAlertRadius) const { + std::vector args; + args.reserve(9); + + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } + } + if (messageId) { args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + args.emplace_back("latitude", latitude); + args.emplace_back("longitude", longitude); + if (horizontalAccuracy) { + args.emplace_back("horizontal_accuracy", horizontalAccuracy); + } + if (heading) { + args.emplace_back("heading", heading); + } + if (proximityAlertRadius) { + args.emplace_back("proximity_alert_radius", proximityAlertRadius); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("editMessageLiveLocation", args)); +} + +Message::Ptr +Api::stopMessageLiveLocation(boost::variant chatId, + std::int32_t messageId, + const std::string &inlineMessageId, + InlineKeyboardMarkup::Ptr replyMarkup) const { + std::vector args; + args.reserve(4); - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("forwardMessage", args)); -} - -std::vector Api::forwardMessages(boost::variant chatId, - boost::variant fromChatId, - const std::vector& messageIds, - std::int32_t messageThreadId, - bool disableNotification, - bool protectContent) const { - std::vector args; - args.reserve(6); - - args.emplace_back("chat_id", chatId); - args.emplace_back("from_chat_id", fromChatId); - if (!messageIds.empty()) { - args.emplace_back("message_ids", _tgTypeParser.parseArray( - [] (const std::int32_t& i)->std::int32_t { - return i; - }, messageIds)); - } - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetMessageId, sendRequest("forwardMessages", args)); -} - -MessageId::Ptr Api::copyMessage(boost::variant chatId, - boost::variant fromChatId, - std::int32_t messageId, - const std::string& caption, - const std::string& parseMode, - const std::vector& captionEntities, - bool disableNotification, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - bool protectContent, - std::int32_t messageThreadId) const { - std::vector args; - args.reserve(11); - - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); } - args.emplace_back("from_chat_id", fromChatId); + } + if (messageId) { args.emplace_back("message_id", messageId); - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessageId(sendRequest("copyMessage", args)); -} - -std::vector Api::copyMessages(boost::variant chatId, - boost::variant fromChatId, - const std::vector& messageIds, - std::int32_t messageThreadId, - bool disableNotification, - bool protectContent, - bool removeCaption) const { - std::vector args; - args.reserve(7); - - args.emplace_back("chat_id", chatId); - args.emplace_back("from_chat_id", fromChatId); - - if (!messageIds.empty()) { - args.emplace_back("message_ids", _tgTypeParser.parseArray( - [] (const std::int32_t& i)->std::int32_t { - return i; - }, messageIds)); - } - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (removeCaption) { - args.emplace_back("remove_caption", removeCaption); - } - - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetMessageId, sendRequest("copyMessages", args)); -} - -Message::Ptr Api::sendPhoto(boost::variant chatId, - boost::variant photo, - const std::string& caption, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - bool disableNotification, - const std::vector& captionEntities, - std::int32_t messageThreadId, - bool protectContent, - bool hasSpoiler, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(12); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (photo.which() == 0) { // InputFile::Ptr - auto file = boost::get(photo); - args.emplace_back("photo", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("photo", boost::get(photo)); - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (hasSpoiler) { - args.emplace_back("has_spoiler", hasSpoiler); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup != nullptr) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPhoto", args)); -} - -Message::Ptr Api::sendAudio(boost::variant chatId, - boost::variant audio, - const std::string& caption, - std::int32_t duration, - const std::string& performer, - const std::string& title, - boost::variant thumbnail, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - bool disableNotification, - const std::vector& captionEntities, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(15); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (audio.which() == 0) { // InputFile::Ptr - auto file = boost::get(audio); - args.emplace_back("audio", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("audio", boost::get(audio)); - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (duration) { - args.emplace_back("duration", duration); - } - if (!performer.empty()) { - args.emplace_back("performer", performer); - } - if (!title.empty()) { - args.emplace_back("title", title); - } - if (thumbnail.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumbnail); - args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); - } else { // std::string - auto thumbnailStr = boost::get(thumbnail); - if (!thumbnailStr.empty()) { - args.emplace_back("thumbnail", thumbnailStr); - } - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAudio", args)); -} - -Message::Ptr Api::sendDocument(boost::variant chatId, - boost::variant document, - boost::variant thumbnail, - const std::string& caption, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - bool disableNotification, - const std::vector& captionEntities, - bool disableContentTypeDetection, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(13); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (document.which() == 0) { // InputFile::Ptr - auto file = boost::get(document); - args.emplace_back("document", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("document", boost::get(document)); - } - if (thumbnail.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumbnail); - args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); - } else { // std::string - auto thumbnailStr = boost::get(thumbnail); - if (!thumbnailStr.empty()) { - args.emplace_back("thumbnail", thumbnailStr); - } - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (disableContentTypeDetection) { - args.emplace_back("disable_content_type_detection", disableContentTypeDetection); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDocument", args)); -} - -Message::Ptr Api::sendVideo(boost::variant chatId, - boost::variant video, - bool supportsStreaming, - std::int32_t duration, - std::int32_t width, - std::int32_t height, - boost::variant thumbnail, - const std::string& caption , - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - bool disableNotification, - const std::vector& captionEntities, - std::int32_t messageThreadId, - bool protectContent, - bool hasSpoiler, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(17); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (video.which() == 0) { // InputFile::Ptr - auto file = boost::get(video); - args.emplace_back("video", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("video", boost::get(video)); - } - if (duration != 0) { - args.emplace_back("duration", duration); - } - if (width != 0) { - args.emplace_back("width", width); - } - if (height != 0) { - args.emplace_back("height", height); - } - if (thumbnail.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumbnail); - args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); - } else { // std::string - auto thumbnailStr = boost::get(thumbnail); - if (!thumbnailStr.empty()) { - args.emplace_back("thumbnail", thumbnailStr); - } - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (hasSpoiler) { - args.emplace_back("has_spoiler", hasSpoiler); - } - if (supportsStreaming) { - args.emplace_back("supports_streaming", supportsStreaming); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup != nullptr) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideo", args)); -} - -Message::Ptr Api::sendAnimation(boost::variant chatId, - boost::variant animation, - std::int32_t duration, - std::int32_t width, - std::int32_t height, - boost::variant thumbnail, - const std::string& caption, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - bool disableNotification, - const std::vector& captionEntities, - std::int32_t messageThreadId, - bool protectContent, - bool hasSpoiler, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(16); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (animation.which() == 0) { // InputFile::Ptr - auto file = boost::get(animation); - args.emplace_back("animation", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("animation", boost::get(animation)); - } - if (duration != 0) { - args.emplace_back("duration", duration); - } - if (width != 0) { - args.emplace_back("width", width); - } - if (height != 0) { - args.emplace_back("height", height); - } - if (thumbnail.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumbnail); - args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); - } else { // std::string - auto thumbnailStr = boost::get(thumbnail); - if (!thumbnailStr.empty()) { - args.emplace_back("thumbnail", thumbnailStr); - } - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (hasSpoiler) { - args.emplace_back("has_spoiler", hasSpoiler); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup != nullptr) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendAnimation", args)); -} - -Message::Ptr Api::sendVoice(boost::variant chatId, - boost::variant voice, - const std::string& caption, - std::int32_t duration, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - bool disableNotification, - const std::vector& captionEntities, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(12); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (voice.which() == 0) { // InputFile::Ptr - auto file = boost::get(voice); - args.emplace_back("voice", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("voice", boost::get(voice)); - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (duration) { - args.emplace_back("duration", duration); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVoice", args)); -} - -Message::Ptr Api::sendVideoNote(boost::variant chatId, - boost::variant videoNote, - ReplyParameters::Ptr replyParameters, - bool disableNotification, - std::int32_t duration, - std::int32_t length, - boost::variant thumbnail, - GenericReply::Ptr replyMarkup, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(11); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (videoNote.which() == 0) { // InputFile::Ptr - auto file = boost::get(videoNote); - args.emplace_back("video_note", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("video_note", boost::get(videoNote)); - } - if (duration) { - args.emplace_back("duration", duration); - } - if (length) { - args.emplace_back("length", length); - } - if (thumbnail.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumbnail); - args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); - } else { // std::string - auto thumbnailStr = boost::get(thumbnail); - if (!thumbnailStr.empty()) { - args.emplace_back("thumbnail", thumbnailStr); - } - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVideoNote", args)); -} - -std::vector Api::sendMediaGroup(boost::variant chatId, - const std::vector& media, - bool disableNotification, - ReplyParameters::Ptr replyParameters, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(7); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("media", _tgTypeParser.parseArray(&TgTypeParser::parseInputMedia, media)); - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetMessage, sendRequest("sendMediaGroup", args)); -} - -Message::Ptr Api::sendLocation(boost::variant chatId, - float latitude, - float longitude, - std::int32_t livePeriod, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - bool disableNotification, - float horizontalAccuracy, - std::int32_t heading, - std::int32_t proximityAlertRadius, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(13); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("latitude", latitude); - args.emplace_back("longitude", longitude); - if (horizontalAccuracy) { - args.emplace_back("horizontal_accuracy", horizontalAccuracy); - } - if (livePeriod) { - args.emplace_back("live_period", std::max(60, std::min(86400, livePeriod))); - } - if (heading) { - args.emplace_back("heading", std::max(1, std::min(360, heading))); - } - if (proximityAlertRadius) { - args.emplace_back("proximity_alert_radius", std::max(1, std::min(100000, proximityAlertRadius))); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendLocation", args)); -} - -Message::Ptr Api::editMessageLiveLocation(float latitude, - float longitude, - boost::variant chatId, - std::int32_t messageId, - const std::string& inlineMessageId, - InlineKeyboardMarkup::Ptr replyMarkup, - float horizontalAccuracy, - std::int32_t heading, - std::int32_t proximityAlertRadius) const { - std::vector args; - args.reserve(9); - - if (chatId.which() == 0) { // std::int64_t - if (boost::get(chatId) != 0) { - args.emplace_back("chat_id", chatId); - } - } else { // std::string - if (boost::get(chatId) != "") { - args.emplace_back("chat_id", chatId); - } - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - args.emplace_back("latitude", latitude); - args.emplace_back("longitude", longitude); - if (horizontalAccuracy) { - args.emplace_back("horizontal_accuracy", horizontalAccuracy); - } - if (heading) { - args.emplace_back("heading", heading); - } - if (proximityAlertRadius) { - args.emplace_back("proximity_alert_radius", proximityAlertRadius); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseInlineKeyboardMarkup(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("editMessageLiveLocation", args)); -} - -Message::Ptr Api::stopMessageLiveLocation(boost::variant chatId, - std::int32_t messageId, - const std::string& inlineMessageId, - InlineKeyboardMarkup::Ptr replyMarkup) const { - std::vector args; - args.reserve(4); - - if (chatId.which() == 0) { // std::int64_t - if (boost::get(chatId) != 0) { - args.emplace_back("chat_id", chatId); - } - } else { // std::string - if (boost::get(chatId) != "") { - args.emplace_back("chat_id", chatId); - } - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseInlineKeyboardMarkup(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("stopMessageLiveLocation", args)); -} - -Message::Ptr Api::sendVenue(boost::variant chatId, - float latitude, - float longitude, - const std::string& title, - const std::string& address, - const std::string& foursquareId, - const std::string& foursquareType, - bool disableNotification, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - const std::string& googlePlaceId, - const std::string& googlePlaceType, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(15); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("latitude", latitude); - args.emplace_back("longitude", longitude); - args.emplace_back("title", title); - args.emplace_back("address", address); - if (!foursquareId.empty()) { - args.emplace_back("foursquare_id", foursquareId); - } - if (!foursquareType.empty()) { - args.emplace_back("foursquare_type", foursquareType); - } - if (!googlePlaceId.empty()) { - args.emplace_back("google_place_id", googlePlaceId); - } - if (!googlePlaceType.empty()) { - args.emplace_back("google_place_type", googlePlaceType); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendVenue", args)); -} - -Message::Ptr Api::sendContact(boost::variant chatId, - const std::string& phoneNumber, - const std::string& firstName, - const std::string& lastName , - const std::string& vcard, - bool disableNotification, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(11); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("phone_number", phoneNumber); - args.emplace_back("first_name", firstName); - if (!lastName.empty()) { - args.emplace_back("last_name", lastName); - } - if (!vcard.empty()) { - args.emplace_back("vcard", vcard); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendContact", args)); -} - -Message::Ptr Api::sendPoll(boost::variant chatId, - const std::string& question, - const std::vector& options, - bool disableNotification, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - bool isAnonymous, - const std::string& type, - bool allowsMultipleAnswers, - std::int32_t correctOptionId, - const std::string& explanation, - const std::string& explanationParseMode, - const std::vector& explanationEntities, - std::int32_t openPeriod, - std::int32_t closeDate, - bool isClosed, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(19); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("question", question); - args.emplace_back("options", _tgTypeParser.parseArray( - [](const std::string& option)->std::string { - return "\"" + StringTools::escapeJsonString(option) + "\""; - }, options)); - if (!isAnonymous) { - args.emplace_back("is_anonymous", isAnonymous); - } - if (!type.empty()) { - args.emplace_back("type", type); - } - if (allowsMultipleAnswers) { - args.emplace_back("allows_multiple_answers", allowsMultipleAnswers); - } - if (correctOptionId != -1) { - args.emplace_back("correct_option_id", correctOptionId); - } - if (!explanation.empty()) { - args.emplace_back("explanation", explanation); - } - if (!explanationParseMode.empty()) { - args.emplace_back("explanation_parse_mode", explanationParseMode); - } - if (!explanationEntities.empty()) { - args.emplace_back("explanation_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, explanationEntities)); - } - if (openPeriod != 0) { - args.emplace_back("open_period", openPeriod); - } - if (closeDate != 0) { - args.emplace_back("close_date", closeDate); - } - if (isClosed) { - args.emplace_back("is_closed", isClosed); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendPoll", args)); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("stopMessageLiveLocation", args)); +} + +Message::Ptr Api::sendVenue( + boost::variant chatId, float latitude, + float longitude, const std::string &title, const std::string &address, + const std::string &foursquareId, const std::string &foursquareType, + bool disableNotification, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, const std::string &googlePlaceId, + const std::string &googlePlaceType, std::int32_t messageThreadId, + bool protectContent, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(15); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("latitude", latitude); + args.emplace_back("longitude", longitude); + args.emplace_back("title", title); + args.emplace_back("address", address); + if (!foursquareId.empty()) { + args.emplace_back("foursquare_id", foursquareId); + } + if (!foursquareType.empty()) { + args.emplace_back("foursquare_type", foursquareType); + } + if (!googlePlaceId.empty()) { + args.emplace_back("google_place_id", googlePlaceId); + } + if (!googlePlaceType.empty()) { + args.emplace_back("google_place_type", googlePlaceType); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendVenue", args)); +} + +Message::Ptr +Api::sendContact(boost::variant chatId, + const std::string &phoneNumber, const std::string &firstName, + const std::string &lastName, const std::string &vcard, + bool disableNotification, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, std::int32_t messageThreadId, + bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(11); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("phone_number", phoneNumber); + args.emplace_back("first_name", firstName); + if (!lastName.empty()) { + args.emplace_back("last_name", lastName); + } + if (!vcard.empty()) { + args.emplace_back("vcard", vcard); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendContact", args)); +} + +Message::Ptr Api::sendPoll( + boost::variant chatId, + const std::string &question, const std::vector &options, + bool disableNotification, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, bool isAnonymous, const std::string &type, + bool allowsMultipleAnswers, std::int32_t correctOptionId, + const std::string &explanation, const std::string &explanationParseMode, + const std::vector &explanationEntities, + std::int32_t openPeriod, std::int32_t closeDate, bool isClosed, + std::int32_t messageThreadId, bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(19); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("question", question); + args.emplace_back("options", putJSON(escapeJSONStringVec(options))); + if (!isAnonymous) { + args.emplace_back("is_anonymous", isAnonymous); + } + if (!type.empty()) { + args.emplace_back("type", type); + } + if (allowsMultipleAnswers) { + args.emplace_back("allows_multiple_answers", allowsMultipleAnswers); + } + if (correctOptionId != -1) { + args.emplace_back("correct_option_id", correctOptionId); + } + if (!explanation.empty()) { + args.emplace_back("explanation", explanation); + } + if (!explanationParseMode.empty()) { + args.emplace_back("explanation_parse_mode", explanationParseMode); + } + if (!explanationEntities.empty()) { + args.emplace_back("explanation_entities", putJSON(explanationEntities)); + } + if (openPeriod != 0) { + args.emplace_back("open_period", openPeriod); + } + if (closeDate != 0) { + args.emplace_back("close_date", closeDate); + } + if (isClosed) { + args.emplace_back("is_closed", isClosed); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendPoll", args)); } Message::Ptr Api::sendDice(boost::variant chatId, bool disableNotification, ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, - const std::string& emoji, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(8); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (!emoji.empty()) { - args.emplace_back("emoji", emoji); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } + const std::string &emoji, + std::int32_t messageThreadId, bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(8); - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDice", args)); + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (!emoji.empty()) { + args.emplace_back("emoji", emoji); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendDice", args)); } bool Api::setMessageReaction(boost::variant chatId, std::int32_t messageId, - const std::vector& reaction, + const std::vector &reaction, bool isBig) const { - std::vector args; - args.reserve(4); + std::vector args; + args.reserve(4); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_id", messageId); - if (!reaction.empty()) { - args.emplace_back("reaction", _tgTypeParser.parseArray(&TgTypeParser::parseReactionType, reaction)); - } - if (isBig) { - args.emplace_back("is_big", isBig); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("message_id", messageId); + if (!reaction.empty()) { + args.emplace_back("reaction", putJSON(reaction)); + } + if (isBig) { + args.emplace_back("is_big", isBig); + } - return sendRequest("setMessageReaction", args).get("", false); + return sendRequest("setMessageReaction", args).get("", false); } -bool Api::sendChatAction(std::int64_t chatId, - const std::string& action, +bool Api::sendChatAction(std::int64_t chatId, const std::string &action, std::int32_t messageThreadId, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(4); + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(4); - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - args.emplace_back("action", action); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + args.emplace_back("action", action); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } - return sendRequest("sendChatAction", args).get("", false); + return sendRequest("sendChatAction", args).get("", false); } UserProfilePhotos::Ptr Api::getUserProfilePhotos(std::int64_t userId, std::int32_t offset, std::int32_t limit) const { - std::vector args; - args.reserve(3); + std::vector args; + args.reserve(3); - args.emplace_back("user_id", userId); - if (offset) { - args.emplace_back("offset", offset); - } - if (limit != 100) { - args.emplace_back("limit", std::max(1, std::min(100, limit))); - } + args.emplace_back("user_id", userId); + if (offset) { + args.emplace_back("offset", offset); + } + if (limit != 100) { + args.emplace_back("limit", std::max(1, std::min(100, limit))); + } - return _tgTypeParser.parseJsonAndGetUserProfilePhotos(sendRequest("getUserProfilePhotos", args)); + return parse(sendRequest("getUserProfilePhotos", args)); } -File::Ptr Api::getFile(const std::string& fileId) const { - std::vector args; - args.reserve(1); +File::Ptr Api::getFile(const std::string &fileId) const { + std::vector args; + args.reserve(1); - args.emplace_back("file_id", fileId); + args.emplace_back("file_id", fileId); - return _tgTypeParser.parseJsonAndGetFile(sendRequest("getFile", args)); + return parse(sendRequest("getFile", args)); } bool Api::banChatMember(boost::variant chatId, - std::int64_t userId, - std::int32_t untilDate, + std::int64_t userId, std::int32_t untilDate, bool revokeMessages) const { - std::vector args; - args.reserve(4); + std::vector args; + args.reserve(4); - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); - if (untilDate != 0) { - args.emplace_back("until_date", untilDate); - } - if (revokeMessages) { - args.emplace_back("revoke_messages", revokeMessages); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + if (untilDate != 0) { + args.emplace_back("until_date", untilDate); + } + if (revokeMessages) { + args.emplace_back("revoke_messages", revokeMessages); + } - return sendRequest("banChatMember", args).get("", false); + return sendRequest("banChatMember", args).get("", false); } bool Api::unbanChatMember(boost::variant chatId, - std::int64_t userId, - bool onlyIfBanned) const { - std::vector args; - args.reserve(3); + std::int64_t userId, bool onlyIfBanned) const { + std::vector args; + args.reserve(3); - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); - if (onlyIfBanned) { - args.emplace_back("only_if_banned", onlyIfBanned); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + if (onlyIfBanned) { + args.emplace_back("only_if_banned", onlyIfBanned); + } - return sendRequest("unbanChatMember", args).get("", false); + return sendRequest("unbanChatMember", args).get("", false); } bool Api::restrictChatMember(boost::variant chatId, @@ -1242,1636 +1188,1616 @@ bool Api::restrictChatMember(boost::variant chatId, TgBot::ChatPermissions::Ptr permissions, std::uint32_t untilDate, bool useIndependentChatPermissions) const { - std::vector args; - args.reserve(5); + std::vector args; + args.reserve(5); - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); - args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); - if (useIndependentChatPermissions != false) { - args.emplace_back("use_independent_chat_permissions", useIndependentChatPermissions); - } - if (untilDate != 0) { - args.emplace_back("until_date", untilDate); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + args.emplace_back("permissions", putJSON(permissions)); + if (useIndependentChatPermissions != false) { + args.emplace_back("use_independent_chat_permissions", + useIndependentChatPermissions); + } + if (untilDate != 0) { + args.emplace_back("until_date", untilDate); + } - return sendRequest("restrictChatMember", args).get("", false); + return sendRequest("restrictChatMember", args).get("", false); } bool Api::promoteChatMember(boost::variant chatId, - std::int64_t userId, - bool canChangeInfo, - bool canPostMessages, - bool canEditMessages, - bool canDeleteMessages, - bool canInviteUsers, - bool canPinMessages, - bool canPromoteMembers, - bool isAnonymous, - bool canManageChat, - bool canManageVideoChats, - bool canRestrictMembers, - bool canManageTopics, - bool canPostStories, - bool canEditStories, - bool canDeleteStories) const { - std::vector args; - args.reserve(17); - - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); - if (isAnonymous != false) { - args.emplace_back("is_anonymous", isAnonymous); - } - if (canManageChat != false) { - args.emplace_back("can_manage_chat", canManageChat); - } - if (canPostMessages != false) { - args.emplace_back("can_post_messages", canPostMessages); - } - if (canEditMessages != false) { - args.emplace_back("can_edit_messages", canEditMessages); - } - if (canDeleteMessages != false) { - args.emplace_back("can_delete_messages", canDeleteMessages); - } - if (canPostStories != false) { - args.emplace_back("can_post_stories", canPostStories); - } - if (canEditStories != false) { - args.emplace_back("can_edit_stories", canEditStories); - } - if (canDeleteStories != false) { - args.emplace_back("can_delete_stories", canDeleteStories); - } - if (canManageVideoChats != false) { - args.emplace_back("can_manage_video_chats", canManageVideoChats); - } - if (canRestrictMembers != false) { - args.emplace_back("can_restrict_members", canRestrictMembers); - } - if (canPromoteMembers != false) { - args.emplace_back("can_promote_members", canPromoteMembers); - } - if (canChangeInfo != false) { - args.emplace_back("can_change_info", canChangeInfo); - } - if (canInviteUsers != false) { - args.emplace_back("can_invite_users", canInviteUsers); - } - if (canPinMessages != false) { - args.emplace_back("can_pin_messages", canPinMessages); - } - if (canManageTopics != false) { - args.emplace_back("can_manage_topics", canManageTopics); - } - - return sendRequest("promoteChatMember", args).get("", false); -} - -bool Api::setChatAdministratorCustomTitle(boost::variant chatId, - std::int64_t userId, - const std::string& customTitle) const { - std::vector args; - args.reserve(3); - - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); - args.emplace_back("custom_title", customTitle); - - return sendRequest("setChatAdministratorCustomTitle", args).get("", false); + std::int64_t userId, bool canChangeInfo, + bool canPostMessages, bool canEditMessages, + bool canDeleteMessages, bool canInviteUsers, + bool canPinMessages, bool canPromoteMembers, + bool isAnonymous, bool canManageChat, + bool canManageVideoChats, bool canRestrictMembers, + bool canManageTopics, bool canPostStories, + bool canEditStories, bool canDeleteStories) const { + std::vector args; + args.reserve(17); + + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + if (isAnonymous != false) { + args.emplace_back("is_anonymous", isAnonymous); + } + if (canManageChat != false) { + args.emplace_back("can_manage_chat", canManageChat); + } + if (canPostMessages != false) { + args.emplace_back("can_post_messages", canPostMessages); + } + if (canEditMessages != false) { + args.emplace_back("can_edit_messages", canEditMessages); + } + if (canDeleteMessages != false) { + args.emplace_back("can_delete_messages", canDeleteMessages); + } + if (canPostStories != false) { + args.emplace_back("can_post_stories", canPostStories); + } + if (canEditStories != false) { + args.emplace_back("can_edit_stories", canEditStories); + } + if (canDeleteStories != false) { + args.emplace_back("can_delete_stories", canDeleteStories); + } + if (canManageVideoChats != false) { + args.emplace_back("can_manage_video_chats", canManageVideoChats); + } + if (canRestrictMembers != false) { + args.emplace_back("can_restrict_members", canRestrictMembers); + } + if (canPromoteMembers != false) { + args.emplace_back("can_promote_members", canPromoteMembers); + } + if (canChangeInfo != false) { + args.emplace_back("can_change_info", canChangeInfo); + } + if (canInviteUsers != false) { + args.emplace_back("can_invite_users", canInviteUsers); + } + if (canPinMessages != false) { + args.emplace_back("can_pin_messages", canPinMessages); + } + if (canManageTopics != false) { + args.emplace_back("can_manage_topics", canManageTopics); + } + + return sendRequest("promoteChatMember", args).get("", false); +} + +bool Api::setChatAdministratorCustomTitle( + boost::variant chatId, std::int64_t userId, + const std::string &customTitle) const { + std::vector args; + args.reserve(3); + + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + args.emplace_back("custom_title", customTitle); + + return sendRequest("setChatAdministratorCustomTitle", args) + .get("", false); } bool Api::banChatSenderChat(boost::variant chatId, std::int64_t senderChatId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("sender_chat_id", senderChatId); + args.emplace_back("chat_id", chatId); + args.emplace_back("sender_chat_id", senderChatId); - return sendRequest("banChatSenderChat", args).get("", false); + return sendRequest("banChatSenderChat", args).get("", false); } bool Api::unbanChatSenderChat(boost::variant chatId, std::int64_t senderChatId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("sender_chat_id", senderChatId); + args.emplace_back("chat_id", chatId); + args.emplace_back("sender_chat_id", senderChatId); - return sendRequest("unbanChatSenderChat", args).get("", false); + return sendRequest("unbanChatSenderChat", args).get("", false); } bool Api::setChatPermissions(boost::variant chatId, ChatPermissions::Ptr permissions, bool useIndependentChatPermissions) const { - std::vector args; - args.reserve(3); + std::vector args; + args.reserve(3); - args.emplace_back("chat_id", chatId); - args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); - if (useIndependentChatPermissions) { - args.emplace_back("use_independent_chat_permissions", useIndependentChatPermissions); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("permissions", putJSON(permissions)); + if (useIndependentChatPermissions) { + args.emplace_back("use_independent_chat_permissions", + useIndependentChatPermissions); + } - return sendRequest("setChatPermissions", args).get("", false); + return sendRequest("setChatPermissions", args).get("", false); } -std::string Api::exportChatInviteLink(boost::variant chatId) const { - std::vector args; - args.reserve(1); +std::string Api::exportChatInviteLink( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("exportChatInviteLink", args).get("", ""); + return sendRequest("exportChatInviteLink", args).get("", ""); } -ChatInviteLink::Ptr Api::createChatInviteLink(boost::variant chatId, - std::int32_t expireDate, - std::int32_t memberLimit, - const std::string& name, - bool createsJoinRequest) const { - std::vector args; - args.reserve(5); +ChatInviteLink::Ptr +Api::createChatInviteLink(boost::variant chatId, + std::int32_t expireDate, std::int32_t memberLimit, + const std::string &name, + bool createsJoinRequest) const { + std::vector args; + args.reserve(5); - args.emplace_back("chat_id", chatId); - if (!name.empty()) { - args.emplace_back("name", name); - } - if (expireDate != 0) { - args.emplace_back("expire_date", expireDate); - } - if (memberLimit != 0) { - args.emplace_back("member_limit", memberLimit); - } - if (createsJoinRequest) { - args.emplace_back("createsJoinRequest", createsJoinRequest); - } - - return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("createChatInviteLink", args)); -} - -ChatInviteLink::Ptr Api::editChatInviteLink(boost::variant chatId, - const std::string& inviteLink, - std::int32_t expireDate, - std::int32_t memberLimit, - const std::string& name, - bool createsJoinRequest) const { - std::vector args; - args.reserve(6); - - args.emplace_back("chat_id", chatId); - args.emplace_back("invite_link", inviteLink); - if (!name.empty()) { - args.emplace_back("name", name); - } - if (expireDate != 0) { - args.emplace_back("expire_date", expireDate); - } - if (memberLimit != 0) { - args.emplace_back("member_limit", memberLimit); - } - if (createsJoinRequest) { - args.emplace_back("createsJoinRequest", createsJoinRequest); - } + args.emplace_back("chat_id", chatId); + if (!name.empty()) { + args.emplace_back("name", name); + } + if (expireDate != 0) { + args.emplace_back("expire_date", expireDate); + } + if (memberLimit != 0) { + args.emplace_back("member_limit", memberLimit); + } + if (createsJoinRequest) { + args.emplace_back("createsJoinRequest", createsJoinRequest); + } + + return parse(sendRequest("createChatInviteLink", args)); +} + +ChatInviteLink::Ptr +Api::editChatInviteLink(boost::variant chatId, + const std::string &inviteLink, std::int32_t expireDate, + std::int32_t memberLimit, const std::string &name, + bool createsJoinRequest) const { + std::vector args; + args.reserve(6); + + args.emplace_back("chat_id", chatId); + args.emplace_back("invite_link", inviteLink); + if (!name.empty()) { + args.emplace_back("name", name); + } + if (expireDate != 0) { + args.emplace_back("expire_date", expireDate); + } + if (memberLimit != 0) { + args.emplace_back("member_limit", memberLimit); + } + if (createsJoinRequest) { + args.emplace_back("createsJoinRequest", createsJoinRequest); + } - return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("editChatInviteLink", args)); + return parse(sendRequest("editChatInviteLink", args)); } -ChatInviteLink::Ptr Api::revokeChatInviteLink(boost::variant chatId, - const std::string& inviteLink) const { - std::vector args; - args.reserve(2); +ChatInviteLink::Ptr +Api::revokeChatInviteLink(boost::variant chatId, + const std::string &inviteLink) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("invite_link", inviteLink); + args.emplace_back("chat_id", chatId); + args.emplace_back("invite_link", inviteLink); - return _tgTypeParser.parseJsonAndGetChatInviteLink(sendRequest("revokeChatInviteLink", args)); + return parse(sendRequest("revokeChatInviteLink", args)); } -bool Api::approveChatJoinRequest(boost::variant chatId, - std::int64_t userId) const { - std::vector args; - args.reserve(2); +bool Api::approveChatJoinRequest( + boost::variant chatId, + std::int64_t userId) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); - return sendRequest("approveChatJoinRequest", args).get("", false); + return sendRequest("approveChatJoinRequest", args).get("", false); } -bool Api::declineChatJoinRequest(boost::variant chatId, - std::int64_t userId) const { - std::vector args; - args.reserve(2); +bool Api::declineChatJoinRequest( + boost::variant chatId, + std::int64_t userId) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); - return sendRequest("declineChatJoinRequest", args).get("", false); + return sendRequest("declineChatJoinRequest", args).get("", false); } bool Api::setChatPhoto(boost::variant chatId, const InputFile::Ptr photo) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("photo", photo->data, true, photo->mimeType, photo->fileName); + args.emplace_back("chat_id", chatId); + args.emplace_back("photo", photo->data, true, photo->mimeType, + photo->fileName); - return sendRequest("setChatPhoto", args).get("", false); + return sendRequest("setChatPhoto", args).get("", false); } -bool Api::deleteChatPhoto(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool Api::deleteChatPhoto( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("deleteChatPhoto", args).get("", false); + return sendRequest("deleteChatPhoto", args).get("", false); } bool Api::setChatTitle(boost::variant chatId, - const std::string& title) const { - std::vector args; - args.reserve(2); - - args.emplace_back("chat_id", chatId); - args.emplace_back("title", title); + const std::string &title) const { + std::vector args; + args.reserve(2); - return sendRequest("setChatTitle", args).get("", false); + args.emplace_back("chat_id", chatId); + args.emplace_back("title", title); + + return sendRequest("setChatTitle", args).get("", false); } bool Api::setChatDescription(boost::variant chatId, - const std::string& description) const { - std::vector args; - args.reserve(2); + const std::string &description) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - if (!description.empty()) { - args.emplace_back("description", description); - } + args.emplace_back("chat_id", chatId); + if (!description.empty()) { + args.emplace_back("description", description); + } - return sendRequest("setChatDescription", args).get("", false); + return sendRequest("setChatDescription", args).get("", false); } bool Api::pinChatMessage(boost::variant chatId, std::int32_t messageId, bool disableNotification) const { - std::vector args; - args.reserve(3); + std::vector args; + args.reserve(3); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_id", messageId); - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("message_id", messageId); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } - return sendRequest("pinChatMessage", args).get("", false); + return sendRequest("pinChatMessage", args).get("", false); } bool Api::unpinChatMessage(boost::variant chatId, std::int32_t messageId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - if (messageId != 0) { - args.emplace_back("message_id", messageId); - } + args.emplace_back("chat_id", chatId); + if (messageId != 0) { + args.emplace_back("message_id", messageId); + } - return sendRequest("unpinChatMessage", args).get("", false); + return sendRequest("unpinChatMessage", args).get("", false); } -bool Api::unpinAllChatMessages(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool Api::unpinAllChatMessages( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("unpinAllChatMessages", args).get("", false); + return sendRequest("unpinAllChatMessages", args).get("", false); } bool Api::leaveChat(boost::variant chatId) const { - std::vector args; - args.reserve(1); + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("leaveChat", args).get("", false); + return sendRequest("leaveChat", args).get("", false); } Chat::Ptr Api::getChat(boost::variant chatId) const { - std::vector args; - args.reserve(1); + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return _tgTypeParser.parseJsonAndGetChat(sendRequest("getChat", args)); + return parse(sendRequest("getChat", args)); } -std::vector Api::getChatAdministrators(boost::variant chatId) const { - std::vector args; - args.reserve(1); +std::vector Api::getChatAdministrators( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetChatMember, sendRequest("getChatAdministrators", args)); + return parseArray(sendRequest("getChatAdministrators", args)); } -int32_t Api::getChatMemberCount(boost::variant chatId) const { - std::vector args; - args.reserve(1); +int32_t Api::getChatMemberCount( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("getChatMemberCount", args).get("", 0); + return sendRequest("getChatMemberCount", args).get("", 0); } -ChatMember::Ptr Api::getChatMember(boost::variant chatId, - std::int64_t userId) const { - std::vector args; - args.reserve(2); +ChatMember::Ptr +Api::getChatMember(boost::variant chatId, + std::int64_t userId) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); - return _tgTypeParser.parseJsonAndGetChatMember(sendRequest("getChatMember", args)); + return parse(sendRequest("getChatMember", args)); } bool Api::setChatStickerSet(boost::variant chatId, - const std::string& stickerSetName) const { - std::vector args; - args.reserve(2); + const std::string &stickerSetName) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("sticker_set_name ", stickerSetName); + args.emplace_back("chat_id", chatId); + args.emplace_back("sticker_set_name ", stickerSetName); - return sendRequest("setChatStickerSet", args).get("", false); + return sendRequest("setChatStickerSet", args).get("", false); } -bool Api::deleteChatStickerSet(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool Api::deleteChatStickerSet( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("deleteChatStickerSet", args).get("", false); + return sendRequest("deleteChatStickerSet", args).get("", false); } std::vector Api::getForumTopicIconStickers() const { - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetSticker, sendRequest("getForumTopicIconStickers")); -} - -ForumTopic::Ptr Api::createForumTopic(boost::variant chatId, - const std::string& name, - std::int32_t iconColor, - const std::string& iconCustomEmojiId) const { - std::vector args; - args.reserve(4); - - args.emplace_back("chat_id", chatId); + return parseArray(sendRequest("getForumTopicIconStickers")); +} + +ForumTopic::Ptr +Api::createForumTopic(boost::variant chatId, + const std::string &name, std::int32_t iconColor, + const std::string &iconCustomEmojiId) const { + std::vector args; + args.reserve(4); + + args.emplace_back("chat_id", chatId); + args.emplace_back("name", name); + if (iconColor != 0) { + args.emplace_back("icon_color", iconColor); + } + if (!iconCustomEmojiId.empty()) { + args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); + } + + return parse(sendRequest("createForumTopic", args)); +} + +bool Api::editForumTopic( + boost::variant chatId, + std::int32_t messageThreadId, const std::string &name, + boost::variant iconCustomEmojiId) const { + std::vector args; + args.reserve(4); + + args.emplace_back("chat_id", chatId); + args.emplace_back("message_thread_id", messageThreadId); + if (!name.empty()) { args.emplace_back("name", name); - if (iconColor != 0) { - args.emplace_back("icon_color", iconColor); - } - if (!iconCustomEmojiId.empty()) { - args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); - } - - return _tgTypeParser.parseJsonAndGetForumTopic(sendRequest("createForumTopic", args)); -} - -bool Api::editForumTopic(boost::variant chatId, - std::int32_t messageThreadId, - const std::string& name, - boost::variant iconCustomEmojiId) const { - std::vector args; - args.reserve(4); - - args.emplace_back("chat_id", chatId); - args.emplace_back("message_thread_id", messageThreadId); - if (!name.empty()) { - args.emplace_back("name", name); + } + if (iconCustomEmojiId.which() == 0) { // std::int32_t + if (boost::get(iconCustomEmojiId) != 0) { + args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); } - if (iconCustomEmojiId.which() == 0) { // std::int32_t - if (boost::get(iconCustomEmojiId) != 0) { - args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); - } - } else { // std::string - if (boost::get(iconCustomEmojiId) != "") { - args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); - } + } else { // std::string + if (boost::get(iconCustomEmojiId) != "") { + args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); } + } - return sendRequest("editForumTopic", args).get("", false); + return sendRequest("editForumTopic", args).get("", false); } bool Api::closeForumTopic(boost::variant chatId, std::int32_t messageThreadId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_thread_id", messageThreadId); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_thread_id", messageThreadId); - return sendRequest("closeForumTopic", args).get("", false); - } + return sendRequest("closeForumTopic", args).get("", false); +} bool Api::reopenForumTopic(boost::variant chatId, std::int32_t messageThreadId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_thread_id", messageThreadId); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_thread_id", messageThreadId); - return sendRequest("reopenForumTopic", args).get("", false); + return sendRequest("reopenForumTopic", args).get("", false); } bool Api::deleteForumTopic(boost::variant chatId, std::int32_t messageThreadId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_thread_id", messageThreadId); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_thread_id", messageThreadId); - return sendRequest("deleteForumTopic", args).get("", false); + return sendRequest("deleteForumTopic", args).get("", false); } -bool Api::unpinAllForumTopicMessages(boost::variant chatId, - std::int32_t messageThreadId) const { - std::vector args; - args.reserve(2); +bool Api::unpinAllForumTopicMessages( + boost::variant chatId, + std::int32_t messageThreadId) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_thread_id", messageThreadId); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_thread_id", messageThreadId); - return sendRequest("unpinAllForumTopicMessages", args).get("", false); + return sendRequest("unpinAllForumTopicMessages", args).get("", false); } -bool Api::editGeneralForumTopic(boost::variant chatId, - std::string name) const { - std::vector args; - args.reserve(2); +bool Api::editGeneralForumTopic( + boost::variant chatId, std::string name) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("name", name); + args.emplace_back("chat_id", chatId); + args.emplace_back("name", name); - return sendRequest("editGeneralForumTopic", args).get("", false); + return sendRequest("editGeneralForumTopic", args).get("", false); } -bool Api::closeGeneralForumTopic(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool Api::closeGeneralForumTopic( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("closeGeneralForumTopic", args).get("", false); + return sendRequest("closeGeneralForumTopic", args).get("", false); } -bool Api::reopenGeneralForumTopic(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool Api::reopenGeneralForumTopic( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("reopenGeneralForumTopic", args).get("", false); + return sendRequest("reopenGeneralForumTopic", args).get("", false); } -bool Api::hideGeneralForumTopic(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool Api::hideGeneralForumTopic( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("hideGeneralForumTopic", args).get("", false); + return sendRequest("hideGeneralForumTopic", args).get("", false); } -bool Api::unhideGeneralForumTopic(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool Api::unhideGeneralForumTopic( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("unhideGeneralForumTopic", args).get("", false); + return sendRequest("unhideGeneralForumTopic", args).get("", false); } -bool Api::unpinAllGeneralForumTopicMessages(boost::variant chatId) const { - std::vector args; - args.reserve(1); +bool Api::unpinAllGeneralForumTopicMessages( + boost::variant chatId) const { + std::vector args; + args.reserve(1); - args.emplace_back("chat_id", chatId); + args.emplace_back("chat_id", chatId); - return sendRequest("unpinAllGeneralForumTopicMessages", args).get("", false); + return sendRequest("unpinAllGeneralForumTopicMessages", args) + .get("", false); } -bool Api::answerCallbackQuery(const std::string& callbackQueryId, - const std::string& text, - bool showAlert, - const std::string& url, +bool Api::answerCallbackQuery(const std::string &callbackQueryId, + const std::string &text, bool showAlert, + const std::string &url, std::int32_t cacheTime) const { - std::vector args; - args.reserve(5); + std::vector args; + args.reserve(5); - args.emplace_back("callback_query_id", callbackQueryId); - if (!text.empty()) { - args.emplace_back("text", text); - } - if (showAlert) { - args.emplace_back("show_alert", showAlert); - } - if (!url.empty()) { - args.emplace_back("url", url); - } - if (cacheTime) { - args.emplace_back("cache_time", cacheTime); - } + args.emplace_back("callback_query_id", callbackQueryId); + if (!text.empty()) { + args.emplace_back("text", text); + } + if (showAlert) { + args.emplace_back("show_alert", showAlert); + } + if (!url.empty()) { + args.emplace_back("url", url); + } + if (cacheTime) { + args.emplace_back("cache_time", cacheTime); + } - return sendRequest("answerCallbackQuery", args).get("", false); + return sendRequest("answerCallbackQuery", args).get("", false); } -UserChatBoosts::Ptr Api::getUserChatBoosts(boost::variant chatId, - std::int32_t userId) const { - std::vector args; - args.reserve(2); +UserChatBoosts::Ptr +Api::getUserChatBoosts(boost::variant chatId, + std::int32_t userId) const { + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("user_id", userId); + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); - return _tgTypeParser.parseJsonAndGetUserChatBoosts(sendRequest("getUserChatBoosts", args)); + return parse(sendRequest("getUserChatBoosts", args)); } -BusinessConnection::Ptr Api::getBusinessConnection(const std::string& businessConnectionId) const { - std::vector args; - args.reserve(1); +BusinessConnection::Ptr +Api::getBusinessConnection(const std::string &businessConnectionId) const { + std::vector args; + args.reserve(1); - args.emplace_back("business_connection_id", businessConnectionId); + args.emplace_back("business_connection_id", businessConnectionId); - return _tgTypeParser.parseJsonAndGetBusinessConnection(sendRequest("getBusinessConnection", args)); + return parse(sendRequest("getBusinessConnection", args)); } -bool Api::setMyCommands(const std::vector& commands, +bool Api::setMyCommands(const std::vector &commands, BotCommandScope::Ptr scope, - const std::string& languageCode) const { - std::vector args; - args.reserve(3); + const std::string &languageCode) const { + std::vector args; + args.reserve(3); - args.emplace_back("commands", _tgTypeParser.parseArray(&TgTypeParser::parseBotCommand, commands)); - if (scope != nullptr) { - args.emplace_back("scope", _tgTypeParser.parseBotCommandScope(scope)); - } - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + args.emplace_back("commands", putJSON(commands)); + if (scope != nullptr) { + args.emplace_back("scope", putJSON(scope)); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return sendRequest("setMyCommands", args).get("", false); + return sendRequest("setMyCommands", args).get("", false); } bool Api::deleteMyCommands(BotCommandScope::Ptr scope, - const std::string& languageCode) const { - std::vector args; - args.reserve(2); + const std::string &languageCode) const { + std::vector args; + args.reserve(2); - if (scope != nullptr) { - args.emplace_back("scope", _tgTypeParser.parseBotCommandScope(scope)); - } - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (scope != nullptr) { + args.emplace_back("scope", putJSON(scope)); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return sendRequest("deleteMyCommands", args).get("", false); + return sendRequest("deleteMyCommands", args).get("", false); } -std::vector Api::getMyCommands(BotCommandScope::Ptr scope, - const std::string& languageCode) const { - std::vector args; - args.reserve(2); +std::vector +Api::getMyCommands(BotCommandScope::Ptr scope, + const std::string &languageCode) const { + std::vector args; + args.reserve(2); - if (scope != nullptr) { - args.emplace_back("scope", _tgTypeParser.parseBotCommandScope(scope)); - } - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (scope != nullptr) { + args.emplace_back("scope", putJSON(scope)); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetBotCommand, sendRequest("getMyCommands", args)); + return parseArray(sendRequest("getMyCommands", args)); } -bool Api::setMyName(const std::string& name, - const std::string& languageCode) const { - std::vector args; - args.reserve(2); +bool Api::setMyName(const std::string &name, + const std::string &languageCode) const { + std::vector args; + args.reserve(2); - if (!name.empty()) { - args.emplace_back("name", name); - } - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (!name.empty()) { + args.emplace_back("name", name); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return sendRequest("setMyName", args).get("", false); + return sendRequest("setMyName", args).get("", false); } -BotName::Ptr Api::getMyName(const std::string& languageCode) const { - std::vector args; - args.reserve(1); +BotName::Ptr Api::getMyName(const std::string &languageCode) const { + std::vector args; + args.reserve(1); - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return _tgTypeParser.parseJsonAndGetBotName(sendRequest("getMyName", args)); + return parse(sendRequest("getMyName", args)); } -bool Api::setMyDescription(const std::string& description, - const std::string& languageCode) const { - std::vector args; - args.reserve(2); +bool Api::setMyDescription(const std::string &description, + const std::string &languageCode) const { + std::vector args; + args.reserve(2); - if (!description.empty()) { - args.emplace_back("description", description); - } - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (!description.empty()) { + args.emplace_back("description", description); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return sendRequest("setMyDescription", args).get("", false); + return sendRequest("setMyDescription", args).get("", false); } -BotDescription::Ptr Api::getMyDescription(const std::string& languageCode) const { - std::vector args; - args.reserve(1); +BotDescription::Ptr +Api::getMyDescription(const std::string &languageCode) const { + std::vector args; + args.reserve(1); - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return _tgTypeParser.parseJsonAndGetBotDescription(sendRequest("getMyDescription", args)); + return parse(sendRequest("getMyDescription", args)); } -bool Api::setMyShortDescription(const std::string& shortDescription, - const std::string& languageCode) const { - std::vector args; - args.reserve(2); +bool Api::setMyShortDescription(const std::string &shortDescription, + const std::string &languageCode) const { + std::vector args; + args.reserve(2); - if (!shortDescription.empty()) { - args.emplace_back("short_description", shortDescription); - } - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (!shortDescription.empty()) { + args.emplace_back("short_description", shortDescription); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return sendRequest("setMyShortDescription", args).get("", false); + return sendRequest("setMyShortDescription", args).get("", false); } -BotShortDescription::Ptr Api::getMyShortDescription(const std::string& languageCode) const { - std::vector args; - args.reserve(1); +BotShortDescription::Ptr +Api::getMyShortDescription(const std::string &languageCode) const { + std::vector args; + args.reserve(1); - if (!languageCode.empty()) { - args.emplace_back("language_code", languageCode); - } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } - return _tgTypeParser.parseJsonAndGetBotShortDescription(sendRequest("getMyShortDescription", args)); + return parse(sendRequest("getMyShortDescription", args)); } bool Api::setChatMenuButton(std::int64_t chatId, MenuButton::Ptr menuButton) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - if (chatId != 0) { - args.emplace_back("chat_id", chatId); - } - if (menuButton != nullptr) { - args.emplace_back("menu_button", _tgTypeParser.parseMenuButton(menuButton)); - } + if (chatId != 0) { + args.emplace_back("chat_id", chatId); + } + if (menuButton != nullptr) { + args.emplace_back("menu_button", putJSON(menuButton)); + } - return sendRequest("setChatMenuButton", args).get("", false); + return sendRequest("setChatMenuButton", args).get("", false); } MenuButton::Ptr Api::getChatMenuButton(std::int64_t chatId) const { - std::vector args; - args.reserve(1); + std::vector args; + args.reserve(1); - if (chatId != 0) { - args.emplace_back("chat_id", chatId); - } + if (chatId != 0) { + args.emplace_back("chat_id", chatId); + } - return _tgTypeParser.parseJsonAndGetMenuButton(sendRequest("getChatMenuButton", args)); + return parse(sendRequest("getChatMenuButton", args)); } bool Api::setMyDefaultAdministratorRights(ChatAdministratorRights::Ptr rights, bool forChannels) const { - std::vector args; - args.reserve(2); - - if (rights != nullptr) { - args.emplace_back("rights", _tgTypeParser.parseChatAdministratorRights(rights)); - } - if (forChannels) { - args.emplace_back("for_channels", forChannels); - } - - return sendRequest("setMyDefaultAdministratorRights", args).get("", false); -} - -ChatAdministratorRights::Ptr Api::getMyDefaultAdministratorRights(bool forChannels) const { - std::vector args; - args.reserve(1); - - if (forChannels) { - args.emplace_back("for_channels", forChannels); - } - - return _tgTypeParser.parseJsonAndGetChatAdministratorRights(sendRequest("getMyDefaultAdministratorRights", args)); -} - -Message::Ptr Api::editMessageText(const std::string& text, - boost::variant chatId, - std::int32_t messageId, - const std::string& inlineMessageId, - const std::string& parseMode, - LinkPreviewOptions::Ptr linkPreviewOptions, - InlineKeyboardMarkup::Ptr replyMarkup, - const std::vector& entities) const { - std::vector args; - args.reserve(8); - - if (chatId.which() == 0) { // std::int64_t - if (boost::get(chatId) != 0) { - args.emplace_back("chat_id", chatId); - } - } else { // std::string - if (boost::get(chatId) != "") { - args.emplace_back("chat_id", chatId); - } - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - args.emplace_back("text", text); - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!entities.empty()) { - args.emplace_back("entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, entities)); - } - if (linkPreviewOptions) { - args.emplace_back("link_preview_options", _tgTypeParser.parseLinkPreviewOptions(linkPreviewOptions)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseInlineKeyboardMarkup(replyMarkup)); - } - - boost::property_tree::ptree p = sendRequest("editMessageText", args); - if (p.get_child_optional("message_id")) { - return _tgTypeParser.parseJsonAndGetMessage(p); - } else { - return nullptr; - } -} + std::vector args; + args.reserve(2); -Message::Ptr Api::editMessageCaption(boost::variant chatId, - std::int32_t messageId, - const std::string& caption, - const std::string& inlineMessageId, - GenericReply::Ptr replyMarkup, - const std::string& parseMode, - const std::vector& captionEntities) const { - std::vector args; - args.reserve(7); - - if (chatId.which() == 0) { // std::int64_t - if (boost::get(chatId) != 0) { - args.emplace_back("chat_id", chatId); - } - } else { // std::string - if (boost::get(chatId) != "") { - args.emplace_back("chat_id", chatId); - } - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - if (!caption.empty()) { - args.emplace_back("caption", caption); - } - if (!parseMode.empty()) { - args.emplace_back("parse_mode", parseMode); - } - if (!captionEntities.empty()) { - args.emplace_back("caption_entities", _tgTypeParser.parseArray(&TgTypeParser::parseMessageEntity, captionEntities)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } + if (rights != nullptr) { + args.emplace_back("rights", putJSON(rights)); + } + if (forChannels) { + args.emplace_back("for_channels", forChannels); + } - boost::property_tree::ptree p = sendRequest("editMessageCaption", args); - if (p.get_child_optional("message_id")) { - return _tgTypeParser.parseJsonAndGetMessage(p); - } else { - return nullptr; - } + return sendRequest("setMyDefaultAdministratorRights", args) + .get("", false); } -Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, - boost::variant chatId, - std::int32_t messageId, - const std::string& inlineMessageId, - GenericReply::Ptr replyMarkup) const { - - std::vector args; - args.reserve(5); +ChatAdministratorRights::Ptr +Api::getMyDefaultAdministratorRights(bool forChannels) const { + std::vector args; + args.reserve(1); - if (chatId.which() == 0) { // std::int64_t - if (boost::get(chatId) != 0) { - args.emplace_back("chat_id", chatId); - } - } else { // std::string - if (boost::get(chatId) != "") { - args.emplace_back("chat_id", chatId); - } - } - args.emplace_back("media", _tgTypeParser.parseInputMedia(media)); - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } + if (forChannels) { + args.emplace_back("for_channels", forChannels); + } - boost::property_tree::ptree p = sendRequest("editMessageMedia", args); - if (p.get_child_optional("message_id")) { - return _tgTypeParser.parseJsonAndGetMessage(p); - } else { - return nullptr; - } + return parse( + sendRequest("getMyDefaultAdministratorRights", args)); } -Message::Ptr Api::editMessageReplyMarkup(boost::variant chatId, - std::int32_t messageId, - const std::string& inlineMessageId, - const GenericReply::Ptr replyMarkup) const { - - std::vector args; - args.reserve(4); +Message::Ptr Api::editMessageText( + const std::string &text, boost::variant chatId, + std::int32_t messageId, const std::string &inlineMessageId, + const std::string &parseMode, LinkPreviewOptions::Ptr linkPreviewOptions, + InlineKeyboardMarkup::Ptr replyMarkup, + const std::vector &entities) const { + std::vector args; + args.reserve(8); - if (chatId.which() == 0) { // std::int64_t - if (boost::get(chatId) != 0) { - args.emplace_back("chat_id", chatId); - } - } else { // std::string - if (boost::get(chatId) != "") { - args.emplace_back("chat_id", chatId); - } + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - boost::property_tree::ptree p = sendRequest("editMessageReplyMarkup", args); - if (p.get_child_optional("message_id")) { - return _tgTypeParser.parseJsonAndGetMessage(p); - } else { - return nullptr; + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); } + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + args.emplace_back("text", text); + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!entities.empty()) { + args.emplace_back("entities", putJSON(entities)); + } + if (linkPreviewOptions) { + args.emplace_back("link_preview_options", putJSON(linkPreviewOptions)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + boost::property_tree::ptree p = sendRequest("editMessageText", args); + if (p.get_child_optional("message_id")) { + return parse(p); + } else { + return nullptr; + } +} + +Message::Ptr Api::editMessageCaption( + boost::variant chatId, std::int32_t messageId, + const std::string &caption, const std::string &inlineMessageId, + GenericReply::Ptr replyMarkup, const std::string &parseMode, + const std::vector &captionEntities) const { + std::vector args; + args.reserve(7); + + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + if (!caption.empty()) { + args.emplace_back("caption", caption); + } + if (!parseMode.empty()) { + args.emplace_back("parse_mode", parseMode); + } + if (!captionEntities.empty()) { + args.emplace_back("caption_entities", putJSON(captionEntities)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + boost::property_tree::ptree p = sendRequest("editMessageCaption", args); + if (p.get_child_optional("message_id")) { + return parse(p); + } else { + return nullptr; + } +} + +Message::Ptr Api::editMessageMedia( + InputMedia::Ptr media, boost::variant chatId, + std::int32_t messageId, const std::string &inlineMessageId, + GenericReply::Ptr replyMarkup) const { + + std::vector args; + args.reserve(5); + + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } + } + args.emplace_back("media", putJSON(media)); + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + boost::property_tree::ptree p = sendRequest("editMessageMedia", args); + if (p.get_child_optional("message_id")) { + return parse(p); + } else { + return nullptr; + } +} + +Message::Ptr +Api::editMessageReplyMarkup(boost::variant chatId, + std::int32_t messageId, + const std::string &inlineMessageId, + const GenericReply::Ptr replyMarkup) const { + + std::vector args; + args.reserve(4); + + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + boost::property_tree::ptree p = sendRequest("editMessageReplyMarkup", args); + if (p.get_child_optional("message_id")) { + return parse(p); + } else { + return nullptr; + } } Poll::Ptr Api::stopPoll(boost::variant chatId, std::int64_t messageId, const InlineKeyboardMarkup::Ptr replyMarkup) const { - std::vector args; - args.reserve(3); + std::vector args; + args.reserve(3); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_id", messageId); - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } + args.emplace_back("chat_id", chatId); + args.emplace_back("message_id", messageId); + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } - return _tgTypeParser.parseJsonAndGetPoll(sendRequest("stopPoll", args)); + return parse(sendRequest("stopPoll", args)); } bool Api::deleteMessage(boost::variant chatId, std::int32_t messageId) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("chat_id", chatId); - args.emplace_back("message_id", messageId); + args.emplace_back("chat_id", chatId); + args.emplace_back("message_id", messageId); - return sendRequest("deleteMessage", args).get("", false); + return sendRequest("deleteMessage", args).get("", false); } bool Api::deleteMessages(boost::variant chatId, - const std::vector& messageIds) const { - std::vector args; - args.reserve(2); - - args.emplace_back("chat_id", chatId); - if (!messageIds.empty()) { - args.emplace_back("message_ids", _tgTypeParser.parseArray( - [] (const std::int32_t& i)->std::int32_t { - return i; - }, messageIds)); - } + const std::vector &messageIds) const { + std::vector args; + args.reserve(2); - return sendRequest("deleteMessages", args).get("", false); -} + args.emplace_back("chat_id", chatId); + if (!messageIds.empty()) { + args.emplace_back("message_ids", putJSON(messageIds)); + } -Message::Ptr Api::sendSticker(boost::variant chatId, - boost::variant sticker, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - bool disableNotification, - std::int32_t messageThreadId, - bool protectContent, - const std::string& emoji, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(9); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - if (sticker.which() == 0) { // InputFile::Ptr - auto file = boost::get(sticker); - args.emplace_back("sticker", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("sticker", boost::get(sticker)); - } - if (!emoji.empty()) { - args.emplace_back("emoji", emoji); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendSticker", args)); + return sendRequest("deleteMessages", args).get("", false); } -StickerSet::Ptr Api::getStickerSet(const std::string& name) const { - std::vector args; - args.reserve(1); +Message::Ptr Api::sendSticker( + boost::variant chatId, + boost::variant sticker, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, + bool disableNotification, std::int32_t messageThreadId, bool protectContent, + const std::string &emoji, const std::string &businessConnectionId) const { + std::vector args; + args.reserve(9); - args.emplace_back("name", name); + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (sticker.which() == 0) { // InputFile::Ptr + auto file = boost::get(sticker); + args.emplace_back("sticker", file->data, true, file->mimeType, + file->fileName); + } else { // std::string + args.emplace_back("sticker", boost::get(sticker)); + } + if (!emoji.empty()) { + args.emplace_back("emoji", emoji); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } - return _tgTypeParser.parseJsonAndGetStickerSet(sendRequest("getStickerSet", args)); + return parse(sendRequest("sendSticker", args)); } -std::vector Api::getCustomEmojiStickers(const std::vector& customEmojiIds) const { - std::vector args; - args.reserve(1); +StickerSet::Ptr Api::getStickerSet(const std::string &name) const { + std::vector args; + args.reserve(1); - args.emplace_back("custom_emoji_ids", _tgTypeParser.parseArray( - [] (const std::string& customEmojiId) -> std::string { - return "\"" + StringTools::escapeJsonString(customEmojiId) + "\""; - }, customEmojiIds)); + args.emplace_back("name", name); - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetSticker, sendRequest("getCustomEmojiStickers", args)); + return parse(sendRequest("getStickerSet", args)); } -File::Ptr Api::uploadStickerFile(std::int64_t userId, - InputFile::Ptr sticker, - const std::string& stickerFormat) const { - std::vector args; - args.reserve(3); +std::vector Api::getCustomEmojiStickers( + const std::vector &customEmojiIds) const { + std::vector args; + args.reserve(1); - args.emplace_back("user_id", userId); - args.emplace_back("sticker", sticker->data, true, sticker->mimeType, sticker->fileName); - args.emplace_back("sticker_format", stickerFormat); + args.emplace_back("custom_emoji_ids", + putJSON(escapeJSONStringVec(customEmojiIds))); - return _tgTypeParser.parseJsonAndGetFile(sendRequest("uploadStickerFile", args)); + return parseArray(sendRequest("getCustomEmojiStickers", args)); } -bool Api::createNewStickerSet(std::int64_t userId, - const std::string& name, - const std::string& title, - const std::vector& stickers, - Sticker::Type stickerType, - bool needsRepainting) const { - std::vector args; - args.reserve(6); +File::Ptr Api::uploadStickerFile(std::int64_t userId, InputFile::Ptr sticker, + const std::string &stickerFormat) const { + std::vector args; + args.reserve(3); - args.emplace_back("user_id", userId); - args.emplace_back("name", name); - args.emplace_back("title", title); - args.emplace_back("stickers", _tgTypeParser.parseArray(&TgTypeParser::parseInputSticker, stickers)); - if (stickerType == Sticker::Type::Regular) { - args.emplace_back("sticker_type", "regular"); - } else if (stickerType == Sticker::Type::Mask) { - args.emplace_back("sticker_type", "mask"); - } else if (stickerType == Sticker::Type::CustomEmoji) { - args.emplace_back("sticker_type", "custom_emoji"); - } - if (needsRepainting) { - args.emplace_back("needs_repainting", needsRepainting); - } + args.emplace_back("user_id", userId); + args.emplace_back("sticker", sticker->data, true, sticker->mimeType, + sticker->fileName); + args.emplace_back("sticker_format", stickerFormat); - return sendRequest("createNewStickerSet", args).get("", false); + return parse(sendRequest("uploadStickerFile", args)); } -bool Api::addStickerToSet(std::int64_t userId, - const std::string& name, +bool Api::createNewStickerSet(std::int64_t userId, const std::string &name, + const std::string &title, + const std::vector &stickers, + Sticker::Type stickerType, + bool needsRepainting) const { + std::vector args; + args.reserve(6); + + args.emplace_back("user_id", userId); + args.emplace_back("name", name); + args.emplace_back("title", title); + args.emplace_back("stickers", putJSON(stickers)); + if (stickerType == Sticker::Type::Regular) { + args.emplace_back("sticker_type", "regular"); + } else if (stickerType == Sticker::Type::Mask) { + args.emplace_back("sticker_type", "mask"); + } else if (stickerType == Sticker::Type::CustomEmoji) { + args.emplace_back("sticker_type", "custom_emoji"); + } + if (needsRepainting) { + args.emplace_back("needs_repainting", needsRepainting); + } + + return sendRequest("createNewStickerSet", args).get("", false); +} + +bool Api::addStickerToSet(std::int64_t userId, const std::string &name, InputSticker::Ptr sticker) const { - std::vector args; - args.reserve(3); + std::vector args; + args.reserve(3); - args.emplace_back("user_id", userId); - args.emplace_back("name", name); - args.emplace_back("sticker", _tgTypeParser.parseInputSticker(sticker)); + args.emplace_back("user_id", userId); + args.emplace_back("name", name); + args.emplace_back("sticker", putJSON(sticker)); - return sendRequest("addStickerToSet", args).get("", false); + return sendRequest("addStickerToSet", args).get("", false); } -bool Api::setStickerPositionInSet(const std::string& sticker, +bool Api::setStickerPositionInSet(const std::string &sticker, std::int32_t position) const { - std::vector args; - args.reserve(2); + std::vector args; + args.reserve(2); - args.emplace_back("sticker", sticker); - args.emplace_back("position", position); + args.emplace_back("sticker", sticker); + args.emplace_back("position", position); - return sendRequest("setStickerPositionInSet", args).get("", false); + return sendRequest("setStickerPositionInSet", args).get("", false); } -bool Api::deleteStickerFromSet(const std::string& sticker) const { - std::vector args; - args.reserve(1); +bool Api::deleteStickerFromSet(const std::string &sticker) const { + std::vector args; + args.reserve(1); - args.emplace_back("sticker", sticker); + args.emplace_back("sticker", sticker); - return sendRequest("deleteStickerFromSet", args).get("", false); + return sendRequest("deleteStickerFromSet", args).get("", false); } -bool Api::replaceStickerInSet(std::int64_t userId, - const std::string& name, - const std::string& oldSticker, - InputSticker::Ptr sticker) const { - std::vector args; - args.reserve(4); +bool Api::replaceStickerInSet(std::int64_t userId, const std::string &name, + const std::string &oldSticker, + InputSticker::Ptr sticker) const { + std::vector args; + args.reserve(4); - args.emplace_back("user_id", userId); - args.emplace_back("name", name); - args.emplace_back("old_sticker", oldSticker); - args.emplace_back("sticker", _tgTypeParser.parseInputSticker(sticker)); + args.emplace_back("user_id", userId); + args.emplace_back("name", name); + args.emplace_back("old_sticker", oldSticker); + args.emplace_back("sticker", putJSON(sticker)); - return sendRequest("replaceStickerInSet", args).get("", false); + return sendRequest("replaceStickerInSet", args).get("", false); } -bool Api::setStickerEmojiList(const std::string& sticker, - const std::vector& emojiList) const { - std::vector args; - args.reserve(2); +bool Api::setStickerEmojiList(const std::string &sticker, + const std::vector &emojiList) const { + std::vector args; + args.reserve(2); - args.emplace_back("sticker", sticker); - args.emplace_back("emoji_list", _tgTypeParser.parseArray( - [](const std::string& emoji)->std::string { - return "\"" + StringTools::escapeJsonString(emoji) + "\""; - }, emojiList)); - - return sendRequest("setStickerEmojiList", args).get("", false); + args.emplace_back("sticker", sticker); + args.emplace_back("emoji_list", putJSON(escapeJSONStringVec(emojiList))); + return sendRequest("setStickerEmojiList", args).get("", false); } -bool Api::setStickerKeywords(const std::string& sticker, - const std::vector& keywords) const { - std::vector args; - args.reserve(2); +bool Api::setStickerKeywords(const std::string &sticker, + const std::vector &keywords) const { + std::vector args; + args.reserve(2); - args.emplace_back("sticker", sticker); - if (!keywords.empty()) { - args.emplace_back("keywords", _tgTypeParser.parseArray( - [](const std::string& keyword)->std::string { - return "\"" + StringTools::escapeJsonString(keyword) + "\""; - }, keywords)); - } + args.emplace_back("sticker", sticker); + if (!keywords.empty()) { + args.emplace_back("keywords", putJSON(escapeJSONStringVec(keywords))); + } - return sendRequest("setStickerKeywords", args).get("", false); + return sendRequest("setStickerKeywords", args).get("", false); } -bool Api::setStickerMaskPosition(const std::string& sticker, +bool Api::setStickerMaskPosition(const std::string &sticker, MaskPosition::Ptr maskPosition) const { - std::vector args; - args.reserve(2); - - args.emplace_back("sticker", sticker); - if (maskPosition != nullptr) { - args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); - } - - return sendRequest("setStickerMaskPosition", args).get("", false); -} + std::vector args; + args.reserve(2); -bool Api::setStickerSetTitle(const std::string& name, - const std::string& title) const { - std::vector args; - args.reserve(2); + args.emplace_back("sticker", sticker); + if (maskPosition != nullptr) { + args.emplace_back("mask_position", putJSON(maskPosition)); + } - args.emplace_back("name", name); - args.emplace_back("title", title); - - return sendRequest("setStickerSetTitle", args).get("", false); -} - -bool Api::setStickerSetThumbnail(const std::string& name, - std::int64_t userId, - const std::string& format, - boost::variant thumbnail) const { - std::vector args; - args.reserve(4); - - args.emplace_back("name", name); - args.emplace_back("user_id", userId); - args.emplace_back("format", format); - if (thumbnail.which() == 0) { // InputFile::Ptr - if (boost::get(thumbnail) != nullptr) { - auto file = boost::get(thumbnail); - args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); - } - } else { // std::string - if (boost::get(thumbnail) != "") { - args.emplace_back("thumbnail", boost::get(thumbnail)); - } - } - - return sendRequest("setStickerSetThumbnail", args).get("", false); -} - -bool Api::setCustomEmojiStickerSetThumbnail(const std::string& name, - const std::string& customEmojiId) const { - std::vector args; - args.reserve(2); - - args.emplace_back("name", name); - if (!customEmojiId.empty()) { - args.emplace_back("custom_emoji_id", customEmojiId); - } - - return sendRequest("setCustomEmojiStickerSetThumbnail", args).get("", false); + return sendRequest("setStickerMaskPosition", args).get("", false); } -bool Api::deleteStickerSet(const std::string& name) const { - std::vector args; - args.reserve(1); +bool Api::setStickerSetTitle(const std::string &name, + const std::string &title) const { + std::vector args; + args.reserve(2); - args.emplace_back("name", name); + args.emplace_back("name", name); + args.emplace_back("title", title); - return sendRequest("deleteStickerSet", args).get("", false); + return sendRequest("setStickerSetTitle", args).get("", false); } -bool Api::answerInlineQuery(const std::string& inlineQueryId, - const std::vector& results, - std::int32_t cacheTime, - bool isPersonal, - const std::string& nextOffset, - InlineQueryResultsButton::Ptr button) const { - std::vector args; - args.reserve(6); - - args.emplace_back("inline_query_id", inlineQueryId); - args.emplace_back("results", _tgTypeParser.parseArray(&TgTypeParser::parseInlineQueryResult, results)); - if (cacheTime != 300) { - args.emplace_back("cache_time", cacheTime); - } - if (isPersonal != false) { - args.emplace_back("is_personal", isPersonal); - } - if (!nextOffset.empty()) { - args.emplace_back("next_offset", nextOffset); - } - if (button != nullptr) { - args.emplace_back("button", _tgTypeParser.parseInlineQueryResultsButton(button)); - } - - return sendRequest("answerInlineQuery", args).get("", false); -} - -SentWebAppMessage::Ptr Api::answerWebAppQuery(const std::string& webAppQueryId, - InlineQueryResult::Ptr result) const { - std::vector args; - args.reserve(2); - - args.emplace_back("web_app_query_id", webAppQueryId); - args.emplace_back("result", _tgTypeParser.parseInlineQueryResult(result)); - - return _tgTypeParser.parseJsonAndGetSentWebAppMessage(sendRequest("answerWebAppQuery", args)); -} - -Message::Ptr Api::sendInvoice(boost::variant chatId, - const std::string& title, - const std::string& description, - const std::string& payload, - const std::string& providerToken, - const std::string& currency, - const std::vector& prices, - const std::string& providerData, - const std::string& photoUrl, - std::int32_t photoSize, - std::int32_t photoWidth, - std::int32_t photoHeight, - bool needName, - bool needPhoneNumber, - bool needEmail, - bool needShippingAddress, - bool sendPhoneNumberToProvider, - bool sendEmailToProvider, - bool isFlexible, - ReplyParameters::Ptr replyParameters, - GenericReply::Ptr replyMarkup, - bool disableNotification, - std::int32_t messageThreadId, - std::int32_t maxTipAmount, - const std::vector& suggestedTipAmounts, - const std::string& startParameter, - bool protectContent) const { - std::vector args; - args.reserve(27); - - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("title", title); - args.emplace_back("description", description); - args.emplace_back("payload", payload); - args.emplace_back("provider_token", providerToken); - args.emplace_back("currency", currency); - args.emplace_back("prices", _tgTypeParser.parseArray(&TgTypeParser::parseLabeledPrice, prices)); - args.emplace_back("max_tip_amount", maxTipAmount); - if (!suggestedTipAmounts.empty()) { - args.emplace_back("suggested_tip_amounts", _tgTypeParser.parseArray([] (const std::int32_t& option) -> std::int32_t { - return option; - }, suggestedTipAmounts)); - } - if (!startParameter.empty()) { - args.emplace_back("start_parameter", startParameter); - } - if (!providerData.empty()) { - args.emplace_back("provider_data", providerData); - } - if (!photoUrl.empty()) { - args.emplace_back("photo_url", photoUrl); - } - if (photoSize) { - args.emplace_back("photo_size", photoSize); - } - if (photoWidth) { - args.emplace_back("photo_width", photoWidth); - } - if (photoHeight) { - args.emplace_back("photo_height", photoHeight); - } - if (needName) { - args.emplace_back("need_name", needName); - } - if (needPhoneNumber) { - args.emplace_back("need_phone_number", needPhoneNumber); - } - if (needEmail) { - args.emplace_back("need_email", needEmail); - } - if (needShippingAddress) { - args.emplace_back("need_shipping_address", needShippingAddress); - } - if (sendPhoneNumberToProvider) { - args.emplace_back("send_phone_number_to_provider", sendPhoneNumberToProvider); - } - if (sendEmailToProvider) { - args.emplace_back("send_email_to_provider", sendEmailToProvider); - } - if (isFlexible) { - args.emplace_back("is_flexible", isFlexible); - } - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendInvoice", args)); -} - -std::string Api::createInvoiceLink(const std::string& title, - const std::string& description, - const std::string& payload, - const std::string& providerToken, - const std::string& currency, - const std::vector& prices, - std::int32_t maxTipAmount, - const std::vector& suggestedTipAmounts, - const std::string& providerData, - const std::string& photoUrl, - std::int32_t photoSize, - std::int32_t photoWidth, - std::int32_t photoHeight, - bool needName, - bool needPhoneNumber, - bool needEmail, - bool needShippingAddress, - bool sendPhoneNumberToProvider, - bool sendEmailToProvider, - bool isFlexible) const { - std::vector args; - args.reserve(20); +bool Api::setStickerSetThumbnail( + const std::string &name, std::int64_t userId, const std::string &format, + boost::variant thumbnail) const { + std::vector args; + args.reserve(4); - args.emplace_back("title", title); - args.emplace_back("description", description); - args.emplace_back("payload", payload); - args.emplace_back("provider_token", providerToken); - args.emplace_back("currency", currency); - args.emplace_back("prices", _tgTypeParser.parseArray(&TgTypeParser::parseLabeledPrice, prices)); - args.emplace_back("max_tip_amount", maxTipAmount); - if (!suggestedTipAmounts.empty()) { - args.emplace_back("suggested_tip_amounts", _tgTypeParser.parseArray([] (const std::int32_t& option) -> std::int32_t { - return option; - }, suggestedTipAmounts)); - } - if (!providerData.empty()) { - args.emplace_back("provider_data", providerData); - } - if (!photoUrl.empty()) { - args.emplace_back("photo_url", photoUrl); - } - if (photoSize) { - args.emplace_back("photo_size", photoSize); - } - if (photoWidth) { - args.emplace_back("photo_width", photoWidth); - } - if (photoHeight) { - args.emplace_back("photo_height", photoHeight); + args.emplace_back("name", name); + args.emplace_back("user_id", userId); + args.emplace_back("format", format); + if (thumbnail.which() == 0) { // InputFile::Ptr + if (boost::get(thumbnail) != nullptr) { + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, + file->fileName); } - if (needName) { - args.emplace_back("need_name", needName); - } - if (needPhoneNumber) { - args.emplace_back("need_phone_number", needPhoneNumber); - } - if (needEmail) { - args.emplace_back("need_email", needEmail); - } - if (needShippingAddress) { - args.emplace_back("need_shipping_address", needShippingAddress); - } - if (sendPhoneNumberToProvider) { - args.emplace_back("send_phone_number_to_provider", sendPhoneNumberToProvider); - } - if (sendEmailToProvider) { - args.emplace_back("send_email_to_provider", sendEmailToProvider); - } - if (isFlexible) { - args.emplace_back("is_flexible", isFlexible); + } else { // std::string + if (boost::get(thumbnail) != "") { + args.emplace_back("thumbnail", boost::get(thumbnail)); } + } - return sendRequest("createInvoiceLink", args).get("", ""); + return sendRequest("setStickerSetThumbnail", args).get("", false); } -bool Api::answerShippingQuery(const std::string& shippingQueryId, - bool ok, - const std::vector& shippingOptions, - const std::string& errorMessage) const { - std::vector args; - args.reserve(4); +bool Api::setCustomEmojiStickerSetThumbnail( + const std::string &name, const std::string &customEmojiId) const { + std::vector args; + args.reserve(2); - args.emplace_back("shipping_query_id", shippingQueryId); - args.emplace_back("ok", ok); - if (!shippingOptions.empty()) { - args.emplace_back("shipping_options", _tgTypeParser.parseArray(&TgTypeParser::parseShippingOption, shippingOptions)); - } - if (!errorMessage.empty()) { - args.emplace_back("error_message", errorMessage); - } + args.emplace_back("name", name); + if (!customEmojiId.empty()) { + args.emplace_back("custom_emoji_id", customEmojiId); + } - return sendRequest("answerShippingQuery", args).get("", false); + return sendRequest("setCustomEmojiStickerSetThumbnail", args) + .get("", false); } -bool Api::answerPreCheckoutQuery(const std::string& preCheckoutQueryId, - bool ok, - const std::string& errorMessage) const { - std::vector args; - args.reserve(3); +bool Api::deleteStickerSet(const std::string &name) const { + std::vector args; + args.reserve(1); - args.emplace_back("pre_checkout_query_id", preCheckoutQueryId); - args.emplace_back("ok", ok); - if (!errorMessage.empty()) { - args.emplace_back("error_message", errorMessage); - } + args.emplace_back("name", name); - return sendRequest("answerPreCheckoutQuery", args).get("", false); + return sendRequest("deleteStickerSet", args).get("", false); } -bool Api::setPassportDataErrors(std::int64_t userId, - const std::vector& errors) const { - std::vector args; - args.reserve(2); - - args.emplace_back("user_id", userId); - args.emplace_back("errors", _tgTypeParser.parseArray(&TgTypeParser::parsePassportElementError, errors)); - - return sendRequest("setPassportDataErrors", args).get("", false); +bool Api::answerInlineQuery(const std::string &inlineQueryId, + const std::vector &results, + std::int32_t cacheTime, bool isPersonal, + const std::string &nextOffset, + InlineQueryResultsButton::Ptr button) const { + std::vector args; + args.reserve(6); + + args.emplace_back("inline_query_id", inlineQueryId); + args.emplace_back("results", putJSON(results)); + if (cacheTime != 300) { + args.emplace_back("cache_time", cacheTime); + } + if (isPersonal != false) { + args.emplace_back("is_personal", isPersonal); + } + if (!nextOffset.empty()) { + args.emplace_back("next_offset", nextOffset); + } + if (button != nullptr) { + args.emplace_back("button", putJSON(button)); + } + + return sendRequest("answerInlineQuery", args).get("", false); +} + +SentWebAppMessage::Ptr +Api::answerWebAppQuery(const std::string &webAppQueryId, + InlineQueryResult::Ptr result) const { + std::vector args; + args.reserve(2); + + args.emplace_back("web_app_query_id", webAppQueryId); + args.emplace_back("result", putJSON(result)); + + return parse(sendRequest("answerWebAppQuery", args)); +} + +Message::Ptr +Api::sendInvoice(boost::variant chatId, + const std::string &title, const std::string &description, + const std::string &payload, const std::string &providerToken, + const std::string ¤cy, + const std::vector &prices, + const std::string &providerData, const std::string &photoUrl, + std::int32_t photoSize, std::int32_t photoWidth, + std::int32_t photoHeight, bool needName, bool needPhoneNumber, + bool needEmail, bool needShippingAddress, + bool sendPhoneNumberToProvider, bool sendEmailToProvider, + bool isFlexible, ReplyParameters::Ptr replyParameters, + GenericReply::Ptr replyMarkup, bool disableNotification, + std::int32_t messageThreadId, std::int32_t maxTipAmount, + const std::vector &suggestedTipAmounts, + const std::string &startParameter, bool protectContent) const { + std::vector args; + args.reserve(27); + + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("title", title); + args.emplace_back("description", description); + args.emplace_back("payload", payload); + args.emplace_back("provider_token", providerToken); + args.emplace_back("currency", currency); + args.emplace_back("prices", putJSON(prices)); + args.emplace_back("max_tip_amount", maxTipAmount); + if (!suggestedTipAmounts.empty()) { + args.emplace_back("suggested_tip_amounts", putJSON(suggestedTipAmounts)); + } + if (!startParameter.empty()) { + args.emplace_back("start_parameter", startParameter); + } + if (!providerData.empty()) { + args.emplace_back("provider_data", providerData); + } + if (!photoUrl.empty()) { + args.emplace_back("photo_url", photoUrl); + } + if (photoSize) { + args.emplace_back("photo_size", photoSize); + } + if (photoWidth) { + args.emplace_back("photo_width", photoWidth); + } + if (photoHeight) { + args.emplace_back("photo_height", photoHeight); + } + if (needName) { + args.emplace_back("need_name", needName); + } + if (needPhoneNumber) { + args.emplace_back("need_phone_number", needPhoneNumber); + } + if (needEmail) { + args.emplace_back("need_email", needEmail); + } + if (needShippingAddress) { + args.emplace_back("need_shipping_address", needShippingAddress); + } + if (sendPhoneNumberToProvider) { + args.emplace_back("send_phone_number_to_provider", + sendPhoneNumberToProvider); + } + if (sendEmailToProvider) { + args.emplace_back("send_email_to_provider", sendEmailToProvider); + } + if (isFlexible) { + args.emplace_back("is_flexible", isFlexible); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendInvoice", args)); +} + +std::string Api::createInvoiceLink( + const std::string &title, const std::string &description, + const std::string &payload, const std::string &providerToken, + const std::string ¤cy, const std::vector &prices, + std::int32_t maxTipAmount, + const std::vector &suggestedTipAmounts, + const std::string &providerData, const std::string &photoUrl, + std::int32_t photoSize, std::int32_t photoWidth, std::int32_t photoHeight, + bool needName, bool needPhoneNumber, bool needEmail, + bool needShippingAddress, bool sendPhoneNumberToProvider, + bool sendEmailToProvider, bool isFlexible) const { + std::vector args; + args.reserve(20); + + args.emplace_back("title", title); + args.emplace_back("description", description); + args.emplace_back("payload", payload); + args.emplace_back("provider_token", providerToken); + args.emplace_back("currency", currency); + args.emplace_back("prices", putJSON(prices)); + args.emplace_back("max_tip_amount", maxTipAmount); + if (!suggestedTipAmounts.empty()) { + args.emplace_back("suggested_tip_amounts", putJSON(suggestedTipAmounts)); + } + if (!providerData.empty()) { + args.emplace_back("provider_data", providerData); + } + if (!photoUrl.empty()) { + args.emplace_back("photo_url", photoUrl); + } + if (photoSize) { + args.emplace_back("photo_size", photoSize); + } + if (photoWidth) { + args.emplace_back("photo_width", photoWidth); + } + if (photoHeight) { + args.emplace_back("photo_height", photoHeight); + } + if (needName) { + args.emplace_back("need_name", needName); + } + if (needPhoneNumber) { + args.emplace_back("need_phone_number", needPhoneNumber); + } + if (needEmail) { + args.emplace_back("need_email", needEmail); + } + if (needShippingAddress) { + args.emplace_back("need_shipping_address", needShippingAddress); + } + if (sendPhoneNumberToProvider) { + args.emplace_back("send_phone_number_to_provider", + sendPhoneNumberToProvider); + } + if (sendEmailToProvider) { + args.emplace_back("send_email_to_provider", sendEmailToProvider); + } + if (isFlexible) { + args.emplace_back("is_flexible", isFlexible); + } + + return sendRequest("createInvoiceLink", args).get("", ""); +} + +bool Api::answerShippingQuery( + const std::string &shippingQueryId, bool ok, + const std::vector &shippingOptions, + const std::string &errorMessage) const { + std::vector args; + args.reserve(4); + + args.emplace_back("shipping_query_id", shippingQueryId); + args.emplace_back("ok", ok); + if (!shippingOptions.empty()) { + args.emplace_back("shipping_options", putJSON(shippingOptions)); + } + if (!errorMessage.empty()) { + args.emplace_back("error_message", errorMessage); + } + + return sendRequest("answerShippingQuery", args).get("", false); +} + +bool Api::answerPreCheckoutQuery(const std::string &preCheckoutQueryId, bool ok, + const std::string &errorMessage) const { + std::vector args; + args.reserve(3); + + args.emplace_back("pre_checkout_query_id", preCheckoutQueryId); + args.emplace_back("ok", ok); + if (!errorMessage.empty()) { + args.emplace_back("error_message", errorMessage); + } + + return sendRequest("answerPreCheckoutQuery", args).get("", false); +} + +bool Api::setPassportDataErrors( + std::int64_t userId, + const std::vector &errors) const { + std::vector args; + args.reserve(2); + + args.emplace_back("user_id", userId); + args.emplace_back("errors", putJSON(errors)); + + return sendRequest("setPassportDataErrors", args).get("", false); } Message::Ptr Api::sendGame(std::int64_t chatId, - const std::string& gameShortName, + const std::string &gameShortName, ReplyParameters::Ptr replyParameters, InlineKeyboardMarkup::Ptr replyMarkup, bool disableNotification, - std::int32_t messageThreadId, - bool protectContent, - const std::string& businessConnectionId) const { - std::vector args; - args.reserve(8); - - if (!businessConnectionId.empty()) { - args.emplace_back("business_connection_id", businessConnectionId); - } - args.emplace_back("chat_id", chatId); - if (messageThreadId != 0) { - args.emplace_back("message_thread_id", messageThreadId); - } - args.emplace_back("game_short_name", gameShortName); - if (disableNotification) { - args.emplace_back("disable_notification", disableNotification); - } - if (protectContent) { - args.emplace_back("protect_content", protectContent); - } - if (replyParameters != nullptr) { - args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); - } - if (replyMarkup) { - args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); - } - - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendGame", args)); -} - -Message::Ptr Api::setGameScore(std::int64_t userId, - std::int32_t score, - bool force, - bool disableEditMessage, - std::int64_t chatId, - std::int32_t messageId, - const std::string& inlineMessageId) const { - std::vector args; - args.reserve(7); - - args.emplace_back("user_id", userId); - args.emplace_back("score", score); - if (force) { - args.emplace_back("force", force); - } - if (disableEditMessage) { - args.emplace_back("disable_edit_message", disableEditMessage); - } - if (chatId) { - args.emplace_back("chat_id", chatId); - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } + std::int32_t messageThreadId, bool protectContent, + const std::string &businessConnectionId) const { + std::vector args; + args.reserve(8); + + if (!businessConnectionId.empty()) { + args.emplace_back("business_connection_id", businessConnectionId); + } + args.emplace_back("chat_id", chatId); + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + args.emplace_back("game_short_name", gameShortName); + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", putJSON(replyParameters)); + } + if (replyMarkup) { + args.emplace_back("reply_markup", putJSON(replyMarkup)); + } + + return parse(sendRequest("sendGame", args)); +} + +Message::Ptr Api::setGameScore(std::int64_t userId, std::int32_t score, + bool force, bool disableEditMessage, + std::int64_t chatId, std::int32_t messageId, + const std::string &inlineMessageId) const { + std::vector args; + args.reserve(7); + + args.emplace_back("user_id", userId); + args.emplace_back("score", score); + if (force) { + args.emplace_back("force", force); + } + if (disableEditMessage) { + args.emplace_back("disable_edit_message", disableEditMessage); + } + if (chatId) { + args.emplace_back("chat_id", chatId); + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } - return _tgTypeParser.parseJsonAndGetMessage(sendRequest("setGameScore", args)); + return parse(sendRequest("setGameScore", args)); } -std::vector Api::getGameHighScores(std::int64_t userId, - std::int64_t chatId, - std::int32_t messageId, - const std::string& inlineMessageId) const { - std::vector args; - args.reserve(4); +std::vector +Api::getGameHighScores(std::int64_t userId, std::int64_t chatId, + std::int32_t messageId, + const std::string &inlineMessageId) const { + std::vector args; + args.reserve(4); - args.emplace_back("user_id", userId); - if (chatId) { - args.emplace_back("chat_id", chatId); - } - if (messageId) { - args.emplace_back("message_id", messageId); - } - if (!inlineMessageId.empty()) { - args.emplace_back("inline_message_id", inlineMessageId); - } + args.emplace_back("user_id", userId); + if (chatId) { + args.emplace_back("chat_id", chatId); + } + if (messageId) { + args.emplace_back("message_id", messageId); + } + if (!inlineMessageId.empty()) { + args.emplace_back("inline_message_id", inlineMessageId); + } - return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetGameHighScore, sendRequest("getGameHighScores", args)); + return parseArray(sendRequest("getGameHighScores", args)); } -std::string Api::downloadFile(const std::string& filePath, - const std::vector& args) const { - std::string url(_url); - url += "/file/bot"; - url += _token; - url += "/"; - url += filePath; +std::string Api::downloadFile(const std::string &filePath, + const std::vector &args) const { + std::string url(_url); + url += "/file/bot"; + url += _token; + url += "/"; + url += filePath; - return _httpClient.makeRequest(url, args); + return _httpClient.makeRequest(url, args); } bool Api::blockedByUser(std::int64_t chatId) const { - bool isBotBlocked = false; + bool isBotBlocked = false; - try { - sendChatAction(chatId, "typing"); + try { + sendChatAction(chatId, "typing"); - } catch (std::exception& e) { - std::string error = e.what(); + } catch (std::exception &e) { + std::string error = e.what(); - if (error.compare("Forbidden: bot was blocked by the user") == 0) { - isBotBlocked = true; - } + if (error.compare("Forbidden: bot was blocked by the user") == 0) { + isBotBlocked = true; } + } - return isBotBlocked; -} - -boost::property_tree::ptree Api::sendRequest(const std::string& method, const std::vector& args) const { - std::string url(_url); - url += "/bot"; - url += _token; - url += "/"; - url += method; - - int requestRetryBackoff = _httpClient.getRequestBackoff(); - int retries = 0; - while (1) - { - try { - std::string serverResponse = _httpClient.makeRequest(url, args); - - if (!serverResponse.compare(0, 6, "")) { - std::string message = "tgbot-cpp library have got html page instead of json response. Maybe you entered wrong bot token."; - throw TgException(message, TgException::ErrorCode::HtmlResponse); - } - - boost::property_tree::ptree result; - try { - result = _tgTypeParser.parseJson(serverResponse); - } catch (boost::property_tree::ptree_error& e) { - std::string message = "tgbot-cpp library can't parse json response. " + std::string(e.what()); - - throw TgException(message, TgException::ErrorCode::InvalidJson); - } - - if (result.get("ok", false)) { - return result.get_child("result"); - } else { - std::string message = result.get("description", ""); - size_t errorCode = result.get("error_code", 0u); - - throw TgException(message, static_cast(errorCode)); - } - } catch (...) { - int max_retries = _httpClient.getRequestMaxRetries(); - if ((max_retries >= 0) && (retries == max_retries)) { - throw; - } else { - std::this_thread::sleep_for(std::chrono::seconds(requestRetryBackoff)); - retries++; - continue; - } - } - } -} + return isBotBlocked; } + +boost::property_tree::ptree +Api::sendRequest(const std::string &method, + const std::vector &args) const { + std::string url(_url); + url += "/bot"; + url += _token; + url += "/"; + url += method; + + int requestRetryBackoff = _httpClient.getRequestBackoff(); + int retries = 0; + while (1) { + try { + std::string serverResponse = _httpClient.makeRequest(url, args); + + if (!serverResponse.compare(0, 6, "")) { + std::string message = + "tgbot-cpp library have got html page instead of json response. " + "Maybe you entered wrong bot token."; + throw TgException(message, TgException::ErrorCode::HtmlResponse); + } + + boost::property_tree::ptree result; + try { + std::istringstream inputJSON(serverResponse); + boost::property_tree::read_json(inputJSON, result); + } catch (boost::property_tree::ptree_error &e) { + std::string message = "tgbot-cpp library can't parse json response. " + + std::string(e.what()); + + throw TgException(message, TgException::ErrorCode::InvalidJson); + } + + if (result.get("ok", false)) { + return result.get_child("result"); + } else { + std::string message = result.get("description", ""); + size_t errorCode = result.get("error_code", 0u); + + throw TgException(message, + static_cast(errorCode)); + } + } catch (...) { + int max_retries = _httpClient.getRequestMaxRetries(); + if ((max_retries >= 0) && (retries == max_retries)) { + throw; + } else { + std::this_thread::sleep_for(std::chrono::seconds(requestRetryBackoff)); + retries++; + continue; + } + } + } +} +} // namespace TgBot diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index d3e9bd92..2469517e 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -1,5580 +1,4846 @@ #include "tgbot/TgTypeParser.h" +#include "tgbot/types/PhotoSize.h" +#include namespace TgBot { -Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const boost::property_tree::ptree& data) const { - auto result(std::make_shared()); - result->updateId = data.get("update_id", 0); - result->message = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "message"); - result->editedMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "edited_message"); - result->channelPost = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "channel_post"); - result->editedChannelPost = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "edited_channel_post"); - result->businessConnection = tryParseJson(&TgTypeParser::parseJsonAndGetBusinessConnection, data, "business_connection"); - result->businessMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "business_message"); - result->editedBusinessMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "edited_business_message"); - result->deletedBusinessMessages = tryParseJson(&TgTypeParser::parseJsonAndGetBusinessMessagesDeleted, data, "deleted_business_messages"); - result->messageReaction = tryParseJson(&TgTypeParser::parseJsonAndGetMessageReactionUpdated, data, "message_reaction"); - result->messageReactionCount = tryParseJson(&TgTypeParser::parseJsonAndGetMessageReactionCountUpdated, data, "message_reaction_count"); - result->inlineQuery = tryParseJson(&TgTypeParser::parseJsonAndGetInlineQuery, data, "inline_query"); - result->chosenInlineResult = tryParseJson(&TgTypeParser::parseJsonAndGetChosenInlineResult, data, "chosen_inline_result"); - result->callbackQuery = tryParseJson(&TgTypeParser::parseJsonAndGetCallbackQuery, data, "callback_query"); - result->shippingQuery = tryParseJson(&TgTypeParser::parseJsonAndGetShippingQuery, data, "shipping_query"); - result->preCheckoutQuery = tryParseJson(&TgTypeParser::parseJsonAndGetPreCheckoutQuery, data, "pre_checkout_query"); - result->poll = tryParseJson(&TgTypeParser::parseJsonAndGetPoll, data, "poll"); - result->pollAnswer = tryParseJson(&TgTypeParser::parseJsonAndGetPollAnswer, data, "poll_answer"); - result->myChatMember = tryParseJson(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "my_chat_member"); - result->chatMember = tryParseJson(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "chat_member"); - result->chatJoinRequest = tryParseJson(&TgTypeParser::parseJsonAndGetChatJoinRequest, data, "chat_join_request"); - result->chatBoost = tryParseJson(&TgTypeParser::parseJsonAndGetChatBoostUpdated, data, "chat_boost"); - result->removedChatBoost = tryParseJson(&TgTypeParser::parseJsonAndGetChatBoostRemoved, data, "removed_chat_boost"); - return result; -} - -std::string TgTypeParser::parseUpdate(const Update::Ptr& object) const { - if (!object) { - return ""; - } - std::string result; - result += '{'; - appendToJson(result, "update_id", object->updateId); - appendToJson(result, "message", parseMessage(object->message)); - appendToJson(result, "edited_message", parseMessage(object->editedMessage)); - appendToJson(result, "channel_post", parseMessage(object->channelPost)); - appendToJson(result, "edited_channel_post", parseMessage(object->editedChannelPost)); - appendToJson(result, "business_connection", parseBusinessConnection(object->businessConnection)); - appendToJson(result, "business_message", parseMessage(object->businessMessage)); - appendToJson(result, "edited_business_message", parseMessage(object->editedBusinessMessage)); - appendToJson(result, "deleted_business_messages", parseBusinessMessagesDeleted(object->deletedBusinessMessages)); - appendToJson(result, "message_reaction", parseMessageReactionUpdated(object->messageReaction)); - appendToJson(result, "message_reaction_count", parseMessageReactionCountUpdated(object->messageReactionCount)); - appendToJson(result, "inline_query", parseInlineQuery(object->inlineQuery)); - appendToJson(result, "chosen_inline_result", parseChosenInlineResult(object->chosenInlineResult)); - appendToJson(result, "callback_query", parseCallbackQuery(object->callbackQuery)); - appendToJson(result, "shipping_query", parseShippingQuery(object->shippingQuery)); - appendToJson(result, "pre_checkout_query", parsePreCheckoutQuery(object->preCheckoutQuery)); - appendToJson(result, "poll", parsePoll(object->poll)); - appendToJson(result, "poll_answer", parsePollAnswer(object->pollAnswer)); - appendToJson(result, "my_chat_member", parseChatMemberUpdated(object->myChatMember)); - appendToJson(result, "chat_member", parseChatMemberUpdated(object->chatMember)); - appendToJson(result, "chat_join_request", parseChatJoinRequest(object->chatJoinRequest)); - appendToJson(result, "chat_boost", parseChatBoostUpdated(object->chatBoost)); - appendToJson(result, "removed_chat_boost", parseChatBoostRemoved(object->removedChatBoost)); - removeLastComma(result); - result += '}'; - return result; -} - -WebhookInfo::Ptr TgTypeParser::parseJsonAndGetWebhookInfo(const boost::property_tree::ptree& data) const { - auto result(std::make_shared()); - result->url = data.get("url", ""); - result->hasCustomCertificate = data.get("has_custom_certificate", false); - result->pendingUpdateCount = data.get("pending_update_count", 0); - result->ipAddress = data.get("ip_address", ""); - result->lastErrorDate = data.get("last_error_date", 0); - result->lastErrorMessage = data.get("last_error_message", ""); - result->lastSynchronizationErrorDate = data.get("last_synchronization_error_date", 0); - result->maxConnections = data.get("max_connections", 0); - result->allowedUpdates = parseJsonAndGetArray( - [] (const boost::property_tree::ptree& innerData)->std::string { - return innerData.get(""); - }, data, "allowed_updates"); - return result; -} - -std::string TgTypeParser::parseWebhookInfo(const WebhookInfo::Ptr& object) const { - if (!object) { - return ""; - } - std::string result; - result += '{'; - appendToJson(result, "url", object->url); - appendToJson(result, "has_custom_certificate", object->hasCustomCertificate); - appendToJson(result, "pending_update_count", object->pendingUpdateCount); - appendToJson(result, "ip_address", object->ipAddress); - appendToJson(result, "last_error_date", object->lastErrorDate); - appendToJson(result, "last_error_message", object->lastErrorMessage); - appendToJson(result, "last_synchronization_error_date", object->lastSynchronizationErrorDate); - appendToJson(result, "max_connections", object->maxConnections); - appendToJson(result, "allowed_updates", parseArray( - [] (const std::string& s)->std::string { - return s; - }, object->allowedUpdates)); - removeLastComma(result); - result += '}'; - return result; -} - -User::Ptr TgTypeParser::parseJsonAndGetUser(const boost::property_tree::ptree& data) const { - auto result(std::make_shared()); - result->id = data.get("id", 0); - result->isBot = data.get("is_bot", false); - result->firstName = data.get("first_name", ""); - result->lastName = data.get("last_name", ""); - result->username = data.get("username", ""); - result->languageCode = data.get("language_code", ""); - result->isPremium = data.get("is_premium", false); - result->addedToAttachmentMenu = data.get("added_to_attachment_menu", false); - result->canJoinGroups = data.get("can_join_groups", false); - result->canReadAllGroupMessages = data.get("can_read_all_group_messages", false); - result->supportsInlineQueries = data.get("supports_inline_queries", false); - result->canConnectToBusiness = data.get("can_connect_to_business", false); - return result; -} - -std::string TgTypeParser::parseUser(const User::Ptr& object) const { - if (!object) { - return ""; - } - std::string result; - result += '{'; - appendToJson(result, "id", object->id); - appendToJson(result, "is_bot", object->isBot); - appendToJson(result, "first_name", object->firstName); - appendToJson(result, "last_name", object->lastName); - appendToJson(result, "username", object->username); - appendToJson(result, "language_code", object->languageCode); - appendToJson(result, "is_premium", object->isPremium); - appendToJson(result, "added_to_attachment_menu", object->addedToAttachmentMenu); - appendToJson(result, "can_join_groups", object->canJoinGroups); - appendToJson(result, "can_read_all_group_messages", object->canReadAllGroupMessages); - appendToJson(result, "supports_inline_queries", object->supportsInlineQueries); - appendToJson(result, "can_connect_to_business", object->canConnectToBusiness); - removeLastComma(result); - result += '}'; - return result; -} - -Chat::Ptr TgTypeParser::parseJsonAndGetChat(const boost::property_tree::ptree& data) const { - auto result(std::make_shared()); - result->id = data.get("id", 0); - std::string type = data.get("type", ""); - if (type == "private") { - result->type = Chat::Type::Private; - } else if (type == "group") { - result->type = Chat::Type::Group; - } else if (type == "supergroup") { - result->type = Chat::Type::Supergroup; - } else if (type == "channel") { - result->type = Chat::Type::Channel; - } - result->title = data.get("title", ""); - result->username = data.get("username", ""); - result->firstName = data.get("first_name", ""); - result->lastName = data.get("last_name", ""); - result->isForum = data.get("is_forum", false); - result->photo = tryParseJson(&TgTypeParser::parseJsonAndGetChatPhoto, data, "photo"); - result->activeUsernames = parseJsonAndGetArray( - [] (const boost::property_tree::ptree& innerData)->std::string { - return innerData.get(""); - }, data, "active_usernames"); - result->birthdate = tryParseJson(&TgTypeParser::parseJsonAndGetBirthdate, data, "birthdate"); - result->businessIntro = tryParseJson(&TgTypeParser::parseJsonAndGetBusinessIntro, data, "business_intro"); - result->businessLocation = tryParseJson(&TgTypeParser::parseJsonAndGetBusinessLocation, data, "business_location"); - result->businessOpeningHours = tryParseJson(&TgTypeParser::parseJsonAndGetBusinessOpeningHours, data, "business_opening_hours"); - result->personalChat = tryParseJson(&TgTypeParser::parseJsonAndGetChat, data, "personal_chat"); - result->availableReactions = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetReactionType, data, "available_reactions"); - result->accentColorId = data.get("accent_color_id", 0); - result->backgroundCustomEmojiId = data.get("background_custom_emoji_id", ""); - result->profileAccentColorId = data.get("profile_accent_color_id", 0); - result->profileBackgroundCustomEmojiId = data.get("profile_background_custom_emoji_id", ""); - result->emojiStatusCustomEmojiId = data.get("emoji_status_custom_emoji_id", ""); - result->emojiStatusExpirationDate = data.get("emoji_status_expiration_date", 0); - result->bio = data.get("bio", ""); - result->hasPrivateForwards = data.get("has_private_forwards", false); - result->hasRestrictedVoiceAndVideoMessages = data.get("has_restricted_voice_and_video_messages", false); - result->joinToSendMessages = data.get("join_to_send_messages", false); - result->joinByRequest = data.get("join_by_request", false); - result->description = data.get("description", ""); - result->inviteLink = data.get("invite_link", ""); - result->pinnedMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message"); - result->permissions = tryParseJson(&TgTypeParser::parseJsonAndGetChatPermissions, data, "permissions"); - result->slowModeDelay = data.get("slow_mode_delay", 0); - result->unrestrictBoostCount = data.get("unrestrict_boost_count", 0); - result->messageAutoDeleteTime = data.get("message_auto_delete_time", 0); - result->hasAggressiveAntiSpamEnabled = data.get("has_aggressive_anti_spam_enabled", false); - result->hasHiddenMembers = data.get("has_hidden_members", false); - result->hasProtectedContent = data.get("has_protected_content", false); - result->hasVisibleHistory = data.get("has_visible_history", false); - result->stickerSetName = data.get("sticker_set_name", ""); - result->canSetStickerSet = data.get("can_set_sticker_set", false); - result->customEmojiStickerSetName = data.get("custom_emoji_sticker_set_name", ""); - result->linkedChatId = data.get("linked_chat_id", 0); - result->location = tryParseJson(&TgTypeParser::parseJsonAndGetChatLocation, data, "location"); - return result; -} - -std::string TgTypeParser::parseChat(const Chat::Ptr& object) const { - if (!object) { - return ""; - } - std::string result; - result += '{'; - appendToJson(result, "id", object->id); - if (object->type == Chat::Type::Private) { - appendToJson(result, "type", "private"); - } else if (object->type == Chat::Type::Group) { - appendToJson(result, "type", "group"); - } else if (object->type == Chat::Type::Supergroup) { - appendToJson(result, "type", "supergroup"); - } else if (object->type == Chat::Type::Channel) { - appendToJson(result, "type", "channel"); - } - appendToJson(result, "title", object->title); - appendToJson(result, "username", object->username); - appendToJson(result, "first_name", object->firstName); - appendToJson(result, "last_name", object->lastName); - appendToJson(result, "is_forum", object->isForum); - appendToJson(result, "photo", parseChatPhoto(object->photo)); - appendToJson(result, "active_usernames", parseArray( - [] (const std::string& s)->std::string { - return s; - }, object->activeUsernames)); - appendToJson(result, "birthdate", parseBirthdate(object->birthdate)); - appendToJson(result, "business_intro", parseBusinessIntro(object->businessIntro)); - appendToJson(result, "business_location", parseBusinessLocation(object->businessLocation)); - appendToJson(result, "business_opening_hours", parseBusinessOpeningHours(object->businessOpeningHours)); - appendToJson(result, "personal_chat", parseChat(object->personalChat)); - appendToJson(result, "available_reactions", parseArray(&TgTypeParser::parseReactionType, object->availableReactions)); - appendToJson(result, "accent_color_id", object->accentColorId); - appendToJson(result, "background_custom_emoji_id", object->backgroundCustomEmojiId); - appendToJson(result, "profile_accent_color_id", object->profileAccentColorId); - appendToJson(result, "profile_background_custom_emoji_id", object->profileBackgroundCustomEmojiId); - appendToJson(result, "emoji_status_custom_emoji_id", object->emojiStatusCustomEmojiId); - appendToJson(result, "emoji_status_expiration_date", object->emojiStatusExpirationDate); - appendToJson(result, "bio", object->bio); - appendToJson(result, "has_private_forwards", object->hasPrivateForwards); - appendToJson(result, "has_restricted_voice_and_video_messages", object->hasRestrictedVoiceAndVideoMessages); - appendToJson(result, "join_to_send_messages", object->joinToSendMessages); - appendToJson(result, "join_by_request", object->joinByRequest); - appendToJson(result, "description", object->description); - appendToJson(result, "invite_link", object->inviteLink); - appendToJson(result, "pinned_message", parseMessage(object->pinnedMessage)); - appendToJson(result, "permissions", parseChatPermissions(object->permissions)); - appendToJson(result, "slow_mode_delay", object->slowModeDelay); - appendToJson(result, "unrestrict_boost_count", object->unrestrictBoostCount); - appendToJson(result, "message_auto_delete_time", object->messageAutoDeleteTime); - appendToJson(result, "has_aggressive_anti_spam_enabled", object->hasAggressiveAntiSpamEnabled); - appendToJson(result, "has_hidden_members", object->hasHiddenMembers); - appendToJson(result, "has_protected_content", object->hasProtectedContent); - appendToJson(result, "has_visible_history", object->hasVisibleHistory); - appendToJson(result, "sticker_set_name", object->stickerSetName); - appendToJson(result, "can_set_sticker_set", object->canSetStickerSet); - appendToJson(result, "custom_emoji_sticker_set_name", object->customEmojiStickerSetName); - appendToJson(result, "linked_chat_id", object->linkedChatId); - appendToJson(result, "location", parseChatLocation(object->location)); - removeLastComma(result); - result += '}'; - return result; -} - -Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::ptree& data) const { - auto result(std::make_shared()); - result->messageId = data.get("message_id", 0); - result->messageThreadId = data.get("message_thread_id", 0); - result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); - result->senderChat = tryParseJson(&TgTypeParser::parseJsonAndGetChat, data, "sender_chat"); - result->senderBoostCount = data.get("sender_boost_count", 0); - result->senderBusinessBot = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "sender_business_bot"); - result->date = data.get("date", 0); - result->businessConnectionId = data.get("business_connection_id", ""); - result->chat = parseJsonAndGetChat(data.find("chat")->second); - result->forwardOrigin = tryParseJson(&TgTypeParser::parseJsonAndGetMessageOrigin, data, "forward_origin"); - result->isTopicMessage = data.get("is_topic_message", false); - result->isAutomaticForward = data.get("is_automatic_forward", false); - result->replyToMessage = tryParseJson(&TgTypeParser::parseJsonAndGetMessage, data, "reply_to_message"); - result->externalReply = tryParseJson(&TgTypeParser::parseJsonAndGetExternalReplyInfo, data, "external_reply"); - result->quote = tryParseJson(&TgTypeParser::parseJsonAndGetTextQuote, data, "quote"); - result->replyToStory = tryParseJson(&TgTypeParser::parseJsonAndGetStory, data, "reply_to_story"); - result->viaBot = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "via_bot"); - result->editDate = data.get("edit_date", 0); - result->hasProtectedContent = data.get("has_protected_content", false); - result->isFromOffline = data.get("is_from_offline", false); - result->mediaGroupId = data.get("media_group_id", ""); - result->authorSignature = data.get("author_signature", ""); - result->text = data.get("text", ""); - result->entities = parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetMessageEntity, data, "entities"); - result->linkPreviewOptions = tryParseJson(&TgTypeParser::parseJsonAndGetLinkPreviewOptions, data, "link_preview_options"); - result->animation = tryParseJson(&TgTypeParser::parseJsonAndGetAnimation, data, "animation"); - result->audio = tryParseJson