diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index dc185bb..47d0d11 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -300,6 +300,7 @@ bool Client::init_methods() { methods_.emplace("setcustomemojistickersetthumbnail", &Client::process_set_custom_emoji_sticker_set_thumbnail_query); 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("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); @@ -6632,6 +6633,10 @@ td::Result> Client::get_mask_position(c } td::Result Client::get_sticker_emojis(JsonValue &&value) { + if (value.type() != JsonValue::Type::Array) { + return Status::Error(400, "expected an Array of string"); + } + td::string result; auto emoji_count = value.get_array().size(); if (emoji_count == 0) { @@ -6652,6 +6657,21 @@ td::Result Client::get_sticker_emojis(JsonValue &&value) { return std::move(result); } +td::Result Client::get_sticker_emojis(td::MutableSlice emoji_list) { + LOG(INFO) << "Parsing JSON object: " << emoji_list; + auto r_value = json_decode(emoji_list); + if (r_value.is_error()) { + LOG(INFO) << "Can't parse JSON object: " << r_value.error(); + return Status::Error(400, "Can't parse emoji list JSON array"); + } + + auto r_emojis = get_sticker_emojis(r_value.move_as_ok()); + if (r_emojis.is_error()) { + return Status::Error(400, PSLICE() << "Can't parse emoji list: " << r_emojis.error().message()); + } + return r_emojis.move_as_ok(); +} + td::Result> Client::get_sticker_format(Slice sticker_format) { if (sticker_format == "static") { return make_object(); @@ -9272,6 +9292,15 @@ td::Status Client::process_delete_sticker_from_set_query(PromisedQueryPtr &query return Status::OK(); } +td::Status Client::process_set_sticker_emoji_list_query(PromisedQueryPtr &query) { + TRY_RESULT(input_file, get_sticker_input_file(query.get())); + TRY_RESULT(emojis, get_sticker_emojis(query->arg("emoji_list"))); + + send_request(make_object(std::move(input_file), emojis), + 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 e9b24eb..c3eadd7 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -405,6 +405,8 @@ class Client final : public WebhookActor::Callback { static td::Result get_sticker_emojis(td::JsonValue &&value); + static td::Result get_sticker_emojis(td::MutableSlice emoji_list); + static td::Result> get_sticker_format(Slice sticker_format); td::Result> get_input_sticker(const Query *query) const; @@ -586,6 +588,7 @@ class Client final : public WebhookActor::Callback { Status process_set_custom_emoji_sticker_set_thumbnail_query(PromisedQueryPtr &query); 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_passport_data_errors_query(PromisedQueryPtr &query); Status process_send_custom_request_query(PromisedQueryPtr &query); Status process_answer_custom_query_query(PromisedQueryPtr &query);