diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 16fd25ed2..180bfe685 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -5023,6 +5023,10 @@ checkChangePhoneNumberCode code:string = Ok; //@commands List of the bot's commands setCommands scope:BotCommandScope language_code:string commands:vector = Ok; +//@description Deletes commands supported by the bot for the given user scope and language; for bots only @scope The scope to which the commands are applied +//@language_code A two-letter ISO 639-1 country code or an empty string +deleteCommands scope:BotCommandScope language_code:string = Ok; + //@description Returns the list of commands supported by the bot for the given user scope and language; for bots only @scope The scope to which the commands are applied //@language_code A two-letter ISO 639-1 country code or an empty string getCommands scope:BotCommandScope language_code:string = BotCommands; diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 368446538..929523321 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -1011,6 +1011,32 @@ class SetBotCommandsQuery : public Td::ResultHandler { } }; +class ResetBotCommandsQuery : public Td::ResultHandler { + Promise promise_; + + public: + explicit ResetBotCommandsQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(BotCommandScope scope, const string &language_code) { + send_query(G()->net_query_creator().create( + telegram_api::bots_resetBotCommands(scope.get_input_bot_command_scope(td), language_code))); + } + + void on_result(uint64 id, BufferSlice packet) override { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(id, result_ptr.move_as_error()); + } + + promise_.set_value(Unit()); + } + + void on_error(uint64 id, Status status) override { + promise_.set_error(std::move(status)); + } +}; + class GetBotCommandsQuery : public Td::ResultHandler { Promise> promise_; @@ -6340,6 +6366,21 @@ void ContactsManager::set_commands(td_api::object_ptr & td_->create_handler(std::move(promise))->send(scope, language_code, std::move(new_commands)); } +void ContactsManager::delete_commands(td_api::object_ptr &&scope_ptr, string &&language_code, + Promise &&promise) { + TRY_RESULT_PROMISE(promise, scope, BotCommandScope::get_bot_command_scope(td_, std::move(scope_ptr))); + + if (!language_code.empty() && (language_code.size() != 2 || language_code[0] < 'a' || language_code[0] > 'z' || + language_code[1] < 'a' || language_code[1] > 'z')) { + return promise.set_error(Status::Error(400, "Invalid language code specified")); + } + if (!scope.have_input_bot_command_scope(td_)) { + return promise.set_error(Status::Error(400, "Invalid scope specified")); + } + + td_->create_handler(std::move(promise))->send(scope, language_code); +} + void ContactsManager::get_commands(td_api::object_ptr &&scope_ptr, string &&language_code, Promise> &&promise) { TRY_RESULT_PROMISE(promise, scope, BotCommandScope::get_bot_command_scope(td_, std::move(scope_ptr))); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 6697a4da2..9093d5688 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -332,6 +332,9 @@ class ContactsManager : public Actor { void set_commands(td_api::object_ptr &&scope_ptr, string &&language_code, vector> &&commands, Promise &&promise); + void delete_commands(td_api::object_ptr &&scope_ptr, string &&language_code, + Promise &&promise); + void get_commands(td_api::object_ptr &&scope_ptr, string &&language_code, Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 48b7bb076..bf89b2b2d 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6878,6 +6878,12 @@ void Td::on_request(uint64 id, td_api::setCommands &request) { std::move(request.commands_), std::move(promise)); } +void Td::on_request(uint64 id, td_api::deleteCommands &request) { + CHECK_IS_BOT(); + CREATE_OK_REQUEST_PROMISE(); + contacts_manager_->delete_commands(std::move(request.scope_), std::move(request.language_code_), std::move(promise)); +} + void Td::on_request(uint64 id, td_api::getCommands &request) { CHECK_IS_BOT(); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index c366ec9e3..1a12c4d59 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -920,6 +920,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::setCommands &request); + void on_request(uint64 id, td_api::deleteCommands &request); + void on_request(uint64 id, td_api::getCommands &request); void on_request(uint64 id, const td_api::setLocation &request);