Add td_api::stopBusinessPoll.

This commit is contained in:
levlam 2024-06-11 15:05:06 +03:00
parent 8ea591c338
commit 8ca99fb186
7 changed files with 95 additions and 15 deletions

View File

@ -8484,6 +8484,13 @@ editBusinessMessageCaption business_connection_id:string chat_id:int53 message_i
//@reply_markup The new message reply markup; pass null if none
editBusinessMessageReplyMarkup business_connection_id:string chat_id:int53 message_id:int53 reply_markup:ReplyMarkup = BusinessMessage;
//@description Stops a poll sent on behalf of a business account; for bots only
//@business_connection_id Unique identifier of business connection on behalf of which the message with the poll was sent
//@chat_id The chat the message belongs to
//@message_id Identifier of the message containing the poll
//@reply_markup The new message reply markup; pass null if none
stopBusinessPoll business_connection_id:string chat_id:int53 message_id:int53 reply_markup:ReplyMarkup = 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;

View File

@ -419,10 +419,6 @@ class BusinessConnectionManager::EditBusinessMessageQuery final : public Td::Res
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);
@ -472,6 +468,56 @@ class BusinessConnectionManager::EditBusinessMessageQuery final : public Td::Res
}
};
class BusinessConnectionManager::StopBusinessPollQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::businessMessage>> promise_;
public:
explicit StopBusinessPollQuery(Promise<td_api::object_ptr<td_api::businessMessage>> &&promise)
: promise_(std::move(promise)) {
}
void send(BusinessConnectionId business_connection_id, DialogId dialog_id, MessageId message_id,
unique_ptr<ReplyMarkup> &&reply_markup) {
auto input_peer = td_->dialog_manager_->get_input_peer(dialog_id, AccessRights::Know);
CHECK(input_peer != nullptr);
int32 flags = telegram_api::messages_editMessage::MEDIA_MASK;
auto input_reply_markup = get_input_reply_markup(td_->user_manager_.get(), reply_markup);
if (input_reply_markup != nullptr) {
flags |= telegram_api::messages_editMessage::REPLY_MARKUP_MASK;
}
auto poll = telegram_api::make_object<telegram_api::poll>(
0, telegram_api::poll::CLOSED_MASK, false /*ignored*/, false /*ignored*/, false /*ignored*/, false /*ignored*/,
telegram_api::make_object<telegram_api::textWithEntities>(string(), Auto()), Auto(), 0, 0);
auto input_media = telegram_api::make_object<telegram_api::inputMediaPoll>(0, std::move(poll),
vector<BufferSlice>(), string(), Auto());
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, string(), std::move(input_media),
std::move(input_reply_markup),
vector<telegram_api::object_ptr<telegram_api::MessageEntity>>(), 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 StopBusinessPollQuery: " << to_string(ptr);
td_->business_connection_manager_->process_sent_business_message(std::move(ptr), std::move(promise_));
}
void on_error(Status status) final {
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 {
@ -1330,6 +1376,18 @@ void BusinessConnectionManager::edit_business_message_reply_markup(
get_input_reply_markup(td_->user_manager_.get(), new_reply_markup));
}
void BusinessConnectionManager::stop_poll(BusinessConnectionId business_connection_id, DialogId dialog_id,
MessageId message_id, td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup,
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));
TRY_RESULT_PROMISE(promise, new_reply_markup,
get_reply_markup(std::move(reply_markup), td_->auth_manager_->is_bot(), true, false, true));
td_->create_handler<StopBusinessPollQuery>(std::move(promise))
->send(business_connection_id, dialog_id, message_id, std::move(new_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_));

View File

@ -99,6 +99,10 @@ class BusinessConnectionManager final : public Actor {
MessageId message_id, td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup,
Promise<td_api::object_ptr<td_api::businessMessage>> &&promise);
void stop_poll(BusinessConnectionId business_connection_id, DialogId dialog_id, MessageId message_id,
td_api::object_ptr<td_api::ReplyMarkup> &&reply_markup,
Promise<td_api::object_ptr<td_api::businessMessage>> &&promise);
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
private:
@ -111,6 +115,7 @@ class BusinessConnectionManager final : public Actor {
class UploadMediaCallback;
class UploadThumbnailCallback;
class EditBusinessMessageQuery;
class StopBusinessPollQuery;
struct UploadMediaResult {
unique_ptr<PendingMessage> message_;

View File

@ -38110,8 +38110,6 @@ void MessagesManager::stop_poll(MessageFullId message_full_id, td_api::object_pt
TRY_RESULT_PROMISE(promise, new_reply_markup,
get_reply_markup(std::move(reply_markup), td_->auth_manager_->is_bot(), true, false,
has_message_sender_user_id(message_full_id.get_dialog_id(), m)));
stop_message_content_poll(td_, m->content.get(), message_full_id, std::move(new_reply_markup), std::move(promise));
}
Result<ServerMessageId> MessagesManager::get_invoice_message_id(MessageFullId message_full_id) {

View File

@ -5849,6 +5849,14 @@ void Td::on_request(uint64 id, td_api::editBusinessMessageReplyMarkup &request)
MessageId(request.message_id_), std::move(request.reply_markup_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::stopBusinessPoll &request) {
CHECK_IS_BOT();
CREATE_REQUEST_PROMISE();
business_connection_manager_->stop_poll(BusinessConnectionId(std::move(request.business_connection_id_)),
DialogId(request.chat_id_), MessageId(request.message_id_),
std::move(request.reply_markup_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::loadQuickReplyShortcuts &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

@ -926,6 +926,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::editBusinessMessageReplyMarkup &request);
void on_request(uint64 id, td_api::stopBusinessPoll &request);
void on_request(uint64 id, const td_api::loadQuickReplyShortcuts &request);
void on_request(uint64 id, const td_api::setQuickReplyShortcutName &request);

View File

@ -5033,16 +5033,13 @@ class CliClient final : public Actor {
MessageId message_id;
string message;
get_args(args, chat_id, message_id, message);
auto input_text =
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)));
send_request(td_api::make_object<td_api::editBusinessMessageText>(business_connection_id_, chat_id, message_id,
nullptr, std::move(input_text)));
} 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)));
send_request(td_api::make_object<td_api::editMessageText>(chat_id, message_id, nullptr, std::move(input_text)));
}
} else if (op == "eqrm") {
ShortcutId shortcut_id;
@ -5966,7 +5963,12 @@ class CliClient final : public Actor {
ChatId chat_id;
MessageId message_id;
get_args(args, chat_id, message_id);
send_request(td_api::make_object<td_api::stopPoll>(chat_id, message_id, nullptr));
if (!business_connection_id_.empty()) {
send_request(
td_api::make_object<td_api::stopBusinessPoll>(business_connection_id_, chat_id, message_id, nullptr));
} else {
send_request(td_api::make_object<td_api::stopPoll>(chat_id, message_id, nullptr));
}
} else {
op_not_found_count++;
}