Add td_api::editBusinessMessageText.
This commit is contained in:
parent
3f99e0a69b
commit
c1c9f40a20
@ -8440,6 +8440,14 @@ sendBusinessMessage business_connection_id:string chat_id:int53 reply_to:InputMe
|
||||
//@input_message_contents Contents of messages to be sent. At most 10 messages can be added to an album. All messages must have the same value of show_caption_above_media
|
||||
sendBusinessMessageAlbum business_connection_id:string chat_id:int53 reply_to:InputMessageReplyTo disable_notification:Bool protect_content:Bool effect_id:int64 input_message_contents:vector<InputMessageContent> = BusinessMessages;
|
||||
|
||||
//@description Edits the text of a text or game message sent on behalf of a business account; for bots only
|
||||
//@business_connection_id Unique identifier of business connection on behalf of which the message was sent
|
||||
//@chat_id The chat the message belongs to
|
||||
//@message_id Identifier of the message
|
||||
//@reply_markup The new message reply markup; pass null if none
|
||||
//@input_message_content New text content of the message. Must be of type inputMessageText
|
||||
editBusinessMessageText business_connection_id:string chat_id:int53 message_id:int53 reply_markup:ReplyMarkup input_message_content:InputMessageContent = BusinessMessage;
|
||||
|
||||
|
||||
//@description Checks validness of a name for a quick reply shortcut. Can be called synchronously @name The name of the shortcut; 1-32 characters
|
||||
checkQuickReplyShortcutName name:string = Ok;
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "td/telegram/files/FileManager.h"
|
||||
#include "td/telegram/files/FileType.h"
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/InputMessageText.h"
|
||||
#include "td/telegram/MessageContent.h"
|
||||
#include "td/telegram/MessageContentType.h"
|
||||
#include "td/telegram/MessageCopyOptions.h"
|
||||
@ -404,6 +405,71 @@ class BusinessConnectionManager::UploadBusinessMediaQuery final : public Td::Res
|
||||
}
|
||||
};
|
||||
|
||||
class BusinessConnectionManager::EditBusinessMessageQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::businessMessage>> promise_;
|
||||
|
||||
public:
|
||||
explicit EditBusinessMessageQuery(Promise<td_api::object_ptr<td_api::businessMessage>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(int32 flags, BusinessConnectionId business_connection_id, DialogId dialog_id, MessageId message_id,
|
||||
const string &text, vector<telegram_api::object_ptr<telegram_api::MessageEntity>> &&entities,
|
||||
telegram_api::object_ptr<telegram_api::InputMedia> &&input_media, bool invert_media,
|
||||
telegram_api::object_ptr<telegram_api::ReplyMarkup> &&reply_markup) {
|
||||
if (input_media != nullptr && false) {
|
||||
return on_error(Status::Error(400, "FILE_PART_1_MISSING"));
|
||||
}
|
||||
|
||||
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Know);
|
||||
CHECK(input_peer != nullptr);
|
||||
|
||||
if (reply_markup != nullptr) {
|
||||
flags |= telegram_api::messages_editMessage::REPLY_MARKUP_MASK;
|
||||
}
|
||||
if (!entities.empty()) {
|
||||
flags |= telegram_api::messages_editMessage::ENTITIES_MASK;
|
||||
}
|
||||
if (!text.empty()) {
|
||||
flags |= telegram_api::messages_editMessage::MESSAGE_MASK;
|
||||
}
|
||||
if (input_media != nullptr) {
|
||||
flags |= telegram_api::messages_editMessage::MEDIA_MASK;
|
||||
}
|
||||
if (invert_media) {
|
||||
flags |= telegram_api::messages_editMessage::INVERT_MEDIA_MASK;
|
||||
}
|
||||
|
||||
int32 server_message_id = message_id.get_server_message_id().get();
|
||||
send_query(G()->net_query_creator().create_with_prefix(
|
||||
business_connection_id.get_invoke_prefix(),
|
||||
telegram_api::messages_editMessage(flags, false /*ignored*/, false /*ignored*/, std::move(input_peer),
|
||||
server_message_id, text, std::move(input_media), std::move(reply_markup),
|
||||
std::move(entities), 0, 0),
|
||||
td_->business_connection_manager_->get_business_connection_dc_id(business_connection_id), {{dialog_id}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_editMessage>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto ptr = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for EditBusinessMessageQuery: " << to_string(ptr);
|
||||
td_->business_connection_manager_->process_sent_business_message(std::move(ptr), std::move(promise_));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
if (status.code() != 403 && !(status.code() == 500 && G()->close_flag())) {
|
||||
LOG(WARNING) << "Failed to edit business message with the error " << status.message();
|
||||
} else {
|
||||
LOG(INFO) << "Receive error for EditBusinessMessageQuery: " << status;
|
||||
}
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class BusinessConnectionManager::UploadMediaCallback final : public FileManager::UploadCallback {
|
||||
public:
|
||||
void on_upload_ok(FileId file_id, telegram_api::object_ptr<telegram_api::InputFile> input_file) final {
|
||||
@ -458,6 +524,7 @@ void BusinessConnectionManager::tear_down() {
|
||||
|
||||
Status BusinessConnectionManager::check_business_connection(const BusinessConnectionId &connection_id,
|
||||
DialogId dialog_id) const {
|
||||
CHECK(td_->auth_manager_->is_bot());
|
||||
auto connection = business_connections_.get_pointer(connection_id);
|
||||
if (connection == nullptr) {
|
||||
return Status::Error(400, "Business connection not found");
|
||||
@ -472,6 +539,16 @@ Status BusinessConnectionManager::check_business_connection(const BusinessConnec
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
Status BusinessConnectionManager::check_business_message_id(MessageId message_id) const {
|
||||
if (!message_id.is_valid()) {
|
||||
return Status::Error(400, "Invalid message identifier specified");
|
||||
}
|
||||
if (!message_id.is_server()) {
|
||||
return Status::Error(400, "Wrong message identifier specified");
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
DcId BusinessConnectionManager::get_business_connection_dc_id(const BusinessConnectionId &connection_id) const {
|
||||
if (connection_id.is_empty()) {
|
||||
return DcId::main();
|
||||
@ -1073,6 +1150,41 @@ void BusinessConnectionManager::process_sent_business_message_album(
|
||||
promise.set_value(std::move(messages));
|
||||
}
|
||||
|
||||
void BusinessConnectionManager::edit_business_message_text(
|
||||
BusinessConnectionId business_connection_id, DialogId dialog_id, MessageId message_id,
|
||||
td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup,
|
||||
td_api::object_ptr<td_api::InputMessageContent> &&input_message_content,
|
||||
Promise<td_api::object_ptr<td_api::businessMessage>> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, check_business_connection(business_connection_id, dialog_id));
|
||||
TRY_STATUS_PROMISE(promise, check_business_message_id(message_id));
|
||||
|
||||
if (input_message_content == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Can't edit message without new content"));
|
||||
}
|
||||
int32 new_message_content_type = input_message_content->get_id();
|
||||
if (new_message_content_type != td_api::inputMessageText::ID) {
|
||||
return promise.set_error(Status::Error(400, "Input message content type must be InputMessageText"));
|
||||
}
|
||||
|
||||
TRY_RESULT_PROMISE(
|
||||
promise, input_message_text,
|
||||
process_input_message_text(td_, DialogId(), std::move(input_message_content), td_->auth_manager_->is_bot()));
|
||||
TRY_RESULT_PROMISE(promise, new_reply_markup,
|
||||
get_reply_markup(std::move(reply_markup), td_->auth_manager_->is_bot(), true, false, true));
|
||||
|
||||
auto input_reply_markup = get_input_reply_markup(td_->user_manager_.get(), new_reply_markup);
|
||||
int32 flags = 0;
|
||||
if (input_message_text.disable_web_page_preview) {
|
||||
flags |= telegram_api::messages_editMessage::NO_WEBPAGE_MASK;
|
||||
}
|
||||
td_->create_handler<EditBusinessMessageQuery>(std::move(promise))
|
||||
->send(flags, business_connection_id, dialog_id, message_id, input_message_text.text.text,
|
||||
get_input_message_entities(td_->user_manager_.get(), input_message_text.text.entities,
|
||||
"edit_business_message_text"),
|
||||
input_message_text.get_input_media_web_page(), input_message_text.show_above_text,
|
||||
std::move(input_reply_markup));
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::updateBusinessConnection> BusinessConnectionManager::get_update_business_connection(
|
||||
const BusinessConnection *connection) const {
|
||||
return td_api::make_object<td_api::updateBusinessConnection>(connection->get_business_connection_object(td_));
|
||||
|
@ -73,6 +73,11 @@ class BusinessConnectionManager final : public Actor {
|
||||
vector<td_api::object_ptr<td_api::InputMessageContent>> &&input_message_contents,
|
||||
Promise<td_api::object_ptr<td_api::businessMessages>> &&promise);
|
||||
|
||||
void edit_business_message_text(BusinessConnectionId business_connection_id, DialogId dialog_id, MessageId message_id,
|
||||
td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup,
|
||||
td_api::object_ptr<td_api::InputMessageContent> &&input_message_content,
|
||||
Promise<td_api::object_ptr<td_api::businessMessage>> &&promise);
|
||||
|
||||
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
||||
|
||||
private:
|
||||
@ -84,6 +89,7 @@ class BusinessConnectionManager final : public Actor {
|
||||
class UploadBusinessMediaQuery;
|
||||
class UploadMediaCallback;
|
||||
class UploadThumbnailCallback;
|
||||
class EditBusinessMessageQuery;
|
||||
|
||||
struct UploadMediaResult {
|
||||
unique_ptr<PendingMessage> message_;
|
||||
@ -104,6 +110,8 @@ class BusinessConnectionManager final : public Actor {
|
||||
|
||||
void tear_down() final;
|
||||
|
||||
Status check_business_message_id(MessageId message_id) const;
|
||||
|
||||
void on_get_business_connection(const BusinessConnectionId &connection_id,
|
||||
Result<telegram_api::object_ptr<telegram_api::Updates>> r_updates);
|
||||
|
||||
|
@ -5805,6 +5805,15 @@ void Td::on_request(uint64 id, td_api::sendBusinessMessageAlbum &request) {
|
||||
MessageEffectId(request.effect_id_), std::move(request.input_message_contents_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::editBusinessMessageText &request) {
|
||||
CHECK_IS_BOT();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
business_connection_manager_->edit_business_message_text(
|
||||
BusinessConnectionId(std::move(request.business_connection_id_)), DialogId(request.chat_id_),
|
||||
MessageId(request.message_id_), std::move(request.reply_markup_), std::move(request.input_message_content_),
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::loadQuickReplyShortcuts &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
|
@ -916,6 +916,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, td_api::sendBusinessMessageAlbum &request);
|
||||
|
||||
void on_request(uint64 id, td_api::editBusinessMessageText &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::loadQuickReplyShortcuts &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::setQuickReplyShortcutName &request);
|
||||
|
@ -5033,9 +5033,17 @@ class CliClient final : public Actor {
|
||||
MessageId message_id;
|
||||
string message;
|
||||
get_args(args, chat_id, message_id, message);
|
||||
send_request(td_api::make_object<td_api::editMessageText>(
|
||||
chat_id, message_id, nullptr,
|
||||
td_api::make_object<td_api::inputMessageText>(as_formatted_text(message), get_link_preview_options(), true)));
|
||||
if (!business_connection_id_.empty()) {
|
||||
send_request(td_api::make_object<td_api::editBusinessMessageText>(
|
||||
business_connection_id_, chat_id, message_id, nullptr,
|
||||
td_api::make_object<td_api::inputMessageText>(as_formatted_text(message), get_link_preview_options(),
|
||||
true)));
|
||||
} else {
|
||||
send_request(td_api::make_object<td_api::editMessageText>(
|
||||
chat_id, message_id, nullptr,
|
||||
td_api::make_object<td_api::inputMessageText>(as_formatted_text(message), get_link_preview_options(),
|
||||
true)));
|
||||
}
|
||||
} else if (op == "eqrm") {
|
||||
ShortcutId shortcut_id;
|
||||
MessageId message_id;
|
||||
|
Loading…
Reference in New Issue
Block a user