From 66761d1950ed4ce5195c504fef40de519da4b6fe Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 27 Feb 2024 14:18:56 +0300 Subject: [PATCH] Add td_api::setBusinessAwayMessageSettings. --- td/generate/scheme/td_api.tl | 3 +++ td/telegram/ContactsManager.cpp | 39 +++++++++++++++++++++++++++++++++ td/telegram/ContactsManager.h | 2 ++ td/telegram/Td.cpp | 8 +++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 25 +++++++++++++++++++++ 6 files changed, 79 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index a3e404600..95d06fb5b 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -9353,6 +9353,9 @@ setBusinessLocation location:businessLocation = Ok; //@description Changes the business work hours of the current user. Requires Telegram Business subscription @work_hours The new work hours of the business; pass null to remove the work hours setBusinessWorkHours work_hours:businessWorkHours = Ok; +//@description Changes the business away message settings of the current user. Requires Telegram Business subscription @away_message_settings The new settings for the away message of the business; pass null to disable the away message +setBusinessAwayMessageSettings away_message_settings:businessAwayMessageSettings = Ok; + //@description Changes the phone number of the user and sends an authentication code to the user's new phone number; for official Android and iOS applications only. On success, returns information about the sent code //@phone_number The new phone number of the user in international format //@settings Settings for the authentication of the user's phone number; pass null to use default settings diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 82cd72a95..04a8c021d 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -1167,6 +1167,41 @@ class UpdateBusinessWorkHoursQuery final : public Td::ResultHandler { } }; +class UpdateBusinessAwayMessageQuery final : public Td::ResultHandler { + Promise promise_; + BusinessAwayMessage away_message_; + + public: + explicit UpdateBusinessAwayMessageQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(BusinessAwayMessage &&away_message) { + away_message_ = std::move(away_message); + int32 flags = 0; + if (!away_message_.is_empty()) { + flags |= telegram_api::account_updateBusinessAwayMessage::MESSAGE_MASK; + } + send_query(G()->net_query_creator().create( + telegram_api::account_updateBusinessAwayMessage(flags, away_message_.get_input_business_away_message(td_)), + {{"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()); + } + + td_->contacts_manager_->on_update_user_away_message(td_->contacts_manager_->get_my_id(), std::move(away_message_)); + + promise_.set_value(Unit()); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class CreateChatQuery final : public Td::ResultHandler { Promise> promise_; @@ -7029,6 +7064,10 @@ void ContactsManager::set_business_work_hours(BusinessWorkHours &&work_hours, Pr td_->create_handler(std::move(promise))->send(std::move(work_hours)); } +void ContactsManager::set_business_away_message(BusinessAwayMessage &&away_message, Promise &&promise) { + td_->create_handler(std::move(promise))->send(std::move(away_message)); +} + void ContactsManager::set_chat_description(ChatId chat_id, const string &description, Promise &&promise) { auto new_description = strip_empty_characters(description, MAX_DESCRIPTION_LENGTH); auto c = get_chat(chat_id); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 64b951164..b08aed2f7 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -472,6 +472,8 @@ class ContactsManager final : public Actor { void set_business_work_hours(BusinessWorkHours &&work_hours, Promise &&promise); + void set_business_away_message(BusinessAwayMessage &&away_message, Promise &&promise); + void set_chat_description(ChatId chat_id, const string &description, Promise &&promise); void set_channel_username(ChannelId channel_id, const string &username, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index a5a258451..48e6c7755 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -22,6 +22,7 @@ #include "td/telegram/BotCommand.h" #include "td/telegram/BotInfoManager.h" #include "td/telegram/BotMenuButton.h" +#include "td/telegram/BusinessAwayMessage.h" #include "td/telegram/BusinessWorkHours.h" #include "td/telegram/CallbackQueriesManager.h" #include "td/telegram/CallId.h" @@ -7777,6 +7778,13 @@ void Td::on_request(uint64 id, td_api::setBusinessWorkHours &request) { contacts_manager_->set_business_work_hours(BusinessWorkHours(std::move(request.work_hours_)), std::move(promise)); } +void Td::on_request(uint64 id, td_api::setBusinessAwayMessageSettings &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + contacts_manager_->set_business_away_message(BusinessAwayMessage(std::move(request.away_message_settings_)), + std::move(promise)); +} + void Td::on_request(uint64 id, td_api::setProfilePhoto &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 53dd91e78..2e16cbb4d 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1380,6 +1380,8 @@ class Td final : public Actor { void on_request(uint64 id, td_api::setBusinessWorkHours &request); + void on_request(uint64 id, td_api::setBusinessAwayMessageSettings &request); + void on_request(uint64 id, td_api::setProfilePhoto &request); void on_request(uint64 id, const td_api::deleteProfilePhoto &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 0d0b40dd0..f987822be 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -5939,6 +5939,31 @@ class CliClient final : public Actor { send_request(td_api::make_object( td_api::make_object(time_zone_id, std::move(intervals)))); } + } else if (op == "sbams") { + string shortcut_id; + string chat_ids; + string schedule; + get_args(args, shortcut_id, chat_ids, schedule); + if (shortcut_id.empty()) { + send_request(td_api::make_object(nullptr)); + } else { + td_api::object_ptr schedule_object; + if (schedule[0] == 'o') { + schedule_object = td_api::make_object(); + } else if (schedule[0] == 'h') { + schedule_object = td_api::make_object(); + } else { + auto start_date = to_integer(schedule); + schedule_object = td_api::make_object( + start_date, start_date + Random::fast(1000, 100000)); + } + send_request(td_api::make_object( + td_api::make_object( + to_integer(shortcut_id), + td_api::make_object(as_chat_ids(chat_ids), rand_bool(), rand_bool(), + rand_bool(), rand_bool(), rand_bool()), + std::move(schedule_object)))); + } } else if (op == "sco") { SearchQuery query; get_args(args, query);