Add td_api::allowBotToSendMessages.
This commit is contained in:
parent
a08f54007e
commit
49c1764746
@ -8217,6 +8217,9 @@ setDefaultChannelAdministratorRights default_channel_administrator_rights:chatAd
|
||||
//@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 Allows the specified bot to send messages to the user @bot_user_id Identifier of the target bot
|
||||
allowBotToSendMessages 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
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "td/telegram/net/NetQueryCreator.h"
|
||||
#include "td/telegram/Td.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
#include "td/telegram/UpdatesManager.h"
|
||||
|
||||
#include "td/utils/algorithm.h"
|
||||
#include "td/utils/buffer.h"
|
||||
@ -123,6 +124,38 @@ class CanBotSendMessageQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class AllowBotSendMessageQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit AllowBotSendMessageQuery(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_allowSendMessage(r_input_user.move_as_ok()),
|
||||
{{bot_user_id}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::bots_allowSendMessage>(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 AllowBotSendMessageQuery: " << 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));
|
||||
}
|
||||
};
|
||||
|
||||
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()) {
|
||||
@ -355,6 +388,10 @@ void BotInfoManager::can_bot_send_messages(UserId bot_user_id, Promise<Unit> &&p
|
||||
td_->create_handler<CanBotSendMessageQuery>(std::move(promise))->send(bot_user_id);
|
||||
}
|
||||
|
||||
void BotInfoManager::allow_bot_to_send_messages(UserId bot_user_id, Promise<Unit> &&promise) {
|
||||
td_->create_handler<AllowBotSendMessageQuery>(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));
|
||||
|
@ -28,6 +28,8 @@ class BotInfoManager final : public Actor {
|
||||
|
||||
void can_bot_send_messages(UserId bot_user_id, Promise<Unit> &&promise);
|
||||
|
||||
void allow_bot_to_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);
|
||||
|
@ -7312,6 +7312,11 @@ void Td::on_request(uint64 id, const td_api::canBotSendMessages &request) {
|
||||
bot_info_manager_->can_bot_send_messages(UserId(request.bot_user_id_), std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::allowBotToSendMessages &request) {
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
bot_info_manager_->allow_bot_to_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();
|
||||
|
@ -1223,6 +1223,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, const td_api::canBotSendMessages &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::allowBotToSendMessages &request);
|
||||
|
||||
void on_request(uint64 id, td_api::setBotName &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getBotName &request);
|
||||
|
@ -5514,6 +5514,10 @@ class CliClient final : public Actor {
|
||||
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 == "abtsm") {
|
||||
UserId bot_user_id;
|
||||
get_args(args, bot_user_id);
|
||||
send_request(td_api::make_object<td_api::allowBotToSendMessages>(bot_user_id));
|
||||
} else if (op == "gbi") {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
|
Loading…
Reference in New Issue
Block a user