Add ability to check shared with bot user/chat.

This commit is contained in:
levlam 2023-01-31 16:52:05 +03:00
parent ade5a089e9
commit a347eb4da3
5 changed files with 19 additions and 10 deletions

View File

@ -6395,14 +6395,16 @@ getLoginUrl chat_id:int53 message_id:int53 button_id:int53 allow_write_access:Bo
//@message_id Identifier of the message with the button //@message_id Identifier of the message with the button
//@button_id Identifier of the button //@button_id Identifier of the button
//@shared_user_id Identifier of the shared user //@shared_user_id Identifier of the shared user
shareUserWithBot chat_id:int53 message_id:int53 button_id:int32 shared_user_id:int53 = Ok; //@only_check Pass true to check that the user can be shared by the button instead of actually sharing them
shareUserWithBot chat_id:int53 message_id:int53 button_id:int32 shared_user_id:int53 only_check:Bool = Ok;
//@description Shares a chat after pressing a keyboardButtonTypeRequestChat button with the bot //@description Shares a chat after pressing a keyboardButtonTypeRequestChat button with the bot
//@chat_id Identifier of the chat with the bot //@chat_id Identifier of the chat with the bot
//@message_id Identifier of the message with the button //@message_id Identifier of the message with the button
//@button_id Identifier of the button //@button_id Identifier of the button
//@shared_chat_id Identifier of the shared chat //@shared_chat_id Identifier of the shared chat
shareChatWithBot chat_id:int53 message_id:int53 button_id:int32 shared_chat_id:int53 = Ok; //@only_check Pass true to check that the chat can be shared by the button instead of actually sharing it. If the chat can be shared, but the bot requested more rights in the chat than it have currently, then the rigts will be given automatically
shareChatWithBot chat_id:int53 message_id:int53 button_id:int32 shared_chat_id:int53 only_check:Bool = 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 //@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

View File

@ -29886,7 +29886,7 @@ void MessagesManager::do_send_screenshot_taken_notification_message(DialogId dia
} }
void MessagesManager::share_dialog_with_bot(FullMessageId full_message_id, int32 button_id, DialogId shared_dialog_id, void MessagesManager::share_dialog_with_bot(FullMessageId full_message_id, int32 button_id, DialogId shared_dialog_id,
Promise<Unit> &&promise) { bool only_check, Promise<Unit> &&promise) {
const Message *m = get_message_force(full_message_id, "share_dialog_with_bot"); const Message *m = get_message_force(full_message_id, "share_dialog_with_bot");
if (m == nullptr) { if (m == nullptr) {
return promise.set_error(Status::Error(400, "Message not found")); return promise.set_error(Status::Error(400, "Message not found"));
@ -29906,6 +29906,10 @@ void MessagesManager::share_dialog_with_bot(FullMessageId full_message_id, int32
} }
TRY_STATUS_PROMISE(promise, m->reply_markup->check_shared_dialog(td_, button_id, shared_dialog_id)); TRY_STATUS_PROMISE(promise, m->reply_markup->check_shared_dialog(td_, button_id, shared_dialog_id));
if (only_check) {
return promise.set_value(Unit());
}
td_->create_handler<SendBotRequestedPeerQuery>(std::move(promise)) td_->create_handler<SendBotRequestedPeerQuery>(std::move(promise))
->send(full_message_id, button_id, shared_dialog_id); ->send(full_message_id, button_id, shared_dialog_id);
} }

View File

@ -467,7 +467,7 @@ class MessagesManager final : public Actor {
Status send_screenshot_taken_notification_message(DialogId dialog_id); Status send_screenshot_taken_notification_message(DialogId dialog_id);
void share_dialog_with_bot(FullMessageId full_message_id, int32 button_id, DialogId shared_dialog_id, void share_dialog_with_bot(FullMessageId full_message_id, int32 button_id, DialogId shared_dialog_id, bool only_check,
Promise<Unit> &&promise); Promise<Unit> &&promise);
Result<MessageId> add_local_message(DialogId dialog_id, td_api::object_ptr<td_api::MessageSender> &&sender, Result<MessageId> add_local_message(DialogId dialog_id, td_api::object_ptr<td_api::MessageSender> &&sender,

View File

@ -7685,14 +7685,15 @@ void Td::on_request(uint64 id, const td_api::shareUserWithBot &request) {
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
messages_manager_->share_dialog_with_bot({DialogId(request.chat_id_), MessageId(request.message_id_)}, messages_manager_->share_dialog_with_bot({DialogId(request.chat_id_), MessageId(request.message_id_)},
request.button_id_, DialogId(UserId(request.shared_user_id_)), request.button_id_, DialogId(UserId(request.shared_user_id_)),
std::move(promise)); request.only_check_, std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::shareChatWithBot &request) { void Td::on_request(uint64 id, const td_api::shareChatWithBot &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
messages_manager_->share_dialog_with_bot({DialogId(request.chat_id_), MessageId(request.message_id_)}, messages_manager_->share_dialog_with_bot({DialogId(request.chat_id_), MessageId(request.message_id_)},
request.button_id_, DialogId(request.shared_chat_id_), std::move(promise)); request.button_id_, DialogId(request.shared_chat_id_), request.only_check_,
std::move(promise));
} }
void Td::on_request(uint64 id, td_api::getInlineQueryResults &request) { void Td::on_request(uint64 id, td_api::getInlineQueryResults &request) {

View File

@ -5175,20 +5175,22 @@ class CliClient final : public Actor {
send_request( send_request(
td_api::make_object<td_api::getLoginUrl>(chat_id, message_id, as_button_id(button_id), op == "glua")); td_api::make_object<td_api::getLoginUrl>(chat_id, message_id, as_button_id(button_id), op == "glua"));
} }
} else if (op == "suwb") { } else if (op == "suwb" || op == "suwbc") {
ChatId chat_id; ChatId chat_id;
MessageId message_id; MessageId message_id;
int32 button_id; int32 button_id;
UserId shared_user_id; UserId shared_user_id;
get_args(args, chat_id, message_id, button_id, shared_user_id); get_args(args, chat_id, message_id, button_id, shared_user_id);
send_request(td_api::make_object<td_api::shareUserWithBot>(chat_id, message_id, button_id, shared_user_id)); send_request(
} else if (op == "scwb") { td_api::make_object<td_api::shareUserWithBot>(chat_id, message_id, button_id, shared_user_id, op == "suwbc"));
} else if (op == "scwb" || op == "scwbc") {
ChatId chat_id; ChatId chat_id;
MessageId message_id; MessageId message_id;
int32 button_id; int32 button_id;
ChatId shared_chat_id; ChatId shared_chat_id;
get_args(args, chat_id, message_id, button_id, shared_chat_id); get_args(args, chat_id, message_id, button_id, shared_chat_id);
send_request(td_api::make_object<td_api::shareChatWithBot>(chat_id, message_id, button_id, shared_chat_id)); send_request(
td_api::make_object<td_api::shareChatWithBot>(chat_id, message_id, button_id, shared_chat_id, op == "scwbc"));
} else if (op == "rsgs") { } else if (op == "rsgs") {
string supergroup_id; string supergroup_id;
string message_ids; string message_ids;