Add td_api::canBotSendMessages.
This commit is contained in:
parent
249da789e7
commit
a08f54007e
@ -8214,6 +8214,10 @@ setDefaultGroupAdministratorRights default_group_administrator_rights:chatAdmini
|
||||
setDefaultChannelAdministratorRights default_channel_administrator_rights:chatAdministratorRights = Ok;
|
||||
|
||||
|
||||
//@description Checks whether the specified bot can send messages to the user. Returns a 404 error if can't and the access can be granted by call to allowBotToSendMessages @bot_user_id Identifier of the target bot
|
||||
canBotSendMessages bot_user_id:int53 = Ok;
|
||||
|
||||
|
||||
//@description Sets the name of a bot. Can be called only if userTypeBot.can_be_edited == true
|
||||
//@bot_user_id Identifier of the target bot
|
||||
//@language_code A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose languages there is no dedicated name
|
||||
|
@ -89,6 +89,40 @@ class SetBotBroadcastDefaultAdminRightsQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class CanBotSendMessageQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit CanBotSendMessageQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(UserId bot_user_id) {
|
||||
auto r_input_user = td_->contacts_manager_->get_input_user(bot_user_id);
|
||||
if (r_input_user.is_error()) {
|
||||
return on_error(r_input_user.move_as_error());
|
||||
}
|
||||
send_query(
|
||||
G()->net_query_creator().create(telegram_api::bots_canSendMessage(r_input_user.move_as_ok()), {{bot_user_id}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::bots_canSendMessage>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
if (result_ptr.ok()) {
|
||||
promise_.set_value(Unit());
|
||||
} else {
|
||||
promise_.set_error(Status::Error(404, "Not Found"));
|
||||
}
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
static Result<telegram_api::object_ptr<telegram_api::InputUser>> get_bot_input_user(const Td *td, UserId bot_user_id) {
|
||||
if (td->auth_manager_->is_bot()) {
|
||||
if (bot_user_id != UserId() && bot_user_id != td->contacts_manager_->get_my_id()) {
|
||||
@ -317,6 +351,10 @@ void BotInfoManager::set_default_channel_administrator_rights(AdministratorRight
|
||||
td_->create_handler<SetBotBroadcastDefaultAdminRightsQuery>(std::move(promise))->send(administrator_rights);
|
||||
}
|
||||
|
||||
void BotInfoManager::can_bot_send_messages(UserId bot_user_id, Promise<Unit> &&promise) {
|
||||
td_->create_handler<CanBotSendMessageQuery>(std::move(promise))->send(bot_user_id);
|
||||
}
|
||||
|
||||
void BotInfoManager::add_pending_set_query(UserId bot_user_id, const string &language_code, int type,
|
||||
const string &value, Promise<Unit> &&promise) {
|
||||
pending_set_bot_info_queries_.emplace_back(bot_user_id, language_code, type, value, std::move(promise));
|
||||
|
@ -26,6 +26,8 @@ class BotInfoManager final : public Actor {
|
||||
|
||||
void set_default_channel_administrator_rights(AdministratorRights administrator_rights, Promise<Unit> &&promise);
|
||||
|
||||
void can_bot_send_messages(UserId bot_user_id, Promise<Unit> &&promise);
|
||||
|
||||
void set_bot_name(UserId bot_user_id, const string &language_code, const string &name, Promise<Unit> &&promise);
|
||||
|
||||
void get_bot_name(UserId bot_user_id, const string &language_code, Promise<string> &&promise);
|
||||
|
@ -7307,6 +7307,11 @@ void Td::on_request(uint64 id, const td_api::setDefaultChannelAdministratorRight
|
||||
AdministratorRights(request.default_channel_administrator_rights_, ChannelType::Broadcast), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::canBotSendMessages &request) {
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
bot_info_manager_->can_bot_send_messages(UserId(request.bot_user_id_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::setBotName &request) {
|
||||
CLEAN_INPUT_STRING(request.name_);
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
|
@ -1221,6 +1221,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, const td_api::setDefaultChannelAdministratorRights &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::canBotSendMessages &request);
|
||||
|
||||
void on_request(uint64 id, td_api::setBotName &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getBotName &request);
|
||||
|
@ -5510,6 +5510,10 @@ class CliClient final : public Actor {
|
||||
InputChatPhoto input_chat_photo;
|
||||
get_args(args, user_id, input_chat_photo);
|
||||
send_request(td_api::make_object<td_api::suggestUserProfilePhoto>(user_id, input_chat_photo));
|
||||
} else if (op == "cbsm") {
|
||||
UserId bot_user_id;
|
||||
get_args(args, bot_user_id);
|
||||
send_request(td_api::make_object<td_api::canBotSendMessages>(bot_user_id));
|
||||
} else if (op == "gbi") {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
|
Loading…
x
Reference in New Issue
Block a user