From c4b42c267847dfbee7244c9b4ff75275cf80c02e Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 10 Apr 2024 18:29:43 +0300 Subject: [PATCH] Add td_api::getBusinessChatLinks. --- td/generate/scheme/td_api.tl | 4 ++++ td/telegram/BusinessManager.cpp | 37 +++++++++++++++++++++++++++++++++ td/telegram/BusinessManager.h | 2 ++ td/telegram/Td.cpp | 6 ++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 2 ++ 6 files changed, 53 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index bca11d72f..555d2edf7 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -9764,6 +9764,10 @@ toggleBusinessConnectedBotChatIsPaused chat_id:int53 is_paused:Bool = Ok; removeBusinessConnectedBotFromChat chat_id:int53 = Ok; +//@description Returns business chat links created for the current account +getBusinessChatLinks = BusinessChatLinks; + + //@description Returns an HTTPS link, which can be used to get information about the current user getUserLink = UserLink; diff --git a/td/telegram/BusinessManager.cpp b/td/telegram/BusinessManager.cpp index 4ef990b2f..36b0a412e 100644 --- a/td/telegram/BusinessManager.cpp +++ b/td/telegram/BusinessManager.cpp @@ -8,11 +8,13 @@ #include "td/telegram/AccessRights.h" #include "td/telegram/BusinessAwayMessage.h" +#include "td/telegram/BusinessChatLink.h" #include "td/telegram/BusinessConnectedBot.h" #include "td/telegram/BusinessGreetingMessage.h" #include "td/telegram/BusinessIntro.h" #include "td/telegram/BusinessRecipients.h" #include "td/telegram/BusinessWorkHours.h" +#include "td/telegram/ChatManager.h" #include "td/telegram/DialogLocation.h" #include "td/telegram/DialogManager.h" #include "td/telegram/Global.h" @@ -185,6 +187,37 @@ class DisablePeerConnectedBotQuery final : public Td::ResultHandler { } }; +class GetBusinessChatLinksQuery final : public Td::ResultHandler { + Promise> promise_; + + public: + explicit GetBusinessChatLinksQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + + void send() { + send_query(G()->net_query_creator().create(telegram_api::account_getBusinessChatLinks(), {{"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 ptr = result_ptr.move_as_ok(); + LOG(INFO) << "Receive result for GetBusinessChatLinksQuery: " << to_string(ptr); + td_->user_manager_->on_get_users(std::move(ptr->users_), "GetBusinessChatLinksQuery"); + td_->chat_manager_->on_get_chats(std::move(ptr->chats_), "GetBusinessChatLinksQuery"); + promise_.set_value( + BusinessChatLinks(td_->user_manager_.get(), std::move(ptr->links_)).get_business_chat_links_object()); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + class UpdateBusinessLocationQuery final : public Td::ResultHandler { Promise promise_; DialogLocation location_; @@ -411,6 +444,10 @@ void BusinessManager::remove_business_connected_bot_from_dialog(DialogId dialog_ td_->create_handler(std::move(promise))->send(dialog_id); } +void BusinessManager::get_business_chat_links(Promise> &&promise) { + td_->create_handler(std::move(promise))->send(); +} + void BusinessManager::set_business_location(DialogLocation &&location, Promise &&promise) { td_->create_handler(std::move(promise))->send(std::move(location)); } diff --git a/td/telegram/BusinessManager.h b/td/telegram/BusinessManager.h index 41492edae..51fe91381 100644 --- a/td/telegram/BusinessManager.h +++ b/td/telegram/BusinessManager.h @@ -38,6 +38,8 @@ class BusinessManager final : public Actor { void remove_business_connected_bot_from_dialog(DialogId dialog_id, Promise &&promise); + void get_business_chat_links(Promise> &&promise); + void set_business_location(DialogLocation &&location, Promise &&promise); void set_business_work_hours(BusinessWorkHours &&work_hours, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 3c63208c0..c49478c45 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7985,6 +7985,12 @@ void Td::on_request(uint64 id, const td_api::removeBusinessConnectedBotFromChat business_manager_->remove_business_connected_bot_from_dialog(DialogId(request.chat_id_), std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getBusinessChatLinks &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + business_manager_->get_business_chat_links(std::move(promise)); +} + void Td::on_request(uint64 id, td_api::setSupergroupUsername &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.username_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index c836cca71..076eb3f49 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1443,6 +1443,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::removeBusinessConnectedBotFromChat &request); + void on_request(uint64 id, const td_api::getBusinessChatLinks &request); + void on_request(uint64 id, td_api::setSupergroupUsername &request); void on_request(uint64 id, td_api::toggleSupergroupUsernameIsActive &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 385a16ca6..9999a9bee 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -6169,6 +6169,8 @@ class CliClient final : public Actor { UserId bot_user_id; get_args(args, bot_user_id); send_request(td_api::make_object(bot_user_id)); + } else if (op == "gbcl") { + send_request(td_api::make_object()); } else if (op == "gbc") { send_request(td_api::make_object(args.empty() ? business_connection_id_ : args)); } else if (op == "sco") {