From 7ee51f8c6de1038b5d6c53a698dd94ebbd697090 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 11 Jun 2024 22:27:25 +0300 Subject: [PATCH] Support editMessageText for business messages. --- telegram-bot-api/Client.cpp | 45 +++++++++++++++++++++++++++---------- telegram-bot-api/Client.h | 2 +- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index fd1a290..bd94386 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -4129,9 +4129,9 @@ class Client::TdOnSendMessageCallback final : public TdQueryCallback { PromisedQueryPtr query_; }; -class Client::TdOnSendBusinessMessageCallback final : public TdQueryCallback { +class Client::TdOnReturnBusinessMessageCallback final : public TdQueryCallback { public: - TdOnSendBusinessMessageCallback(Client *client, td::string business_connection_id, PromisedQueryPtr query) + TdOnReturnBusinessMessageCallback(Client *client, td::string business_connection_id, PromisedQueryPtr query) : client_(client), business_connection_id_(std::move(business_connection_id)), query_(std::move(query)) { } @@ -4143,7 +4143,7 @@ class Client::TdOnSendBusinessMessageCallback final : public TdQueryCallback { CHECK(result->get_id() == td_api::businessMessage::ID); auto message = client_->create_business_message(std::move(business_connection_id_), move_object_as(result)); - answer_query(JsonMessage(message.get(), true, "sent business message", client_), std::move(query_)); + answer_query(JsonMessage(message.get(), true, "business message", client_), std::move(query_)); } private: @@ -10269,6 +10269,7 @@ td::Status Client::process_set_message_reaction_query(PromisedQueryPtr &query) { td::Status Client::process_edit_message_text_query(PromisedQueryPtr &query) { TRY_RESULT(input_message_text, get_input_message_text(query.get())); + auto business_connection_id = query->arg("business_connection_id"); auto chat_id = query->arg("chat_id"); auto message_id = get_message_id(query.get()); TRY_RESULT(reply_markup, get_reply_markup(query.get(), bot_user_ids_)); @@ -10286,10 +10287,30 @@ td::Status Client::process_edit_message_text_query(PromisedQueryPtr &query) { } else { resolve_reply_markup_bot_usernames( std::move(reply_markup), std::move(query), - [this, chat_id = chat_id.str(), message_id, input_message_text = std::move(input_message_text)]( - object_ptr reply_markup, PromisedQueryPtr query) mutable { + [this, business_connection_id = business_connection_id.str(), chat_id_str = chat_id.str(), message_id, + input_message_text = std::move(input_message_text)](object_ptr reply_markup, + PromisedQueryPtr query) mutable { + if (!business_connection_id.empty()) { + auto r_chat_id = get_business_connection_chat_id(chat_id_str); + if (r_chat_id.is_error()) { + return fail_query_with_error(std::move(query), 400, r_chat_id.error().message()); + } + auto chat_id = r_chat_id.move_as_ok(); + return check_business_connection( + business_connection_id, std::move(query), + [this, business_connection_id, chat_id, message_id, input_message_text = std::move(input_message_text), + reply_markup = std::move(reply_markup)](const BusinessConnection *business_connection, + PromisedQueryPtr query) mutable { + send_request(make_object(business_connection_id, chat_id, message_id, + std::move(reply_markup), + std::move(input_message_text)), + td::make_unique(this, business_connection_id, + std::move(query))); + }); + } + check_message( - chat_id, message_id, false, AccessRights::Edit, "message to edit", std::move(query), + chat_id_str, message_id, false, AccessRights::Edit, "message to edit", std::move(query), [this, input_message_text = std::move(input_message_text), reply_markup = std::move(reply_markup)]( int64 chat_id, int64 message_id, PromisedQueryPtr query) mutable { send_request(make_object(chat_id, message_id, std::move(reply_markup), @@ -12051,12 +12072,12 @@ void Client::do_send_message(object_ptr input_messa effect_id, reply_markup = std::move(reply_markup), input_message_content = std::move(input_message_content)](const BusinessConnection *business_connection, PromisedQueryPtr query) mutable { - send_request( - make_object(business_connection->id_, chat_id, - get_input_message_reply_to(std::move(reply_parameters)), - disable_notification, protect_content, effect_id, - std::move(reply_markup), std::move(input_message_content)), - td::make_unique(this, business_connection->id_, std::move(query))); + send_request(make_object( + business_connection->id_, chat_id, + get_input_message_reply_to(std::move(reply_parameters)), disable_notification, + protect_content, effect_id, std::move(reply_markup), std::move(input_message_content)), + td::make_unique(this, business_connection->id_, + std::move(query))); }); } diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index d264203..4a47f77 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -206,7 +206,7 @@ class Client final : public WebhookActor::Callback { class TdOnInitCallback; class TdOnGetUserProfilePhotosCallback; class TdOnSendMessageCallback; - class TdOnSendBusinessMessageCallback; + class TdOnReturnBusinessMessageCallback; class TdOnSendMessageAlbumCallback; class TdOnSendBusinessMessageAlbumCallback; class TdOnForwardMessagesCallback;