Add td_api::sendChosenUser.

This commit is contained in:
levlam 2023-01-13 17:03:35 +03:00
parent 4922b0c776
commit 0b54e28467
8 changed files with 89 additions and 0 deletions

View File

@ -6288,6 +6288,14 @@ getLoginUrlInfo chat_id:int53 message_id:int53 button_id:int53 = LoginUrlInfo;
getLoginUrl chat_id:int53 message_id:int53 button_id:int53 allow_write_access:Bool = HttpUrl;
//@description Sends a user chosen after pressing a keyboardButtonTypeRequestUser button to the bot
//@chat_id Identifier of the chat with the bot
//@message_id Identifier of the message with the button
//@button_id Identifier of the button
//@user_id Identifier of the chosen user
sendChosenUser chat_id:int53 message_id:int53 button_id:int32 user_id:int53 = Ok;
//@description Sends an inline query to a bot and returns its results. Returns an error with code 502 if the bot fails to answer the query before the query timeout expires
//@bot_user_id The identifier of the target bot
//@chat_id Identifier of the chat where the query was sent

View File

@ -4219,6 +4219,47 @@ class SendScreenshotNotificationQuery final : public Td::ResultHandler {
}
};
class SendBotRequestedPeer final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit SendBotRequestedPeer(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(FullMessageId full_message_id, int32 button_id, DialogId requested_dialog_id) {
auto dialog_id = full_message_id.get_dialog_id();
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
return on_error(Status::Error(400, "Can't access the chat"));
}
auto requested_peer = td_->messages_manager_->get_input_peer(requested_dialog_id, AccessRights::Read);
if (requested_peer == nullptr) {
return on_error(Status::Error(400, "Can't access the chosen chat"));
}
send_query(G()->net_query_creator().create(
telegram_api::messages_sendBotRequestedPeer(std::move(input_peer),
full_message_id.get_message_id().get_server_message_id().get(),
button_id, std::move(requested_peer)),
{{dialog_id, MessageContentType::Text}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_sendBotRequestedPeer>(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 SendBotRequestedPeer: " << to_string(ptr);
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class SetTypingQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
DialogId dialog_id_;
@ -29706,6 +29747,21 @@ void MessagesManager::do_send_screenshot_taken_notification_message(DialogId dia
->send(dialog_id, random_id);
}
void MessagesManager::send_chosen_user(FullMessageId full_message_id, int32 button_id, UserId user_id,
Promise<Unit> &&promise) {
const Message *m = get_message_force(full_message_id, "send_chosen_user");
if (m == nullptr) {
return promise.set_error(Status::Error(400, "Message not found"));
}
if (m->reply_markup == nullptr) {
return promise.set_error(Status::Error(400, "Message has no buttons"));
}
CHECK(m->message_id.is_valid() && m->message_id.is_server());
TRY_STATUS_PROMISE(promise, m->reply_markup->check_chosen_user(td_, button_id, user_id));
td_->create_handler<SendBotRequestedPeer>(std::move(promise))->send(full_message_id, button_id, DialogId(user_id));
}
Result<MessageId> MessagesManager::add_local_message(
DialogId dialog_id, td_api::object_ptr<td_api::MessageSender> &&sender, MessageId reply_to_message_id,
bool disable_notification, tl_object_ptr<td_api::InputMessageContent> &&input_message_content) {

View File

@ -462,6 +462,8 @@ class MessagesManager final : public Actor {
Status send_screenshot_taken_notification_message(DialogId dialog_id);
void send_chosen_user(FullMessageId full_message_id, int32 button_id, UserId user_id, Promise<Unit> &&promise);
Result<MessageId> add_local_message(DialogId dialog_id, td_api::object_ptr<td_api::MessageSender> &&sender,
MessageId reply_to_message_id, bool disable_notification,
tl_object_ptr<td_api::InputMessageContent> &&input_message_content)

View File

@ -1047,6 +1047,11 @@ tl_object_ptr<td_api::ReplyMarkup> ReplyMarkup::get_reply_markup_object(Contacts
}
}
Status ReplyMarkup::check_chosen_user(Td *td, int32 button_id, UserId user_id) const {
// TODO
return Status::OK();
}
tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup(ContactsManager *contacts_manager,
const unique_ptr<ReplyMarkup> &reply_markup) {
if (reply_markup == nullptr) {

View File

@ -80,6 +80,8 @@ struct ReplyMarkup {
tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup(ContactsManager *contacts_manager) const;
tl_object_ptr<td_api::ReplyMarkup> get_reply_markup_object(ContactsManager *contacts_manager) const;
Status check_chosen_user(Td *td, int32 button_id, UserId user_id) const;
};
bool operator==(const ReplyMarkup &lhs, const ReplyMarkup &rhs);

View File

@ -7631,6 +7631,13 @@ void Td::on_request(uint64 id, const td_api::getLoginUrl &request) {
request.allow_write_access_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::sendChosenUser &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
messages_manager_->send_chosen_user({DialogId(request.chat_id_), MessageId(request.message_id_)}, request.button_id_,
UserId(request.user_id_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::getInlineQueryResults &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.query_);

View File

@ -1290,6 +1290,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getLoginUrl &request);
void on_request(uint64 id, const td_api::sendChosenUser &request);
void on_request(uint64 id, td_api::getInlineQueryResults &request);
void on_request(uint64 id, td_api::answerInlineQuery &request);

View File

@ -5102,6 +5102,13 @@ class CliClient final : public Actor {
send_request(
td_api::make_object<td_api::getLoginUrl>(chat_id, message_id, as_button_id(button_id), op == "glua"));
}
} else if (op == "scu") {
ChatId chat_id;
MessageId message_id;
int32 button_id;
UserId user_id;
get_args(args, chat_id, message_id, button_id, user_id);
send_request(td_api::make_object<td_api::sendChosenUser>(chat_id, message_id, button_id, user_id));
} else if (op == "rsgs") {
string supergroup_id;
string message_ids;