diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 8c5ed9e52..889db0318 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -7604,6 +7604,10 @@ setDefaultChannelAdministratorRights default_channel_administrator_rights:chatAd //@param_description New bot's description on the specified language setBotInfoDescription language_code:string description:string = Ok; +//@description Returns the text shown in the chat with the bot if the chat is empty in the given language; bots only +//@language_code A two-letter ISO 639-1 language code or an empty string +getBotInfoDescription language_code:string = Text; + //@description Returns all active sessions of the current user getActiveSessions = Sessions; diff --git a/td/telegram/Account.cpp b/td/telegram/Account.cpp index 506f1dda2..0c4f8e0fb 100644 --- a/td/telegram/Account.cpp +++ b/td/telegram/Account.cpp @@ -628,6 +628,37 @@ class SetBotInfoQuery final : public Td::ResultHandler { } }; +class GetBotInfoQuery final : public Td::ResultHandler { + Promise promise_; + size_t index_ = 0; + + public: + explicit GetBotInfoQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(const string &language_code, size_t index) { + index_ = index; + send_query(G()->net_query_creator().create(telegram_api::bots_getBotInfo(language_code), {{"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()); + } + + auto result = result_ptr.move_as_ok(); + if (result.size() != 2) { + return on_error(Status::Error(500, "Failed to get bot info")); + } + promise_.set_value(std::move(result[index_])); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class ExportContactTokenQuery final : public Td::ResultHandler { Promise> promise_; @@ -772,6 +803,11 @@ void set_bot_info_description(Td *td, const string &language_code, const string td->create_handler(std::move(promise))->send(language_code, false, string(), true, description); } +void get_bot_info_description(Td *td, const string &language_code, Promise &&promise) { + TRY_STATUS_PROMISE(promise, validate_bot_language_code(language_code)); + td->create_handler(std::move(promise))->send(language_code, 1); +} + 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 dc2ecfd93..c23d3216d 100644 --- a/td/telegram/Account.h +++ b/td/telegram/Account.h @@ -52,6 +52,8 @@ void set_default_channel_administrator_rights(Td *td, AdministratorRights admini void set_bot_info_description(Td *td, const string &language_code, const string &description, Promise &&promise); +void get_bot_info_description(Td *td, const string &language_code, 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 28a2b128b..2568825c1 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7019,6 +7019,19 @@ void Td::on_request(uint64 id, td_api::setBotInfoDescription &request) { set_bot_info_description(this, request.language_code_, request.description_, std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getBotInfoDescription &request) { + CHECK_IS_BOT(); + 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_info_description(this, request.language_code_, std::move(query_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 3fe46d093..f2d274b74 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1120,6 +1120,8 @@ class Td final : public Actor { void on_request(uint64 id, td_api::setBotInfoDescription &request); + void on_request(uint64 id, const td_api::getBotInfoDescription &request); + void on_request(uint64 id, const td_api::setLocation &request); void on_request(uint64 id, td_api::setProfilePhoto &request);