Add setBotName/getBotName.
This commit is contained in:
parent
dceeb363d5
commit
62818418ea
@ -7635,6 +7635,17 @@ setDefaultGroupAdministratorRights default_group_administrator_rights:chatAdmini
|
||||
setDefaultChannelAdministratorRights default_channel_administrator_rights:chatAdministratorRights = 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 description will be shown to all users, for which language there are no dedicated description
|
||||
//@name New bot's name on the specified language
|
||||
setBotName bot_user_id:int53 language_code:string name:string = Ok;
|
||||
|
||||
//@description Returns the name of a bot in the given language. 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 or an empty string
|
||||
getBotName bot_user_id:int53 language_code:string = Text;
|
||||
|
||||
//@description Sets the text shown in the chat with a bot if the chat is empty. 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 description will be shown to all users, for which language there are no dedicated description
|
||||
|
@ -609,18 +609,24 @@ static Result<telegram_api::object_ptr<telegram_api::InputUser>> get_bot_input_u
|
||||
class SetBotInfoQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
UserId bot_user_id_;
|
||||
bool set_name_ = false;
|
||||
|
||||
void invalidate_bot_info() {
|
||||
td_->contacts_manager_->invalidate_user_full(bot_user_id_);
|
||||
if (!set_name_) {
|
||||
td_->contacts_manager_->invalidate_user_full(bot_user_id_);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
explicit SetBotInfoQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(UserId bot_user_id, const string &language_code, bool set_about, const string &about, bool set_description,
|
||||
const string &description) {
|
||||
void send(UserId bot_user_id, const string &language_code, bool set_name, const string &name, bool set_about,
|
||||
const string &about, bool set_description, const string &description) {
|
||||
int32 flags = 0;
|
||||
if (set_name) {
|
||||
flags |= telegram_api::bots_setBotInfo::NAME_MASK;
|
||||
}
|
||||
if (set_about) {
|
||||
flags |= telegram_api::bots_setBotInfo::ABOUT_MASK;
|
||||
}
|
||||
@ -637,9 +643,10 @@ class SetBotInfoQuery final : public Td::ResultHandler {
|
||||
} else {
|
||||
bot_user_id_ = td_->contacts_manager_->get_my_id();
|
||||
}
|
||||
set_name_ = set_name;
|
||||
invalidate_bot_info();
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::bots_setBotInfo(flags, r_input_user.move_as_ok(), language_code, string(), about, description),
|
||||
telegram_api::bots_setBotInfo(flags, r_input_user.move_as_ok(), language_code, name, about, description),
|
||||
{{bot_user_id}}));
|
||||
}
|
||||
|
||||
@ -651,8 +658,12 @@ class SetBotInfoQuery final : public Td::ResultHandler {
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(WARNING, !result) << "Failed to set bot info";
|
||||
invalidate_bot_info();
|
||||
promise_.set_value(Unit());
|
||||
if (set_name_) {
|
||||
td_->contacts_manager_->reload_user(bot_user_id_, std::move(promise_));
|
||||
} else {
|
||||
invalidate_bot_info();
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
@ -845,11 +856,23 @@ void set_default_channel_administrator_rights(Td *td, AdministratorRights admini
|
||||
td->create_handler<SetBotBroadcastDefaultAdminRightsQuery>(std::move(promise))->send(administrator_rights);
|
||||
}
|
||||
|
||||
void set_bot_name(Td *td, UserId bot_user_id, const string &language_code, const string &name,
|
||||
Promise<Unit> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, validate_bot_language_code(language_code));
|
||||
td->create_handler<SetBotInfoQuery>(std::move(promise))
|
||||
->send(bot_user_id, language_code, true, name, false, string(), false, string());
|
||||
}
|
||||
|
||||
void get_bot_name(Td *td, UserId bot_user_id, const string &language_code, Promise<string> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, validate_bot_language_code(language_code));
|
||||
td->create_handler<GetBotInfoQuery>(std::move(promise))->send(bot_user_id, language_code, 2);
|
||||
}
|
||||
|
||||
void set_bot_info_description(Td *td, UserId bot_user_id, const string &language_code, const string &description,
|
||||
Promise<Unit> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, validate_bot_language_code(language_code));
|
||||
td->create_handler<SetBotInfoQuery>(std::move(promise))
|
||||
->send(bot_user_id, language_code, false, string(), true, description);
|
||||
->send(bot_user_id, language_code, false, string(), false, string(), true, description);
|
||||
}
|
||||
|
||||
void get_bot_info_description(Td *td, UserId bot_user_id, const string &language_code, Promise<string> &&promise) {
|
||||
@ -861,7 +884,7 @@ void set_bot_info_about(Td *td, UserId bot_user_id, const string &language_code,
|
||||
Promise<Unit> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, validate_bot_language_code(language_code));
|
||||
td->create_handler<SetBotInfoQuery>(std::move(promise))
|
||||
->send(bot_user_id, language_code, true, about, false, string());
|
||||
->send(bot_user_id, language_code, false, string(), true, about, false, string());
|
||||
}
|
||||
|
||||
void get_bot_info_about(Td *td, UserId bot_user_id, const string &language_code, Promise<string> &&promise) {
|
||||
|
@ -51,6 +51,10 @@ void set_default_group_administrator_rights(Td *td, AdministratorRights administ
|
||||
void set_default_channel_administrator_rights(Td *td, AdministratorRights administrator_rights,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
void set_bot_name(Td *td, UserId bot_user_id, const string &language_code, const string &name, Promise<Unit> &&promise);
|
||||
|
||||
void get_bot_name(Td *td, UserId bot_user_id, const string &language_code, Promise<string> &&promise);
|
||||
|
||||
void set_bot_info_description(Td *td, UserId bot_user_id, const string &language_code, const string &description,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
|
@ -7004,6 +7004,24 @@ void Td::on_request(uint64 id, const td_api::setDefaultChannelAdministratorRight
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::setBotName &request) {
|
||||
CLEAN_INPUT_STRING(request.name_);
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
set_bot_name(this, UserId(request.bot_user_id_), request.language_code_, request.name_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getBotName &request) {
|
||||
CREATE_REQUEST_PROMISE();
|
||||
auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result<string> result) mutable {
|
||||
if (result.is_error()) {
|
||||
promise.set_error(result.move_as_error());
|
||||
} else {
|
||||
promise.set_value(td_api::make_object<td_api::text>(result.move_as_ok()));
|
||||
}
|
||||
});
|
||||
get_bot_name(this, UserId(request.bot_user_id_), request.language_code_, std::move(query_promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::setBotInfoDescription &request) {
|
||||
CLEAN_INPUT_STRING(request.description_);
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
|
@ -1137,6 +1137,10 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, const td_api::setDefaultChannelAdministratorRights &request);
|
||||
|
||||
void on_request(uint64 id, td_api::setBotName &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getBotName &request);
|
||||
|
||||
void on_request(uint64 id, td_api::setBotInfoDescription &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getBotInfoDescription &request);
|
||||
|
@ -5016,6 +5016,17 @@ 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 == "sbn") {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
string name;
|
||||
get_args(args, bot_user_id, language_code, name);
|
||||
send_request(td_api::make_object<td_api::setBotName>(bot_user_id, language_code, name));
|
||||
} else if (op == "gbn") {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
get_args(args, bot_user_id, language_code);
|
||||
send_request(td_api::make_object<td_api::getBotName>(bot_user_id, language_code));
|
||||
} else if (op == "sbid") {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
@ -5025,7 +5036,6 @@ class CliClient final : public Actor {
|
||||
} else if (op == "gbid") {
|
||||
UserId bot_user_id;
|
||||
string language_code;
|
||||
string description;
|
||||
get_args(args, bot_user_id, language_code);
|
||||
send_request(td_api::make_object<td_api::getBotInfoDescription>(bot_user_id, language_code));
|
||||
} else if (op == "sbisd") {
|
||||
|
Loading…
Reference in New Issue
Block a user