diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 2c82c4857..0732cff2c 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7408,6 +7408,13 @@ addMessageReaction chat_id:int53 message_id:int53 reaction_type:ReactionType is_ //@reaction_type Type of the reaction to remove removeMessageReaction chat_id:int53 message_id:int53 reaction_type:ReactionType = Ok; +//@description Sets reactions on a message; for bots only +//@chat_id Identifier of the chat to which the message belongs +//@message_id Identifier of the message +//@reaction_types Types of the reaction to set +//@is_big Pass true if the reactions are added with a big animation +setMessageReactions chat_id:int53 message_id:int53 reaction_types:vector is_big:Bool = Ok; + //@description Returns reactions added for a message, along with their sender //@chat_id Identifier of the chat to which the message belongs //@message_id Identifier of the message diff --git a/td/telegram/MessageReaction.cpp b/td/telegram/MessageReaction.cpp index 865d02b94..dcfc340d1 100644 --- a/td/telegram/MessageReaction.cpp +++ b/td/telegram/MessageReaction.cpp @@ -876,6 +876,19 @@ void send_message_reaction(Td *td, MessageFullId message_full_id, vectorsend(message_full_id, std::move(reaction_types), is_big, add_to_recent); } +void set_message_reactions(Td *td, MessageFullId message_full_id, vector reaction_types, bool is_big, + Promise &&promise) { + if (!td->messages_manager_->have_message_force(message_full_id, "set_message_reactions")) { + return promise.set_error(Status::Error(400, "Message not found")); + } + for (const auto &reaction_type : reaction_types) { + if (reaction_type.is_empty()) { + return promise.set_error(Status::Error(400, "Invalid reaction type specified")); + } + } + send_message_reaction(td, message_full_id, std::move(reaction_types), is_big, false, std::move(promise)); +} + void get_message_added_reactions(Td *td, MessageFullId message_full_id, ReactionType reaction_type, string offset, int32 limit, Promise> &&promise) { if (!td->messages_manager_->have_message_force(message_full_id, "get_message_added_reactions")) { diff --git a/td/telegram/MessageReaction.h b/td/telegram/MessageReaction.h index 67e0c5a2f..9562ea47e 100644 --- a/td/telegram/MessageReaction.h +++ b/td/telegram/MessageReaction.h @@ -216,6 +216,9 @@ void reload_message_reactions(Td *td, DialogId dialog_id, vector &&me void send_message_reaction(Td *td, MessageFullId message_full_id, vector reaction_types, bool is_big, bool add_to_recent, Promise &&promise); +void set_message_reactions(Td *td, MessageFullId message_full_id, vector reaction_types, bool is_big, + Promise &&promise); + void get_message_added_reactions(Td *td, MessageFullId message_full_id, ReactionType reaction_type, string offset, int32 limit, Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 8ecc6c406..cd4733167 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5489,6 +5489,13 @@ void Td::on_request(uint64 id, const td_api::removeMessageReaction &request) { ReactionType(request.reaction_type_), std::move(promise)); } +void Td::on_request(uint64 id, const td_api::setMessageReactions &request) { + CHECK_IS_BOT(); + CREATE_OK_REQUEST_PROMISE(); + set_message_reactions(this, {DialogId(request.chat_id_), MessageId(request.message_id_)}, + ReactionType::get_reaction_types(request.reaction_types_), request.is_big_, std::move(promise)); +} + void Td::on_request(uint64 id, td_api::getMessageAddedReactions &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.offset_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 8d2c6325d..8f7ab776d 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -747,6 +747,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::removeMessageReaction &request); + void on_request(uint64 id, const td_api::setMessageReactions &request); + void on_request(uint64 id, td_api::getMessageAddedReactions &request); void on_request(uint64 id, const td_api::setDefaultReactionType &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 5809c5009..1186d2b74 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2778,6 +2778,14 @@ class CliClient final : public Actor { string reaction; get_args(args, chat_id, message_id, reaction); send_request(td_api::make_object(chat_id, message_id, as_reaction_type(reaction))); + } else if (op == "reactbot" || op == "reactbotbig") { + ChatId chat_id; + MessageId message_id; + string reactions; + get_args(args, chat_id, message_id, reactions); + auto reaction_types = transform(autosplit_str(reactions), as_reaction_type); + send_request(td_api::make_object(chat_id, message_id, std::move(reaction_types), + op == "reactbotbig")); } else if (op == "gmars") { ChatId chat_id; MessageId message_id;