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 ++++++++++++++++++++++------- src/TgTypeParser.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 104 insertions(+), 12 deletions(-) (limited to 'src') 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); diff --git a/src/TgTypeParser.cpp b/src/TgTypeParser.cpp index efd1c08..76a4add 100644 --- a/src/TgTypeParser.cpp +++ b/src/TgTypeParser.cpp @@ -1109,6 +1109,7 @@ 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()); + result->webAppName = data.get("web_app_name", ""); return result; } @@ -1118,7 +1119,8 @@ std::string TgTypeParser::parseWriteAccessAllowed(const WriteAccessAllowed::Ptr& } std::string result; result += '{'; - //removeLastComma(result); + appendToJson(result, "web_app_name", object->webAppName); + removeLastComma(result); result += '}'; return result; } @@ -1456,10 +1458,12 @@ InlineKeyboardButton::Ptr TgTypeParser::parseJsonAndGetInlineKeyboardButton(cons result->loginUrl = tryParseJson(&TgTypeParser::parseJsonAndGetLoginUrl, data, "login_url"); result->switchInlineQuery = data.get("switch_inline_query", ""); result->switchInlineQueryCurrentChat = data.get("switch_inline_query_current_chat", ""); + result->switchInlineQueryChosenChat = tryParseJson(&TgTypeParser::parseJsonAndGetSwitchInlineQueryChosenChat, data, "switch_inline_query_chosen_chat"); result->callbackGame = tryParseJson(&TgTypeParser::parseJsonAndGetCallbackGame, data, "callback_game"); result->pay = data.get("pay", false); return result; } + std::string TgTypeParser::parseInlineKeyboardButton(const InlineKeyboardButton::Ptr& object) const { if (!object) { return ""; @@ -1473,6 +1477,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,6 +1509,32 @@ 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()); + result->query = data.get("query", ""); + result->allowUserChats = data.get("allow_user_chats", false); + result->allowBotChats = data.get("allow_bot_chats", false); + result->allowGroupChats = data.get("allow_group_chats", false); + result->allowChannelChats = data.get("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()); result->id = data.get("id"); @@ -1880,10 +1911,11 @@ ChatMemberUpdated::Ptr TgTypeParser::parseJsonAndGetChatMemberUpdated(const boos auto result(std::make_shared()); result->chat = tryParseJson(&TgTypeParser::parseJsonAndGetChat, data, "chat"); result->from = tryParseJson(&TgTypeParser::parseJsonAndGetUser, data, "from"); - result->date = data.get("date", 0); + result->date = data.get("date", 0); result->oldChatMember = tryParseJson(&TgTypeParser::parseJsonAndGetChatMember, data, "old_chat_member"); result->newChatMember = tryParseJson(&TgTypeParser::parseJsonAndGetChatMember, data, "new_chat_member"); result->inviteLink = tryParseJson(&TgTypeParser::parseJsonAndGetChatInviteLink, data, "invite_link"); + result->viaChatFolderInviteLink = data.get("via_chat_folder_invite_link", false); return result; } @@ -1899,6 +1931,7 @@ std::string TgTypeParser::parseChatMemberUpdated(const ChatMemberUpdated::Ptr& o 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; @@ -2220,6 +2253,21 @@ std::string TgTypeParser::parseBotCommandScopeChatMember(const BotCommandScopeCh return result; } +BotName::Ptr TgTypeParser::parseJsonAndGetBotName(const boost::property_tree::ptree& data) const { + auto result(std::make_shared()); + result->name = data.get("name", ""); + return result; +} + +std::string TgTypeParser::parseBotName(const BotName::Ptr& object) const { + 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()); result->description = data.get("description", ""); @@ -2734,6 +2782,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()); + result->text = data.get("text", ""); + result->webApp = tryParseJson(&TgTypeParser::parseJsonAndGetWebAppInfo, data, "web_app"); + result->startParameter = data.get("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("type", ""); InlineQueryResult::Ptr result; -- cgit v1.2.3