diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 54c1b8d66..4ad7781ac 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -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 diff --git a/td/telegram/Account.cpp b/td/telegram/Account.cpp index 3e2276128..5d62cd2bd 100644 --- a/td/telegram/Account.cpp +++ b/td/telegram/Account.cpp @@ -609,18 +609,24 @@ static Result> get_bot_input_u class SetBotInfoQuery final : public Td::ResultHandler { Promise 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 &&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(std::move(promise))->send(administrator_rights); } +void set_bot_name(Td *td, UserId bot_user_id, const string &language_code, const string &name, + Promise &&promise) { + TRY_STATUS_PROMISE(promise, validate_bot_language_code(language_code)); + td->create_handler(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 &&promise) { + TRY_STATUS_PROMISE(promise, validate_bot_language_code(language_code)); + td->create_handler(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 &&promise) { TRY_STATUS_PROMISE(promise, validate_bot_language_code(language_code)); td->create_handler(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 &&promise) { @@ -861,7 +884,7 @@ void set_bot_info_about(Td *td, UserId bot_user_id, const string &language_code, Promise &&promise) { TRY_STATUS_PROMISE(promise, validate_bot_language_code(language_code)); td->create_handler(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 &&promise) { diff --git a/td/telegram/Account.h b/td/telegram/Account.h index 5c663251a..7b004895c 100644 --- a/td/telegram/Account.h +++ b/td/telegram/Account.h @@ -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 &&promise); +void set_bot_name(Td *td, UserId bot_user_id, const string &language_code, const string &name, Promise &&promise); + +void get_bot_name(Td *td, UserId bot_user_id, const string &language_code, Promise &&promise); + void set_bot_info_description(Td *td, UserId bot_user_id, const string &language_code, const string &description, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 3082662aa..056b3239f 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -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 result) mutable { + if (result.is_error()) { + promise.set_error(result.move_as_error()); + } else { + promise.set_value(td_api::make_object(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(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 27ffb2145..0db0f9d2c 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -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); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 3133a4448..c33c4a7c8 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -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(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(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(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(bot_user_id, language_code)); } else if (op == "sbisd") {