From 7b72d7a35fce82049fa63444b0ce5f2a3fc22129 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Sun, 14 Apr 2024 23:43:12 +0200 Subject: Update to Bot API 6.6 --- src/Api.cpp | 374 ++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 261 insertions(+), 113 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index c8ce399..bb0ac45 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -293,7 +293,7 @@ Message::Ptr Api::sendAudio(boost::variant chatId, std::int32_t duration, const std::string& performer, const std::string& title, - boost::variant thumb, + boost::variant thumbnail, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, const std::string& parseMode, @@ -333,13 +333,13 @@ Message::Ptr Api::sendAudio(boost::variant chatId, if (!title.empty()) { args.emplace_back("title", title); } - if (thumb.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); } else { // std::string - auto thumbStr = boost::get(thumb); - if (!thumbStr.empty()) { - args.emplace_back("thumb", thumbStr); + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); } } if (disableNotification) { @@ -363,7 +363,7 @@ Message::Ptr Api::sendAudio(boost::variant chatId, Message::Ptr Api::sendDocument(boost::variant chatId, boost::variant document, - boost::variant thumb, + boost::variant thumbnail, const std::string& caption, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, @@ -387,13 +387,13 @@ Message::Ptr Api::sendDocument(boost::variant chatId, } else { // std::string args.emplace_back("document", boost::get(document)); } - if (thumb.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); } else { // std::string - auto thumbStr = boost::get(thumb); - if (!thumbStr.empty()) { - args.emplace_back("thumb", thumbStr); + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); } } if (!caption.empty()) { @@ -433,7 +433,7 @@ Message::Ptr Api::sendVideo(boost::variant chatId, std::int32_t duration, std::int32_t width, std::int32_t height, - boost::variant thumb, + boost::variant thumbnail, const std::string& caption , std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, @@ -466,13 +466,13 @@ Message::Ptr Api::sendVideo(boost::variant chatId, if (height != 0) { args.emplace_back("height", height); } - if (thumb.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); } else { // std::string - auto thumbStr = boost::get(thumb); - if (!thumbStr.empty()) { - args.emplace_back("thumb", thumbStr); + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); } } if (!caption.empty()) { @@ -514,7 +514,7 @@ Message::Ptr Api::sendAnimation(boost::variant chatId std::int32_t duration, std::int32_t width, std::int32_t height, - boost::variant thumb, + boost::variant thumbnail, const std::string& caption, std::int32_t replyToMessageId, GenericReply::Ptr replyMarkup, @@ -547,13 +547,13 @@ Message::Ptr Api::sendAnimation(boost::variant chatId if (height != 0) { args.emplace_back("height", height); } - if (thumb.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); } else { // std::string - auto thumbStr = boost::get(thumb); - if (!thumbStr.empty()) { - args.emplace_back("thumb", thumbStr); + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); } } if (!caption.empty()) { @@ -649,7 +649,7 @@ Message::Ptr Api::sendVideoNote(boost::variant chatId bool disableNotification, std::int32_t duration, std::int32_t length, - boost::variant thumb, + boost::variant thumbnail, GenericReply::Ptr replyMarkup, bool allowSendingWithoutReply, bool protectContent, @@ -673,13 +673,13 @@ Message::Ptr Api::sendVideoNote(boost::variant chatId if (length) { args.emplace_back("length", length); } - if (thumb.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + if (thumbnail.which() == 0) { // InputFile::Ptr + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); } else { // std::string - auto thumbStr = boost::get(thumb); - if (!thumbStr.empty()) { - args.emplace_back("thumb", thumbStr); + auto thumbnailStr = boost::get(thumbnail); + if (!thumbnailStr.empty()) { + args.emplace_back("thumbnail", thumbnailStr); } } if (disableNotification) { @@ -797,8 +797,14 @@ Message::Ptr Api::editMessageLiveLocation(float latitude, std::vector args; args.reserve(9); - if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { - args.emplace_back("chat_id", chatId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } } if (messageId) { args.emplace_back("message_id", messageId); @@ -831,8 +837,14 @@ Message::Ptr Api::stopMessageLiveLocation(boost::variant args; args.reserve(4); - if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { - args.emplace_back("chat_id", chatId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } } if (messageId) { args.emplace_back("message_id", messageId); @@ -1539,7 +1551,7 @@ ForumTopic::Ptr Api::createForumTopic(boost::variant bool Api::editForumTopic(boost::variant chatId, std::int32_t messageThreadId, const std::string& name, - boost::variant iconCustomEmojiId) const { + boost::variant iconCustomEmojiId) const { std::vector args; args.reserve(4); @@ -1548,8 +1560,14 @@ bool Api::editForumTopic(boost::variant chatId, if (!name.empty()) { args.emplace_back("name", name); } - if (iconCustomEmojiId.which() == 1) { // std::string - args.emplace_back("icon_custom_emoji_id", boost::get(iconCustomEmojiId)); + if (iconCustomEmojiId.which() == 0) { // std::int32_t + if (boost::get(iconCustomEmojiId) != 0) { + args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); + } + } else { // std::string + if (boost::get(iconCustomEmojiId) != "") { + args.emplace_back("icon_custom_emoji_id", iconCustomEmojiId); + } } return sendRequest("editForumTopic", args).get("", false); @@ -1689,7 +1707,7 @@ bool Api::setMyCommands(const std::vector& commands, } bool Api::deleteMyCommands(BotCommandScope::Ptr scope, - const std::string& languageCode) const { + const std::string& languageCode) const { std::vector args; args.reserve(2); @@ -1707,7 +1725,7 @@ std::vector Api::getMyCommands(BotCommandScope::Ptr scope, const std::string& languageCode) const { std::vector args; args.reserve(2); -; + if (scope != nullptr) { args.emplace_back("scope", _tgTypeParser.parseBotCommandScope(scope)); } @@ -1718,6 +1736,58 @@ std::vector Api::getMyCommands(BotCommandScope::Ptr scope, return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetBotCommand, sendRequest("getMyCommands", args)); } +bool Api::setMyDescription(const std::string& description, + const std::string& languageCode) const { + std::vector args; + args.reserve(2); + + if (!description.empty()) { + args.emplace_back("description", description); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } + + return sendRequest("setMyDescription", args).get("", false); +} + +BotDescription::Ptr Api::getMyDescription(const std::string& languageCode) const { + std::vector 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 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("", false); +} + +BotShortDescription::Ptr Api::getMyShortDescription(const std::string& languageCode) const { + std::vector 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 args; @@ -1781,8 +1851,14 @@ Message::Ptr Api::editMessageText(const std::string& text, std::vector args; args.reserve(8); - if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { - args.emplace_back("chat_id", chatId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } } if (messageId) { args.emplace_back("message_id", messageId); @@ -1822,8 +1898,14 @@ Message::Ptr Api::editMessageCaption(boost::variant c std::vector args; args.reserve(7); - if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { - args.emplace_back("chat_id", chatId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } } if (messageId) { args.emplace_back("message_id", messageId); @@ -1861,10 +1943,16 @@ Message::Ptr Api::editMessageMedia(InputMedia::Ptr media, std::vector args; args.reserve(5); - args.emplace_back("media", _tgTypeParser.parseInputMedia(media)); - if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { - args.emplace_back("chat_id", chatId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } } + args.emplace_back("media", _tgTypeParser.parseInputMedia(media)); if (messageId) { args.emplace_back("message_id", messageId); } @@ -1891,8 +1979,14 @@ Message::Ptr Api::editMessageReplyMarkup(boost::variant args; args.reserve(4); - if ((boost::get(chatId) != 0) || (boost::get(chatId) != "")) { - args.emplace_back("chat_id", chatId); + if (chatId.which() == 0) { // std::int64_t + if (boost::get(chatId) != 0) { + args.emplace_back("chat_id", chatId); + } + } else { // std::string + if (boost::get(chatId) != "") { + args.emplace_back("chat_id", chatId); + } } if (messageId) { args.emplace_back("message_id", messageId); @@ -1945,9 +2039,10 @@ Message::Ptr Api::sendSticker(boost::variant chatId, bool disableNotification, bool allowSendingWithoutReply, bool protectContent, - std::int32_t messageThreadId) const { + std::int32_t messageThreadId, + const std::string& emoji) const { std::vector args; - args.reserve(8); + args.reserve(9); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -1959,6 +2054,9 @@ Message::Ptr Api::sendSticker(boost::variant chatId, } else { // std::string args.emplace_back("sticker", boost::get(sticker)); } + if (!emoji.empty()) { + args.emplace_back("emoji", emoji); + } if (disableNotification) { args.emplace_back("disable_notification", disableNotification); } @@ -1991,7 +2089,8 @@ std::vector Api::getCustomEmojiStickers(const std::vector args; args.reserve(1); - args.emplace_back("custom_emoji_ids", _tgTypeParser.parseArray([] (const std::string& customEmojiId) -> std::string { + args.emplace_back("custom_emoji_ids", _tgTypeParser.parseArray( + [] (const std::string& customEmojiId) -> std::string { return "\"" + StringTools::escapeJsonString(customEmojiId) + "\""; }, customEmojiIds)); @@ -1999,12 +2098,14 @@ std::vector Api::getCustomEmojiStickers(const std::vector 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 +2113,37 @@ 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 pngSticker, - InputFile::Ptr tgsSticker, - InputFile::Ptr webmSticker, - const std::string& stickerType) const { + const std::vector& stickers, + const std::string& stickerFormat, + const std::string& stickerType, + bool needsRepainting) const { std::vector args; - args.reserve(10); + args.reserve(7); 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(pngSticker); - args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("png_sticker", boost::get(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("stickers", _tgTypeParser.parseArray(&TgTypeParser::parseInputSticker, stickers)); + args.emplace_back("sticker_format", stickerFormat); 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("", false); } bool Api::addStickerToSet(std::int64_t userId, - const std::string& name, - const std::string& emojis, - MaskPosition::Ptr maskPosition, - boost::variant pngSticker, - InputFile::Ptr tgsSticker, - InputFile::Ptr webmSticker) const { + const std::string& name, + InputSticker::Ptr sticker) const { std::vector 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(pngSticker); - args.emplace_back("png_sticker", file->data, true, file->mimeType, file->fileName); - } else { // std::string - args.emplace_back("png_sticker", boost::get(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("", false); } @@ -2100,22 +2168,102 @@ bool Api::deleteStickerFromSet(const std::string& sticker) const { return sendRequest("deleteStickerFromSet", args).get("", false); } -bool Api::setStickerSetThumb(const std::string& name, - std::int64_t userId, - boost::variant thumb) const { +bool Api::setStickerEmojiList(const std::string& sticker, + const std::vector& emojiList) const { + std::vector args; + args.reserve(2); + + args.emplace_back("sticker", sticker); + args.emplace_back("emoji_list", _tgTypeParser.parseArray( + [](const std::string& emoji)->std::string { + return "\"" + StringTools::escapeJsonString(emoji) + "\""; + }, emojiList)); + + return sendRequest("setStickerEmojiList", args).get("", false); +} + +bool Api::setStickerKeywords(const std::string& sticker, + const std::vector& keywords) const { + std::vector args; + args.reserve(2); + + args.emplace_back("sticker", sticker); + if (!keywords.empty()) { + args.emplace_back("keywords", _tgTypeParser.parseArray( + [](const std::string& keyword)->std::string { + return "\"" + StringTools::escapeJsonString(keyword) + "\""; + }, keywords)); + } + + return sendRequest("setStickerKeywords", args).get("", false); +} + +bool Api::setStickerMaskPosition(const std::string& sticker, + MaskPosition::Ptr maskPosition) const { + std::vector args; + args.reserve(2); + + args.emplace_back("sticker", sticker); + if (maskPosition != nullptr) { + args.emplace_back("mask_position", _tgTypeParser.parseMaskPosition(maskPosition)); + } + + return sendRequest("setStickerMaskPosition", args).get("", false); +} + +bool Api::setStickerSetTitle(const std::string& name, + const std::string& title) const { + std::vector args; + args.reserve(2); + + args.emplace_back("name", name); + args.emplace_back("title", title); + + return sendRequest("setStickerSetTitle", args).get("", false); +} + +bool Api::setStickerSetThumbnail(const std::string& name, + std::int64_t userId, + boost::variant thumbnail) const { std::vector args; args.reserve(3); args.emplace_back("name", name); args.emplace_back("user_id", userId); - if (thumb.which() == 0) { // InputFile::Ptr - auto file = boost::get(thumb); - args.emplace_back("thumb", file->data, true, file->mimeType, file->fileName); + if (thumbnail.which() == 0) { // InputFile::Ptr + if (boost::get(thumbnail) != nullptr) { + auto file = boost::get(thumbnail); + args.emplace_back("thumbnail", file->data, true, file->mimeType, file->fileName); + } } else { // std::string - args.emplace_back("thumb", boost::get(thumb)); + if (boost::get(thumbnail) != "") { + args.emplace_back("thumbnail", boost::get(thumbnail)); + } + } + + return sendRequest("setStickerSetThumbnail", args).get("", false); +} + +bool Api::setCustomEmojiStickerSetThumbnail(const std::string& name, + const std::string& customEmojiId) const { + std::vector args; + args.reserve(2); + + args.emplace_back("name", name); + if (!customEmojiId.empty()) { + args.emplace_back("custom_emoji_id", customEmojiId); } - return sendRequest("setStickerSetThumb", args).get("", false); + return sendRequest("setCustomEmojiStickerSetThumbnail", args).get("", false); +} + +bool Api::deleteStickerSet(const std::string& name) const { + std::vector args; + args.reserve(1); + + args.emplace_back("name", name); + + return sendRequest("deleteStickerSet", args).get("", false); } bool Api::answerInlineQuery(const std::string& inlineQueryId, -- cgit v1.2.3 From fbeb025e21fad2fa1fb6cd5ae186eabf9a349091 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Mon, 15 Apr 2024 01:24:12 +0200 Subject: Update to Bot API 6.7 --- src/Api.cpp | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index bb0ac45..8a91aee 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1736,6 +1736,32 @@ std::vector Api::getMyCommands(BotCommandScope::Ptr scope, return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetBotCommand, sendRequest("getMyCommands", args)); } +bool Api::setMyName(const std::string& name, + const std::string& languageCode) const { + std::vector args; + args.reserve(2); + + if (!name.empty()) { + args.emplace_back("name", name); + } + if (!languageCode.empty()) { + args.emplace_back("language_code", languageCode); + } + + return sendRequest("setMyName", args).get("", false); +} + +BotName::Ptr Api::getMyName(const std::string& languageCode) const { + std::vector 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 args; @@ -2271,27 +2297,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 args; - args.reserve(7); + args.reserve(6); args.emplace_back("inline_query_id", inlineQueryId); args.emplace_back("results", _tgTypeParser.parseArray(&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("", false); -- cgit v1.2.3 From 5aaaa79ee2441dd36a3af4e1c869717bf9b2c927 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Mon, 15 Apr 2024 12:46:10 +0200 Subject: Update to Bot API 6.8 --- src/Api.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 8a91aee..b3ce4ea 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1664,6 +1664,15 @@ bool Api::unhideGeneralForumTopic(boost::variant chat return sendRequest("unhideGeneralForumTopic", args).get("", false); } +bool Api::unpinAllGeneralForumTopicMessages(boost::variant chatId) const { + std::vector args; + args.reserve(1); + + args.emplace_back("chat_id", chatId); + + return sendRequest("unpinAllGeneralForumTopicMessages", args).get("", false); +} + bool Api::answerCallbackQuery(const std::string& callbackQueryId, const std::string& text, bool showAlert, -- cgit v1.2.3 From 90cb57b61ee3ed9db0164b351ac9a98c83645426 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Mon, 15 Apr 2024 14:06:55 +0200 Subject: Update to Bot API 6.9 --- src/Api.cpp | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index b3ce4ea..0d11295 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -1156,7 +1156,7 @@ bool Api::unbanChatMember(boost::variant chatId, bool Api::restrictChatMember(boost::variant chatId, std::int64_t userId, TgBot::ChatPermissions::Ptr permissions, - std::int64_t untilDate, + std::uint32_t untilDate, bool useIndependentChatPermissions) const { std::vector args; args.reserve(5); @@ -1164,10 +1164,10 @@ bool Api::restrictChatMember(boost::variant 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); } @@ -1187,46 +1187,58 @@ bool Api::promoteChatMember(boost::variant chatId, bool canManageChat, bool canManageVideoChats, bool canRestrictMembers, - bool canManageTopics) const { + bool canManageTopics, + bool canPostStories, + bool canEditStories, + bool canDeleteStories) const { std::vector 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); } -- cgit v1.2.3 From b5b5cd9e88fc5a87f196e54144b163b4729570d1 Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Sat, 20 Apr 2024 14:17:26 +0200 Subject: Update to Bot API 7.0 --- src/Api.cpp | 401 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 220 insertions(+), 181 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index 0d11295..cdd5ad7 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -112,17 +112,16 @@ bool Api::close() const { Message::Ptr Api::sendMessage(boost::variant 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& entities, - bool allowSendingWithoutReply, - bool protectContent, - std::int32_t messageThreadId) const { + std::int32_t messageThreadId, + bool protectContent) const { std::vector args; - args.reserve(11); + args.reserve(10); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -135,8 +134,8 @@ Message::Ptr Api::sendMessage(boost::variant chatId, if (!entities.empty()) { args.emplace_back("entities", _tgTypeParser.parseArray(&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 +143,8 @@ Message::Ptr Api::sendMessage(boost::variant 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 +178,36 @@ Message::Ptr Api::forwardMessage(boost::variant chatI return _tgTypeParser.parseJsonAndGetMessage(sendRequest("forwardMessage", args)); } +std::vector Api::forwardMessages(boost::variant chatId, + boost::variant fromChatId, + const std::vector& messageIds, + std::int32_t messageThreadId, + bool disableNotification, + bool protectContent) const { + std::vector args; + args.reserve(6); + + args.emplace_back("chat_id", chatId); + args.emplace_back("from_chat_id", fromChatId); + if (!messageIds.empty()) { + args.emplace_back("message_ids", _tgTypeParser.parseArray( + [] (const std::int32_t& i)->std::int32_t { + return i; + }, messageIds)); + } + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + + return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetMessageId, sendRequest("forwardMessages", args)); +} + MessageId::Ptr Api::copyMessage(boost::variant chatId, boost::variant fromChatId, std::int32_t messageId, @@ -189,13 +215,12 @@ MessageId::Ptr Api::copyMessage(boost::variant chatId const std::string& parseMode, const std::vector& captionEntities, bool disableNotification, - std::int32_t replyToMessageId, - bool allowSendingWithoutReply, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, bool protectContent, std::int32_t messageThreadId) const { std::vector args; - args.reserve(12); + args.reserve(11); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -218,11 +243,8 @@ MessageId::Ptr Api::copyMessage(boost::variant 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,20 +253,54 @@ MessageId::Ptr Api::copyMessage(boost::variant chatId return _tgTypeParser.parseJsonAndGetMessageId(sendRequest("copyMessage", args)); } +std::vector Api::copyMessages(boost::variant chatId, + boost::variant fromChatId, + const std::vector& messageIds, + std::int32_t messageThreadId, + bool disableNotification, + bool protectContent, + bool removeCaption) const { + std::vector args; + args.reserve(7); + + args.emplace_back("chat_id", chatId); + args.emplace_back("from_chat_id", fromChatId); + + if (!messageIds.empty()) { + args.emplace_back("message_ids", _tgTypeParser.parseArray( + [] (const std::int32_t& i)->std::int32_t { + return i; + }, messageIds)); + } + if (messageThreadId != 0) { + args.emplace_back("message_thread_id", messageThreadId); + } + if (disableNotification) { + args.emplace_back("disable_notification", disableNotification); + } + if (protectContent) { + args.emplace_back("protect_content", protectContent); + } + if (removeCaption) { + args.emplace_back("remove_caption", removeCaption); + } + + return _tgTypeParser.parseJsonAndGetArray(&TgTypeParser::parseJsonAndGetMessageId, sendRequest("copyMessages", args)); +} + Message::Ptr Api::sendPhoto(boost::variant chatId, boost::variant photo, const std::string& caption, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector& captionEntities, - bool allowSendingWithoutReply, - bool protectContent, std::int32_t messageThreadId, + bool protectContent, bool hasSpoiler) const { std::vector args; - args.reserve(12); + args.reserve(11); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -274,11 +330,8 @@ Message::Ptr Api::sendPhoto(boost::variant 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)); @@ -294,16 +347,15 @@ Message::Ptr Api::sendAudio(boost::variant chatId, const std::string& performer, const std::string& title, boost::variant thumbnail, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector& captionEntities, - bool allowSendingWithoutReply, - bool protectContent, - std::int32_t messageThreadId) const { + std::int32_t messageThreadId, + bool protectContent) const { std::vector args; - args.reserve(15); + args.reserve(14); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -348,11 +400,8 @@ Message::Ptr Api::sendAudio(boost::variant 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)); @@ -365,17 +414,16 @@ Message::Ptr Api::sendDocument(boost::variant chatId, boost::variant document, boost::variant thumbnail, const std::string& caption, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector& captionEntities, bool disableContentTypeDetection, - bool allowSendingWithoutReply, - bool protectContent, - std::int32_t messageThreadId) const { + std::int32_t messageThreadId, + bool protectContent) const { std::vector args; - args.reserve(13); + args.reserve(12); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -414,11 +462,8 @@ Message::Ptr Api::sendDocument(boost::variant 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)); @@ -435,17 +480,16 @@ Message::Ptr Api::sendVideo(boost::variant chatId, std::int32_t height, boost::variant thumbnail, const std::string& caption , - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector& captionEntities, - bool allowSendingWithoutReply, - bool protectContent, std::int32_t messageThreadId, + bool protectContent, bool hasSpoiler) const { std::vector args; - args.reserve(17); + args.reserve(16); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -496,11 +540,8 @@ Message::Ptr Api::sendVideo(boost::variant 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)); @@ -516,17 +557,16 @@ Message::Ptr Api::sendAnimation(boost::variant chatId std::int32_t height, boost::variant thumbnail, const std::string& caption, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& parseMode, bool disableNotification, const std::vector& captionEntities, - bool allowSendingWithoutReply, - bool protectContent, std::int32_t messageThreadId, - bool hasSpoiler ) const { + bool protectContent, + bool hasSpoiler) const { std::vector args; - args.reserve(16); + args.reserve(15); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -574,11 +614,8 @@ Message::Ptr Api::sendAnimation(boost::variant 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,16 +628,15 @@ Message::Ptr Api::sendVoice(boost::variant chatId, boost::variant 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& captionEntities, - bool allowSendingWithoutReply, - bool protectContent, - std::int32_t messageThreadId) const { + std::int32_t messageThreadId, + bool protectContent) const { std::vector args; - args.reserve(12); + args.reserve(11); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -630,11 +666,8 @@ Message::Ptr Api::sendVoice(boost::variant 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,17 +678,16 @@ Message::Ptr Api::sendVoice(boost::variant chatId, Message::Ptr Api::sendVideoNote(boost::variant chatId, boost::variant videoNote, - std::int64_t replyToMessageId, + ReplyParameters::Ptr replyParameters, bool disableNotification, std::int32_t duration, std::int32_t length, boost::variant thumbnail, GenericReply::Ptr replyMarkup, - bool allowSendingWithoutReply, - bool protectContent, - std::int32_t messageThreadId) const { + std::int32_t messageThreadId, + bool protectContent) const { std::vector args; - args.reserve(11); + args.reserve(10); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -688,11 +720,8 @@ Message::Ptr Api::sendVideoNote(boost::variant 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,12 +733,11 @@ Message::Ptr Api::sendVideoNote(boost::variant chatId std::vector Api::sendMediaGroup(boost::variant chatId, const std::vector& media, bool disableNotification, - std::int32_t replyToMessageId, - bool allowSendingWithoutReply, - bool protectContent, - std::int32_t messageThreadId) const { + ReplyParameters::Ptr replyParameters, + std::int32_t messageThreadId, + bool protectContent) const { std::vector args; - args.reserve(7); + args.reserve(6); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -722,11 +750,8 @@ std::vector Api::sendMediaGroup(boost::variant(&TgTypeParser::parseJsonAndGetMessage, sendRequest("sendMediaGroup", args)); @@ -736,17 +761,16 @@ Message::Ptr Api::sendLocation(boost::variant 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, - bool protectContent, - std::int32_t messageThreadId) const { + std::int32_t messageThreadId, + bool protectContent) const { std::vector args; - args.reserve(13); + args.reserve(12); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -772,11 +796,8 @@ Message::Ptr Api::sendLocation(boost::variant 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)); @@ -867,15 +888,14 @@ Message::Ptr Api::sendVenue(boost::variant 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, - bool protectContent, - std::int32_t messageThreadId) const { + std::int32_t messageThreadId, + bool protectContent) const { std::vector args; - args.reserve(15); + args.reserve(14); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -903,11 +923,8 @@ Message::Ptr Api::sendVenue(boost::variant 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)); @@ -922,13 +939,12 @@ Message::Ptr Api::sendContact(boost::variant chatId, const std::string& lastName , const std::string& vcard, bool disableNotification, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, - bool allowSendingWithoutReply, - bool protectContent, - std::int32_t messageThreadId) const { + std::int32_t messageThreadId, + bool protectContent) const { std::vector args; - args.reserve(11); + args.reserve(10); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -948,11 +964,8 @@ Message::Ptr Api::sendContact(boost::variant 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)); @@ -965,7 +978,7 @@ Message::Ptr Api::sendPoll(boost::variant chatId, const std::string& question, const std::vector& options, bool disableNotification, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, bool isAnonymous, const std::string& type, @@ -977,11 +990,10 @@ Message::Ptr Api::sendPoll(boost::variant chatId, std::int32_t openPeriod, std::int32_t closeDate, bool isClosed, - bool allowSendingWithoutReply, - bool protectContent, - std::int32_t messageThreadId) const { + std::int32_t messageThreadId, + bool protectContent) const { std::vector args; - args.reserve(19); + args.reserve(18); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -1028,11 +1040,8 @@ Message::Ptr Api::sendPoll(boost::variant 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)); @@ -1043,14 +1052,13 @@ Message::Ptr Api::sendPoll(boost::variant chatId, Message::Ptr Api::sendDice(boost::variant chatId, bool disableNotification, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, const std::string& emoji, - bool allowSendingWithoutReply, - bool protectContent, - std::int32_t messageThreadId) const { + std::int32_t messageThreadId, + bool protectContent) const { std::vector args; - args.reserve(8); + args.reserve(7); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -1065,11 +1073,8 @@ Message::Ptr Api::sendDice(boost::variant 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)); @@ -1078,6 +1083,25 @@ Message::Ptr Api::sendDice(boost::variant chatId, return _tgTypeParser.parseJsonAndGetMessage(sendRequest("sendDice", args)); } +bool Api::setMessageReaction(boost::variant chatId, + std::int32_t messageId, + const std::vector& reaction, + bool isBig) const { + std::vector args; + args.reserve(4); + + args.emplace_back("chat_id", chatId); + args.emplace_back("message_id", messageId); + if (!reaction.empty()) { + args.emplace_back("reaction", _tgTypeParser.parseArray(&TgTypeParser::parseReactionType, reaction)); + } + if (isBig) { + args.emplace_back("is_big", isBig); + } + + return sendRequest("setMessageReaction", args).get("", false); +} + bool Api::sendChatAction(std::int64_t chatId, const std::string& action, std::int32_t messageThreadId) const { @@ -1710,6 +1734,17 @@ bool Api::answerCallbackQuery(const std::string& callbackQueryId, return sendRequest("answerCallbackQuery", args).get("", false); } +UserChatBoosts::Ptr Api::getUserChatBoosts(boost::variant chatId, + std::int32_t userId) const { + std::vector args; + args.reserve(2); + + args.emplace_back("chat_id", chatId); + args.emplace_back("user_id", userId); + + return _tgTypeParser.parseJsonAndGetUserChatBoosts(sendRequest("getUserChatBoosts", args)); +} + bool Api::setMyCommands(const std::vector& commands, BotCommandScope::Ptr scope, const std::string& languageCode) const { @@ -1892,7 +1927,7 @@ 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& entities) const { std::vector args; @@ -1920,8 +1955,8 @@ Message::Ptr Api::editMessageText(const std::string& text, if (!entities.empty()) { args.emplace_back("entities", _tgTypeParser.parseArray(&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)); @@ -2079,17 +2114,32 @@ bool Api::deleteMessage(boost::variant chatId, return sendRequest("deleteMessage", args).get("", false); } +bool Api::deleteMessages(boost::variant chatId, + const std::vector& messageIds) const { + std::vector args; + args.reserve(2); + + args.emplace_back("chat_id", chatId); + if (!messageIds.empty()) { + args.emplace_back("message_ids", _tgTypeParser.parseArray( + [] (const std::int32_t& i)->std::int32_t { + return i; + }, messageIds)); + } + + return sendRequest("deleteMessages", args).get("", false); +} + Message::Ptr Api::sendSticker(boost::variant chatId, boost::variant sticker, - std::int32_t replyToMessageId, + ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, bool disableNotification, - bool allowSendingWithoutReply, - bool protectContent, std::int32_t messageThreadId, + bool protectContent, const std::string& emoji) const { std::vector args; - args.reserve(9); + args.reserve(8); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -2110,11 +2160,8 @@ Message::Ptr Api::sendSticker(boost::variant 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)); @@ -2370,17 +2417,16 @@ Message::Ptr Api::sendInvoice(boost::variant 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& suggestedTipAmounts, const std::string& startParameter, - bool protectContent, - std::int32_t messageThreadId) const { + bool protectContent) const { std::vector args; - args.reserve(28); + args.reserve(27); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -2443,11 +2489,8 @@ Message::Ptr Api::sendInvoice(boost::variant 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)); @@ -2578,14 +2621,13 @@ 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, - bool protectContent, - std::int32_t messageThreadId) const { + std::int32_t messageThreadId, + bool protectContent) const { std::vector args; - args.reserve(8); + args.reserve(7); args.emplace_back("chat_id", chatId); if (messageThreadId != 0) { @@ -2598,11 +2640,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)); -- cgit v1.2.3 From 283cc4ba4670ed5546f007ec1a85b3fab40e6d6a Mon Sep 17 00:00:00 2001 From: llnulldisk <48621230+llnulldisk@users.noreply.github.com> Date: Mon, 22 Apr 2024 20:14:57 +0200 Subject: Update to Bot API 7.2 --- src/Api.cpp | 178 ++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 137 insertions(+), 41 deletions(-) (limited to 'src/Api.cpp') diff --git a/src/Api.cpp b/src/Api.cpp index cdd5ad7..2c4b82a 100644 --- a/src/Api.cpp +++ b/src/Api.cpp @@ -119,10 +119,14 @@ Message::Ptr Api::sendMessage(boost::variant chatId, bool disableNotification, const std::vector& entities, std::int32_t messageThreadId, - bool protectContent) const { + bool protectContent, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(10); + 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); @@ -298,10 +302,14 @@ Message::Ptr Api::sendPhoto(boost::variant chatId, const std::vector& captionEntities, std::int32_t messageThreadId, bool protectContent, - bool hasSpoiler) const { + bool hasSpoiler, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(11); + 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); @@ -353,10 +361,14 @@ Message::Ptr Api::sendAudio(boost::variant chatId, bool disableNotification, const std::vector& captionEntities, std::int32_t messageThreadId, - bool protectContent) const { + bool protectContent, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(14); + 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); @@ -421,10 +433,14 @@ Message::Ptr Api::sendDocument(boost::variant chatId, const std::vector& captionEntities, bool disableContentTypeDetection, std::int32_t messageThreadId, - bool protectContent) const { + bool protectContent, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(12); + 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); @@ -487,10 +503,14 @@ Message::Ptr Api::sendVideo(boost::variant chatId, const std::vector& captionEntities, std::int32_t messageThreadId, bool protectContent, - bool hasSpoiler) const { + bool hasSpoiler, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(16); + 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); @@ -564,10 +584,14 @@ Message::Ptr Api::sendAnimation(boost::variant chatId const std::vector& captionEntities, std::int32_t messageThreadId, bool protectContent, - bool hasSpoiler) const { + bool hasSpoiler, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(15); + 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); @@ -634,10 +658,14 @@ Message::Ptr Api::sendVoice(boost::variant chatId, bool disableNotification, const std::vector& captionEntities, std::int32_t messageThreadId, - bool protectContent) const { + bool protectContent, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(11); + 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); @@ -685,10 +713,14 @@ Message::Ptr Api::sendVideoNote(boost::variant chatId boost::variant thumbnail, GenericReply::Ptr replyMarkup, std::int32_t messageThreadId, - bool protectContent) const { + bool protectContent, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(10); + 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); @@ -735,10 +767,14 @@ std::vector Api::sendMediaGroup(boost::variant args; - args.reserve(6); + 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); @@ -768,10 +804,14 @@ Message::Ptr Api::sendLocation(boost::variant chatId, std::int32_t heading, std::int32_t proximityAlertRadius, std::int32_t messageThreadId, - bool protectContent) const { + bool protectContent, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(12); + 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); @@ -893,10 +933,14 @@ Message::Ptr Api::sendVenue(boost::variant chatId, const std::string& googlePlaceId, const std::string& googlePlaceType, std::int32_t messageThreadId, - bool protectContent) const { + bool protectContent, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(14); + 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); @@ -942,10 +986,14 @@ Message::Ptr Api::sendContact(boost::variant chatId, ReplyParameters::Ptr replyParameters, GenericReply::Ptr replyMarkup, std::int32_t messageThreadId, - bool protectContent) const { + bool protectContent, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(10); + 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); @@ -991,10 +1039,14 @@ Message::Ptr Api::sendPoll(boost::variant chatId, std::int32_t closeDate, bool isClosed, std::int32_t messageThreadId, - bool protectContent) const { + bool protectContent, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(18); + 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); @@ -1056,10 +1108,14 @@ Message::Ptr Api::sendDice(boost::variant chatId, GenericReply::Ptr replyMarkup, const std::string& emoji, std::int32_t messageThreadId, - bool protectContent) const { + bool protectContent, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(7); + 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); @@ -1104,10 +1160,14 @@ bool Api::setMessageReaction(boost::variant chatId, 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 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) { @@ -1745,6 +1805,15 @@ UserChatBoosts::Ptr Api::getUserChatBoosts(boost::variant args; + args.reserve(1); + + args.emplace_back("business_connection_id", businessConnectionId); + + return _tgTypeParser.parseJsonAndGetBusinessConnection(sendRequest("getBusinessConnection", args)); +} + bool Api::setMyCommands(const std::vector& commands, BotCommandScope::Ptr scope, const std::string& languageCode) const { @@ -2137,10 +2206,14 @@ Message::Ptr Api::sendSticker(boost::variant chatId, bool disableNotification, std::int32_t messageThreadId, bool protectContent, - const std::string& emoji) const { + const std::string& emoji, + const std::string& businessConnectionId) const { std::vector 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); @@ -2208,19 +2281,21 @@ bool Api::createNewStickerSet(std::int64_t userId, const std::string& name, const std::string& title, const std::vector& stickers, - const std::string& stickerFormat, - const std::string& stickerType, + Sticker::Type stickerType, bool needsRepainting) const { std::vector args; - args.reserve(7); + args.reserve(6); args.emplace_back("user_id", userId); args.emplace_back("name", name); args.emplace_back("title", title); args.emplace_back("stickers", _tgTypeParser.parseArray(&TgTypeParser::parseInputSticker, stickers)); - args.emplace_back("sticker_format", stickerFormat); - if (!stickerType.empty()) { - args.emplace_back("sticker_type", stickerType); + if (stickerType == Sticker::Type::Regular) { + args.emplace_back("sticker_type", "regular"); + } else if (stickerType == Sticker::Type::Mask) { + args.emplace_back("sticker_type", "mask"); + } else if (stickerType == Sticker::Type::CustomEmoji) { + args.emplace_back("sticker_type", "custom_emoji"); } if (needsRepainting) { args.emplace_back("needs_repainting", needsRepainting); @@ -2262,6 +2337,21 @@ bool Api::deleteStickerFromSet(const std::string& sticker) const { return sendRequest("deleteStickerFromSet", args).get("", false); } +bool Api::replaceStickerInSet(std::int64_t userId, + const std::string& name, + const std::string& oldSticker, + InputSticker::Ptr sticker) const { + std::vector args; + args.reserve(4); + + 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("", false); +} + bool Api::setStickerEmojiList(const std::string& sticker, const std::vector& emojiList) const { std::vector args; @@ -2318,12 +2408,14 @@ bool Api::setStickerSetTitle(const std::string& name, bool Api::setStickerSetThumbnail(const std::string& name, std::int64_t userId, + const std::string& format, boost::variant thumbnail) const { std::vector args; - args.reserve(3); + args.reserve(4); args.emplace_back("name", name); args.emplace_back("user_id", userId); + args.emplace_back("format", format); if (thumbnail.which() == 0) { // InputFile::Ptr if (boost::get(thumbnail) != nullptr) { auto file = boost::get(thumbnail); @@ -2625,10 +2717,14 @@ Message::Ptr Api::sendGame(std::int64_t chatId, InlineKeyboardMarkup::Ptr replyMarkup, bool disableNotification, std::int32_t messageThreadId, - bool protectContent) const { + bool protectContent, + const std::string& businessConnectionId) const { std::vector args; - args.reserve(7); + 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); -- cgit v1.2.3