Add td_api::setBotInfoDescription.

This commit is contained in:
levlam 2023-02-27 01:00:17 +03:00
parent 00983863e3
commit 72bebaf3f5
5 changed files with 62 additions and 0 deletions

View File

@ -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;

View File

@ -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<Unit> promise_;
public:
explicit SetBotInfoQuery(Promise<Unit> &&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<telegram_api::bots_setBotInfo>(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<td_api::object_ptr<td_api::userLink>> promise_;
@ -727,6 +766,12 @@ void set_default_channel_administrator_rights(Td *td, AdministratorRights admini
td->create_handler<SetBotBroadcastDefaultAdminRightsQuery>(std::move(promise))->send(administrator_rights);
}
void set_bot_info_description(Td *td, const string &language_code, const string &description, Promise<Unit> &&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<SetBotInfoQuery>(std::move(promise))->send(language_code, false, string(), true, description);
}
void export_contact_token(Td *td, Promise<td_api::object_ptr<td_api::userLink>> &&promise) {
td->create_handler<ExportContactTokenQuery>(std::move(promise))->send();
}

View File

@ -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<Unit> &&promise);
void set_bot_info_description(Td *td, const string &language_code, const string &description, Promise<Unit> &&promise);
void export_contact_token(Td *td, Promise<td_api::object_ptr<td_api::userLink>> &&promise);
void import_contact_token(Td *td, const string &token, Promise<td_api::object_ptr<td_api::user>> &&promise);

View File

@ -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();

View File

@ -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);