diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index c42d9cbc1..8c5ed9e52 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7599,6 +7599,12 @@ setDefaultGroupAdministratorRights default_group_administrator_rights:chatAdmini setDefaultChannelAdministratorRights default_channel_administrator_rights:chatAdministratorRights = Ok; +//@description Sets the text shown in the chat with the bot if the chat is empty; bots only +//@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 +//@param_description New bot's description on the specified language +setBotInfoDescription language_code:string description:string = Ok; + + //@description Returns all active sessions of the current user getActiveSessions = Sessions; diff --git a/td/telegram/Account.cpp b/td/telegram/Account.cpp index 9e6727e10..506f1dda2 100644 --- a/td/telegram/Account.cpp +++ b/td/telegram/Account.cpp @@ -9,6 +9,7 @@ #include "td/telegram/ContactsManager.h" #include "td/telegram/DeviceTokenManager.h" #include "td/telegram/Global.h" +#include "td/telegram/misc.h" #include "td/telegram/net/NetQueryCreator.h" #include "td/telegram/Td.h" #include "td/telegram/telegram_api.h" @@ -589,6 +590,44 @@ class SetBotBroadcastDefaultAdminRightsQuery final : public Td::ResultHandler { } }; +class SetBotInfoQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit SetBotInfoQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(const string &language_code, bool set_about, const string &about, bool set_description, + const string &description) { + int32 flags = 0; + if (set_about) { + flags |= telegram_api::bots_setBotInfo::ABOUT_MASK; + } + if (set_description) { + flags |= telegram_api::bots_setBotInfo::DESCRIPTION_MASK; + } + send_query(G()->net_query_creator().create(telegram_api::bots_setBotInfo(flags, language_code, about, description), + {{"me"}})); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + bool result = result_ptr.move_as_ok(); + LOG_IF(WARNING, !result) << "Failed to set bot info"; + td_->contacts_manager_->invalidate_user_full(td_->contacts_manager_->get_my_id()); + promise_.set_value(Unit()); + } + + void on_error(Status status) final { + td_->contacts_manager_->invalidate_user_full(td_->contacts_manager_->get_my_id()); + promise_.set_error(std::move(status)); + } +}; + class ExportContactTokenQuery final : public Td::ResultHandler { Promise> promise_; @@ -727,6 +766,12 @@ void set_default_channel_administrator_rights(Td *td, AdministratorRights admini td->create_handler(std::move(promise))->send(administrator_rights); } +void set_bot_info_description(Td *td, const string &language_code, const string &description, Promise &&promise) { + TRY_STATUS_PROMISE(promise, validate_bot_language_code(language_code)); + td->contacts_manager_->invalidate_user_full(td->contacts_manager_->get_my_id()); + td->create_handler(std::move(promise))->send(language_code, false, string(), true, description); +} + void export_contact_token(Td *td, Promise> &&promise) { td->create_handler(std::move(promise))->send(); } diff --git a/td/telegram/Account.h b/td/telegram/Account.h index 1053858d0..dc2ecfd93 100644 --- a/td/telegram/Account.h +++ b/td/telegram/Account.h @@ -50,6 +50,8 @@ 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_info_description(Td *td, const string &language_code, const string &description, Promise &&promise); + void export_contact_token(Td *td, Promise> &&promise); void import_contact_token(Td *td, const string &token, Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index d2e588a58..28a2b128b 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7012,6 +7012,13 @@ void Td::on_request(uint64 id, const td_api::setDefaultChannelAdministratorRight std::move(promise)); } +void Td::on_request(uint64 id, td_api::setBotInfoDescription &request) { + CHECK_IS_BOT(); + CLEAN_INPUT_STRING(request.description_); + CREATE_OK_REQUEST_PROMISE(); + set_bot_info_description(this, request.language_code_, request.description_, std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::setLocation &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 9880b2954..3fe46d093 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1118,6 +1118,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::setDefaultChannelAdministratorRights &request); + void on_request(uint64 id, td_api::setBotInfoDescription &request); + void on_request(uint64 id, const td_api::setLocation &request); void on_request(uint64 id, td_api::setProfilePhoto &request);