From 116e7aab247f5b3cd46f048aae1a07865f443993 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 17:54:59 +0300 Subject: [PATCH] Add setStickerKeywords. --- telegram-bot-api/Client.cpp | 28 ++++++++++++++++++++++++++++ telegram-bot-api/Client.h | 1 + 2 files changed, 29 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 47d0d11..42e1a72 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -301,6 +301,7 @@ bool Client::init_methods() { methods_.emplace("setstickerpositioninset", &Client::process_set_sticker_position_in_set_query); methods_.emplace("deletestickerfromset", &Client::process_delete_sticker_from_set_query); methods_.emplace("setstickeremojilist", &Client::process_set_sticker_emoji_list_query); + methods_.emplace("setstickerkeywords", &Client::process_set_sticker_keywords_query); methods_.emplace("setpassportdataerrors", &Client::process_set_passport_data_errors_query); methods_.emplace("sendcustomrequest", &Client::process_send_custom_request_query); methods_.emplace("answercustomquery", &Client::process_answer_custom_query_query); @@ -9301,6 +9302,33 @@ td::Status Client::process_set_sticker_emoji_list_query(PromisedQueryPtr &query) return Status::OK(); } +td::Status Client::process_set_sticker_keywords_query(PromisedQueryPtr &query) { + TRY_RESULT(input_file, get_sticker_input_file(query.get())); + td::vector input_keywords; + if (query->has_arg("keywords")) { + auto r_value = json_decode(query->arg("keywords")); + if (r_value.is_error()) { + LOG(INFO) << "Can't parse JSON object: " << r_value.error(); + return Status::Error(400, "Can't parse keywords JSON object"); + } + auto value = r_value.move_as_ok(); + + if (value.type() != JsonValue::Type::Array) { + return Status::Error(400, "Field \"keywords\" must be an Array"); + } + for (auto &keyword : value.get_array()) { + if (keyword.type() != JsonValue::Type::String) { + return Status::Error(400, "keyword must be a string"); + } + input_keywords.push_back(keyword.get_string().str()); + } + } + + send_request(make_object(std::move(input_file), std::move(input_keywords)), + td::make_unique(std::move(query))); + return Status::OK(); +} + td::Status Client::process_set_passport_data_errors_query(PromisedQueryPtr &query) { TRY_RESULT(user_id, get_user_id(query.get())); TRY_RESULT(passport_element_errors, get_passport_element_errors(query.get())); diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index c3eadd7..b623bfb 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -589,6 +589,7 @@ class Client final : public WebhookActor::Callback { Status process_set_sticker_position_in_set_query(PromisedQueryPtr &query); Status process_delete_sticker_from_set_query(PromisedQueryPtr &query); Status process_set_sticker_emoji_list_query(PromisedQueryPtr &query); + Status process_set_sticker_keywords_query(PromisedQueryPtr &query); Status process_set_passport_data_errors_query(PromisedQueryPtr &query); Status process_send_custom_request_query(PromisedQueryPtr &query); Status process_answer_custom_query_query(PromisedQueryPtr &query);