summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorllnulldisk <48621230+llnulldisk@users.noreply.github.com>2024-04-15 01:24:12 +0200
committerllnulldisk <48621230+llnulldisk@users.noreply.github.com>2024-04-15 01:24:12 +0200
commitfbeb025e21fad2fa1fb6cd5ae186eabf9a349091 (patch)
tree032c992390707b7f68c0e5259c9a23d74ec8553f /src
parent38258eb91f752222e1e64f0499a408643a107149 (diff)
Update to Bot API 6.7
Diffstat (limited to 'src')
-rw-r--r--src/Api.cpp42
-rw-r--r--src/TgTypeParser.cpp74
2 files changed, 104 insertions, 12 deletions
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<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;
@@ -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<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);
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<WriteAccessAllowed>());
+ result->webAppName = data.get<std::string>("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<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 +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<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");
@@ -1880,10 +1911,11 @@ ChatMemberUpdated::Ptr TgTypeParser::parseJsonAndGetChatMemberUpdated(const boos
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->date = data.get<std::uint64_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;
}
@@ -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<BotName>());
+ result->name = data.get<std::string>("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<BotDescription>());
result->description = data.get<std::string>("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<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;