diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Api.cpp | 924 | ||||
-rw-r--r-- | src/TgTypeParser.cpp | 1746 | ||||
-rw-r--r-- | src/types/ChatBoostSource.cpp | 11 | ||||
-rw-r--r-- | src/types/InputFile.cpp | 6 | ||||
-rw-r--r-- | src/types/MessageOrigin.cpp | 13 | ||||
-rw-r--r-- | src/types/ReactionType.cpp | 9 |
6 files changed, 2146 insertions, 563 deletions
diff --git a/src/Api.cpp b/src/Api.cpp index c8ce399..2c4b82a 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -112,18 +112,21 @@ bool Api::close() const { Message::Ptr Api::sendMessage(boost::variant<std::int64_t, std::string> chatId, const std::string& text, - bool disableWebPagePreview, - std::int32_t replyToMessageId, + LinkPreviewOptions::Ptr linkPreviewOptions, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector<MessageEntity::Ptr>& entities, - bool allowSendingWithoutReply, + std::int32_t messageThreadId, bool protectContent, - std::int32_t messageThreadId) const { + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -135,8 +138,8 @@ Message::Ptr Api::sendMessage(boost::variant<std::int64_t, std::string> chatId, if (!entities.empty()) { args.emplace_back("entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, entities)); } - if (disableWebPagePreview) { - args.emplace_back("disable_web_page_preview", disableWebPagePreview); + if (linkPreviewOptions != nullptr) { + args.emplace_back("link_preview_options", _tgTypeParser.parseLinkPreviewOptions(linkPreviewOptions)); } if (disableNotification) { args.emplace_back("disable_notification", disableNotification); @@ -144,11 +147,8 @@ Message::Ptr Api::sendMessage(boost::variant<std::int64_t, std::string> chatId, if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId != 0) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -182,6 +182,36 @@ Message::Ptr Api::forwardMessage(boost::variant<std::int64_t, std::string> chatI return _tgTypeParser.parseJsonAndGetMessage(sendRequest("forwardMessage", args)); } +std::vector<MessageId::Ptr> Api::forwardMessages(boost::variant<std::int64_t, std::string> chatId, + boost::variant<std::int64_t, std::string> fromChatId, + const std::vector<std::int32_t>& messageIds, + std::int32_t messageThreadId, + bool disableNotification, + bool protectContent) const { + std::vector<HttpReqArg> 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<std::int32_t>( + [] (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); + } + + return _tgTypeParser.parseJsonAndGetArray<MessageId>(&TgTypeParser::parseJsonAndGetMessageId, sendRequest("forwardMessages", args)); +} + MessageId::Ptr Api::copyMessage(boost::variant<std::int64_t, std::string> chatId, boost::variant<std::int64_t, std::string> fromChatId, std::int32_t messageId, @@ -189,13 +219,12 @@ MessageId::Ptr Api::copyMessage(boost::variant<std::int64_t, std::string> chatId const std::string& parseMode, const std::vector<MessageEntity::Ptr>& captionEntities, bool disableNotification, - std::int32_t replyToMessageId, - bool allowSendingWithoutReply, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, bool protectContent, std::int32_t messageThreadId) const { std::vector<HttpReqArg> args; - args.reserve(12); + args.reserve(11); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -218,11 +247,8 @@ MessageId::Ptr Api::copyMessage(boost::variant<std::int64_t, std::string> chatId if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -231,21 +257,59 @@ MessageId::Ptr Api::copyMessage(boost::variant<std::int64_t, std::string> chatId return _tgTypeParser.parseJsonAndGetMessageId(sendRequest("copyMessage", args)); } +std::vector<MessageId::Ptr> Api::copyMessages(boost::variant<std::int64_t, std::string> chatId, + boost::variant<std::int64_t, std::string> fromChatId, + const std::vector<std::int32_t>& messageIds, + std::int32_t messageThreadId, + bool disableNotification, + bool protectContent, + bool removeCaption) const { + std::vector<HttpReqArg> 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<std::int32_t>( + [] (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<MessageId>(&TgTypeParser::parseJsonAndGetMessageId, sendRequest("copyMessages", args)); +} + Message::Ptr Api::sendPhoto(boost::variant<std::int64_t, std::string> chatId, boost::variant<InputFile::Ptr, std::string> photo, const std::string& caption, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector<MessageEntity::Ptr>& captionEntities, - bool allowSendingWithoutReply, - bool protectContent, std::int32_t messageThreadId, - bool hasSpoiler) const { + bool protectContent, + bool hasSpoiler, + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -274,11 +338,8 @@ Message::Ptr Api::sendPhoto(boost::variant<std::int64_t, std::string> chatId, if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId != 0) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup != nullptr) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -293,18 +354,21 @@ Message::Ptr Api::sendAudio(boost::variant<std::int64_t, std::string> chatId, std::int32_t duration, const std::string& performer, const std::string& title, - boost::variant<InputFile::Ptr, std::string> thumb, - std::int32_t replyToMessageId, + boost::variant<InputFile::Ptr, std::string> thumbnail, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector<MessageEntity::Ptr>& captionEntities, - bool allowSendingWithoutReply, + std::int32_t messageThreadId, bool protectContent, - std::int32_t messageThreadId) const { + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -333,13 +397,13 @@ Message::Ptr Api::sendAudio(boost::variant<std::int64_t, std::string> chatId, if (!title.empty()) { args.emplace_back("title", title); } - if (thumb.which() == 0) { // InputFile::Ptr - auto file = boost::get<InputFile::Ptr>(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get<InputFile::Ptr>(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); } else { // std::string - auto thumbStr = boost::get<std::string>(thumb); - if (!thumbStr.empty()) { - args.emplace_back("thumb", thumbStr); + auto thumbnailStr = boost::get<std::string>(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); } } if (disableNotification) { @@ -348,11 +412,8 @@ Message::Ptr Api::sendAudio(boost::variant<std::int64_t, std::string> chatId, if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -363,20 +424,23 @@ Message::Ptr Api::sendAudio(boost::variant<std::int64_t, std::string> chatId, Message::Ptr Api::sendDocument(boost::variant<std::int64_t, std::string> chatId, boost::variant<InputFile::Ptr, std::string> document, - boost::variant<InputFile::Ptr, std::string> thumb, + boost::variant<InputFile::Ptr, std::string> thumbnail, const std::string& caption, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector<MessageEntity::Ptr>& captionEntities, bool disableContentTypeDetection, - bool allowSendingWithoutReply, + std::int32_t messageThreadId, bool protectContent, - std::int32_t messageThreadId) const { + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -387,13 +451,13 @@ Message::Ptr Api::sendDocument(boost::variant<std::int64_t, std::string> chatId, } else { // std::string args.emplace_back("document", boost::get<std::string>(document)); } - if (thumb.which() == 0) { // InputFile::Ptr - auto file = boost::get<InputFile::Ptr>(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get<InputFile::Ptr>(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); } else { // std::string - auto thumbStr = boost::get<std::string>(thumb); - if (!thumbStr.empty()) { - args.emplace_back("thumb", thumbStr); + auto thumbnailStr = boost::get<std::string>(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); } } if (!caption.empty()) { @@ -414,11 +478,8 @@ Message::Ptr Api::sendDocument(boost::variant<std::int64_t, std::string> chatId, if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -433,20 +494,23 @@ Message::Ptr Api::sendVideo(boost::variant<std::int64_t, std::string> chatId, std::int32_t duration, std::int32_t width, std::int32_t height, - boost::variant<InputFile::Ptr, std::string> thumb, + boost::variant<InputFile::Ptr, std::string> thumbnail, const std::string& caption , - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector<MessageEntity::Ptr>& captionEntities, - bool allowSendingWithoutReply, - bool protectContent, std::int32_t messageThreadId, - bool hasSpoiler) const { + bool protectContent, + bool hasSpoiler, + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -466,13 +530,13 @@ Message::Ptr Api::sendVideo(boost::variant<std::int64_t, std::string> chatId, if (height != 0) { args.emplace_back("height", height); } - if (thumb.which() == 0) { // InputFile::Ptr - auto file = boost::get<InputFile::Ptr>(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get<InputFile::Ptr>(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); } else { // std::string - auto thumbStr = boost::get<std::string>(thumb); - if (!thumbStr.empty()) { - args.emplace_back("thumb", thumbStr); + auto thumbnailStr = boost::get<std::string>(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); } } if (!caption.empty()) { @@ -496,11 +560,8 @@ Message::Ptr Api::sendVideo(boost::variant<std::int64_t, std::string> chatId, if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId != 0) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup != nullptr) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -514,20 +575,23 @@ Message::Ptr Api::sendAnimation(boost::variant<std::int64_t, std::string> chatId std::int32_t duration, std::int32_t width, std::int32_t height, - boost::variant<InputFile::Ptr, std::string> thumb, + boost::variant<InputFile::Ptr, std::string> thumbnail, const std::string& caption, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector<MessageEntity::Ptr>& captionEntities, - bool allowSendingWithoutReply, - bool protectContent, std::int32_t messageThreadId, - bool hasSpoiler ) const { + bool protectContent, + bool hasSpoiler, + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -547,13 +611,13 @@ Message::Ptr Api::sendAnimation(boost::variant<std::int64_t, std::string> chatId if (height != 0) { args.emplace_back("height", height); } - if (thumb.which() == 0) { // InputFile::Ptr - auto file = boost::get<InputFile::Ptr>(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get<InputFile::Ptr>(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); } else { // std::string - auto thumbStr = boost::get<std::string>(thumb); - if (!thumbStr.empty()) { - args.emplace_back("thumb", thumbStr); + auto thumbnailStr = boost::get<std::string>(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); } } if (!caption.empty()) { @@ -574,11 +638,8 @@ Message::Ptr Api::sendAnimation(boost::variant<std::int64_t, std::string> chatId if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId != 0) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup != nullptr) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -591,17 +652,20 @@ Message::Ptr Api::sendVoice(boost::variant<std::int64_t, std::string> chatId, boost::variant<InputFile::Ptr, std::string> voice, const std::string& caption, std::int32_t duration, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector<MessageEntity::Ptr>& captionEntities, - bool allowSendingWithoutReply, + std::int32_t messageThreadId, bool protectContent, - std::int32_t messageThreadId) const { + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -630,11 +694,8 @@ Message::Ptr Api::sendVoice(boost::variant<std::int64_t, std::string> chatId, if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -645,18 +706,21 @@ Message::Ptr Api::sendVoice(boost::variant<std::int64_t, std::string> chatId, Message::Ptr Api::sendVideoNote(boost::variant<std::int64_t, std::string> chatId, boost::variant<InputFile::Ptr, std::string> videoNote, - std::int64_t replyToMessageId, + ReplyParameters::Ptr replyParameters, bool disableNotification, std::int32_t duration, std::int32_t length, - boost::variant<InputFile::Ptr, std::string> thumb, + boost::variant<InputFile::Ptr, std::string> thumbnail, GenericReply::Ptr replyMarkup, - bool allowSendingWithoutReply, + std::int32_t messageThreadId, bool protectContent, - std::int32_t messageThreadId) const { + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -673,13 +737,13 @@ Message::Ptr Api::sendVideoNote(boost::variant<std::int64_t, std::string> chatId if (length) { args.emplace_back("length", length); } - if (thumb.which() == 0) { // InputFile::Ptr - auto file = boost::get<InputFile::Ptr>(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get<InputFile::Ptr>(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); } else { // std::string - auto thumbStr = boost::get<std::string>(thumb); - if (!thumbStr.empty()) { - args.emplace_back("thumb", thumbStr); + auto thumbnailStr = boost::get<std::string>(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); } } if (disableNotification) { @@ -688,11 +752,8 @@ Message::Ptr Api::sendVideoNote(boost::variant<std::int64_t, std::string> chatId if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -704,13 +765,16 @@ Message::Ptr Api::sendVideoNote(boost::variant<std::int64_t, std::string> chatId std::vector<Message::Ptr> Api::sendMediaGroup(boost::variant<std::int64_t, std::string> chatId, const std::vector<InputMedia::Ptr>& media, bool disableNotification, - std::int32_t replyToMessageId, - bool allowSendingWithoutReply, + ReplyParameters::Ptr replyParameters, + std::int32_t messageThreadId, bool protectContent, - std::int32_t messageThreadId) const { + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -722,11 +786,8 @@ std::vector<Message::Ptr> Api::sendMediaGroup(boost::variant<std::int64_t, std:: if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId != 0) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } return _tgTypeParser.parseJsonAndGetArray<Message>(&TgTypeParser::parseJsonAndGetMessage, sendRequest("sendMediaGroup", args)); @@ -736,18 +797,21 @@ Message::Ptr Api::sendLocation(boost::variant<std::int64_t, std::string> chatId, float latitude, float longitude, std::int32_t livePeriod, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, bool disableNotification, float horizontalAccuracy, std::int32_t heading, std::int32_t proximityAlertRadius, - bool allowSendingWithoutReply, + std::int32_t messageThreadId, bool protectContent, - std::int32_t messageThreadId) const { + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -772,11 +836,8 @@ Message::Ptr Api::sendLocation(boost::variant<std::int64_t, std::string> chatId, if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -797,8 +858,14 @@ Message::Ptr Api::editMessageLiveLocation(float latitude, std::vector<HttpReqArg> args; args.reserve(9); - if ((boost::get<std::int64_t>(chatId) != 0) || (boost::get<std::string>(chatId) != "")) { - args.emplace_back("chat_id", chatId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get<std::int64_t>(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get<std::string>(chatId) != "") { + args.emplace_back("chat_id", chatId); + } } if (messageId) { args.emplace_back("message_id", messageId); @@ -831,8 +898,14 @@ Message::Ptr Api::stopMessageLiveLocation(boost::variant<std::int64_t, std::stri std::vector<HttpReqArg> args; args.reserve(4); - if ((boost::get<std::int64_t>(chatId) != 0) || (boost::get<std::string>(chatId) != "")) { - args.emplace_back("chat_id", chatId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get<std::int64_t>(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get<std::string>(chatId) != "") { + args.emplace_back("chat_id", chatId); + } } if (messageId) { args.emplace_back("message_id", messageId); @@ -855,16 +928,19 @@ Message::Ptr Api::sendVenue(boost::variant<std::int64_t, std::string> chatId, const std::string& foursquareId, const std::string& foursquareType, bool disableNotification, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& googlePlaceId, const std::string& googlePlaceType, - bool allowSendingWithoutReply, + std::int32_t messageThreadId, bool protectContent, - std::int32_t messageThreadId) const { + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -891,11 +967,8 @@ Message::Ptr Api::sendVenue(boost::variant<std::int64_t, std::string> chatId, if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -910,14 +983,17 @@ Message::Ptr Api::sendContact(boost::variant<std::int64_t, std::string> chatId, const std::string& lastName , const std::string& vcard, bool disableNotification, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, - bool allowSendingWithoutReply, + std::int32_t messageThreadId, bool protectContent, - std::int32_t messageThreadId) const { + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -936,11 +1012,8 @@ Message::Ptr Api::sendContact(boost::variant<std::int64_t, std::string> chatId, if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -953,7 +1026,7 @@ Message::Ptr Api::sendPoll(boost::variant<std::int64_t, std::string> chatId, const std::string& question, const std::vector<std::string>& options, bool disableNotification, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, bool isAnonymous, const std::string& type, @@ -965,12 +1038,15 @@ Message::Ptr Api::sendPoll(boost::variant<std::int64_t, std::string> chatId, std::int32_t openPeriod, std::int32_t closeDate, bool isClosed, - bool allowSendingWithoutReply, + std::int32_t messageThreadId, bool protectContent, - std::int32_t messageThreadId) const { + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -1016,11 +1092,8 @@ Message::Ptr Api::sendPoll(boost::variant<std::int64_t, std::string> chatId, if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId != 0) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -1031,15 +1104,18 @@ Message::Ptr Api::sendPoll(boost::variant<std::int64_t, std::string> chatId, Message::Ptr Api::sendDice(boost::variant<std::int64_t, std::string> chatId, bool disableNotification, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& emoji, - bool allowSendingWithoutReply, + std::int32_t messageThreadId, bool protectContent, - std::int32_t messageThreadId) const { + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -1053,11 +1129,8 @@ Message::Ptr Api::sendDice(boost::variant<std::int64_t, std::string> chatId, if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId != 0) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -1066,12 +1139,35 @@ Message::Ptr Api::sendDice(boost::variant<std::int64_t, std::string> chatId, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDice", args)); } +bool Api::setMessageReaction(boost::variant<std::int64_t, std::string> chatId, + std::int32_t messageId, + const std::vector<ReactionType::Ptr>& reaction, + bool isBig) const { + std::vector<HttpReqArg> 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<ReactionType>(&TgTypeParser::parseReactionType, reaction)); + } + if (isBig) { + args.emplace_back("is_big", isBig); + } + + return sendRequest("setMessageReaction", args).get<bool>("", false); +} + bool Api::sendChatAction(std::int64_t chatId, const std::string& action, - std::int32_t messageThreadId) const { + std::int32_t messageThreadId, + const std::string& businessConnectionId) const { std::vector<HttpReqArg> args; - args.reserve(3); + 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) { @@ -1144,7 +1240,7 @@ bool Api::unbanChatMember(boost::variant<std::int64_t, std::string> chatId, bool Api::restrictChatMember(boost::variant<std::int64_t, std::string> chatId, std::int64_t userId, TgBot::ChatPermissions::Ptr permissions, - std::int64_t untilDate, + std::uint32_t untilDate, bool useIndependentChatPermissions) const { std::vector<HttpReqArg> args; args.reserve(5); @@ -1152,10 +1248,10 @@ bool Api::restrictChatMember(boost::variant<std::int64_t, std::string> chatId, args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); args.emplace_back("permissions", _tgTypeParser.parseChatPermissions(permissions)); - if (useIndependentChatPermissions) { + if (useIndependentChatPermissions != false) { args.emplace_back("use_independent_chat_permissions", useIndependentChatPermissions); } - if (untilDate) { + if (untilDate != 0) { args.emplace_back("until_date", untilDate); } @@ -1175,46 +1271,58 @@ bool Api::promoteChatMember(boost::variant<std::int64_t, std::string> chatId, bool canManageChat, bool canManageVideoChats, bool canRestrictMembers, - bool canManageTopics) const { + bool canManageTopics, + bool canPostStories, + bool canEditStories, + bool canDeleteStories) const { std::vector<HttpReqArg> args; - args.reserve(14); + args.reserve(17); args.emplace_back("chat_id", chatId); args.emplace_back("user_id", userId); - if (isAnonymous) { + if (isAnonymous != false) { args.emplace_back("is_anonymous", isAnonymous); } - if (canManageChat) { + if (canManageChat != false) { args.emplace_back("can_manage_chat", canManageChat); } - if (canPostMessages) { + if (canPostMessages != false) { args.emplace_back("can_post_messages", canPostMessages); } - if (canEditMessages) { + if (canEditMessages != false) { args.emplace_back("can_edit_messages", canEditMessages); } - if (canDeleteMessages) { + if (canDeleteMessages != false) { args.emplace_back("can_delete_messages", canDeleteMessages); } - if (canManageVideoChats) { + 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) { + if (canRestrictMembers != false) { args.emplace_back("can_restrict_members", canRestrictMembers); } - if (canPromoteMembers) { + if (canPromoteMembers != false) { args.emplace_back("can_promote_members", canPromoteMembers); } - if (canChangeInfo) { + if (canChangeInfo != false) { args.emplace_back("can_change_info", canChangeInfo); } - if (canInviteUsers) { + if (canInviteUsers != false) { args.emplace_back("can_invite_users", canInviteUsers); } - if (canPinMessages) { + if (canPinMessages != false) { args.emplace_back("can_pin_messages", canPinMessages); } - if (canManageTopics) { + if (canManageTopics != false) { args.emplace_back("can_manage_topics", canManageTopics); } @@ -1539,7 +1647,7 @@ ForumTopic::Ptr Api::createForumTopic(boost::variant<std::int64_t, std::string> bool Api::editForumTopic(boost::variant<std::int64_t, std::string> chatId, std::int32_t messageThreadId, const std::string& name, - boost::variant<std::int8_t, std::string> iconCustomEmojiId) const { + boost::variant<std::int32_t, std::string> iconCustomEmojiId) const { std::vector<HttpReqArg> args; args.reserve(4); @@ -1548,8 +1656,14 @@ bool Api::editForumTopic(boost::variant<std::int64_t, std::string> chatId, if (!name.empty()) { args.emplace_back("name", name); } - if (iconCustomEmojiId.which() == 1) { // std::string - args.emplace_back("icon_custom_emoji_id", boost::get<std::string>(iconCustomEmojiId)); + if (iconCustomEmojiId.which() == 0) { // std::int32_t + if (boost::get<std::int32_t>(iconCustomEmojiId) != 0) { + args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); + } + } else { // std::string + if (boost::get<std::string>(iconCustomEmojiId) != "") { + args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); + } } return sendRequest("editForumTopic", args).get<bool>("", false); @@ -1646,6 +1760,15 @@ bool Api::unhideGeneralForumTopic(boost::variant<std::int64_t, std::string> chat return sendRequest("unhideGeneralForumTopic", args).get<bool>("", false); } +bool Api::unpinAllGeneralForumTopicMessages(boost::variant<std::int64_t, std::string> chatId) const { + std::vector<HttpReqArg> args; + args.reserve(1); + + args.emplace_back("chat_id", chatId); + + return sendRequest("unpinAllGeneralForumTopicMessages", args).get<bool>("", false); +} + bool Api::answerCallbackQuery(const std::string& callbackQueryId, const std::string& text, bool showAlert, @@ -1671,6 +1794,26 @@ bool Api::answerCallbackQuery(const std::string& callbackQueryId, return sendRequest("answerCallbackQuery", args).get<bool>("", false); } +UserChatBoosts::Ptr Api::getUserChatBoosts(boost::variant<std::int64_t, std::string> chatId, + std::int32_t userId) const { + std::vector<HttpReqArg> args; + args.reserve(2); + + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + + return _tgTypeParser.parseJsonAndGetUserChatBoosts(sendRequest("getUserChatBoosts", args)); +} + +BusinessConnection::Ptr Api::getBusinessConnection(const std::string& businessConnectionId) const { + std::vector<HttpReqArg> args; + args.reserve(1); + + args.emplace_back("business_connection_id", businessConnectionId); + + return _tgTypeParser.parseJsonAndGetBusinessConnection(sendRequest("getBusinessConnection", args)); +} + bool Api::setMyCommands(const std::vector<BotCommand::Ptr>& commands, BotCommandScope::Ptr scope, const std::string& languageCode) const { @@ -1689,7 +1832,7 @@ bool Api::setMyCommands(const std::vector<BotCommand::Ptr>& commands, } bool Api::deleteMyCommands(BotCommandScope::Ptr scope, - const std::string& languageCode) const { + const std::string& languageCode) const { std::vector<HttpReqArg> args; args.reserve(2); @@ -1707,7 +1850,7 @@ std::vector<BotCommand::Ptr> Api::getMyCommands(BotCommandScope::Ptr scope, const std::string& languageCode) const { std::vector<HttpReqArg> args; args.reserve(2); -; + if (scope != nullptr) { args.emplace_back("scope", _tgTypeParser.parseBotCommandScope(scope)); } @@ -1718,6 +1861,84 @@ std::vector<BotCommand::Ptr> Api::getMyCommands(BotCommandScope::Ptr scope, return _tgTypeParser.parseJsonAndGetArray<BotCommand>(&TgTypeParser::parseJsonAndGetBotCommand, sendRequest("getMyCommands", args)); } +bool Api::setMyName(const std::string& name, + const std::string& languageCode) const { + std::vector<HttpReqArg> args; + args.reserve(2); + + if (!name.empty()) { + args.emplace_back("name", name); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } + + return sendRequest("setMyName", args).get<bool>("", false); +} + +BotName::Ptr Api::getMyName(const std::string& languageCode) const { + std::vector<HttpReqArg> args; + args.reserve(1); + + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } + + return _tgTypeParser.parseJsonAndGetBotName(sendRequest("getMyName", args)); +} + +bool Api::setMyDescription(const std::string& description, + const std::string& languageCode) const { + std::vector<HttpReqArg> args; + args.reserve(2); + + if (!description.empty()) { + args.emplace_back("description", description); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } + + return sendRequest("setMyDescription", args).get<bool>("", false); +} + +BotDescription::Ptr Api::getMyDescription(const std::string& languageCode) const { + std::vector<HttpReqArg> args; + args.reserve(1); + + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } + + return _tgTypeParser.parseJsonAndGetBotDescription(sendRequest("getMyDescription", args)); +} + +bool Api::setMyShortDescription(const std::string& shortDescription, + const std::string& languageCode) const { + std::vector<HttpReqArg> args; + args.reserve(2); + + if (!shortDescription.empty()) { + args.emplace_back("short_description", shortDescription); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } + + return sendRequest("setMyShortDescription", args).get<bool>("", false); +} + +BotShortDescription::Ptr Api::getMyShortDescription(const std::string& languageCode) const { + std::vector<HttpReqArg> args; + args.reserve(1); + + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } + + return _tgTypeParser.parseJsonAndGetBotShortDescription(sendRequest("getMyShortDescription", args)); +} + bool Api::setChatMenuButton(std::int64_t chatId, MenuButton::Ptr menuButton) const { std::vector<HttpReqArg> args; @@ -1775,14 +1996,20 @@ Message::Ptr Api::editMessageText(const std::string& text, std::int32_t messageId, const std::string& inlineMessageId, const std::string& parseMode, - bool disableWebPagePreview, + LinkPreviewOptions::Ptr linkPreviewOptions, InlineKeyboardMarkup::Ptr replyMarkup, const std::vector<MessageEntity::Ptr>& entities) const { std::vector<HttpReqArg> args; args.reserve(8); - if ((boost::get<std::int64_t>(chatId) != 0) || (boost::get<std::string>(chatId) != "")) { - args.emplace_back("chat_id", chatId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get<std::int64_t>(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get<std::string>(chatId) != "") { + args.emplace_back("chat_id", chatId); + } } if (messageId) { args.emplace_back("message_id", messageId); @@ -1797,8 +2024,8 @@ Message::Ptr Api::editMessageText(const std::string& text, if (!entities.empty()) { args.emplace_back("entities", _tgTypeParser.parseArray<MessageEntity>(&TgTypeParser::parseMessageEntity, entities)); } - if (disableWebPagePreview) { - args.emplace_back("disable_web_page_preview", disableWebPagePreview); + if (linkPreviewOptions) { + args.emplace_back("link_preview_options", _tgTypeParser.parseLinkPreviewOptions(linkPreviewOptions)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseInlineKeyboardMarkup(replyMarkup)); @@ -1822,8 +2049,14 @@ Message::Ptr Api::editMessageCaption(boost::variant<std::int64_t, std::string> c std::vector<HttpReqArg> args; args.reserve(7); - if ((boost::get<std::int64_t>(chatId) != 0) || (boost::get<std::string>(chatId) != "")) { - args.emplace_back("chat_id", chatId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get<std::int64_t>(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get<std::string>(chatId) != "") { + args.emplace_back("chat_id", chatId); + } } if (messageId) { args.emplace_back("message_id", messageId); @@ -1861,10 +2094,16 @@ Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, std::vector<HttpReqArg> args; args.reserve(5); - args.emplace_back("media", _tgTypeParser.parseInputMedia(media)); - if ((boost::get<std::int64_t>(chatId) != 0) || (boost::get<std::string>(chatId) != "")) { - args.emplace_back("chat_id", chatId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get<std::int64_t>(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get<std::string>(chatId) != "") { + args.emplace_back("chat_id", chatId); + } } + args.emplace_back("media", _tgTypeParser.parseInputMedia(media)); if (messageId) { args.emplace_back("message_id", messageId); } @@ -1891,8 +2130,14 @@ Message::Ptr Api::editMessageReplyMarkup(boost::variant<std::int64_t, std::strin std::vector<HttpReqArg> args; args.reserve(4); - if ((boost::get<std::int64_t>(chatId) != 0) || (boost::get<std::string>(chatId) != "")) { - args.emplace_back("chat_id", chatId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get<std::int64_t>(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get<std::string>(chatId) != "") { + args.emplace_back("chat_id", chatId); + } } if (messageId) { args.emplace_back("message_id", messageId); @@ -1938,17 +2183,37 @@ bool Api::deleteMessage(boost::variant<std::int64_t, std::string> chatId, return sendRequest("deleteMessage", args).get<bool>("", false); } +bool Api::deleteMessages(boost::variant<std::int64_t, std::string> chatId, + const std::vector<std::int32_t>& messageIds) const { + std::vector<HttpReqArg> args; + args.reserve(2); + + args.emplace_back("chat_id", chatId); + if (!messageIds.empty()) { + args.emplace_back("message_ids", _tgTypeParser.parseArray<std::int32_t>( + [] (const std::int32_t& i)->std::int32_t { + return i; + }, messageIds)); + } + + return sendRequest("deleteMessages", args).get<bool>("", false); +} + Message::Ptr Api::sendSticker(boost::variant<std::int64_t, std::string> chatId, boost::variant<InputFile::Ptr, std::string> sticker, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, bool disableNotification, - bool allowSendingWithoutReply, + std::int32_t messageThreadId, bool protectContent, - std::int32_t messageThreadId) const { + const std::string& emoji, + const std::string& businessConnectionId) const { std::vector<HttpReqArg> args; - args.reserve(8); + 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); @@ -1959,17 +2224,17 @@ Message::Ptr Api::sendSticker(boost::variant<std::int64_t, std::string> chatId, } else { // std::string args.emplace_back("sticker", boost::get<std::string>(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 (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -1991,7 +2256,8 @@ std::vector<Sticker::Ptr> Api::getCustomEmojiStickers(const std::vector<std::str std::vector<HttpReqArg> args; args.reserve(1); - args.emplace_back("custom_emoji_ids", _tgTypeParser.parseArray<std::string>([] (const std::string& customEmojiId) -> std::string { + args.emplace_back("custom_emoji_ids", _tgTypeParser.parseArray<std::string>( + [] (const std::string& customEmojiId) -> std::string { return "\"" + StringTools::escapeJsonString(customEmojiId) + "\""; }, customEmojiIds)); @@ -1999,12 +2265,14 @@ std::vector<Sticker::Ptr> Api::getCustomEmojiStickers(const std::vector<std::str } File::Ptr Api::uploadStickerFile(std::int64_t userId, - const InputFile::Ptr pngSticker) const { + InputFile::Ptr sticker, + const std::string& stickerFormat) const { std::vector<HttpReqArg> args; - args.reserve(2); + args.reserve(3); args.emplace_back("user_id", userId); - args.emplace_back("png_sticker", pngSticker->data, true, pngSticker->mimeType, pngSticker->fileName); + args.emplace_back("sticker", sticker->data, true, sticker->mimeType, sticker->fileName); + args.emplace_back("sticker_format", stickerFormat); return _tgTypeParser.parseJsonAndGetFile(sendRequest("uploadStickerFile", args)); } @@ -2012,70 +2280,39 @@ File::Ptr Api::uploadStickerFile(std::int64_t userId, bool Api::createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, - const std::string& emojis, - MaskPosition::Ptr maskPosition, - boost::variant<InputFile::Ptr, std::string> pngSticker, - InputFile::Ptr tgsSticker, - InputFile::Ptr webmSticker, - const std::string& stickerType) const { + const std::vector<InputSticker::Ptr>& stickers, + Sticker::Type stickerType, + bool needsRepainting) const { std::vector<HttpReqArg> args; - args.reserve(10); + args.reserve(6); args.emplace_back("user_id", userId); args.emplace_back("name", name); args.emplace_back("title", title); - if (pngSticker.which() == 0) { // InputFile::Ptr - auto file = boost::get<InputFile::Ptr>(pngSticker); - args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("png_sticker", boost::get<std::string>(pngSticker)); - } - if (tgsSticker != nullptr) { - args.emplace_back("tgs_sticker", tgsSticker->data, true, tgsSticker->mimeType, tgsSticker->fileName); + args.emplace_back("stickers", _tgTypeParser.parseArray<InputSticker>(&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 (webmSticker != nullptr) { - args.emplace_back("webm_sticker", webmSticker->data, true, webmSticker->mimeType, webmSticker->fileName); - } - if (!stickerType.empty()) { - args.emplace_back("sticker_type", stickerType); - } - args.emplace_back("emojis", emojis); - if (maskPosition != nullptr) { - args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); + if (needsRepainting) { + args.emplace_back("needs_repainting", needsRepainting); } return sendRequest("createNewStickerSet", args).get<bool>("", false); } bool Api::addStickerToSet(std::int64_t userId, - const std::string& name, - const std::string& emojis, - MaskPosition::Ptr maskPosition, - boost::variant<InputFile::Ptr, std::string> pngSticker, - InputFile::Ptr tgsSticker, - InputFile::Ptr webmSticker) const { + const std::string& name, + InputSticker::Ptr sticker) const { std::vector<HttpReqArg> args; - args.reserve(7); + args.reserve(3); args.emplace_back("user_id", userId); args.emplace_back("name", name); - - if (pngSticker.which() == 0) { // InputFile::Ptr - auto file = boost::get<InputFile::Ptr>(pngSticker); - args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("png_sticker", boost::get<std::string>(pngSticker)); - } - if (tgsSticker != nullptr) { - args.emplace_back("tgs_sticker", tgsSticker->data, true, tgsSticker->mimeType, tgsSticker->fileName); - } - if (webmSticker != nullptr) { - args.emplace_back("webm_sticker", webmSticker->data, true, webmSticker->mimeType, webmSticker->fileName); - } - args.emplace_back("emojis", emojis); - if (maskPosition != nullptr) { - args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); - } + args.emplace_back("sticker", _tgTypeParser.parseInputSticker(sticker)); return sendRequest("addStickerToSet", args).get<bool>("", false); } @@ -2100,22 +2337,119 @@ bool Api::deleteStickerFromSet(const std::string& sticker) const { return sendRequest("deleteStickerFromSet", args).get<bool>("", false); } -bool Api::setStickerSetThumb(const std::string& name, - std::int64_t userId, - boost::variant<InputFile::Ptr, std::string> thumb) const { +bool Api::replaceStickerInSet(std::int64_t userId, + const std::string& name, + const std::string& oldSticker, + InputSticker::Ptr sticker) const { std::vector<HttpReqArg> args; - args.reserve(3); + 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)); + + return sendRequest("replaceStickerInSet", args).get<bool>("", false); +} + +bool Api::setStickerEmojiList(const std::string& sticker, + const std::vector<std::string>& emojiList) const { + std::vector<HttpReqArg> args; + args.reserve(2); + + args.emplace_back("sticker", sticker); + args.emplace_back("emoji_list", _tgTypeParser.parseArray<std::string>( + [](const std::string& emoji)->std::string { + return "\"" + StringTools::escapeJsonString(emoji) + "\""; + }, emojiList)); + + return sendRequest("setStickerEmojiList", args).get<bool>("", false); +} + +bool Api::setStickerKeywords(const std::string& sticker, + const std::vector<std::string>& keywords) const { + std::vector<HttpReqArg> args; + args.reserve(2); + + args.emplace_back("sticker", sticker); + if (!keywords.empty()) { + args.emplace_back("keywords", _tgTypeParser.parseArray<std::string>( + [](const std::string& keyword)->std::string { + return "\"" + StringTools::escapeJsonString(keyword) + "\""; + }, keywords)); + } + + return sendRequest("setStickerKeywords", args).get<bool>("", false); +} + +bool Api::setStickerMaskPosition(const std::string& sticker, + MaskPosition::Ptr maskPosition) const { + std::vector<HttpReqArg> 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<bool>("", false); +} + +bool Api::setStickerSetTitle(const std::string& name, + const std::string& title) const { + std::vector<HttpReqArg> args; + args.reserve(2); + + args.emplace_back("name", name); + args.emplace_back("title", title); + + return sendRequest("setStickerSetTitle", args).get<bool>("", false); +} + +bool Api::setStickerSetThumbnail(const std::string& name, + std::int64_t userId, + const std::string& format, + boost::variant<InputFile::Ptr, std::string> thumbnail) const { + std::vector<HttpReqArg> args; + args.reserve(4); args.emplace_back("name", name); args.emplace_back("user_id", userId); - if (thumb.which() == 0) { // InputFile::Ptr - auto file = boost::get<InputFile::Ptr>(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + args.emplace_back("format", format); + if (thumbnail.which() == 0) { // InputFile::Ptr + if (boost::get<InputFile::Ptr>(thumbnail) != nullptr) { + auto file = boost::get<InputFile::Ptr>(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); + } } else { // std::string - args.emplace_back("thumb", boost::get<std::string>(thumb)); + if (boost::get<std::string>(thumbnail) != "") { + args.emplace_back("thumbnail", boost::get<std::string>(thumbnail)); + } + } + + return sendRequest("setStickerSetThumbnail", args).get<bool>("", false); +} + +bool Api::setCustomEmojiStickerSetThumbnail(const std::string& name, + const std::string& customEmojiId) const { + std::vector<HttpReqArg> args; + args.reserve(2); + + args.emplace_back("name", name); + if (!customEmojiId.empty()) { + args.emplace_back("custom_emoji_id", customEmojiId); } - return sendRequest("setStickerSetThumb", args).get<bool>("", false); + return sendRequest("setCustomEmojiStickerSetThumbnail", args).get<bool>("", false); +} + +bool Api::deleteStickerSet(const std::string& name) const { + std::vector<HttpReqArg> args; + args.reserve(1); + + args.emplace_back("name", name); + + return sendRequest("deleteStickerSet", args).get<bool>("", false); } bool Api::answerInlineQuery(const std::string& inlineQueryId, @@ -2123,27 +2457,23 @@ bool Api::answerInlineQuery(const std::string& inlineQueryId, std::int32_t cacheTime, bool isPersonal, const std::string& nextOffset, - const std::string& switchPmText, - const std::string& switchPmParameter) const { + InlineQueryResultsButton::Ptr button) const { std::vector<HttpReqArg> args; - args.reserve(7); + args.reserve(6); args.emplace_back("inline_query_id", inlineQueryId); args.emplace_back("results", _tgTypeParser.parseArray<InlineQueryResult>(&TgTypeParser::parseInlineQueryResult, results)); - if (cacheTime) { + if (cacheTime != 300) { args.emplace_back("cache_time", cacheTime); } - if (isPersonal) { + if (isPersonal != false) { args.emplace_back("is_personal", isPersonal); } if (!nextOffset.empty()) { args.emplace_back("next_offset", nextOffset); } - if (!switchPmText.empty()) { - args.emplace_back("switch_pm_text", switchPmText); - } - if (!switchPmParameter.empty()) { - args.emplace_back("switch_pm_parameter", switchPmParameter); + if (button != nullptr) { + args.emplace_back("button", _tgTypeParser.parseInlineQueryResultsButton(button)); } return sendRequest("answerInlineQuery", args).get<bool>("", false); @@ -2179,17 +2509,16 @@ Message::Ptr Api::sendInvoice(boost::variant<std::int64_t, std::string> chatId, bool sendPhoneNumberToProvider, bool sendEmailToProvider, bool isFlexible, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, bool disableNotification, - bool allowSendingWithoutReply, + std::int32_t messageThreadId, std::int32_t maxTipAmount, const std::vector<std::int32_t>& suggestedTipAmounts, const std::string& startParameter, - bool protectContent, - std::int32_t messageThreadId) const { + bool protectContent) const { std::vector<HttpReqArg> args; - args.reserve(28); + args.reserve(27); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -2252,11 +2581,8 @@ Message::Ptr Api::sendInvoice(boost::variant<std::int64_t, std::string> chatId, if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); @@ -2387,15 +2713,18 @@ bool Api::setPassportDataErrors(std::int64_t userId, Message::Ptr Api::sendGame(std::int64_t chatId, const std::string& gameShortName, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, InlineKeyboardMarkup::Ptr replyMarkup, bool disableNotification, - bool allowSendingWithoutReply, + std::int32_t messageThreadId, bool protectContent, - std::int32_t messageThreadId) const { + const std::string& businessConnectionId) const { std::vector<HttpReqArg> 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); @@ -2407,11 +2736,8 @@ Message::Ptr Api::sendGame(std::int64_t chatId, if (protectContent) { args.emplace_back("protect_content", protectContent); } - if (replyToMessageId) { - args.emplace_back("reply_to_message_id", replyToMessageId); - } - if (allowSendingWithoutReply) { - args.emplace_back("allow_sending_without_reply", allowSendingWithoutReply); + if (replyParameters != nullptr) { + args.emplace_back("reply_parameters", _tgTypeParser.parseReplyParameters(replyParameters)); } if (replyMarkup) { args.emplace_back("reply_markup", _tgTypeParser.parseGenericReply(replyMarkup)); diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index 9e04851..d3e9bd9 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -9,6 +9,12 @@ Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const boost::property_tree::ptre result->editedMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "edited_message"); result->channelPost = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "channel_post"); result->editedChannelPost = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "edited_channel_post"); + result->businessConnection = tryParseJson<BusinessConnection>(&TgTypeParser::parseJsonAndGetBusinessConnection, data, "business_connection"); + result->businessMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "business_message"); + result->editedBusinessMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "edited_business_message"); + result->deletedBusinessMessages = tryParseJson<BusinessMessagesDeleted>(&TgTypeParser::parseJsonAndGetBusinessMessagesDeleted, data, "deleted_business_messages"); + result->messageReaction = tryParseJson<MessageReactionUpdated>(&TgTypeParser::parseJsonAndGetMessageReactionUpdated, data, "message_reaction"); + result->messageReactionCount = tryParseJson<MessageReactionCountUpdated>(&TgTypeParser::parseJsonAndGetMessageReactionCountUpdated, data, "message_reaction_count"); result->inlineQuery = tryParseJson<InlineQuery>(&TgTypeParser::parseJsonAndGetInlineQuery, data, "inline_query"); result->chosenInlineResult = tryParseJson<ChosenInlineResult>(&TgTypeParser::parseJsonAndGetChosenInlineResult, data, "chosen_inline_result"); result->callbackQuery = tryParseJson<CallbackQuery>(&TgTypeParser::parseJsonAndGetCallbackQuery, data, "callback_query"); @@ -19,6 +25,8 @@ Update::Ptr TgTypeParser::parseJsonAndGetUpdate(const boost::property_tree::ptre result->myChatMember = tryParseJson<ChatMemberUpdated>(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "my_chat_member"); result->chatMember = tryParseJson<ChatMemberUpdated>(&TgTypeParser::parseJsonAndGetChatMemberUpdated, data, "chat_member"); result->chatJoinRequest = tryParseJson<ChatJoinRequest>(&TgTypeParser::parseJsonAndGetChatJoinRequest, data, "chat_join_request"); + result->chatBoost = tryParseJson<ChatBoostUpdated>(&TgTypeParser::parseJsonAndGetChatBoostUpdated, data, "chat_boost"); + result->removedChatBoost = tryParseJson<ChatBoostRemoved>(&TgTypeParser::parseJsonAndGetChatBoostRemoved, data, "removed_chat_boost"); return result; } @@ -33,6 +41,12 @@ std::string TgTypeParser::parseUpdate(const Update::Ptr& object) const { 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)); @@ -43,6 +57,8 @@ std::string TgTypeParser::parseUpdate(const Update::Ptr& object) const { 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; @@ -61,8 +77,7 @@ WebhookInfo::Ptr TgTypeParser::parseJsonAndGetWebhookInfo(const boost::property_ result->allowedUpdates = parseJsonAndGetArray<std::string>( [] (const boost::property_tree::ptree& innerData)->std::string { return innerData.get<std::string>(""); - } - , data, "allowed_updates"); + }, data, "allowed_updates"); return result; } @@ -80,11 +95,10 @@ std::string TgTypeParser::parseWebhookInfo(const WebhookInfo::Ptr& object) const 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<std::string>([] (const std::string& s)->std::string { + appendToJson(result, "allowed_updates", parseArray<std::string>( + [] (const std::string& s)->std::string { return s; - } - , object->allowedUpdates)); + }, object->allowedUpdates)); removeLastComma(result); result += '}'; return result; @@ -103,6 +117,7 @@ User::Ptr TgTypeParser::parseJsonAndGetUser(const boost::property_tree::ptree& d result->canJoinGroups = data.get<bool>("can_join_groups", false); result->canReadAllGroupMessages = data.get<bool>("can_read_all_group_messages", false); result->supportsInlineQueries = data.get<bool>("supports_inline_queries", false); + result->canConnectToBusiness = data.get<bool>("can_connect_to_business", false); return result; } @@ -123,6 +138,7 @@ std::string TgTypeParser::parseUser(const User::Ptr& object) const { 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; @@ -151,7 +167,18 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const boost::property_tree::ptree& d [] (const boost::property_tree::ptree& innerData)->std::string { return innerData.get<std::string>(""); }, data, "active_usernames"); + result->birthdate = tryParseJson<Birthdate>(&TgTypeParser::parseJsonAndGetBirthdate, data, "birthdate"); + result->businessIntro = tryParseJson<BusinessIntro>(&TgTypeParser::parseJsonAndGetBusinessIntro, data, "business_intro"); + result->businessLocation = tryParseJson<BusinessLocation>(&TgTypeParser::parseJsonAndGetBusinessLocation, data, "business_location"); + result->businessOpeningHours = tryParseJson<BusinessOpeningHours>(&TgTypeParser::parseJsonAndGetBusinessOpeningHours, data, "business_opening_hours"); + result->personalChat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "personal_chat"); + result->availableReactions = parseJsonAndGetArray<ReactionType>(&TgTypeParser::parseJsonAndGetReactionType, data, "available_reactions"); + result->accentColorId = data.get<std::int32_t>("accent_color_id", 0); + result->backgroundCustomEmojiId = data.get<std::string>("background_custom_emoji_id", ""); + result->profileAccentColorId = data.get<std::int32_t>("profile_accent_color_id", 0); + result->profileBackgroundCustomEmojiId = data.get<std::string>("profile_background_custom_emoji_id", ""); result->emojiStatusCustomEmojiId = data.get<std::string>("emoji_status_custom_emoji_id", ""); + result->emojiStatusExpirationDate = data.get<std::uint32_t>("emoji_status_expiration_date", 0); result->bio = data.get<std::string>("bio", ""); result->hasPrivateForwards = data.get<bool>("has_private_forwards", false); result->hasRestrictedVoiceAndVideoMessages = data.get<bool>("has_restricted_voice_and_video_messages", false); @@ -162,12 +189,15 @@ Chat::Ptr TgTypeParser::parseJsonAndGetChat(const boost::property_tree::ptree& d result->pinnedMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message"); result->permissions = tryParseJson<ChatPermissions>(&TgTypeParser::parseJsonAndGetChatPermissions, data, "permissions"); result->slowModeDelay = data.get<std::int32_t>("slow_mode_delay", 0); + result->unrestrictBoostCount = data.get<std::int32_t>("unrestrict_boost_count", 0); result->messageAutoDeleteTime = data.get<std::int32_t>("message_auto_delete_time", 0); - result->hasProtectedContent = data.get<bool>("has_protected_content", false); result->hasAggressiveAntiSpamEnabled = data.get<bool>("has_aggressive_anti_spam_enabled", false); result->hasHiddenMembers = data.get<bool>("has_hidden_members", false); + result->hasProtectedContent = data.get<bool>("has_protected_content", false); + result->hasVisibleHistory = data.get<bool>("has_visible_history", false); result->stickerSetName = data.get<std::string>("sticker_set_name", ""); result->canSetStickerSet = data.get<bool>("can_set_sticker_set", false); + result->customEmojiStickerSetName = data.get<std::string>("custom_emoji_sticker_set_name", ""); result->linkedChatId = data.get<std::int64_t>("linked_chat_id", 0); result->location = tryParseJson<ChatLocation>(&TgTypeParser::parseJsonAndGetChatLocation, data, "location"); return result; @@ -195,11 +225,22 @@ std::string TgTypeParser::parseChat(const Chat::Ptr& object) const { appendToJson(result, "last_name", object->lastName); appendToJson(result, "is_forum", object->isForum); appendToJson(result, "photo", parseChatPhoto(object->photo)); - appendToJson(result, "active_usernames", - parseArray<std::string>([] (const std::string& s)->std::string { + appendToJson(result, "active_usernames", parseArray<std::string>( + [] (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); @@ -210,12 +251,15 @@ std::string TgTypeParser::parseChat(const Chat::Ptr& object) const { 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); @@ -229,29 +273,33 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::pt result->messageThreadId = data.get<std::int32_t>("message_thread_id", 0); result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); result->senderChat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "sender_chat"); - result->date = data.get<std::int32_t>("date", 0); + result->senderBoostCount = data.get<std::int32_t>("sender_boost_count", 0); + result->senderBusinessBot = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "sender_business_bot"); + result->date = data.get<std::uint32_t>("date", 0); + result->businessConnectionId = data.get<std::string>("business_connection_id", ""); result->chat = parseJsonAndGetChat(data.find("chat")->second); - result->forwardFrom = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "forward_from"); - result->forwardFromChat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "forward_from_chat"); - result->forwardFromMessageId = data.get<std::int32_t>("forward_from_message_id", 0); - result->forwardSignature = data.get<std::string>("forward_signature", ""); - result->forwardSenderName = data.get<std::string>("forward_sender_name", ""); - result->forwardDate = data.get<std::int32_t>("forward_date", 0); + result->forwardOrigin = tryParseJson<MessageOrigin>(&TgTypeParser::parseJsonAndGetMessageOrigin, data, "forward_origin"); result->isTopicMessage = data.get<bool>("is_topic_message", false); result->isAutomaticForward = data.get<bool>("is_automatic_forward", false); result->replyToMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "reply_to_message"); + result->externalReply = tryParseJson<ExternalReplyInfo>(&TgTypeParser::parseJsonAndGetExternalReplyInfo, data, "external_reply"); + result->quote = tryParseJson<TextQuote>(&TgTypeParser::parseJsonAndGetTextQuote, data, "quote"); + result->replyToStory = tryParseJson<Story>(&TgTypeParser::parseJsonAndGetStory, data, "reply_to_story"); result->viaBot = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "via_bot"); - result->editDate = data.get<std::int32_t>("edit_date", 0); + result->editDate = data.get<std::uint32_t>("edit_date", 0); result->hasProtectedContent = data.get<bool>("has_protected_content", false); + result->isFromOffline = data.get<bool>("is_from_offline", false); result->mediaGroupId = data.get<std::string>("media_group_id", ""); result->authorSignature = data.get<std::string>("author_signature", ""); result->text = data.get<std::string>("text", ""); result->entities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "entities"); + result->linkPreviewOptions = tryParseJson<LinkPreviewOptions>(&TgTypeParser::parseJsonAndGetLinkPreviewOptions, data, "link_preview_options"); result->animation = tryParseJson<Animation>(&TgTypeParser::parseJsonAndGetAnimation, data, "animation"); result->audio = tryParseJson<Audio>(&TgTypeParser::parseJsonAndGetAudio, data, "audio"); result->document = tryParseJson<Document>(&TgTypeParser::parseJsonAndGetDocument, data, "document"); result->photo = parseJsonAndGetArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "photo"); result->sticker = tryParseJson<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "sticker"); + result->story = tryParseJson<Story>(&TgTypeParser::parseJsonAndGetStory, data, "story"); result->video = tryParseJson<Video>(&TgTypeParser::parseJsonAndGetVideo, data, "video"); result->videoNote = tryParseJson<VideoNote>(&TgTypeParser::parseJsonAndGetVideoNote, data, "video_note"); result->voice = tryParseJson<Voice>(&TgTypeParser::parseJsonAndGetVoice, data, "voice"); @@ -278,18 +326,23 @@ Message::Ptr TgTypeParser::parseJsonAndGetMessage(const boost::property_tree::pt result->pinnedMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "pinned_message"); result->invoice = tryParseJson<Invoice>(&TgTypeParser::parseJsonAndGetInvoice, data, "invoice"); result->successfulPayment = tryParseJson<SuccessfulPayment>(&TgTypeParser::parseJsonAndGetSuccessfulPayment, data, "successful_payment"); - result->userShared = tryParseJson<UserShared>(&TgTypeParser::parseJsonAndGetUserShared, data, "user_shared"); + result->usersShared = tryParseJson<UsersShared>(&TgTypeParser::parseJsonAndGetUsersShared, data, "users_shared"); result->chatShared = tryParseJson<ChatShared>(&TgTypeParser::parseJsonAndGetChatShared, data, "chat_shared"); result->connectedWebsite = data.get<std::string>("connected_website", ""); result->writeAccessAllowed = tryParseJson<WriteAccessAllowed>(&TgTypeParser::parseJsonAndGetWriteAccessAllowed, data, "write_access_allowed"); result->passportData = tryParseJson<PassportData>(&TgTypeParser::parseJsonAndGetPassportData, data, "passport_data"); result->proximityAlertTriggered = tryParseJson<ProximityAlertTriggered>(&TgTypeParser::parseJsonAndGetProximityAlertTriggered, data, "proximity_alert_triggered"); + result->boostAdded = tryParseJson<ChatBoostAdded>(&TgTypeParser::parseJsonAndGetChatBoostAdded, data, "boost_added"); result->forumTopicCreated = tryParseJson<ForumTopicCreated>(&TgTypeParser::parseJsonAndGetForumTopicCreated, data, "forum_topic_created"); result->forumTopicEdited = tryParseJson<ForumTopicEdited>(&TgTypeParser::parseJsonAndGetForumTopicEdited, data, "forum_topic_edited"); result->forumTopicClosed = tryParseJson<ForumTopicClosed>(&TgTypeParser::parseJsonAndGetForumTopicClosed, data, "forum_topic_closed"); result->forumTopicReopened = tryParseJson<ForumTopicReopened>(&TgTypeParser::parseJsonAndGetForumTopicReopened, data, "forum_topic_reopened"); result->generalForumTopicHidden = tryParseJson<GeneralForumTopicHidden>(&TgTypeParser::parseJsonAndGetGeneralForumTopicHidden, data, "general_forum_topic_hidden"); result->generalForumTopicUnhidden = tryParseJson<GeneralForumTopicUnhidden>(&TgTypeParser::parseJsonAndGetGeneralForumTopicUnhidden, data, "general_forum_topic_unhidden"); + result->giveawayCreated = tryParseJson<GiveawayCreated>(&TgTypeParser::parseJsonAndGetGiveawayCreated, data, "giveaway_created"); + result->giveaway = tryParseJson<Giveaway>(&TgTypeParser::parseJsonAndGetGiveaway, data, "giveaway"); + result->giveawayWinners = tryParseJson<GiveawayWinners>(&TgTypeParser::parseJsonAndGetGiveawayWinners, data, "giveaway_winners"); + result->giveawayCompleted = tryParseJson<GiveawayCompleted>(&TgTypeParser::parseJsonAndGetGiveawayCompleted, data, "giveaway_completed"); result->videoChatScheduled = tryParseJson<VideoChatScheduled>(&TgTypeParser::parseJsonAndGetVideoChatScheduled, data, "video_chat_scheduled"); result->videoChatStarted = tryParseJson<VideoChatStarted>(&TgTypeParser::parseJsonAndGetVideoChatStarted, data, "video_chat_started"); result->videoChatEnded = tryParseJson<VideoChatEnded>(&TgTypeParser::parseJsonAndGetVideoChatEnded, data, "video_chat_ended"); @@ -309,29 +362,33 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const { appendToJson(result, "message_thread_id", object->messageThreadId); appendToJson(result, "from", parseUser(object->from)); appendToJson(result, "sender_chat", parseChat(object->senderChat)); + appendToJson(result, "sender_boost_count", object->senderBoostCount); + appendToJson(result, "sender_business_bot", parseUser(object->senderBusinessBot)); appendToJson(result, "date", object->date); + appendToJson(result, "business_connection_id", object->businessConnectionId); appendToJson(result, "chat", parseChat(object->chat)); - appendToJson(result, "forward_from", parseUser(object->forwardFrom)); - appendToJson(result, "forward_from_chat", parseChat(object->forwardFromChat)); - appendToJson(result, "forward_from_message_id", object->forwardFromMessageId); - appendToJson(result, "forward_signature", object->forwardSignature); - appendToJson(result, "forward_sender_name", object->forwardSenderName); - appendToJson(result, "forward_date", object->forwardDate); + appendToJson(result, "forward_origin", parseMessageOrigin(object->forwardOrigin)); appendToJson(result, "is_topic_message", object->isTopicMessage); appendToJson(result, "is_automatic_forward", object->isAutomaticForward); appendToJson(result, "reply_to_message", parseMessage(object->replyToMessage)); + appendToJson(result, "external_reply", parseExternalReplyInfo(object->externalReply)); + appendToJson(result, "quote", parseTextQuote(object->quote)); + appendToJson(result, "reply_to_story", parseStory(object->replyToStory)); appendToJson(result, "via_bot", parseUser(object->viaBot)); appendToJson(result, "edit_date", object->editDate); appendToJson(result, "has_protected_content", object->hasProtectedContent); + appendToJson(result, "is_from_offline", object->isFromOffline); appendToJson(result, "media_group_id", object->mediaGroupId); appendToJson(result, "author_signature", object->authorSignature); appendToJson(result, "text", object->text); appendToJson(result, "entities", parseArray(&TgTypeParser::parseMessageEntity, object->entities)); + appendToJson(result, "link_preview_options", parseLinkPreviewOptions(object->linkPreviewOptions)); appendToJson(result, "animation", parseAnimation(object->animation)); appendToJson(result, "audio", parseAudio(object->audio)); appendToJson(result, "document", parseDocument(object->document)); appendToJson(result, "photo", parseArray(&TgTypeParser::parsePhotoSize, object->photo)); appendToJson(result, "sticker", parseSticker(object->sticker)); + appendToJson(result, "story", parseStory(object->story)); appendToJson(result, "video", parseVideo(object->video)); appendToJson(result, "video_note", parseVideoNote(object->videoNote)); appendToJson(result, "voice", parseVoice(object->voice)); @@ -358,18 +415,23 @@ std::string TgTypeParser::parseMessage(const Message::Ptr& object) const { appendToJson(result, "pinned_message", parseMessage(object->pinnedMessage)); appendToJson(result, "invoice", parseInvoice(object->invoice)); appendToJson(result, "successful_payment", parseSuccessfulPayment(object->successfulPayment)); - appendToJson(result, "user_shared", parseUserShared(object->userShared)); + appendToJson(result, "users_shared", parseUsersShared(object->usersShared)); appendToJson(result, "chat_shared", parseChatShared(object->chatShared)); appendToJson(result, "connected_website", object->connectedWebsite); appendToJson(result, "write_access_allowed", parseWriteAccessAllowed(object->writeAccessAllowed)); appendToJson(result, "passport_data", parsePassportData(object->passportData)); appendToJson(result, "proximity_alert_triggered", parseProximityAlertTriggered(object->proximityAlertTriggered)); + appendToJson(result, "boost_added", parseChatBoostAdded(object->boostAdded)); appendToJson(result, "forum_topic_created", parseForumTopicCreated(object->forumTopicCreated)); appendToJson(result, "forum_topic_edited", parseForumTopicEdited(object->forumTopicEdited)); appendToJson(result, "forum_topic_closed", parseForumTopicClosed(object->forumTopicClosed)); appendToJson(result, "forum_topic_reopened", parseForumTopicReopened(object->forumTopicReopened)); appendToJson(result, "general_forum_topic_hidden", parseGeneralForumTopicHidden(object->generalForumTopicHidden)); appendToJson(result, "general_forum_topic_unhidden", parseGeneralForumTopicUnhidden(object->generalForumTopicUnhidden)); + appendToJson(result, "giveaway_created", parseGiveawayCreated(object->giveawayCreated)); + appendToJson(result, "giveaway", parseGiveaway(object->giveaway)); + appendToJson(result, "giveaway_winners", parseGiveawayWinners(object->giveawayWinners)); + appendToJson(result, "giveaway_completed", parseGiveawayCompleted(object->giveawayCompleted)); appendToJson(result, "video_chat_scheduled", parseVideoChatScheduled(object->videoChatScheduled)); appendToJson(result, "video_chat_started", parseVideoChatStarted(object->videoChatStarted)); appendToJson(result, "video_chat_ended", parseVideoChatEnded(object->videoChatEnded)); @@ -399,6 +461,28 @@ std::string TgTypeParser::parseMessageId(const MessageId::Ptr& object) const { return result; } +InaccessibleMessage::Ptr TgTypeParser::parseJsonAndGetInaccessibleMessage(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<InaccessibleMessage>()); + result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); + result->messageId = data.get<std::int32_t>("message_id", 0); + result->date = data.get<std::uint8_t>("date", 0); + return result; +} + +std::string TgTypeParser::parseInaccessibleMessage(const InaccessibleMessage::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "chat", parseChat(object->chat)); + appendToJson(result, "message_id", object->messageId); + appendToJson(result, "date", object->date); + removeLastComma(result); + result += '}'; + return result; +} + MessageEntity::Ptr TgTypeParser::parseJsonAndGetMessageEntity(const boost::property_tree::ptree& data) const { auto result(std::make_shared<MessageEntity>()); std::string type = data.get<std::string>("type", ""); @@ -426,6 +510,8 @@ MessageEntity::Ptr TgTypeParser::parseJsonAndGetMessageEntity(const boost::prope result->type = MessageEntity::Type::Strikethrough; } else if (type == "spoiler") { result->type = MessageEntity::Type::Spoiler; + } else if (type == "blockquote") { + result->type = MessageEntity::Type::Blockquote; } else if (type == "code") { result->type = MessageEntity::Type::Code; } else if (type == "pre") { @@ -476,6 +562,8 @@ std::string TgTypeParser::parseMessageEntity(const MessageEntity::Ptr& object) c appendToJson(result, "type", "strikethrough"); } else if (object->type == MessageEntity::Type::Spoiler) { appendToJson(result, "type", "spoiler"); + } else if (object->type == MessageEntity::Type::Blockquote) { + appendToJson(result, "type", "blockquote"); } else if (object->type == MessageEntity::Type::Code) { appendToJson(result, "type", "code"); } else if (object->type == MessageEntity::Type::Pre) { @@ -498,6 +586,250 @@ std::string TgTypeParser::parseMessageEntity(const MessageEntity::Ptr& object) c return result; } +TextQuote::Ptr TgTypeParser::parseJsonAndGetTextQuote(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<TextQuote>()); + result->text = data.get<std::string>("text", ""); + result->entities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "entities"); + result->position = data.get<std::int32_t>("position", 0); + result->isManual = data.get<bool>("is_manual", false); + return result; +} + +std::string TgTypeParser::parseTextQuote(const TextQuote::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "text", object->text); + appendToJson(result, "entities", parseArray(&TgTypeParser::parseMessageEntity, object->entities)); + appendToJson(result, "position", object->position); + appendToJson(result, "is_manual", object->isManual); + removeLastComma(result); + result += '}'; + return result; +} + +ExternalReplyInfo::Ptr TgTypeParser::parseJsonAndGetExternalReplyInfo(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<ExternalReplyInfo>()); + result->origin = tryParseJson<MessageOrigin>(&TgTypeParser::parseJsonAndGetMessageOrigin, data, "origin"); + result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); + result->messageId = data.get<std::int32_t>("message_id", 0); + result->linkPreviewOptions = tryParseJson<LinkPreviewOptions>(&TgTypeParser::parseJsonAndGetLinkPreviewOptions, data, "link_preview_options"); + result->animation = tryParseJson<Animation>(&TgTypeParser::parseJsonAndGetAnimation, data, "animation"); + result->audio = tryParseJson<Audio>(&TgTypeParser::parseJsonAndGetAudio, data, "audio"); + result->document = tryParseJson<Document>(&TgTypeParser::parseJsonAndGetDocument, data, "document"); + result->photo = parseJsonAndGetArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "photo"); + result->sticker = tryParseJson<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "sticker"); + result->story = tryParseJson<Story>(&TgTypeParser::parseJsonAndGetStory, data, "story"); + result->video = tryParseJson<Video>(&TgTypeParser::parseJsonAndGetVideo, data, "video"); + result->videoNote = tryParseJson<VideoNote>(&TgTypeParser::parseJsonAndGetVideoNote, data, "video_note"); + result->voice = tryParseJson<Voice>(&TgTypeParser::parseJsonAndGetVoice, data, "voice"); + result->hasMediaSpoiler = data.get<bool>("has_media_spoiler", false); + result->contact = tryParseJson<Contact>(&TgTypeParser::parseJsonAndGetContact, data, "contact"); + result->dice = tryParseJson<Dice>(&TgTypeParser::parseJsonAndGetDice, data, "dice"); + result->game = tryParseJson<Game>(&TgTypeParser::parseJsonAndGetGame, data, "game"); + result->giveaway = tryParseJson<Giveaway>(&TgTypeParser::parseJsonAndGetGiveaway, data, "giveaway"); + result->giveawayWinners = tryParseJson<GiveawayWinners>(&TgTypeParser::parseJsonAndGetGiveawayWinners, data, "giveaway_winners"); + result->invoice = tryParseJson<Invoice>(&TgTypeParser::parseJsonAndGetInvoice, data, "invoice"); + result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location"); + result->poll = tryParseJson<Poll>(&TgTypeParser::parseJsonAndGetPoll, data, "poll"); + result->venue = tryParseJson<Venue>(&TgTypeParser::parseJsonAndGetVenue, data, "venue"); + return result; +} + +std::string TgTypeParser::parseExternalReplyInfo(const ExternalReplyInfo::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "origin", parseMessageOrigin(object->origin)); + appendToJson(result, "chat", parseChat(object->chat)); + appendToJson(result, "message_id", object->messageId); + appendToJson(result, "link_preview_options", parseLinkPreviewOptions(object->linkPreviewOptions)); + appendToJson(result, "animation", parseAnimation(object->animation)); + appendToJson(result, "audio", parseAudio(object->audio)); + appendToJson(result, "document", parseDocument(object->document)); + appendToJson(result, "photo", parseArray(&TgTypeParser::parsePhotoSize, object->photo)); + appendToJson(result, "sticker", parseSticker(object->sticker)); + appendToJson(result, "story", parseStory(object->story)); + appendToJson(result, "video", parseVideo(object->video)); + appendToJson(result, "video_note", parseVideoNote(object->videoNote)); + appendToJson(result, "voice", parseVoice(object->voice)); + appendToJson(result, "has_media_spoiler", object->hasMediaSpoiler); + appendToJson(result, "contact", parseContact(object->contact)); + appendToJson(result, "dice", parseDice(object->dice)); + appendToJson(result, "game", parseGame(object->game)); + appendToJson(result, "giveaway", parseGiveaway(object->giveaway)); + appendToJson(result, "giveaway_winners", parseGiveawayWinners(object->giveawayWinners)); + appendToJson(result, "invoice", parseInvoice(object->invoice)); + appendToJson(result, "location", parseLocation(object->location)); + appendToJson(result, "poll", parsePoll(object->poll)); + appendToJson(result, "venue", parseVenue(object->venue)); + removeLastComma(result); + result += '}'; + return result; +} + +ReplyParameters::Ptr TgTypeParser::parseJsonAndGetReplyParameters(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<ReplyParameters>()); + result->messageId = data.get<std::int32_t>("message_id", 0); + result->chatId = data.get<std::int64_t>("chat_id", 0); + result->allowSendingWithoutReply = data.get<bool>("allow_sending_without_reply", false); + result->quote = data.get<std::string>("quote", ""); + result->quoteParseMode = data.get<std::string>("quote_parse_mode", ""); + result->quoteEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "quote_entities"); + result->quotePosition = data.get<std::int32_t>("quote_position", 0); + return result; +} + +std::string TgTypeParser::parseReplyParameters(const ReplyParameters::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "message_id", object->messageId); + appendToJson(result, "chat_id", object->chatId); + appendToJson(result, "allow_sending_without_reply", object->allowSendingWithoutReply); + appendToJson(result, "quote", object->quote); + appendToJson(result, "quote_parse_mode", object->quoteParseMode); + appendToJson(result, "quote_entities", parseArray(&TgTypeParser::parseMessageEntity, object->quoteEntities)); + appendToJson(result, "quote_position", object->quotePosition); + removeLastComma(result); + result += '}'; + return result; +} + +MessageOrigin::Ptr TgTypeParser::parseJsonAndGetMessageOrigin(const boost::property_tree::ptree& data) const { + std::string type = data.get<std::string>("type", ""); + MessageOrigin::Ptr result; + + if (type == MessageOriginUser::TYPE) { + result = std::static_pointer_cast<MessageOrigin>(parseJsonAndGetMessageOriginUser(data)); + } else if (type == MessageOriginHiddenUser::TYPE) { + result = std::static_pointer_cast<MessageOrigin>(parseJsonAndGetMessageOriginHiddenUser(data)); + } else if (type == MessageOriginChat::TYPE) { + result = std::static_pointer_cast<MessageOrigin>(parseJsonAndGetMessageOriginChat(data)); + } else if (type == MessageOriginChannel::TYPE) { + result = std::static_pointer_cast<MessageOrigin>(parseJsonAndGetMessageOriginChannel(data)); + } else { + result = std::make_shared<MessageOrigin>(); + } + + result->type = type; + result->date = data.get<std::int32_t>("date", 0); + + return result; +} + +std::string TgTypeParser::parseMessageOrigin(const MessageOrigin::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "type", object->type); + appendToJson(result, "date", object->date); + + if (object->type == MessageOriginUser::TYPE) { + result += parseMessageOriginUser(std::static_pointer_cast<MessageOriginUser>(object)); + } else if (object->type == MessageOriginHiddenUser::TYPE) { + result += parseMessageOriginHiddenUser(std::static_pointer_cast<MessageOriginHiddenUser>(object)); + } else if (object->type == MessageOriginChat::TYPE) { + result += parseMessageOriginChat(std::static_pointer_cast<MessageOriginChat>(object)); + } else if (object->type == MessageOriginChannel::TYPE) { + result += parseMessageOriginChannel(std::static_pointer_cast<MessageOriginChannel>(object)); + } + + removeLastComma(result); + result += '}'; + return result; +} + +MessageOriginUser::Ptr TgTypeParser::parseJsonAndGetMessageOriginUser(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetMessageOrigin(). + auto result(std::make_shared<MessageOriginUser>()); + result->senderUser = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "sender_user"); + return result; +} + +std::string TgTypeParser::parseMessageOriginUser(const MessageOriginUser::Ptr& object) const { + if (!object) { + return ""; + } + // This function will be called by parseMessageOrigin(), so I don't add + // curly brackets to the result std::string. + std::string result; + appendToJson(result, "sender_user", parseUser(object->senderUser)); + // The last comma will be erased by parseMessageOrigin(). + return result; +} + +MessageOriginHiddenUser::Ptr TgTypeParser::parseJsonAndGetMessageOriginHiddenUser(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetMessageOrigin(). + auto result(std::make_shared<MessageOriginHiddenUser>()); + result->senderUserName = data.get<std::string>("sender_user_name", ""); + return result; +} + +std::string TgTypeParser::parseMessageOriginHiddenUser(const MessageOriginHiddenUser::Ptr& object) const { + if (!object) { + return ""; + } + // This function will be called by parseMessageOrigin(), so I don't add + // curly brackets to the result std::string. + std::string result; + appendToJson(result, "sender_user_name", object->senderUserName); + // The last comma will be erased by parseMessageOrigin(). + return result; +} + +MessageOriginChat::Ptr TgTypeParser::parseJsonAndGetMessageOriginChat(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetMessageOrigin(). + auto result(std::make_shared<MessageOriginChat>()); + result->senderChat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "sender_chat"); + result->authorSignature = data.get<std::string>("author_signature", ""); + return result; +} + +std::string TgTypeParser::parseMessageOriginChat(const MessageOriginChat::Ptr& object) const { + if (!object) { + return ""; + } + // This function will be called by parseMessageOrigin(), so I don't add + // curly brackets to the result std::string. + std::string result; + appendToJson(result, "sender_chat", parseChat(object->senderChat)); + appendToJson(result, "author_signature", object->authorSignature); + // The last comma will be erased by parseMessageOrigin(). + return result; +} + +MessageOriginChannel::Ptr TgTypeParser::parseJsonAndGetMessageOriginChannel(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetMessageOrigin(). + auto result(std::make_shared<MessageOriginChannel>()); + result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); + result->messageId = data.get<std::int32_t>("message_id", 0); + result->authorSignature = data.get<std::string>("author_signature", ""); + return result; +} + +std::string TgTypeParser::parseMessageOriginChannel(const MessageOriginChannel::Ptr& object) const { + if (!object) { + return ""; + } + // This function will be called by parseMessageOrigin(), so I don't add + // curly brackets to the result std::string. + std::string result; + appendToJson(result, "chat", parseChat(object->chat)); + appendToJson(result, "message_id", object->messageId); + appendToJson(result, "author_signature", object->authorSignature); + // The last comma will be erased by parseMessageOrigin(). + return result; +} + PhotoSize::Ptr TgTypeParser::parseJsonAndGetPhotoSize(const boost::property_tree::ptree& data) const { auto result(std::make_shared<PhotoSize>()); result->fileId = data.get<std::string>("file_id", ""); @@ -531,7 +863,7 @@ Animation::Ptr TgTypeParser::parseJsonAndGetAnimation(const boost::property_tree result->width = data.get<std::int32_t>("width", 0); result->height = data.get<std::int32_t>("height", 0); result->duration = data.get<std::int32_t>("duration", 0); - result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); + result->thumbnail = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumbnail"); result->fileName = data.get<std::string>("file_name", ""); result->mimeType = data.get<std::string>("mime_type", ""); result->fileSize = data.get<std::int64_t>("file_size", 0); @@ -549,7 +881,7 @@ std::string TgTypeParser::parseAnimation(const Animation::Ptr& object) const { appendToJson(result, "width", object->width); appendToJson(result, "height", object->height); appendToJson(result, "duration", object->duration); - appendToJson(result, "thumb", parsePhotoSize(object->thumb)); + appendToJson(result, "thumbnail", parsePhotoSize(object->thumbnail)); appendToJson(result, "file_name", object->fileName); appendToJson(result, "mime_type", object->mimeType); appendToJson(result, "file_size", object->fileSize); @@ -568,7 +900,7 @@ Audio::Ptr TgTypeParser::parseJsonAndGetAudio(const boost::property_tree::ptree& result->fileName = data.get<std::string>("file_name", ""); result->mimeType = data.get<std::string>("mime_type", ""); result->fileSize = data.get<std::int64_t>("file_size", 0); - result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); + result->thumbnail = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumbnail"); return result; } @@ -586,7 +918,7 @@ std::string TgTypeParser::parseAudio(const Audio::Ptr& object) const { appendToJson(result, "file_name", object->fileName); appendToJson(result, "mime_type", object->mimeType); appendToJson(result, "file_size", object->fileSize); - appendToJson(result, "thumb", parsePhotoSize(object->thumb)); + appendToJson(result, "thumbnail", parsePhotoSize(object->thumbnail)); removeLastComma(result); result += '}'; return result; @@ -596,7 +928,7 @@ Document::Ptr TgTypeParser::parseJsonAndGetDocument(const boost::property_tree:: auto result(std::make_shared<Document>()); result->fileId = data.get<std::string>("file_id", ""); result->fileUniqueId = data.get<std::string>("file_unique_id", ""); - result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); + result->thumbnail = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumbnail"); result->fileName = data.get<std::string>("file_name", ""); result->mimeType = data.get<std::string>("mime_type", ""); result->fileSize = data.get<std::int64_t>("file_size", 0); @@ -611,7 +943,7 @@ std::string TgTypeParser::parseDocument(const Document::Ptr& object) const { result += '{'; appendToJson(result, "file_id", object->fileId); appendToJson(result, "file_unique_id", object->fileUniqueId); - appendToJson(result, "thumb", parsePhotoSize(object->thumb)); + appendToJson(result, "thumbnail", parsePhotoSize(object->thumbnail)); appendToJson(result, "file_name", object->fileName); appendToJson(result, "mime_type", object->mimeType); appendToJson(result, "file_size", object->fileSize); @@ -620,6 +952,26 @@ std::string TgTypeParser::parseDocument(const Document::Ptr& object) const { return result; } +Story::Ptr TgTypeParser::parseJsonAndGetStory(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<Story>()); + result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); + result->id = data.get<std::int32_t>("id", 0); + return result; +} + +std::string TgTypeParser::parseStory(const Story::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "chat", parseChat(object->chat)); + appendToJson(result, "id", object->id); + removeLastComma(result); + result += '}'; + return result; +} + Video::Ptr TgTypeParser::parseJsonAndGetVideo(const boost::property_tree::ptree& data) const { auto result(std::make_shared<Video>()); result->fileId = data.get<std::string>("file_id", ""); @@ -627,7 +979,7 @@ Video::Ptr TgTypeParser::parseJsonAndGetVideo(const boost::property_tree::ptree& result->width = data.get<std::int32_t>("width", 0); result->height = data.get<std::int32_t>("height", 0); result->duration = data.get<std::int32_t>("duration", 0); - result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); + result->thumbnail = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumbnail"); result->fileName = data.get<std::string>("file_name", ""); result->mimeType = data.get<std::string>("mime_type", ""); result->fileSize = data.get<std::int64_t>("file_size", 0); @@ -645,7 +997,7 @@ std::string TgTypeParser::parseVideo(const Video::Ptr& object) const { appendToJson(result, "width", object->width); appendToJson(result, "height", object->height); appendToJson(result, "duration", object->duration); - appendToJson(result, "thumb", parsePhotoSize(object->thumb)); + appendToJson(result, "thumbnail", parsePhotoSize(object->thumbnail)); appendToJson(result, "file_name", object->fileName); appendToJson(result, "mime_type", object->mimeType); appendToJson(result, "file_size", object->fileSize); @@ -660,8 +1012,8 @@ VideoNote::Ptr TgTypeParser::parseJsonAndGetVideoNote(const boost::property_tree result->fileUniqueId = data.get<std::string>("file_unique_id", ""); result->length = data.get<std::int32_t>("length", 0); result->duration = data.get<std::int32_t>("duration", 0); - result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); - result->fileSize = data.get("file_size", 0); + result->thumbnail = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumbnail"); + result->fileSize = data.get<std::int32_t>("file_size", 0); return result; } @@ -675,7 +1027,7 @@ std::string TgTypeParser::parseVideoNote(const VideoNote::Ptr& object) const { appendToJson(result, "file_unique_id", object->fileUniqueId); appendToJson(result, "length", object->length); appendToJson(result, "duration", object->duration); - appendToJson(result, "thumb", parsePhotoSize(object->thumb)); + appendToJson(result, "thumbnail", parsePhotoSize(object->thumbnail)); appendToJson(result, "file_size", object->fileSize); removeLastComma(result); result += '}'; @@ -710,11 +1062,11 @@ std::string TgTypeParser::parseVoice(const Voice::Ptr& object) const { Contact::Ptr TgTypeParser::parseJsonAndGetContact(const boost::property_tree::ptree& data) const { auto result(std::make_shared<Contact>()); - result->phoneNumber = data.get<std::string>("phone_number"); - result->firstName = data.get<std::string>("first_name"); - result->lastName = data.get("last_name", ""); - result->userId = data.get("user_id", 0); - result->vcard = data.get("vcard", ""); + result->phoneNumber = data.get<std::string>("phone_number", ""); + result->firstName = data.get<std::string>("first_name", ""); + result->lastName = data.get<std::string>("last_name", ""); + result->userId = data.get<std::int64_t>("user_id", 0); + result->vcard = data.get<std::string>("vcard", ""); return result; } @@ -756,8 +1108,8 @@ std::string TgTypeParser::parseDice(const Dice::Ptr& object) const { PollOption::Ptr TgTypeParser::parseJsonAndGetPollOption(const boost::property_tree::ptree& data) const { auto result(std::make_shared<PollOption>()); - result->text = data.get("text", ""); - result->voterCount = data.get("voter_count", 0); + result->text = data.get<std::string>("text", ""); + result->voterCount = data.get<std::int32_t>("voter_count", 0); return result; } @@ -777,6 +1129,7 @@ std::string TgTypeParser::parsePollOption(const PollOption::Ptr& object) const { PollAnswer::Ptr TgTypeParser::parseJsonAndGetPollAnswer(const boost::property_tree::ptree& data) const { auto result(std::make_shared<PollAnswer>()); result->pollId = data.get<std::string>("poll_id", ""); + result->voterChat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "voter_chat"); result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user"); result->optionIds = parseJsonAndGetArray<std::int32_t>( [] (const boost::property_tree::ptree& innerData)->std::int32_t { @@ -792,8 +1145,10 @@ std::string TgTypeParser::parsePollAnswer(const PollAnswer::Ptr& object) const { std::string result; result += '{'; appendToJson(result, "poll_id", object->pollId); + appendToJson(result, "voter_chat", parseChat(object->voterChat)); appendToJson(result, "user", parseUser(object->user)); - appendToJson(result, "option_ids", parseArray<std::int32_t>([] (std::int32_t i)->std::int32_t { + appendToJson(result, "option_ids", parseArray<std::int32_t>( + [] (std::int32_t i)->std::int32_t { return i; }, object->optionIds)); removeLastComma(result); @@ -808,7 +1163,7 @@ Poll::Ptr TgTypeParser::parseJsonAndGetPoll(const boost::property_tree::ptree& d result->options = parseJsonAndGetArray<PollOption>(&TgTypeParser::parseJsonAndGetPollOption, data, "options"); result->totalVoterCount = data.get<std::int32_t>("total_voter_count", 0); result->isClosed = data.get<bool>("is_closed", false); - result->isAnonymous = data.get<bool>("is_anonymous", true); + result->isAnonymous = data.get<bool>("is_anonymous", false); result->type = data.get<std::string>("type", ""); result->allowsMultipleAnswers = data.get<bool>("allows_multiple_answers", false); result->correctOptionId = data.get<std::int32_t>("correct_option_id", 0); @@ -834,7 +1189,7 @@ std::string TgTypeParser::parsePoll(const Poll::Ptr& object) const { appendToJson(result, "type", object->type); appendToJson(result, "allows_multiple_answers", object->allowsMultipleAnswers); appendToJson(result, "correct_option_id", object->correctOptionId); - appendToJson(result, "explanation", object->correctOptionId); + appendToJson(result, "explanation", object->explanation); appendToJson(result, "explanation_entities", parseArray(&TgTypeParser::parseMessageEntity, object->explanationEntities)); appendToJson(result, "open_period", object->openPeriod); appendToJson(result, "close_date", object->closeDate); @@ -845,8 +1200,8 @@ std::string TgTypeParser::parsePoll(const Poll::Ptr& object) const { Location::Ptr TgTypeParser::parseJsonAndGetLocation(const boost::property_tree::ptree& data) const { auto result(std::make_shared<Location>()); - result->longitude = data.get<float>("longitude", 0); result->latitude = data.get<float>("latitude", 0); + result->longitude = data.get<float>("longitude", 0); result->horizontalAccuracy = data.get<float>("horizontal_accuracy", 0); result->livePeriod = data.get<std::int32_t>("live_period", 0); result->heading = data.get<std::int32_t>("heading", 0); @@ -860,8 +1215,8 @@ std::string TgTypeParser::parseLocation(const Location::Ptr& object) const { } std::string result; result += '{'; - appendToJson(result, "longitude", object->longitude); appendToJson(result, "latitude", object->latitude); + appendToJson(result, "longitude", object->longitude); appendToJson(result, "horizontal_accuracy", object->horizontalAccuracy); appendToJson(result, "live_period", object->livePeriod); appendToJson(result, "heading", object->heading); @@ -961,6 +1316,24 @@ std::string TgTypeParser::parseMessageAutoDeleteTimerChanged(const MessageAutoDe return result; } +ChatBoostAdded::Ptr TgTypeParser::parseJsonAndGetChatBoostAdded(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<ChatBoostAdded>()); + result->boostCount = data.get<std::int32_t>("boost_count", 0); + return result; +} + +std::string TgTypeParser::parseChatBoostAdded(const ChatBoostAdded::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "boost_count", object->boostCount); + removeLastComma(result); + result += '}'; + return result; +} + ForumTopicCreated::Ptr TgTypeParser::parseJsonAndGetForumTopicCreated(const boost::property_tree::ptree& data) const { auto result(std::make_shared<ForumTopicCreated>()); result->name = data.get<std::string>("name", ""); @@ -983,7 +1356,7 @@ std::string TgTypeParser::parseForumTopicCreated(const ForumTopicCreated::Ptr& o return result; } -ForumTopicClosed::Ptr TgTypeParser::parseJsonAndGetForumTopicClosed(const boost::property_tree::ptree& data) const { +ForumTopicClosed::Ptr TgTypeParser::parseJsonAndGetForumTopicClosed(const boost::property_tree::ptree& /*data*/) const { auto result(std::make_shared<ForumTopicClosed>()); return result; } @@ -994,7 +1367,7 @@ std::string TgTypeParser::parseForumTopicClosed(const ForumTopicClosed::Ptr& obj } std::string result; result += '{'; - //removeLastComma(result); + // removeLastComma(result); result += '}'; return result; } @@ -1019,7 +1392,7 @@ std::string TgTypeParser::parseForumTopicEdited(const ForumTopicEdited::Ptr& obj return result; } -ForumTopicReopened::Ptr TgTypeParser::parseJsonAndGetForumTopicReopened(const boost::property_tree::ptree& data) const { +ForumTopicReopened::Ptr TgTypeParser::parseJsonAndGetForumTopicReopened(const boost::property_tree::ptree& /*data*/) const { auto result(std::make_shared<ForumTopicReopened>()); return result; } @@ -1030,12 +1403,12 @@ std::string TgTypeParser::parseForumTopicReopened(const ForumTopicReopened::Ptr& } std::string result; result += '{'; - //removeLastComma(result); + // removeLastComma(result); result += '}'; return result; } -GeneralForumTopicHidden::Ptr TgTypeParser::parseJsonAndGetGeneralForumTopicHidden(const boost::property_tree::ptree& data) const { +GeneralForumTopicHidden::Ptr TgTypeParser::parseJsonAndGetGeneralForumTopicHidden(const boost::property_tree::ptree& /*data*/) const { auto result(std::make_shared<GeneralForumTopicHidden>()); return result; } @@ -1046,12 +1419,12 @@ std::string TgTypeParser::parseGeneralForumTopicHidden(const GeneralForumTopicHi } std::string result; result += '{'; - //removeLastComma(result); + // removeLastComma(result); result += '}'; return result; } -GeneralForumTopicUnhidden::Ptr TgTypeParser::parseJsonAndGetGeneralForumTopicUnhidden(const boost::property_tree::ptree& data) const { +GeneralForumTopicUnhidden::Ptr TgTypeParser::parseJsonAndGetGeneralForumTopicUnhidden(const boost::property_tree::ptree& /*data*/) const { auto result(std::make_shared<GeneralForumTopicUnhidden>()); return result; } @@ -1062,26 +1435,52 @@ std::string TgTypeParser::parseGeneralForumTopicUnhidden(const GeneralForumTopic } std::string result; result += '{'; - //removeLastComma(result); + // removeLastComma(result); result += '}'; return result; } -UserShared::Ptr TgTypeParser::parseJsonAndGetUserShared(const boost::property_tree::ptree& data) const { - auto result(std::make_shared<UserShared>()); - result->requestId = data.get<std::int32_t>("request_id", 0); +SharedUser::Ptr TgTypeParser::parseJsonAndGetSharedUser(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<SharedUser>()); result->userId = data.get<std::int64_t>("user_id", 0); + result->firstName = data.get<std::string>("first_name", ""); + result->lastName = data.get<std::string>("last_name", ""); + result->username = data.get<std::string>("username", ""); + result->photo = parseJsonAndGetArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "photo"); return result; } -std::string TgTypeParser::parseUserShared(const UserShared::Ptr& object) const { +std::string TgTypeParser::parseSharedUser(const SharedUser::Ptr& object) const { if (!object) { return ""; } std::string result; result += '{'; - appendToJson(result, "request_id", object->requestId); appendToJson(result, "user_id", object->userId); + appendToJson(result, "first_name", object->firstName); + appendToJson(result, "last_name", object->lastName); + appendToJson(result, "username", object->username); + appendToJson(result, "photo", parseArray(&TgTypeParser::parsePhotoSize, object->photo)); + removeLastComma(result); + result += '}'; + return result; +} + +UsersShared::Ptr TgTypeParser::parseJsonAndGetUsersShared(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<UsersShared>()); + result->requestId = data.get<std::int32_t>("request_id", 0); + result->users = parseJsonAndGetArray<SharedUser>(&TgTypeParser::parseJsonAndGetSharedUser, data, "users"); + return result; +} + +std::string TgTypeParser::parseUsersShared(const UsersShared::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "request_id", object->requestId); + appendToJson(result, "users", parseArray(&TgTypeParser::parseSharedUser, object->users)); removeLastComma(result); result += '}'; return result; @@ -1090,7 +1489,10 @@ std::string TgTypeParser::parseUserShared(const UserShared::Ptr& object) const { ChatShared::Ptr TgTypeParser::parseJsonAndGetChatShared(const boost::property_tree::ptree& data) const { auto result(std::make_shared<ChatShared>()); result->requestId = data.get<std::int32_t>("request_id", 0); - result->userId = data.get<std::int64_t>("user_id", 0); + result->chatId = data.get<std::int64_t>("chat_id", 0); + result->title = data.get<std::string>("title", ""); + result->username = data.get<std::string>("username", ""); + result->photo = parseJsonAndGetArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "photo"); return result; } @@ -1101,7 +1503,10 @@ std::string TgTypeParser::parseChatShared(const ChatShared::Ptr& object) const { std::string result; result += '{'; appendToJson(result, "request_id", object->requestId); - appendToJson(result, "user_id", object->userId); + appendToJson(result, "chat_id", object->chatId); + appendToJson(result, "title", object->title); + appendToJson(result, "username", object->username); + appendToJson(result, "photo", parseArray(&TgTypeParser::parsePhotoSize, object->photo)); removeLastComma(result); result += '}'; return result; @@ -1109,6 +1514,9 @@ std::string TgTypeParser::parseChatShared(const ChatShared::Ptr& object) const { WriteAccessAllowed::Ptr TgTypeParser::parseJsonAndGetWriteAccessAllowed(const boost::property_tree::ptree& data) const { auto result(std::make_shared<WriteAccessAllowed>()); + result->fromRequest = data.get<bool>("from_request", false); + result->webAppName = data.get<std::string>("web_app_name", ""); + result->fromAttachmentMenu = data.get<bool>("from_attachment_menu", false); return result; } @@ -1118,7 +1526,10 @@ std::string TgTypeParser::parseWriteAccessAllowed(const WriteAccessAllowed::Ptr& } std::string result; result += '{'; - //removeLastComma(result); + appendToJson(result, "from_request", object->fromRequest); + appendToJson(result, "web_app_name", object->webAppName); + appendToJson(result, "from_attachment_menu", object->fromAttachmentMenu); + removeLastComma(result); result += '}'; return result; } @@ -1141,7 +1552,7 @@ std::string TgTypeParser::parseVideoChatScheduled(const VideoChatScheduled::Ptr& return result; } -VideoChatStarted::Ptr TgTypeParser::parseJsonAndGetVideoChatStarted(const boost::property_tree::ptree& data) const { +VideoChatStarted::Ptr TgTypeParser::parseJsonAndGetVideoChatStarted(const boost::property_tree::ptree& /*data*/) const { auto result(std::make_shared<VideoChatStarted>()); return result; } @@ -1152,6 +1563,7 @@ std::string TgTypeParser::parseVideoChatStarted(const VideoChatStarted::Ptr& obj } std::string result; result += '{'; + // removeLastComma(result); result += '}'; return result; } @@ -1192,9 +1604,149 @@ std::string TgTypeParser::parseVideoChatParticipantsInvited(const VideoChatParti return result; } +GiveawayCreated::Ptr TgTypeParser::parseJsonAndGetGiveawayCreated(const boost::property_tree::ptree& /*data*/) const { + auto result(std::make_shared<GiveawayCreated>()); + return result; +} + +std::string TgTypeParser::parseGiveawayCreated(const GiveawayCreated::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + // removeLastComma(result); + result += '}'; + return result; +} + +Giveaway::Ptr TgTypeParser::parseJsonAndGetGiveaway(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<Giveaway>()); + result->chats = parseJsonAndGetArray<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chats"); + result->winnersSelectionDate = data.get<std::uint32_t>("winners_selection_date", 0); + result->winnerCount = data.get<std::int32_t>("winner_count", 0); + result->onlyNewMembers = data.get<bool>("only_new_members", false); + result->hasPublicWinners = data.get<bool>("has_public_winners", false); + result->prizeDescription = data.get<std::string>("prize_description", ""); + result->countryCodes = parseJsonAndGetArray<std::string>( + [] (const boost::property_tree::ptree& innerData)->std::string { + return innerData.get<std::string>(""); + }, data, "country_codes"); + result->premiumSubscriptionMonthCount = data.get<std::int32_t>("premium_subscription_month_count", 0); + return result; +} + +std::string TgTypeParser::parseGiveaway(const Giveaway::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "chats", parseArray(&TgTypeParser::parseChat, object->chats)); + appendToJson(result, "winners_selection_date", object->winnersSelectionDate); + appendToJson(result, "winner_count", object->winnerCount); + appendToJson(result, "only_new_members", object->onlyNewMembers); + appendToJson(result, "has_public_winners", object->hasPublicWinners); + appendToJson(result, "prize_description", object->prizeDescription); + appendToJson(result, "country_codes", parseArray<std::string>( + [] (const std::string& s)->std::string { + return s; + }, object->countryCodes)); + appendToJson(result, "premium_subscription_month_count", object->premiumSubscriptionMonthCount); + removeLastComma(result); + result += '}'; + return result; +} + +GiveawayWinners::Ptr TgTypeParser::parseJsonAndGetGiveawayWinners(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<GiveawayWinners>()); + result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); + result->giveawayMessageId = data.get<std::int32_t>("giveaway_message_id", 0); + result->winnersSelectionDate = data.get<std::uint32_t>("winners_selection_date", 0); + result->winnerCount = data.get<std::int32_t>("winner_count", 0); + result->winners = parseJsonAndGetArray<User>(&TgTypeParser::parseJsonAndGetUser, data, "winners"); + result->additionalChatCount = data.get<std::int32_t>("additional_chat_count", 0); + result->premiumSubscriptionMonthCount = data.get<std::int32_t>("premium_subscription_month_count", 0); + result->unclaimedPrizeCount = data.get<std::int32_t>("unclaimed_prize_count", 0); + result->onlyNewMembers = data.get<bool>("only_new_members", false); + result->wasRefunded = data.get<bool>("was_refunded", false); + result->prizeDescription = data.get<std::string>("prize_description", ""); + return result; +} + +std::string TgTypeParser::parseGiveawayWinners(const GiveawayWinners::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "chat", parseChat(object->chat)); + appendToJson(result, "giveaway_message_id", object->giveawayMessageId); + appendToJson(result, "winners_selection_date", object->winnersSelectionDate); + appendToJson(result, "winner_count", object->winnerCount); + appendToJson(result, "winners", parseArray(&TgTypeParser::parseUser, object->winners)); + appendToJson(result, "additional_chat_count", object->additionalChatCount); + appendToJson(result, "premium_subscription_month_count", object->premiumSubscriptionMonthCount); + appendToJson(result, "unclaimed_prize_count", object->unclaimedPrizeCount); + appendToJson(result, "only_new_members", object->onlyNewMembers); + appendToJson(result, "was_refunded", object->wasRefunded); + appendToJson(result, "prize_description", object->prizeDescription); + removeLastComma(result); + result += '}'; + return result; +} + +GiveawayCompleted::Ptr TgTypeParser::parseJsonAndGetGiveawayCompleted(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<GiveawayCompleted>()); + result->winnerCount = data.get<std::int32_t>("winner_count", 0); + result->unclaimedPrizeCount = data.get<std::int32_t>("unclaimed_prize_count", 0); + result->giveawayMessage = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "giveaway_message"); + return result; +} + +std::string TgTypeParser::parseGiveawayCompleted(const GiveawayCompleted::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "winner_count", object->winnerCount); + appendToJson(result, "unclaimed_prize_count", object->unclaimedPrizeCount); + appendToJson(result, "giveaway_message", parseMessage(object->giveawayMessage)); + removeLastComma(result); + result += '}'; + return result; +} + +LinkPreviewOptions::Ptr TgTypeParser::parseJsonAndGetLinkPreviewOptions(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<LinkPreviewOptions>()); + result->isDisabled = data.get<bool>("is_disabled", false); + result->url = data.get<std::string>("url", ""); + result->preferSmallMedia = data.get<bool>("prefer_small_media", false); + result->preferLargeMedia = data.get<bool>("prefer_large_media", false); + result->showAboveText = data.get<bool>("show_above_text", false); + return result; +} + +std::string TgTypeParser::parseLinkPreviewOptions(const LinkPreviewOptions::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "is_disabled", object->isDisabled); + appendToJson(result, "url", object->url); + appendToJson(result, "prefer_small_media", object->preferSmallMedia); + appendToJson(result, "prefer_large_media", object->preferLargeMedia); + appendToJson(result, "show_above_text", object->showAboveText); + removeLastComma(result); + result += '}'; + return result; +} + UserProfilePhotos::Ptr TgTypeParser::parseJsonAndGetUserProfilePhotos(const boost::property_tree::ptree& data) const { auto result(std::make_shared<UserProfilePhotos>()); - result->totalCount = data.get<std::int32_t>("total_count"); + result->totalCount = data.get<std::int32_t>("total_count", 0); result->photos = parseJsonAndGet2DArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "photos"); return result; } @@ -1299,7 +1851,7 @@ std::string TgTypeParser::parseReplyKeyboardMarkup(const ReplyKeyboardMarkup::Pt KeyboardButton::Ptr TgTypeParser::parseJsonAndGetKeyboardButton(const boost::property_tree::ptree& data) const { auto result(std::make_shared<KeyboardButton>()); result->text = data.get<std::string>("text", ""); - result->requestUser = tryParseJson<KeyboardButtonRequestUser>(&TgTypeParser::parseJsonAndGetKeyboardButtonRequestUser, data, "request_user"); + result->requestUsers = tryParseJson<KeyboardButtonRequestUsers>(&TgTypeParser::parseJsonAndGetKeyboardButtonRequestUsers, data, "request_users"); result->requestChat = tryParseJson<KeyboardButtonRequestChat>(&TgTypeParser::parseJsonAndGetKeyboardButtonRequestChat, data, "request_chat"); result->requestContact = data.get<bool>("request_contact", false); result->requestLocation = data.get<bool>("request_location", false); @@ -1315,7 +1867,7 @@ std::string TgTypeParser::parseKeyboardButton(const KeyboardButton::Ptr& object) std::string result; result += '{'; appendToJson(result, "text", object->text); - appendToJson(result, "request_user", parseKeyboardButtonRequestUser(object->requestUser)); + appendToJson(result, "request_users", parseKeyboardButtonRequestUsers(object->requestUsers)); appendToJson(result, "request_chat", parseKeyboardButtonRequestChat(object->requestChat)); appendToJson(result, "request_contact", object->requestContact); appendToJson(result, "request_location", object->requestLocation); @@ -1326,15 +1878,19 @@ std::string TgTypeParser::parseKeyboardButton(const KeyboardButton::Ptr& object) return result; } -KeyboardButtonRequestUser::Ptr TgTypeParser::parseJsonAndGetKeyboardButtonRequestUser(const boost::property_tree::ptree& data) const { - auto result(std::make_shared<KeyboardButtonRequestUser>()); +KeyboardButtonRequestUsers::Ptr TgTypeParser::parseJsonAndGetKeyboardButtonRequestUsers(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<KeyboardButtonRequestUsers>()); result->requestId = data.get<std::int32_t>("request_id", 0); result->userIsBot = data.get<bool>("user_is_bot", false); result->userIsPremium = data.get<bool>("user_is_premium", false); + result->maxQuantity = data.get<std::uint8_t>("max_quantity", 1); + result->requestName = data.get<bool>("request_name", false); + result->requestUsername = data.get<bool>("request_username", false); + result->requestPhoto = data.get<bool>("request_photo", false); return result; } -std::string TgTypeParser::parseKeyboardButtonRequestUser(const KeyboardButtonRequestUser::Ptr& object) const { +std::string TgTypeParser::parseKeyboardButtonRequestUsers(const KeyboardButtonRequestUsers::Ptr& object) const { if (!object) { return ""; } @@ -1343,6 +1899,10 @@ std::string TgTypeParser::parseKeyboardButtonRequestUser(const KeyboardButtonReq appendToJson(result, "request_id", object->requestId); appendToJson(result, "user_is_bot", object->userIsBot); appendToJson(result, "user_is_premium", object->userIsPremium); + appendToJson(result, "max_quantity", object->maxQuantity); + appendToJson(result, "request_name", object->requestName); + appendToJson(result, "request_username", object->requestUsername); + appendToJson(result, "request_photo", object->requestPhoto); removeLastComma(result); result += '}'; return result; @@ -1358,6 +1918,9 @@ KeyboardButtonRequestChat::Ptr TgTypeParser::parseJsonAndGetKeyboardButtonReques result->userAdministratorRights = tryParseJson<ChatAdministratorRights>(&TgTypeParser::parseJsonAndGetChatAdministratorRights, data, "user_administrator_rights"); result->botAdministratorRights = tryParseJson<ChatAdministratorRights>(&TgTypeParser::parseJsonAndGetChatAdministratorRights, data, "bot_administrator_rights"); result->botIsMember = data.get<bool>("bot_is_member", false); + result->requestTitle = data.get<bool>("request_title", false); + result->requestUsername = data.get<bool>("request_username", false); + result->requestPhoto = data.get<bool>("request_photo", false); return result; } @@ -1375,6 +1938,9 @@ std::string TgTypeParser::parseKeyboardButtonRequestChat(const KeyboardButtonReq appendToJson(result, "user_administrator_rights", parseChatAdministratorRights(object->userAdministratorRights)); appendToJson(result, "bot_administrator_rights", parseChatAdministratorRights(object->botAdministratorRights)); appendToJson(result, "bot_is_member", object->botIsMember); + appendToJson(result, "request_title", object->requestTitle); + appendToJson(result, "request_username", object->requestUsername); + appendToJson(result, "request_photo", object->requestPhoto); removeLastComma(result); result += '}'; return result; @@ -1400,6 +1966,7 @@ std::string TgTypeParser::parseKeyboardButtonPollType(const KeyboardButtonPollTy ReplyKeyboardRemove::Ptr TgTypeParser::parseJsonAndGetReplyKeyboardRemove(const boost::property_tree::ptree& data) const { auto result(std::make_shared<ReplyKeyboardRemove>()); + result->removeKeyboard = data.get<bool>("remove_keyboard", false); result->selective = data.get<bool>("selective", false); return result; } @@ -1456,10 +2023,12 @@ InlineKeyboardButton::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardButton(cons result->loginUrl = tryParseJson<LoginUrl>(&TgTypeParser::parseJsonAndGetLoginUrl, data, "login_url"); result->switchInlineQuery = data.get<std::string>("switch_inline_query", ""); result->switchInlineQueryCurrentChat = data.get<std::string>("switch_inline_query_current_chat", ""); + result->switchInlineQueryChosenChat = tryParseJson<SwitchInlineQueryChosenChat>(&TgTypeParser::parseJsonAndGetSwitchInlineQueryChosenChat, data, "switch_inline_query_chosen_chat"); result->callbackGame = tryParseJson<CallbackGame>(&TgTypeParser::parseJsonAndGetCallbackGame, data, "callback_game"); result->pay = data.get<bool>("pay", false); return result; } + std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const { if (!object) { return ""; @@ -1473,6 +2042,7 @@ std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton:: appendToJson(result, "login_url", parseLoginUrl(object->loginUrl)); appendToJson(result, "switch_inline_query", object->switchInlineQuery); appendToJson(result, "switch_inline_query_current_chat", object->switchInlineQueryCurrentChat); + appendToJson(result, "switch_inline_query_chosen_chat", parseSwitchInlineQueryChosenChat(object->switchInlineQueryChosenChat)); appendToJson(result, "callback_game", parseCallbackGame(object->callbackGame)); appendToJson(result, "pay", object->pay); removeLastComma(result); @@ -1504,15 +2074,41 @@ std::string TgTypeParser::parseLoginUrl(const LoginUrl::Ptr& object) const { return result; } +SwitchInlineQueryChosenChat::Ptr TgTypeParser::parseJsonAndGetSwitchInlineQueryChosenChat(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<SwitchInlineQueryChosenChat>()); + result->query = data.get<std::string>("query", ""); + result->allowUserChats = data.get<bool>("allow_user_chats", false); + result->allowBotChats = data.get<bool>("allow_bot_chats", false); + result->allowGroupChats = data.get<bool>("allow_group_chats", false); + result->allowChannelChats = data.get<bool>("allow_channel_chats", false); + return result; +} + +std::string TgTypeParser::parseSwitchInlineQueryChosenChat(const SwitchInlineQueryChosenChat::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "query", object->query); + appendToJson(result, "allow_user_chats", object->allowUserChats); + appendToJson(result, "allow_bot_chats", object->allowBotChats); + appendToJson(result, "allow_group_chats", object->allowGroupChats); + appendToJson(result, "allow_channel_chats", object->allowChannelChats); + removeLastComma(result); + result += '}'; + return result; +} + CallbackQuery::Ptr TgTypeParser::parseJsonAndGetCallbackQuery(const boost::property_tree::ptree& data) const { auto result(std::make_shared<CallbackQuery>()); - result->id = data.get<std::string>("id"); + result->id = data.get<std::string>("id", ""); result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); result->message = tryParseJson<Message>(&TgTypeParser::parseJsonAndGetMessage, data, "message"); result->inlineMessageId = data.get<std::string>("inline_message_id", ""); - result->chatInstance = data.get<std::string>("chat_instance"); - result->gameShortName = data.get<std::string>("game_short_name", ""); + result->chatInstance = data.get<std::string>("chat_instance", ""); result->data = data.get<std::string>("data", ""); + result->gameShortName = data.get<std::string>("game_short_name", ""); return result; } @@ -1520,7 +2116,6 @@ std::string TgTypeParser::parseCallbackQuery(const CallbackQuery::Ptr& object) c if (!object) { return ""; } - std::string result; result += '{'; appendToJson(result, "id", object->id); @@ -1528,8 +2123,8 @@ std::string TgTypeParser::parseCallbackQuery(const CallbackQuery::Ptr& object) c appendToJson(result, "message", parseMessage(object->message)); appendToJson(result, "inline_message_id", object->inlineMessageId); appendToJson(result, "chat_instance", object->chatInstance); - appendToJson(result, "game_short_name", object->gameShortName); appendToJson(result, "data", object->data); + appendToJson(result, "game_short_name", object->gameShortName); removeLastComma(result); result += '}'; return result; @@ -1537,6 +2132,7 @@ std::string TgTypeParser::parseCallbackQuery(const CallbackQuery::Ptr& object) c ForceReply::Ptr TgTypeParser::parseJsonAndGetForceReply(const boost::property_tree::ptree& data) const { auto result(std::make_shared<ForceReply>()); + result->forceReply = data.get<bool>("force_reply", false); result->inputFieldPlaceholder = data.get<std::string>("input_field_placeholder", ""); result->selective = data.get<bool>("selective", false); return result; @@ -1624,6 +2220,9 @@ ChatAdministratorRights::Ptr TgTypeParser::parseJsonAndGetChatAdministratorRight result->canPromoteMembers = data.get<bool>("can_promote_members", false); result->canChangeInfo = data.get<bool>("can_change_info", false); result->canInviteUsers = data.get<bool>("can_invite_users", false); + result->canPostStories = data.get<bool>("can_post_stories", false); + result->canEditStories = data.get<bool>("can_edit_stories", false); + result->canDeleteStories = data.get<bool>("can_delete_stories", false); result->canPostMessages = data.get<bool>("can_post_messages", false); result->canEditMessages = data.get<bool>("can_edit_messages", false); result->canPinMessages = data.get<bool>("can_pin_messages", false); @@ -1645,6 +2244,9 @@ std::string TgTypeParser::parseChatAdministratorRights(const ChatAdministratorRi appendToJson(result, "can_promote_members", object->canPromoteMembers); appendToJson(result, "can_change_info", object->canChangeInfo); appendToJson(result, "can_invite_users", object->canInviteUsers); + appendToJson(result, "can_post_stories", object->canPostStories); + appendToJson(result, "can_edit_stories", object->canEditStories); + appendToJson(result, "can_delete_stories", object->canDeleteStories); appendToJson(result, "can_post_messages", object->canPostMessages); appendToJson(result, "can_edit_messages", object->canEditMessages); appendToJson(result, "can_pin_messages", object->canPinMessages); @@ -1654,6 +2256,36 @@ std::string TgTypeParser::parseChatAdministratorRights(const ChatAdministratorRi return result; } +ChatMemberUpdated::Ptr TgTypeParser::parseJsonAndGetChatMemberUpdated(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<ChatMemberUpdated>()); + result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); + result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); + result->date = data.get<std::uint32_t>("date", 0); + result->oldChatMember = tryParseJson<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, data, "old_chat_member"); + result->newChatMember = tryParseJson<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, data, "new_chat_member"); + result->inviteLink = tryParseJson<ChatInviteLink>(&TgTypeParser::parseJsonAndGetChatInviteLink, data, "invite_link"); + result->viaChatFolderInviteLink = data.get<bool>("via_chat_folder_invite_link", false); + return result; +} + +std::string TgTypeParser::parseChatMemberUpdated(const ChatMemberUpdated::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "chat", parseChat(object->chat)); + appendToJson(result, "from", parseUser(object->from)); + appendToJson(result, "date", object->date); + appendToJson(result, "old_chat_member", parseChatMember(object->oldChatMember)); + appendToJson(result, "new_chat_member", parseChatMember(object->newChatMember)); + appendToJson(result, "invite_link", parseChatInviteLink(object->inviteLink)); + appendToJson(result, "via_chat_folder_invite_link", object->viaChatFolderInviteLink); + removeLastComma(result); + result += '}'; + return result; +} + ChatMember::Ptr TgTypeParser::parseJsonAndGetChatMember(const boost::property_tree::ptree& data) const { std::string status = data.get<std::string>("status", ""); ChatMember::Ptr result; @@ -1711,8 +2343,8 @@ std::string TgTypeParser::parseChatMember(const ChatMember::Ptr& object) const { ChatMemberOwner::Ptr TgTypeParser::parseJsonAndGetChatMemberOwner(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGetChatMember(). auto result(std::make_shared<ChatMemberOwner>()); - result->customTitle = data.get<std::string>("custom_title", ""); result->isAnonymous = data.get<bool>("is_anonymous", false); + result->customTitle = data.get<std::string>("custom_title", ""); return result; } @@ -1723,8 +2355,8 @@ std::string TgTypeParser::parseChatMemberOwner(const ChatMemberOwner::Ptr& objec // This function will be called by parseChatMember(), so I don't add // curly brackets to the result std::string. std::string result; - appendToJson(result, "custom_title", object->customTitle); appendToJson(result, "is_anonymous", object->isAnonymous); + appendToJson(result, "custom_title", object->customTitle); // The last comma will be erased by parseChatMember(). return result; } @@ -1741,6 +2373,9 @@ ChatMemberAdministrator::Ptr TgTypeParser::parseJsonAndGetChatMemberAdministrato result->canPromoteMembers = data.get<bool>("can_promote_members", false); result->canChangeInfo = data.get<bool>("can_change_info", false); result->canInviteUsers = data.get<bool>("can_invite_users", false); + result->canPostStories = data.get<bool>("can_post_stories", false); + result->canEditStories = data.get<bool>("can_edit_stories", false); + result->canDeleteStories = data.get<bool>("can_delete_stories", false); result->canPostMessages = data.get<bool>("can_post_messages", false); result->canEditMessages = data.get<bool>("can_edit_messages", false); result->canPinMessages = data.get<bool>("can_pin_messages", false); @@ -1765,6 +2400,9 @@ std::string TgTypeParser::parseChatMemberAdministrator(const ChatMemberAdministr appendToJson(result, "can_promote_members", object->canPromoteMembers); appendToJson(result, "can_change_info", object->canChangeInfo); appendToJson(result, "can_invite_users", object->canInviteUsers); + appendToJson(result, "can_post_stories", object->canPostStories); + appendToJson(result, "can_edit_stories", object->canEditStories); + appendToJson(result, "can_delete_stories", object->canDeleteStories); appendToJson(result, "can_post_messages", object->canPostMessages); appendToJson(result, "can_edit_messages", object->canEditMessages); appendToJson(result, "can_pin_messages", object->canPinMessages); @@ -1774,7 +2412,7 @@ std::string TgTypeParser::parseChatMemberAdministrator(const ChatMemberAdministr return result; } -ChatMemberMember::Ptr TgTypeParser::parseJsonAndGetChatMemberMember(const boost::property_tree::ptree& data) const { +ChatMemberMember::Ptr TgTypeParser::parseJsonAndGetChatMemberMember(const boost::property_tree::ptree& /*data*/) const { // NOTE: This function will be called by parseJsonAndGetChatMember(). auto result(std::make_shared<ChatMemberMember>()); return result; @@ -1840,7 +2478,7 @@ std::string TgTypeParser::parseChatMemberRestricted(const ChatMemberRestricted:: return result; } -ChatMemberLeft::Ptr TgTypeParser::parseJsonAndGetChatMemberLeft(const boost::property_tree::ptree& data) const { +ChatMemberLeft::Ptr TgTypeParser::parseJsonAndGetChatMemberLeft(const boost::property_tree::ptree& /*data*/) const { // NOTE: This function will be called by parseJsonAndGetChatMember(). auto result(std::make_shared<ChatMemberLeft>()); return result; @@ -1860,7 +2498,7 @@ std::string TgTypeParser::parseChatMemberLeft(const ChatMemberLeft::Ptr& object) ChatMemberBanned::Ptr TgTypeParser::parseJsonAndGetChatMemberBanned(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGetChatMember(). auto result(std::make_shared<ChatMemberBanned>()); - result->untilDate = data.get<uint32_t>("until_date", 0); + result->untilDate = data.get<std::uint32_t>("until_date", 0); return result; } @@ -1876,34 +2514,6 @@ std::string TgTypeParser::parseChatMemberBanned(const ChatMemberBanned::Ptr& obj return result; } -ChatMemberUpdated::Ptr TgTypeParser::parseJsonAndGetChatMemberUpdated(const boost::property_tree::ptree& data) const { - auto result(std::make_shared<ChatMemberUpdated>()); - result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); - result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); - result->date = data.get<uint32_t>("date", 0); - result->oldChatMember = tryParseJson<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, data, "old_chat_member"); - result->newChatMember = tryParseJson<ChatMember>(&TgTypeParser::parseJsonAndGetChatMember, data, "new_chat_member"); - result->inviteLink = tryParseJson<ChatInviteLink>(&TgTypeParser::parseJsonAndGetChatInviteLink, data, "invite_link"); - return result; -} - -std::string TgTypeParser::parseChatMemberUpdated(const ChatMemberUpdated::Ptr& object) const { - if (!object) { - return ""; - } - std::string result; - result += '{'; - appendToJson(result, "chat", parseChat(object->chat)); - appendToJson(result, "from", parseUser(object->from)); - appendToJson(result, "date", object->date); - appendToJson(result, "old_chat_member", parseChatMember(object->oldChatMember)); - appendToJson(result, "new_chat_member", parseChatMember(object->newChatMember)); - appendToJson(result, "invite_link", parseChatInviteLink(object->inviteLink)); - removeLastComma(result); - result += '}'; - return result; -} - ChatJoinRequest::Ptr TgTypeParser::parseJsonAndGetChatJoinRequest(const boost::property_tree::ptree& data) const { auto result(std::make_shared<ChatJoinRequest>()); result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); @@ -1976,6 +2586,110 @@ std::string TgTypeParser::parseChatPermissions(const ChatPermissions::Ptr& objec return result; } +Birthdate::Ptr TgTypeParser::parseJsonAndGetBirthdate(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<Birthdate>()); + result->day = data.get<std::uint8_t>("day", 0); + result->month = data.get<std::uint8_t>("month", 0); + result->year = data.get<std::uint16_t>("year", 0); + return result; +} + +std::string TgTypeParser::parseBirthdate(const Birthdate::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "day", object->day); + appendToJson(result, "month", object->month); + appendToJson(result, "year", object->year); + removeLastComma(result); + result += '}'; + return result; +} + +BusinessIntro::Ptr TgTypeParser::parseJsonAndGetBusinessIntro(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<BusinessIntro>()); + result->title = data.get<std::string>("title", ""); + result->message = data.get<std::string>("message", ""); + result->sticker = tryParseJson<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "sticker"); + return result; +} + +std::string TgTypeParser::parseBusinessIntro(const BusinessIntro::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "title", object->title); + appendToJson(result, "message", object->message); + appendToJson(result, "sticker", parseSticker(object->sticker)); + removeLastComma(result); + result += '}'; + return result; +} + +BusinessLocation::Ptr TgTypeParser::parseJsonAndGetBusinessLocation(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<BusinessLocation>()); + result->address = data.get<std::string>("address", ""); + result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location"); + return result; +} + +std::string TgTypeParser::parseBusinessLocation(const BusinessLocation::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "address", object->address); + appendToJson(result, "location", parseLocation(object->location)); + removeLastComma(result); + result += '}'; + return result; +} + +BusinessOpeningHoursInterval::Ptr TgTypeParser::parseJsonAndGetBusinessOpeningHoursInterval(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<BusinessOpeningHoursInterval>()); + result->openingMinute = data.get<std::int32_t>("opening_minute", 0); + result->closingMinute = data.get<std::int32_t>("closing_minute", 0); + return result; +} + +std::string TgTypeParser::parseBusinessOpeningHoursInterval(const BusinessOpeningHoursInterval::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "opening_minute", object->openingMinute); + appendToJson(result, "closing_minute", object->closingMinute); + removeLastComma(result); + result += '}'; + return result; +} + +BusinessOpeningHours::Ptr TgTypeParser::parseJsonAndGetBusinessOpeningHours(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<BusinessOpeningHours>()); + result->timeZoneName = data.get<std::string>("time_zone_name", ""); + result->openingHours = parseJsonAndGetArray<BusinessOpeningHoursInterval>(&TgTypeParser::parseJsonAndGetBusinessOpeningHoursInterval, data, "opening_hours"); + return result; +} + +std::string TgTypeParser::parseBusinessOpeningHours(const BusinessOpeningHours::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "time_zone_name", object->timeZoneName); + appendToJson(result, "opening_hours", parseArray(&TgTypeParser::parseBusinessOpeningHoursInterval, object->openingHours)); + removeLastComma(result); + result += '}'; + return result; +} + ChatLocation::Ptr TgTypeParser::parseJsonAndGetChatLocation(const boost::property_tree::ptree& data) const { auto result(std::make_shared<ChatLocation>()); result->location = tryParseJson<Location>(&TgTypeParser::parseJsonAndGetLocation, data, "location"); @@ -1996,6 +2710,154 @@ std::string TgTypeParser::parseChatLocation(const ChatLocation::Ptr& object) con return result; } +ReactionType::Ptr TgTypeParser::parseJsonAndGetReactionType(const boost::property_tree::ptree& data) const { + std::string type = data.get<std::string>("type", ""); + ReactionType::Ptr result; + + if (type == ReactionTypeEmoji::TYPE) { + result = std::static_pointer_cast<ReactionType>(parseJsonAndGetReactionTypeEmoji(data)); + } else if (type == ReactionTypeCustomEmoji::TYPE) { + result = std::static_pointer_cast<ReactionType>(parseJsonAndGetReactionTypeCustomEmoji(data)); + } else { + result = std::make_shared<ReactionType>(); + } + + result->type = type; + + return result; +} + +std::string TgTypeParser::parseReactionType(const ReactionType::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "type", object->type); + + if (object->type == ReactionTypeEmoji::TYPE) { + result += parseReactionTypeEmoji(std::static_pointer_cast<ReactionTypeEmoji>(object)); + } else if (object->type == ReactionTypeCustomEmoji::TYPE) { + result += parseReactionTypeCustomEmoji(std::static_pointer_cast<ReactionTypeCustomEmoji>(object)); + } + + removeLastComma(result); + result += '}'; + return result; +} + +ReactionTypeEmoji::Ptr TgTypeParser::parseJsonAndGetReactionTypeEmoji(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetReactionType(). + auto result(std::make_shared<ReactionTypeEmoji>()); + result->emoji = data.get<std::string>("emoji", ""); + return result; +} + +std::string TgTypeParser::parseReactionTypeEmoji(const ReactionTypeEmoji::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + // This function will be called by parseReactionType(), so I don't add + // curly brackets to the result std::string. + appendToJson(result, "emoji", object->emoji); + // The last comma will be erased by parseReactionType(). + return result; +} + +ReactionTypeCustomEmoji::Ptr TgTypeParser::parseJsonAndGetReactionTypeCustomEmoji(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetReactionType(). + auto result(std::make_shared<ReactionTypeCustomEmoji>()); + result->customEmojiId = data.get<std::string>("custom_emoji_id", ""); + return result; +} + +std::string TgTypeParser::parseReactionTypeCustomEmoji(const ReactionTypeCustomEmoji::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + // This function will be called by parseReactionType(), so I don't add + // curly brackets to the result std::string. + appendToJson(result, "custom_emoji_id", object->customEmojiId); + // The last comma will be erased by parseReactionType(). + return result; +} + +ReactionCount::Ptr TgTypeParser::parseJsonAndGetReactionCount(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<ReactionCount>()); + result->type = tryParseJson<ReactionType>(&TgTypeParser::parseJsonAndGetReactionType, data, "type"); + result->totalCount = data.get<std::int32_t>("total_count", 0); + return result; +} + +std::string TgTypeParser::parseReactionCount(const ReactionCount::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "type", parseReactionType(object->type)); + appendToJson(result, "total_count", object->totalCount); + removeLastComma(result); + result += '}'; + return result; +} + +MessageReactionUpdated::Ptr TgTypeParser::parseJsonAndGetMessageReactionUpdated(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<MessageReactionUpdated>()); + result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); + result->messageId = data.get<std::int32_t>("message_id", 0); + result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user"); + result->actorChat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "actor_chat"); + result->date = data.get<std::uint32_t>("date", 0); + result->oldReaction = parseJsonAndGetArray<ReactionType>(&TgTypeParser::parseJsonAndGetReactionType, data, "old_reaction"); + result->newReaction = parseJsonAndGetArray<ReactionType>(&TgTypeParser::parseJsonAndGetReactionType, data, "new_reaction"); + return result; +} + +std::string TgTypeParser::parseMessageReactionUpdated(const MessageReactionUpdated::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "chat", parseChat(object->chat)); + appendToJson(result, "message_id", object->messageId); + appendToJson(result, "user", parseUser(object->user)); + appendToJson(result, "actor_chat", parseChat(object->actorChat)); + appendToJson(result, "date", object->date); + appendToJson(result, "old_reaction", parseArray(&TgTypeParser::parseReactionType, object->oldReaction)); + appendToJson(result, "new_reaction", parseArray(&TgTypeParser::parseReactionType, object->newReaction)); + removeLastComma(result); + result += '}'; + return result; +} + +MessageReactionCountUpdated::Ptr TgTypeParser::parseJsonAndGetMessageReactionCountUpdated(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<MessageReactionCountUpdated>()); + result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); + result->messageId = data.get<std::int32_t>("message_id", 0); + result->date = data.get<std::uint32_t>("date", 0); + result->reactions = parseJsonAndGetArray<ReactionCount>(&TgTypeParser::parseJsonAndGetReactionCount, data, "reactions"); + return result; +} + +std::string TgTypeParser::parseMessageReactionCountUpdated(const MessageReactionCountUpdated::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "chat", parseChat(object->chat)); + appendToJson(result, "message_id", object->messageId); + appendToJson(result, "date", object->date); + appendToJson(result, "reactions", parseArray(&TgTypeParser::parseReactionCount, object->reactions)); + removeLastComma(result); + result += '}'; + return result; +} + ForumTopic::Ptr TgTypeParser::parseJsonAndGetForumTopic(const boost::property_tree::ptree& data) const { auto result(std::make_shared<ForumTopic>()); result->messageThreadId = data.get<std::int32_t>("message_thread_id", 0); @@ -2022,12 +2884,15 @@ std::string TgTypeParser::parseForumTopic(const ForumTopic::Ptr& object) const { BotCommand::Ptr TgTypeParser::parseJsonAndGetBotCommand(const boost::property_tree::ptree& data) const { auto result(std::make_shared<BotCommand>()); - result->command = data.get("command", ""); - result->description = data.get("description", ""); + result->command = data.get<std::string>("command", ""); + result->description = data.get<std::string>("description", ""); return result; } std::string TgTypeParser::parseBotCommand(const BotCommand::Ptr& object) const { + if (!object) { + return ""; + } std::string result; result += '{'; appendToJson(result, "command", object->command); @@ -2093,7 +2958,7 @@ std::string TgTypeParser::parseBotCommandScope(const BotCommandScope::Ptr& objec return result; } -BotCommandScopeDefault::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeDefault(const boost::property_tree::ptree& data) const { +BotCommandScopeDefault::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeDefault(const boost::property_tree::ptree& /*data*/) const { // NOTE: This function will be called by parseJsonAndGetBotCommandScope(). auto result(std::make_shared<BotCommandScopeDefault>()); return result; @@ -2110,7 +2975,7 @@ std::string TgTypeParser::parseBotCommandScopeDefault(const BotCommandScopeDefau return result; } -BotCommandScopeAllPrivateChats::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeAllPrivateChats(const boost::property_tree::ptree& data) const { +BotCommandScopeAllPrivateChats::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeAllPrivateChats(const boost::property_tree::ptree& /*data*/) const { // NOTE: This function will be called by parseJsonAndGetBotCommandScope(). auto result(std::make_shared<BotCommandScopeAllPrivateChats>()); return result; @@ -2127,7 +2992,7 @@ std::string TgTypeParser::parseBotCommandScopeAllPrivateChats(const BotCommandSc return result; } -BotCommandScopeAllGroupChats::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeAllGroupChats(const boost::property_tree::ptree& data) const { +BotCommandScopeAllGroupChats::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeAllGroupChats(const boost::property_tree::ptree& /*data*/) const { // NOTE: This function will be called by parseJsonAndGetBotCommandScope(). auto result(std::make_shared<BotCommandScopeAllGroupChats>()); return result; @@ -2144,7 +3009,7 @@ std::string TgTypeParser::parseBotCommandScopeAllGroupChats(const BotCommandScop return result; } -BotCommandScopeAllChatAdministrators::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeAllChatAdministrators(const boost::property_tree::ptree& data) const { +BotCommandScopeAllChatAdministrators::Ptr TgTypeParser::parseJsonAndGetBotCommandScopeAllChatAdministrators(const boost::property_tree::ptree& /*data*/) const { // NOTE: This function will be called by parseJsonAndGetBotCommandScope(). auto result(std::make_shared<BotCommandScopeAllChatAdministrators>()); return result; @@ -2220,6 +3085,60 @@ std::string TgTypeParser::parseBotCommandScopeChatMember(const BotCommandScopeCh return result; } +BotName::Ptr TgTypeParser::parseJsonAndGetBotName(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<BotName>()); + result->name = data.get<std::string>("name", ""); + return result; +} + +std::string TgTypeParser::parseBotName(const BotName::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "name", object->name); + removeLastComma(result); + result += '}'; + return result; +} + +BotDescription::Ptr TgTypeParser::parseJsonAndGetBotDescription(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<BotDescription>()); + result->description = data.get<std::string>("description", ""); + return result; +} + +std::string TgTypeParser::parseBotDescription(const BotDescription::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "description", object->description); + removeLastComma(result); + result += '}'; + return result; +} + +BotShortDescription::Ptr TgTypeParser::parseJsonAndGetBotShortDescription(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<BotShortDescription>()); + result->shortDescription = data.get<std::string>("short_description", ""); + return result; +} + +std::string TgTypeParser::parseBotShortDescription(const BotShortDescription::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "short_description", object->shortDescription); + removeLastComma(result); + result += '}'; + return result; +} + MenuButton::Ptr TgTypeParser::parseJsonAndGetMenuButton(const boost::property_tree::ptree& data) const { std::string type = data.get<std::string>("type", ""); MenuButton::Ptr result; @@ -2260,7 +3179,7 @@ std::string TgTypeParser::parseMenuButton(const MenuButton::Ptr& object) const { return result; } -MenuButtonCommands::Ptr TgTypeParser::parseJsonAndGetMenuButtonCommands(const boost::property_tree::ptree& data) const { +MenuButtonCommands::Ptr TgTypeParser::parseJsonAndGetMenuButtonCommands(const boost::property_tree::ptree& /*data*/) const { // NOTE: This function will be called by parseJsonAndGetMenuButton(). auto result(std::make_shared<MenuButtonCommands>()); return result; @@ -2298,7 +3217,7 @@ std::string TgTypeParser::parseMenuButtonWebApp(const MenuButtonWebApp::Ptr& obj return result; } -MenuButtonDefault::Ptr TgTypeParser::parseJsonAndGetMenuButtonDefault(const boost::property_tree::ptree& data) const { +MenuButtonDefault::Ptr TgTypeParser::parseJsonAndGetMenuButtonDefault(const boost::property_tree::ptree& /*data*/) const { // NOTE: This function will be called by parseJsonAndGetMenuButton(). auto result(std::make_shared<MenuButtonDefault>()); return result; @@ -2315,6 +3234,245 @@ std::string TgTypeParser::parseMenuButtonDefault(const MenuButtonDefault::Ptr& o return result; } +ChatBoostSource::Ptr TgTypeParser::parseJsonAndGetChatBoostSource(const boost::property_tree::ptree& data) const { + std::string source = data.get<std::string>("source", ""); + ChatBoostSource::Ptr result; + + if (source == ChatBoostSourcePremium::SOURCE) { + result = std::static_pointer_cast<ChatBoostSource>(parseJsonAndGetChatBoostSourcePremium(data)); + } else if (source == ChatBoostSourceGiftCode::SOURCE) { + result = std::static_pointer_cast<ChatBoostSource>(parseJsonAndGetChatBoostSourceGiftCode(data)); + } else if (source == ChatBoostSourceGiveaway::SOURCE) { + result = std::static_pointer_cast<ChatBoostSource>(parseJsonAndGetChatBoostSourceGiveaway(data)); + } else { + result = std::make_shared<ChatBoostSource>(); + } + + result->source = source; + result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user"); + + return result; +} + +std::string TgTypeParser::parseChatBoostSource(const ChatBoostSource::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "source", object->source); + appendToJson(result, "user", parseUser(object->user)); + + if (object->source == ChatBoostSourcePremium::SOURCE) { + result += parseChatBoostSourcePremium(std::static_pointer_cast<ChatBoostSourcePremium>(object)); + } else if (object->source == ChatBoostSourceGiftCode::SOURCE) { + result += parseChatBoostSourceGiftCode(std::static_pointer_cast<ChatBoostSourceGiftCode>(object)); + } else if (object->source == ChatBoostSourceGiveaway::SOURCE) { + result += parseChatBoostSourceGiveaway(std::static_pointer_cast<ChatBoostSourceGiveaway>(object)); + } + + removeLastComma(result); + result += '}'; + return result; +} + +ChatBoostSourcePremium::Ptr TgTypeParser::parseJsonAndGetChatBoostSourcePremium(const boost::property_tree::ptree& /*data*/) const { + // NOTE: This function will be called by parseJsonAndGetChatBoostSource(). + auto result(std::make_shared<ChatBoostSourcePremium>()); + return result; +} + +std::string TgTypeParser::parseChatBoostSourcePremium(const ChatBoostSourcePremium::Ptr& object) const { + if (!object) { + return ""; + } + // This function will be called by parseChatBoostSource(), so I don't add + // curly brackets to the result std::string. + std::string result; + // The last comma will be erased by parseChatBoostSource(). + return result; +} + +ChatBoostSourceGiftCode::Ptr TgTypeParser::parseJsonAndGetChatBoostSourceGiftCode(const boost::property_tree::ptree& /*data*/) const { + // NOTE: This function will be called by parseJsonAndGetChatBoostSource(). + auto result(std::make_shared<ChatBoostSourceGiftCode>()); + return result; +} + +std::string TgTypeParser::parseChatBoostSourceGiftCode(const ChatBoostSourceGiftCode::Ptr& object) const { + if (!object) { + return ""; + } + // This function will be called by parseChatBoostSource(), so I don't add + // curly brackets to the result std::string. + std::string result; + // The last comma will be erased by parseChatBoostSource(). + return result; +} + +ChatBoostSourceGiveaway::Ptr TgTypeParser::parseJsonAndGetChatBoostSourceGiveaway(const boost::property_tree::ptree& data) const { + // NOTE: This function will be called by parseJsonAndGetChatBoostSource(). + auto result(std::make_shared<ChatBoostSourceGiveaway>()); + result->giveawayMessageId = data.get<std::int32_t>("giveaway_message_id", 0); + result->isUnclaimed = data.get<bool>("is_unclaimed", false); + return result; +} + +std::string TgTypeParser::parseChatBoostSourceGiveaway(const ChatBoostSourceGiveaway::Ptr& object) const { + if (!object) { + return ""; + } + // This function will be called by parseChatBoostSource(), so I don't add + // curly brackets to the result std::string. + std::string result; + appendToJson(result, "giveaway_message_id", object->giveawayMessageId); + appendToJson(result, "is_unclaimed", object->isUnclaimed); + // The last comma will be erased by parseChatBoostSource(). + return result; +} + +ChatBoost::Ptr TgTypeParser::parseJsonAndGetChatBoost(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<ChatBoost>()); + result->boostId = data.get<std::string>("boost_id", ""); + result->addDate = data.get<std::uint32_t>("add_date", 0); + result->expirationDate = data.get<std::uint32_t>("expiration_date", 0); + result->source = tryParseJson<ChatBoostSource>(&TgTypeParser::parseJsonAndGetChatBoostSource, data, "source"); + return result; +} + +std::string TgTypeParser::parseChatBoost(const ChatBoost::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "boost_id", object->boostId); + appendToJson(result, "add_date", object->addDate); + appendToJson(result, "expiration_date", object->expirationDate); + appendToJson(result, "source", parseChatBoostSource(object->source)); + removeLastComma(result); + result += '}'; + return result; +} + +ChatBoostUpdated::Ptr TgTypeParser::parseJsonAndGetChatBoostUpdated(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<ChatBoostUpdated>()); + result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); + result->boost = tryParseJson<ChatBoost>(&TgTypeParser::parseJsonAndGetChatBoost, data, "boost"); + return result; +} + +std::string TgTypeParser::parseChatBoostUpdated(const ChatBoostUpdated::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "chat", parseChat(object->chat)); + appendToJson(result, "boost", parseChatBoost(object->boost)); + removeLastComma(result); + result += '}'; + return result; +} + +ChatBoostRemoved::Ptr TgTypeParser::parseJsonAndGetChatBoostRemoved(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<ChatBoostRemoved>()); + result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); + result->boostId = data.get<std::string>("boost_id", ""); + result->removeDate = data.get<std::uint32_t>("remove_date", 0); + result->source = tryParseJson<ChatBoostSource>(&TgTypeParser::parseJsonAndGetChatBoostSource, data, "source"); + return result; +} + +std::string TgTypeParser::parseChatBoostRemoved(const ChatBoostRemoved::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "chat", parseChat(object->chat)); + appendToJson(result, "boost_id", object->boostId); + appendToJson(result, "remove_date", object->removeDate); + appendToJson(result, "source", parseChatBoostSource(object->source)); + removeLastComma(result); + result += '}'; + return result; +} + +UserChatBoosts::Ptr TgTypeParser::parseJsonAndGetUserChatBoosts(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<UserChatBoosts>()); + result->boosts = parseJsonAndGetArray<ChatBoost>(&TgTypeParser::parseJsonAndGetChatBoost, data, "boosts"); + return result; +} + +std::string TgTypeParser::parseUserChatBoosts(const UserChatBoosts::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "boosts", parseArray(&TgTypeParser::parseChatBoost, object->boosts)); + removeLastComma(result); + result += '}'; + return result; +} + +BusinessConnection::Ptr TgTypeParser::parseJsonAndGetBusinessConnection(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<BusinessConnection>()); + result->id = data.get<std::string>("id", ""); + result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user"); + result->userChatId = data.get<std::int64_t>("user_chat_id", 0); + result->date = data.get<std::uint32_t>("date", 0); + result->canReply = data.get<bool>("can_reply", false); + result->isEnabled = data.get<bool>("is_enabled", false); + return result; +} + +std::string TgTypeParser::parseBusinessConnection(const BusinessConnection::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "id", object->id); + appendToJson(result, "user", parseUser(object->user)); + appendToJson(result, "user_chat_id", object->userChatId); + appendToJson(result, "date", object->date); + appendToJson(result, "can_reply", object->canReply); + appendToJson(result, "is_enabled", object->isEnabled); + removeLastComma(result); + result += '}'; + return result; +} + +BusinessMessagesDeleted::Ptr TgTypeParser::parseJsonAndGetBusinessMessagesDeleted(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<BusinessMessagesDeleted>()); + result->businessConnectionId = data.get<std::string>("business_connection_id", ""); + result->chat = tryParseJson<Chat>(&TgTypeParser::parseJsonAndGetChat, data, "chat"); + result->messageIds = parseJsonAndGetArray<std::int32_t>( + [] (const boost::property_tree::ptree& innerData)->std::int32_t { + return innerData.get<std::int32_t>(""); + }, data, "message_ids"); + return result; +} + +std::string TgTypeParser::parseBusinessMessagesDeleted(const BusinessMessagesDeleted::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "business_connection_id", object->businessConnectionId); + appendToJson(result, "chat", parseChat(object->chat)); + appendToJson(result, "message_ids", parseArray<std::int32_t>( + [] (std::int32_t i)->std::int32_t { + return i; + }, object->messageIds)); + removeLastComma(result); + result += '}'; + return result; +} + ResponseParameters::Ptr TgTypeParser::parseJsonAndGetResponseParameters(const boost::property_tree::ptree& data) const { auto result(std::make_shared<ResponseParameters>()); result->migrateToChatId = data.get<std::int64_t>("migrate_to_chat_id", 0); @@ -2413,7 +3571,7 @@ std::string TgTypeParser::parseInputMediaPhoto(const InputMediaPhoto::Ptr& objec InputMediaVideo::Ptr TgTypeParser::parseJsonAndGetInputMediaVideo(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGetInputMedia(). auto result(std::make_shared<InputMediaVideo>()); - result->thumb = data.get<std::string>("thumb", ""); + result->thumbnail = data.get<std::string>("thumbnail", ""); result->width = data.get<std::int32_t>("width", 0); result->height = data.get<std::int32_t>("height", 0); result->duration = data.get<std::int32_t>("duration", 0); @@ -2429,7 +3587,7 @@ std::string TgTypeParser::parseInputMediaVideo(const InputMediaVideo::Ptr& objec // This function will be called by parseInputMedia(), so I don't add // curly brackets to the result std::string. std::string result; - appendToJson(result, "thumb", object->thumb); + appendToJson(result, "thumbnail", object->thumbnail); appendToJson(result, "width", object->width); appendToJson(result, "height", object->height); appendToJson(result, "duration", object->duration); @@ -2442,7 +3600,7 @@ std::string TgTypeParser::parseInputMediaVideo(const InputMediaVideo::Ptr& objec InputMediaAnimation::Ptr TgTypeParser::parseJsonAndGetInputMediaAnimation(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGetInputMedia(). auto result(std::make_shared<InputMediaAnimation>()); - result->thumb = data.get<std::string>("thumb", ""); + result->thumbnail = data.get<std::string>("thumbnail", ""); result->width = data.get<std::int32_t>("width", 0); result->height = data.get<std::int32_t>("height", 0); result->duration = data.get<std::int32_t>("duration", 0); @@ -2457,7 +3615,7 @@ std::string TgTypeParser::parseInputMediaAnimation(const InputMediaAnimation::Pt // This function will be called by parseInputMedia(), so I don't add // curly brackets to the result std::string. std::string result; - appendToJson(result, "thumb", object->thumb); + appendToJson(result, "thumbnail", object->thumbnail); appendToJson(result, "width", object->width); appendToJson(result, "height", object->height); appendToJson(result, "duration", object->duration); @@ -2469,7 +3627,7 @@ std::string TgTypeParser::parseInputMediaAnimation(const InputMediaAnimation::Pt InputMediaAudio::Ptr TgTypeParser::parseJsonAndGetInputMediaAudio(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGetInputMedia(). auto result(std::make_shared<InputMediaAudio>()); - result->thumb = data.get<std::string>("thumb", ""); + result->thumbnail = data.get<std::string>("thumbnail", ""); result->duration = data.get<std::int32_t>("duration", 0); result->performer = data.get<std::string>("performer", ""); result->title = data.get<std::string>("title", ""); @@ -2483,7 +3641,7 @@ std::string TgTypeParser::parseInputMediaAudio(const InputMediaAudio::Ptr& objec // This function will be called by parseInputMedia(), so I don't add // curly brackets to the result std::string. std::string result; - appendToJson(result, "thumb", object->thumb); + appendToJson(result, "thumbnail", object->thumbnail); appendToJson(result, "duration", object->duration); appendToJson(result, "performer", object->performer); appendToJson(result, "title", object->title); @@ -2494,7 +3652,7 @@ std::string TgTypeParser::parseInputMediaAudio(const InputMediaAudio::Ptr& objec InputMediaDocument::Ptr TgTypeParser::parseJsonAndGetInputMediaDocument(const boost::property_tree::ptree& data) const { // NOTE: This function will be called by parseJsonAndGetInputMedia(). auto result(std::make_shared<InputMediaDocument>()); - result->thumb = data.get<std::string>("thumb", ""); + result->thumbnail = data.get<std::string>("thumbnail", ""); result->disableContentTypeDetection = data.get<bool>("disable_content_type_detection", false); return result; } @@ -2506,7 +3664,7 @@ std::string TgTypeParser::parseInputMediaDocument(const InputMediaDocument::Ptr& // This function will be called by parseInputMedia(), so I don't add // curly brackets to the result std::string. std::string result; - appendToJson(result, "thumb", object->thumb); + appendToJson(result, "thumbnail", object->thumbnail); appendToJson(result, "disable_content_type_detection", object->disableContentTypeDetection); // The last comma will be erased by parseInputMedia(). return result; @@ -2528,12 +3686,13 @@ Sticker::Ptr TgTypeParser::parseJsonAndGetSticker(const boost::property_tree::pt result->height = data.get<std::int32_t>("height", 0); result->isAnimated = data.get<bool>("is_animated", false); result->isVideo = data.get<bool>("is_video", false); - result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); + result->thumbnail = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumbnail"); result->emoji = data.get<std::string>("emoji", ""); result->setName = data.get<std::string>("set_name", ""); result->premiumAnimation = tryParseJson<File>(&TgTypeParser::parseJsonAndGetFile, data, "premium_animation"); result->maskPosition = tryParseJson<MaskPosition>(&TgTypeParser::parseJsonAndGetMaskPosition, data, "mask_position"); result->customEmojiId = data.get<std::string>("custom_emoji_id", ""); + result->needsRepainting = data.get<bool>("needs_repainting", true); result->fileSize = data.get<std::int32_t>("file_size", 0); return result; } @@ -2557,12 +3716,13 @@ std::string TgTypeParser::parseSticker(const Sticker::Ptr& object) const { appendToJson(result, "height", object->height); appendToJson(result, "is_animated", object->isAnimated); appendToJson(result, "is_video", object->isVideo); - appendToJson(result, "thumb", parsePhotoSize(object->thumb)); + appendToJson(result, "thumbnail", parsePhotoSize(object->thumbnail)); appendToJson(result, "emoji", object->emoji); appendToJson(result, "set_name", object->setName); appendToJson(result, "premium_animation", parseFile(object->premiumAnimation)); appendToJson(result, "mask_position", parseMaskPosition(object->maskPosition)); appendToJson(result, "custom_emoji_id", object->customEmojiId); + appendToJson(result, "needs_repainting", object->needsRepainting); appendToJson(result, "file_size", object->fileSize); removeLastComma(result); result += '}'; @@ -2573,18 +3733,16 @@ StickerSet::Ptr TgTypeParser::parseJsonAndGetStickerSet(const boost::property_tr auto result(std::make_shared<StickerSet>()); result->name = data.get<std::string>("name", ""); result->title = data.get<std::string>("title", ""); - std::string type = data.get<std::string>("type", ""); - if (type == "regular") { - result->type = StickerSet::Type::Regular; - } else if (type == "mask") { - result->type = StickerSet::Type::Mask; - } else if (type == "custom_emoji") { - result->type = StickerSet::Type::CustomEmoji; + std::string stickerType = data.get<std::string>("sticker_type", ""); + if (stickerType == "regular") { + result->stickerType = StickerSet::Type::Regular; + } else if (stickerType == "mask") { + result->stickerType = StickerSet::Type::Mask; + } else if (stickerType == "custom_emoji") { + result->stickerType = StickerSet::Type::CustomEmoji; } - result->isAnimated = data.get<bool>("is_animated", false); - result->isVideo = data.get<bool>("is_video", false); result->stickers = parseJsonAndGetArray<Sticker>(&TgTypeParser::parseJsonAndGetSticker, data, "stickers"); - result->thumb = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumb"); + result->thumbnail = tryParseJson<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "thumbnail"); return result; } @@ -2596,17 +3754,15 @@ std::string TgTypeParser::parseStickerSet(const StickerSet::Ptr& object) const { result += '{'; appendToJson(result, "name", object->name); appendToJson(result, "title", object->title); - if (object->type == StickerSet::Type::Regular) { - appendToJson(result, "type", "regular"); - } else if (object->type == StickerSet::Type::Mask) { - appendToJson(result, "type", "mask"); - } else if (object->type == StickerSet::Type::CustomEmoji) { - appendToJson(result, "type", "custom_emoji"); + if (object->stickerType == StickerSet::Type::Regular) { + appendToJson(result, "sticker_type", "regular"); + } else if (object->stickerType == StickerSet::Type::Mask) { + appendToJson(result, "sticker_type", "mask"); + } else if (object->stickerType == StickerSet::Type::CustomEmoji) { + appendToJson(result, "sticker_type", "custom_emoji"); } - appendToJson(result, "is_animated", object->isAnimated); - appendToJson(result, "is_video", object->isVideo); appendToJson(result, "stickers", parseArray(&TgTypeParser::parseSticker, object->stickers)); - appendToJson(result, "thumb", parsePhotoSize(object->thumb)); + appendToJson(result, "thumbnail", parsePhotoSize(object->thumbnail)); removeLastComma(result); result += '}'; return result; @@ -2614,7 +3770,7 @@ std::string TgTypeParser::parseStickerSet(const StickerSet::Ptr& object) const { MaskPosition::Ptr TgTypeParser::parseJsonAndGetMaskPosition(const boost::property_tree::ptree& data) const { auto result(std::make_shared<MaskPosition>()); - result->point = data.get("point", ""); + result->point = data.get<std::string>("point", ""); result->xShift = data.get<float>("x_shift", 0); result->yShift = data.get<float>("y_shift", 0); result->scale = data.get<float>("scale", 0); @@ -2636,6 +3792,44 @@ std::string TgTypeParser::parseMaskPosition(const MaskPosition::Ptr& object) con return result; } +InputSticker::Ptr TgTypeParser::parseJsonAndGetInputSticker(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<InputSticker>()); + result->sticker = data.get<std::string>("sticker", ""); + result->format = data.get<std::string>("format", ""); + result->emojiList = parseJsonAndGetArray<std::string>( + [] (const boost::property_tree::ptree& innerData)->std::string { + return innerData.get<std::string>(""); + }, data, "emoji_list"); + result->maskPosition = tryParseJson<MaskPosition>(&TgTypeParser::parseJsonAndGetMaskPosition, data, "mask_position"); + result->keywords = parseJsonAndGetArray<std::string>( + [] (const boost::property_tree::ptree& innerData)->std::string { + return innerData.get<std::string>(""); + }, data, "keywords"); + return result; +} + +std::string TgTypeParser::parseInputSticker(const InputSticker::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "sticker", object->sticker); + appendToJson(result, "format", object->format); + appendToJson(result, "emoji_list", parseArray<std::string>( + [] (const std::string& s)->std::string { + return s; + }, object->emojiList)); + appendToJson(result, "mask_position", parseMaskPosition(object->maskPosition)); + appendToJson(result, "keywords", parseArray<std::string>( + [] (const std::string& s)->std::string { + return s; + }, object->keywords)); + removeLastComma(result); + result += '}'; + return result; +} + InlineQuery::Ptr TgTypeParser::parseJsonAndGetInlineQuery(const boost::property_tree::ptree& data) const { auto result(std::make_shared<InlineQuery>()); result->id = data.get<std::string>("id", ""); @@ -2664,6 +3858,28 @@ std::string TgTypeParser::parseInlineQuery(const InlineQuery::Ptr& object) const return result; } +InlineQueryResultsButton::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultsButton(const boost::property_tree::ptree& data) const { + auto result(std::make_shared<InlineQueryResultsButton>()); + result->text = data.get<std::string>("text", ""); + result->webApp = tryParseJson<WebAppInfo>(&TgTypeParser::parseJsonAndGetWebAppInfo, data, "web_app"); + result->startParameter = data.get<std::string>("start_parameter", ""); + return result; +} + +std::string TgTypeParser::parseInlineQueryResultsButton(const InlineQueryResultsButton::Ptr& object) const { + if (!object) { + return ""; + } + std::string result; + result += '{'; + appendToJson(result, "text", object->text); + appendToJson(result, "web_app", parseWebAppInfo(object->webApp)); + appendToJson(result, "start_parameter", object->startParameter); + removeLastComma(result); + result += '}'; + return result; +} + InlineQueryResult::Ptr TgTypeParser::parseJsonAndGetInlineQueryResult(const boost::property_tree::ptree& data) const { std::string type = data.get<std::string>("type", ""); InlineQueryResult::Ptr result; @@ -2784,9 +4000,9 @@ InlineQueryResultArticle::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultArti result->url = data.get<std::string>("url", ""); result->hideUrl = data.get<bool>("hide_url", false); result->description = data.get<std::string>("description", ""); - result->thumbUrl = data.get<std::string>("thumb_url", ""); - result->thumbWidth = data.get<std::int32_t>("thumb_width", 0); - result->thumbHeight = data.get<std::int32_t>("thumb_height", 0); + result->thumbnailUrl = data.get<std::string>("thumbnail_url", ""); + result->thumbnailWidth = data.get<std::int32_t>("thumbnail_width", 0); + result->thumbnailHeight = data.get<std::int32_t>("thumbnail_height", 0); return result; } @@ -2802,9 +4018,9 @@ std::string TgTypeParser::parseInlineQueryResultArticle(const InlineQueryResultA appendToJson(result, "url", object->url); appendToJson(result, "hide_url", object->hideUrl); appendToJson(result, "description", object->description); - appendToJson(result, "thumb_url", object->thumbUrl); - appendToJson(result, "thumb_width", object->thumbWidth); - appendToJson(result, "thumb_height", object->thumbHeight); + appendToJson(result, "thumbnail_url", object->thumbnailUrl); + appendToJson(result, "thumbnail_width", object->thumbnailWidth); + appendToJson(result, "thumbnail_height", object->thumbnailHeight); // The last comma will be erased by parseInlineQueryResult(). return result; } @@ -2813,7 +4029,7 @@ InlineQueryResultPhoto::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultPhoto( // NOTE: This function will be called by parseJsonAndGetInlineQueryResult(). auto result(std::make_shared<InlineQueryResultPhoto>()); result->photoUrl = data.get<std::string>("photo_url", ""); - result->thumbUrl = data.get<std::string>("thumb_url", ""); + result->thumbnailUrl = data.get<std::string>("thumbnail_url", ""); result->photoWidth = data.get<std::int32_t>("photo_width", 0); result->photoHeight = data.get<std::int32_t>("photo_height", 0); result->title = data.get<std::string>("title", ""); @@ -2833,7 +4049,7 @@ std::string TgTypeParser::parseInlineQueryResultPhoto(const InlineQueryResultPho // curly brackets to the result std::string. std::string result; appendToJson(result, "photo_url", object->photoUrl); - appendToJson(result, "thumb_url", object->thumbUrl); + appendToJson(result, "thumbnail_url", object->thumbnailUrl); appendToJson(result, "photo_width", object->photoWidth); appendToJson(result, "photo_height", object->photoHeight); appendToJson(result, "title", object->title); @@ -2853,8 +4069,8 @@ InlineQueryResultGif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultGif(cons result->gifWidth = data.get<std::int32_t>("gif_width", 0); result->gifHeight = data.get<std::int32_t>("gif_height", 0); result->gifDuration = data.get<std::int32_t>("gif_duration", 0); - result->thumbUrl = data.get<std::string>("thumb_url", ""); - result->thumbMimeType = data.get<std::string>("thumb_mime_type", ""); + result->thumbnailUrl = data.get<std::string>("thumbnail_url", ""); + result->thumbnailMimeType = data.get<std::string>("thumbnail_mime_type", ""); result->title = data.get<std::string>("title", ""); result->caption = data.get<std::string>("caption", ""); result->parseMode = data.get<std::string>("parse_mode", ""); @@ -2874,8 +4090,8 @@ std::string TgTypeParser::parseInlineQueryResultGif(const InlineQueryResultGif:: appendToJson(result, "gif_width", object->gifWidth); appendToJson(result, "gif_height", object->gifHeight); appendToJson(result, "gif_duration", object->gifDuration); - appendToJson(result, "thumb_url", object->thumbUrl); - appendToJson(result, "thumb_mime_type", object->thumbMimeType); + appendToJson(result, "thumbnail_url", object->thumbnailUrl); + appendToJson(result, "thumbnail_mime_type", object->thumbnailMimeType); appendToJson(result, "title", object->title); appendToJson(result, "caption", object->caption); appendToJson(result, "parse_mode", object->parseMode); @@ -2892,8 +4108,8 @@ InlineQueryResultMpeg4Gif::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultMpe result->mpeg4Width = data.get<std::int32_t>("mpeg4_width", 0); result->mpeg4Height = data.get<std::int32_t>("mpeg4_height", 0); result->mpeg4Duration = data.get<std::int32_t>("mpeg4_duration", 0); - result->thumbUrl = data.get<std::string>("thumb_url", ""); - result->thumbMimeType = data.get<std::string>("thumb_mime_type", ""); + result->thumbnailUrl = data.get<std::string>("thumbnail_url", ""); + result->thumbnailMimeType = data.get<std::string>("thumbnail_mime_type", ""); result->title = data.get<std::string>("title", ""); result->caption = data.get<std::string>("caption", ""); result->parseMode = data.get<std::string>("parse_mode", ""); @@ -2913,8 +4129,8 @@ std::string TgTypeParser::parseInlineQueryResultMpeg4Gif(const InlineQueryResult appendToJson(result, "mpeg4_width", object->mpeg4Width); appendToJson(result, "mpeg4_height", object->mpeg4Height); appendToJson(result, "mpeg4_duration", object->mpeg4Duration); - appendToJson(result, "thumb_url", object->thumbUrl); - appendToJson(result, "thumb_mime_type", object->thumbMimeType); + appendToJson(result, "thumbnail_url", object->thumbnailUrl); + appendToJson(result, "thumbnail_mime_type", object->thumbnailMimeType); appendToJson(result, "title", object->title); appendToJson(result, "caption", object->caption); appendToJson(result, "parse_mode", object->parseMode); @@ -2929,7 +4145,7 @@ InlineQueryResultVideo::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVideo( auto result(std::make_shared<InlineQueryResultVideo>()); result->videoUrl = data.get<std::string>("video_url", ""); result->mimeType = data.get<std::string>("mime_type", ""); - result->thumbUrl = data.get<std::string>("thumb_url", ""); + result->thumbnailUrl = data.get<std::string>("thumbnail_url", ""); result->title = data.get<std::string>("title", ""); result->caption = data.get<std::string>("caption", ""); result->parseMode = data.get<std::string>("parse_mode", ""); @@ -2951,7 +4167,7 @@ std::string TgTypeParser::parseInlineQueryResultVideo(const InlineQueryResultVid std::string result; appendToJson(result, "video_url", object->videoUrl); appendToJson(result, "mime_type", object->mimeType); - appendToJson(result, "thumb_url", object->thumbUrl); + appendToJson(result, "thumbnail_url", object->thumbnailUrl); appendToJson(result, "title", object->title); appendToJson(result, "caption", object->caption); appendToJson(result, "parse_mode", object->parseMode); @@ -3040,9 +4256,9 @@ InlineQueryResultDocument::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultDoc result->mimeType = data.get<std::string>("mime_type", ""); result->description = data.get<std::string>("description", ""); result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content"); - result->thumbUrl = data.get<std::string>("thumb_url", ""); - result->thumbWidth = data.get<std::int32_t>("thumb_width", 0); - result->thumbHeight = data.get<std::int32_t>("thumb_height", 0); + result->thumbnailUrl = data.get<std::string>("thumbnail_url", ""); + result->thumbnailWidth = data.get<std::int32_t>("thumbnail_width", 0); + result->thumbnailHeight = data.get<std::int32_t>("thumbnail_height", 0); return result; } @@ -3061,9 +4277,9 @@ std::string TgTypeParser::parseInlineQueryResultDocument(const InlineQueryResult appendToJson(result, "mime_type", object->mimeType); appendToJson(result, "description", object->description); appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent)); - appendToJson(result, "thumb_url", object->thumbUrl); - appendToJson(result, "thumb_width", object->thumbWidth); - appendToJson(result, "thumb_height", object->thumbHeight); + appendToJson(result, "thumbnail_url", object->thumbnailUrl); + appendToJson(result, "thumbnail_width", object->thumbnailWidth); + appendToJson(result, "thumbnail_height", object->thumbnailHeight); // The last comma will be erased by parseInlineQueryResult(). return result; } @@ -3079,9 +4295,9 @@ InlineQueryResultLocation::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultLoc result->heading = data.get<std::int32_t>("heading", 0); result->proximityAlertRadius = data.get<std::int32_t>("proximity_alert_radius", 0); result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content"); - result->thumbUrl = data.get<std::string>("thumb_url", ""); - result->thumbWidth = data.get<std::int32_t>("thumb_width", 0); - result->thumbHeight = data.get<std::int32_t>("thumb_height", 0); + result->thumbnailUrl = data.get<std::string>("thumbnail_url", ""); + result->thumbnailWidth = data.get<std::int32_t>("thumbnail_width", 0); + result->thumbnailHeight = data.get<std::int32_t>("thumbnail_height", 0); return result; } @@ -3100,9 +4316,9 @@ std::string TgTypeParser::parseInlineQueryResultLocation(const InlineQueryResult appendToJson(result, "heading", object->heading); appendToJson(result, "proximity_alert_radius", object->proximityAlertRadius); appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent)); - appendToJson(result, "thumb_url", object->thumbUrl); - appendToJson(result, "thumb_width", object->thumbWidth); - appendToJson(result, "thumb_height", object->thumbHeight); + appendToJson(result, "thumbnail_url", object->thumbnailUrl); + appendToJson(result, "thumbnail_width", object->thumbnailWidth); + appendToJson(result, "thumbnail_height", object->thumbnailHeight); // The last comma will be erased by parseInlineQueryResult(). return result; } @@ -3119,9 +4335,9 @@ InlineQueryResultVenue::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultVenue( result->googlePlaceId = data.get<std::string>("google_place_id", ""); result->googlePlaceType = data.get<std::string>("google_place_type", ""); result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content"); - result->thumbUrl = data.get<std::string>("thumb_url", ""); - result->thumbWidth = data.get<std::int32_t>("thumb_width", 0); - result->thumbHeight = data.get<std::int32_t>("thumb_height", 0); + result->thumbnailUrl = data.get<std::string>("thumbnail_url", ""); + result->thumbnailWidth = data.get<std::int32_t>("thumbnail_width", 0); + result->thumbnailHeight = data.get<std::int32_t>("thumbnail_height", 0); return result; } @@ -3141,9 +4357,9 @@ std::string TgTypeParser::parseInlineQueryResultVenue(const InlineQueryResultVen appendToJson(result, "google_place_id", object->googlePlaceId); appendToJson(result, "google_place_type", object->googlePlaceType); appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent)); - appendToJson(result, "thumb_url", object->thumbUrl); - appendToJson(result, "thumb_width", object->thumbWidth); - appendToJson(result, "thumb_height", object->thumbHeight); + appendToJson(result, "thumbnail_url", object->thumbnailUrl); + appendToJson(result, "thumbnail_width", object->thumbnailWidth); + appendToJson(result, "thumbnail_height", object->thumbnailHeight); // The last comma will be erased by parseInlineQueryResult(). return result; } @@ -3156,9 +4372,9 @@ InlineQueryResultContact::Ptr TgTypeParser::parseJsonAndGetInlineQueryResultCont result->lastName = data.get<std::string>("last_name", ""); result->vcard = data.get<std::string>("vcard", ""); result->inputMessageContent = tryParseJson<InputMessageContent>(&TgTypeParser::parseJsonAndGetInputMessageContent, data, "input_message_content"); - result->thumbUrl = data.get<std::string>("thumb_url", ""); - result->thumbWidth = data.get<std::int32_t>("thumb_width", 0); - result->thumbHeight = data.get<std::int32_t>("thumb_height", 0); + result->thumbnailUrl = data.get<std::string>("thumbnail_url", ""); + result->thumbnailWidth = data.get<std::int32_t>("thumbnail_width", 0); + result->thumbnailHeight = data.get<std::int32_t>("thumbnail_height", 0); return result; } @@ -3174,9 +4390,9 @@ std::string TgTypeParser::parseInlineQueryResultContact(const InlineQueryResultC appendToJson(result, "last_name", object->lastName); appendToJson(result, "vcard", object->vcard); appendToJson(result, "input_message_content", parseInputMessageContent(object->inputMessageContent)); - appendToJson(result, "thumb_url", object->thumbUrl); - appendToJson(result, "thumb_width", object->thumbWidth); - appendToJson(result, "thumb_height", object->thumbHeight); + appendToJson(result, "thumbnail_url", object->thumbnailUrl); + appendToJson(result, "thumbnail_width", object->thumbnailWidth); + appendToJson(result, "thumbnail_height", object->thumbnailHeight); // The last comma will be erased by parseInlineQueryResult(). return result; } @@ -3484,7 +4700,7 @@ InputTextMessageContent::Ptr TgTypeParser::parseJsonAndGetInputTextMessageConten result->messageText = data.get<std::string>("message_text", ""); result->parseMode = data.get<std::string>("parse_mode", ""); result->entities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "entities"); - result->disableWebPagePreview = data.get<bool>("disable_web_page_preview", false); + result->linkPreviewOptions = tryParseJson<LinkPreviewOptions>(&TgTypeParser::parseJsonAndGetLinkPreviewOptions, data, "link_preview_options"); return result; } @@ -3497,7 +4713,7 @@ std::string TgTypeParser::parseInputTextMessageContent(const InputTextMessageCon appendToJson(result, "message_text", object->messageText); appendToJson(result, "parse_mode", object->parseMode); appendToJson(result, "entities", parseArray(&TgTypeParser::parseMessageEntity, object->entities)); - appendToJson(result, "disable_web_page_preview", object->disableWebPagePreview); + appendToJson(result, "link_preview_options", parseLinkPreviewOptions(object->linkPreviewOptions)); // The last comma will be erased by parseInputMessageContent(). return result; } @@ -3665,6 +4881,8 @@ std::string TgTypeParser::parseChosenInlineResult(const ChosenInlineResult::Ptr& result += '{'; appendToJson(result, "result_id", object->resultId); appendToJson(result, "from", parseUser(object->from)); + appendToJson(result, "location", parseLocation(object->location)); + appendToJson(result, "inline_message_id", object->inlineMessageId); appendToJson(result, "query", object->query); removeLastComma(result); result += '}'; @@ -3691,12 +4909,15 @@ std::string TgTypeParser::parseSentWebAppMessage(const SentWebAppMessage::Ptr& o LabeledPrice::Ptr TgTypeParser::parseJsonAndGetLabeledPrice(const boost::property_tree::ptree& data) const { auto result(std::make_shared<LabeledPrice>()); - result->label = data.get<std::string>("label"); - result->amount = data.get<std::int32_t>("amount"); + result->label = data.get<std::string>("label", ""); + result->amount = data.get<std::int32_t>("amount", 0); return result; } std::string TgTypeParser::parseLabeledPrice(const LabeledPrice::Ptr& object) const { + if (!object) { + return ""; + } std::string result; result += '{'; appendToJson(result, "label", object->label); @@ -3708,11 +4929,11 @@ std::string TgTypeParser::parseLabeledPrice(const LabeledPrice::Ptr& object) con Invoice::Ptr TgTypeParser::parseJsonAndGetInvoice(const boost::property_tree::ptree& data) const { auto result(std::make_shared<Invoice>()); - result->title = data.get<std::string>("title"); - result->description = data.get<std::string>("description"); - result->startParameter = data.get<std::string>("start_parameter"); - result->currency = data.get<std::string>("currency"); - result->totalAmount = data.get<std::int32_t>("total_amount"); + result->title = data.get<std::string>("title", ""); + result->description = data.get<std::string>("description", ""); + result->startParameter = data.get<std::string>("start_parameter", ""); + result->currency = data.get<std::string>("currency", ""); + result->totalAmount = data.get<std::int32_t>("total_amount", 0); return result; } @@ -3733,23 +4954,24 @@ std::string TgTypeParser::parseInvoice(const Invoice::Ptr& object) const { } ShippingAddress::Ptr TgTypeParser::parseJsonAndGetShippingAddress(const boost::property_tree::ptree& data) const { - ShippingAddress::Ptr result; - result->countryCode = data.get<std::string>("country_code"); + auto result(std::make_shared<ShippingAddress>()); + result->countryCode = data.get<std::string>("country_code", ""); result->state = data.get<std::string>("state", ""); - result->city = data.get<std::string>("city"); - result->streetLine1 = data.get<std::string>("street_line1"); - result->streetLine2 = data.get<std::string>("street_line2"); - result->postCode = data.get<std::string>("post_code"); + result->city = data.get<std::string>("city", ""); + result->streetLine1 = data.get<std::string>("street_line1", ""); + result->streetLine2 = data.get<std::string>("street_line2", ""); + result->postCode = data.get<std::string>("post_code", ""); return result; } std::string TgTypeParser::parseShippingAddress(const ShippingAddress::Ptr& object) const { + if (!object) { + return ""; + } std::string result; result += '{'; appendToJson(result, "country_code", object->countryCode); - if (!object->state.empty()) { - appendToJson(result, "state", object->state); - } + appendToJson(result, "state", object->state); appendToJson(result, "city", object->city); appendToJson(result, "street_line1", object->streetLine1); appendToJson(result, "street_line2", object->streetLine2); @@ -3764,7 +4986,7 @@ OrderInfo::Ptr TgTypeParser::parseJsonAndGetOrderInfo(const boost::property_tree result->name = data.get<std::string>("name", ""); result->phoneNumber = data.get<std::string>("phone_number", ""); result->email = data.get<std::string>("email", ""); - result->shippingAddress = tryParseJson(&TgTypeParser::parseJsonAndGetShippingAddress, data, "shipping_address"); + result->shippingAddress = tryParseJson<ShippingAddress>(&TgTypeParser::parseJsonAndGetShippingAddress, data, "shipping_address"); return result; } @@ -3774,20 +4996,10 @@ std::string TgTypeParser::parseOrderInfo(const OrderInfo::Ptr& object) const { } std::string result; result += '{'; - if (!object->name.empty()) { - appendToJson(result, "name", object->name); - } - if (!object->phoneNumber.empty()) { - appendToJson(result, "phone_number", object->phoneNumber); - } - if (!object->email.empty()) { - appendToJson(result, "email", object->email); - } - if (!object->shippingAddress) { - result += R"("shipping_address":)"; - result += parseShippingAddress(object->shippingAddress); - result += ","; - } + appendToJson(result, "name", object->name); + appendToJson(result, "phone_number", object->phoneNumber); + appendToJson(result, "email", object->email); + appendToJson(result, "shipping_address", parseShippingAddress(object->shippingAddress)); removeLastComma(result); result += '}'; return result; @@ -3795,44 +5007,51 @@ std::string TgTypeParser::parseOrderInfo(const OrderInfo::Ptr& object) const { ShippingOption::Ptr TgTypeParser::parseJsonAndGetShippingOption(const boost::property_tree::ptree& data) const { auto result(std::make_shared<ShippingOption>()); - result->id = data.get<std::string>("id"); - result->title = data.get<std::string>("title"); + result->id = data.get<std::string>("id", ""); + result->title = data.get<std::string>("title", ""); result->prices = parseJsonAndGetArray<LabeledPrice>(&TgTypeParser::parseJsonAndGetLabeledPrice, data, "prices"); return result; } std::string TgTypeParser::parseShippingOption(const ShippingOption::Ptr& object) const { + if (!object) { + return ""; + } std::string result; result += '{'; appendToJson(result, "id", object->id); appendToJson(result, "title", object->title); + appendToJson(result, "prices", parseArray(&TgTypeParser::parseLabeledPrice, object->prices)); removeLastComma(result); - result += R"("prices":)"; - result += parseArray(&TgTypeParser::parseLabeledPrice, object->prices); result += '}'; return result; } SuccessfulPayment::Ptr TgTypeParser::parseJsonAndGetSuccessfulPayment(const boost::property_tree::ptree& data) const { auto result(std::make_shared<SuccessfulPayment>()); - result->currency = data.get<std::string>("currency"); - result->totalAmount = data.get<std::int32_t>("total_amount"); - result->invoicePayload = data.get<std::string>("invoice_payload"); - result->shippingOptionId = data.get<std::string>("shipping_option_id"); - result->orderInfo = tryParseJson(&TgTypeParser::parseJsonAndGetOrderInfo, data, "order_info"); + result->currency = data.get<std::string>("currency", ""); + result->totalAmount = data.get<std::int32_t>("total_amount", 0); + result->invoicePayload = data.get<std::string>("invoice_payload", ""); + result->shippingOptionId = data.get<std::string>("shipping_option_id", ""); + result->orderInfo = tryParseJson<OrderInfo>(&TgTypeParser::parseJsonAndGetOrderInfo, data, "order_info"); + result->telegramPaymentChargeId = data.get<std::string>("telegram_payment_charge_id", ""); + result->providerPaymentChargeId = data.get<std::string>("provider_payment_charge_id", ""); return result; } std::string TgTypeParser::parseSuccessfulPayment(const SuccessfulPayment::Ptr& object) const { + if (!object) { + return ""; + } std::string result; result += '{'; appendToJson(result, "currency", object->currency); appendToJson(result, "total_amount", object->totalAmount); appendToJson(result, "invoice_payload", object->invoicePayload); appendToJson(result, "shipping_option_id", object->shippingOptionId); - result += R"("order_info":)"; - result += parseOrderInfo(object->orderInfo); - result += ","; + appendToJson(result, "order_info", parseOrderInfo(object->orderInfo)); + appendToJson(result, "telegram_payment_charge_id", object->telegramPaymentChargeId); + appendToJson(result, "provider_payment_charge_id", object->providerPaymentChargeId); removeLastComma(result); result += '}'; return result; @@ -3840,24 +5059,23 @@ std::string TgTypeParser::parseSuccessfulPayment(const SuccessfulPayment::Ptr& o ShippingQuery::Ptr TgTypeParser::parseJsonAndGetShippingQuery(const boost::property_tree::ptree& data) const { auto result(std::make_shared<ShippingQuery>()); - result->id = data.get<std::string>("id"); - result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); - result->invoicePayload = data.get<std::string>("invoice_payload"); - result->shippingAddress = tryParseJson(&TgTypeParser::parseJsonAndGetShippingAddress, data, "shipping_address"); + result->id = data.get<std::string>("id", ""); + result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); + result->invoicePayload = data.get<std::string>("invoice_payload", ""); + result->shippingAddress = tryParseJson<ShippingAddress>(&TgTypeParser::parseJsonAndGetShippingAddress, data, "shipping_address"); return result; } std::string TgTypeParser::parseShippingQuery(const ShippingQuery::Ptr& object) const { + if (!object) { + return ""; + } std::string result; result += '{'; appendToJson(result, "id", object->id); - result += R"("from":)"; - result += parseUser(object->from); - result += ","; + appendToJson(result, "from", parseUser(object->from)); appendToJson(result, "invoice_payload", object->invoicePayload); - result += R"("shipping_address":)"; - result += parseShippingAddress(object->shippingAddress); - result += ","; + appendToJson(result, "shipping_address", parseShippingAddress(object->shippingAddress)); removeLastComma(result); result += '}'; return result; @@ -3865,22 +5083,29 @@ std::string TgTypeParser::parseShippingQuery(const ShippingQuery::Ptr& object) c PreCheckoutQuery::Ptr TgTypeParser::parseJsonAndGetPreCheckoutQuery(const boost::property_tree::ptree& data) const { auto result(std::make_shared<PreCheckoutQuery>()); - result->id = data.get<std::string>("id"); - result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "user"); - result->currency = data.get<std::string>("currency"); - result->totalAmount = data.get<std::int32_t>("total_amount"); + result->id = data.get<std::string>("id", ""); + result->from = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "from"); + result->currency = data.get<std::string>("currency", ""); + result->totalAmount = data.get<std::int32_t>("total_amount", 0); + result->invoicePayload = data.get<std::string>("invoice_payload", ""); + result->shippingOptionId = data.get<std::string>("shipping_option_id", ""); + result->orderInfo = tryParseJson<OrderInfo>(&TgTypeParser::parseJsonAndGetOrderInfo, data, "order_info"); return result; } std::string TgTypeParser::parsePreCheckoutQuery(const PreCheckoutQuery::Ptr& object) const { + if (!object) { + return ""; + } std::string result; result += '{'; appendToJson(result, "id", object->id); - result += R"("user":)"; - result += parseUser(object->from); - result += ","; + appendToJson(result, "from", parseUser(object->from)); appendToJson(result, "currency", object->currency); appendToJson(result, "total_amount", object->totalAmount); + appendToJson(result, "invoice_payload", object->invoicePayload); + appendToJson(result, "shipping_option_id", object->shippingOptionId); + appendToJson(result, "order_info", parseOrderInfo(object->orderInfo)); removeLastComma(result); result += '}'; return result; @@ -3889,7 +5114,7 @@ std::string TgTypeParser::parsePreCheckoutQuery(const PreCheckoutQuery::Ptr& obj PassportData::Ptr TgTypeParser::parseJsonAndGetPassportData(const boost::property_tree::ptree& data) const { auto result(std::make_shared<PassportData>()); result->data = parseJsonAndGetArray<EncryptedPassportElement>(&TgTypeParser::parseJsonAndGetEncryptedPassportElement, data, "data"); - result->credentials = tryParseJson(&TgTypeParser::parseJsonAndGetEncryptedCredentials, data, "credentials"); + result->credentials = tryParseJson<EncryptedCredentials>(&TgTypeParser::parseJsonAndGetEncryptedCredentials, data, "credentials"); return result; } @@ -3937,9 +5162,9 @@ EncryptedPassportElement::Ptr TgTypeParser::parseJsonAndGetEncryptedPassportElem result->phoneNumber = data.get<std::string>("phone_number", ""); result->email = data.get<std::string>("email", ""); result->files = parseJsonAndGetArray<PassportFile>(&TgTypeParser::parseJsonAndGetPassportFile, data, "files"); - result->frontSide = tryParseJson(&TgTypeParser::parseJsonAndGetPassportFile, data, "front_side"); - result->reverseSide = tryParseJson(&TgTypeParser::parseJsonAndGetPassportFile, data, "reverse_side"); - result->selfie = tryParseJson(&TgTypeParser::parseJsonAndGetPassportFile, data, "selfie"); + result->frontSide = tryParseJson<PassportFile>(&TgTypeParser::parseJsonAndGetPassportFile, data, "front_side"); + result->reverseSide = tryParseJson<PassportFile>(&TgTypeParser::parseJsonAndGetPassportFile, data, "reverse_side"); + result->selfie = tryParseJson<PassportFile>(&TgTypeParser::parseJsonAndGetPassportFile, data, "selfie"); result->translation = parseJsonAndGetArray<PassportFile>(&TgTypeParser::parseJsonAndGetPassportFile, data, "translation"); result->hash = data.get<std::string>("hash", ""); return result; @@ -4243,10 +5468,10 @@ std::string TgTypeParser::parsePassportElementErrorUnspecified(const PassportEle Game::Ptr TgTypeParser::parseJsonAndGetGame(const boost::property_tree::ptree& data) const { auto result(std::make_shared<Game>()); - result->title = data.get("title", ""); - result->description = data.get("description", ""); + result->title = data.get<std::string>("title", ""); + result->description = data.get<std::string>("description", ""); result->photo = parseJsonAndGetArray<PhotoSize>(&TgTypeParser::parseJsonAndGetPhotoSize, data, "photo"); - result->text = data.get("text", ""); + result->text = data.get<std::string>("text", ""); result->textEntities = parseJsonAndGetArray<MessageEntity>(&TgTypeParser::parseJsonAndGetMessageEntity, data, "text_entities"); result->animation = tryParseJson<Animation>(&TgTypeParser::parseJsonAndGetAnimation, data, "animation"); return result; @@ -4269,7 +5494,7 @@ std::string TgTypeParser::parseGame(const Game::Ptr& object) const { return result; } -CallbackGame::Ptr TgTypeParser::parseJsonAndGetCallbackGame(const boost::property_tree::ptree& data) const { +CallbackGame::Ptr TgTypeParser::parseJsonAndGetCallbackGame(const boost::property_tree::ptree& /*data*/) const { auto result(std::make_shared<CallbackGame>()); return result; } @@ -4280,13 +5505,14 @@ std::string TgTypeParser::parseCallbackGame(const CallbackGame::Ptr& object) con } std::string result; result += '{'; + //removeLastComma(result); result += '}'; return result; } GameHighScore::Ptr TgTypeParser::parseJsonAndGetGameHighScore(const boost::property_tree::ptree& data) const { auto result(std::make_shared<GameHighScore>()); - result->position = data.get("position", ""); + result->position = data.get<std::int32_t>("position", 0); result->user = tryParseJson<User>(&TgTypeParser::parseJsonAndGetUser, data, "user"); result->score = data.get<std::int32_t>("score", 0); return result; diff --git a/src/types/ChatBoostSource.cpp b/src/types/ChatBoostSource.cpp new file mode 100644 index 0000000..84417b6 --- /dev/null +++ b/src/types/ChatBoostSource.cpp @@ -0,0 +1,11 @@ +#include "tgbot/types/ChatBoostSourcePremium.h" +#include "tgbot/types/ChatBoostSourceGiftCode.h" +#include "tgbot/types/ChatBoostSourceGiveaway.h" + +#include <string> + +using namespace TgBot; + +const std::string ChatBoostSourcePremium::SOURCE = "premium"; +const std::string ChatBoostSourceGiftCode::SOURCE = "gift_code"; +const std::string ChatBoostSourceGiveaway::SOURCE = "giveaway"; diff --git a/src/types/InputFile.cpp b/src/types/InputFile.cpp index c4d804d..2deb082 100644 --- a/src/types/InputFile.cpp +++ b/src/types/InputFile.cpp @@ -5,12 +5,10 @@ #include <memory> #include <string> -using namespace std; - namespace TgBot { -InputFile::Ptr InputFile::fromFile(const string& filePath, const string& mimeType) { - auto result(make_shared<InputFile>()); +InputFile::Ptr InputFile::fromFile(const std::string& filePath, const std::string& mimeType) { + auto result(std::make_shared<InputFile>()); result->data = FileTools::read(filePath); result->mimeType = mimeType; result->fileName = std::filesystem::path(filePath).filename().string(); diff --git a/src/types/MessageOrigin.cpp b/src/types/MessageOrigin.cpp new file mode 100644 index 0000000..c2471d9 --- /dev/null +++ b/src/types/MessageOrigin.cpp @@ -0,0 +1,13 @@ +#include "tgbot/types/MessageOriginUser.h" +#include "tgbot/types/MessageOriginHiddenUser.h" +#include "tgbot/types/MessageOriginChat.h" +#include "tgbot/types/MessageOriginChannel.h" + +#include <string> + +using namespace TgBot; + +const std::string MessageOriginUser::TYPE = "user"; +const std::string MessageOriginHiddenUser::TYPE = "hidden_user"; +const std::string MessageOriginChat::TYPE = "chat"; +const std::string MessageOriginChannel::TYPE = "channel"; diff --git a/src/types/ReactionType.cpp b/src/types/ReactionType.cpp new file mode 100644 index 0000000..3dd984b --- /dev/null +++ b/src/types/ReactionType.cpp @@ -0,0 +1,9 @@ +#include "tgbot/types/ReactionTypeEmoji.h" +#include "tgbot/types/ReactionTypeCustomEmoji.h" + +#include <string> + +using namespace TgBot; + +const std::string ReactionTypeEmoji::TYPE = "emoji"; +const std::string ReactionTypeCustomEmoji::TYPE = "custom_emoji"; |