Add td_api::createBusinessChatLink.

This commit is contained in:
levlam 2024-04-11 01:43:42 +03:00
parent c9224b24ab
commit 8e35a2477c
7 changed files with 61 additions and 1 deletions

View File

@ -9772,6 +9772,9 @@ removeBusinessConnectedBotFromChat chat_id:int53 = Ok;
//@description Returns business chat links created for the current account
getBusinessChatLinks = BusinessChatLinks;
//@description Creates a business chat link for the current account. Requires Telegram Business subscription. Returns the created link @link Description of the link to create
createBusinessChatLink link:inputBusinessChatLink = BusinessChatLink;
//@description Returns an HTTPS link, which can be used to get information about the current user
getUserLink = UserLink;

View File

@ -18,6 +18,7 @@
#include "td/telegram/DialogLocation.h"
#include "td/telegram/DialogManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/InputBusinessChatLink.h"
#include "td/telegram/MessagesManager.h"
#include "td/telegram/Td.h"
#include "td/telegram/telegram_api.h"
@ -218,6 +219,36 @@ class GetBusinessChatLinksQuery final : public Td::ResultHandler {
}
};
class CreateBusinessChatLinkQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::businessChatLink>> promise_;
public:
explicit CreateBusinessChatLinkQuery(Promise<td_api::object_ptr<td_api::businessChatLink>> &&promise)
: promise_(std::move(promise)) {
}
void send(InputBusinessChatLink &&link) {
send_query(G()->net_query_creator().create(
telegram_api::account_createBusinessChatLink(link.get_input_business_chat_link(td_->user_manager_.get())),
{{"me"}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_createBusinessChatLink>(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 CreateBusinessChatLinkQuery: " << to_string(ptr);
promise_.set_value(BusinessChatLink(td_->user_manager_.get(), std::move(ptr)).get_business_chat_link_object());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class UpdateBusinessLocationQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
DialogLocation location_;
@ -448,6 +479,12 @@ void BusinessManager::get_business_chat_links(Promise<td_api::object_ptr<td_api:
td_->create_handler<GetBusinessChatLinksQuery>(std::move(promise))->send();
}
void BusinessManager::create_business_chat_link(td_api::object_ptr<td_api::inputBusinessChatLink> &&link,
Promise<td_api::object_ptr<td_api::businessChatLink>> &&promise) {
td_->create_handler<CreateBusinessChatLinkQuery>(std::move(promise))
->send(InputBusinessChatLink(td_, std::move(link)));
}
void BusinessManager::set_business_location(DialogLocation &&location, Promise<Unit> &&promise) {
td_->create_handler<UpdateBusinessLocationQuery>(std::move(promise))->send(std::move(location));
}

View File

@ -40,6 +40,9 @@ class BusinessManager final : public Actor {
void get_business_chat_links(Promise<td_api::object_ptr<td_api::businessChatLinks>> &&promise);
void create_business_chat_link(td_api::object_ptr<td_api::inputBusinessChatLink> &&link,
Promise<td_api::object_ptr<td_api::businessChatLink>> &&promise);
void set_business_location(DialogLocation &&location, Promise<Unit> &&promise);
void set_business_work_hours(BusinessWorkHours &&work_hours, Promise<Unit> &&promise);

View File

@ -13,6 +13,9 @@
namespace td {
InputBusinessChatLink::InputBusinessChatLink(const Td *td, td_api::object_ptr<td_api::inputBusinessChatLink> &&link) {
if (link == nullptr) {
return;
}
auto r_text =
get_formatted_text(td, td->dialog_manager_->get_my_dialog_id(), std::move(link->text_), false, true, true, false);
if (r_text.is_error()) {
@ -20,7 +23,7 @@ InputBusinessChatLink::InputBusinessChatLink(const Td *td, td_api::object_ptr<td
} else {
text_ = r_text.move_as_ok();
}
if (!clean_input_string(link->title_)) {
if (clean_input_string(link->title_)) {
title_ = std::move(link->title_);
}
}

View File

@ -7991,6 +7991,12 @@ void Td::on_request(uint64 id, const td_api::getBusinessChatLinks &request) {
business_manager_->get_business_chat_links(std::move(promise));
}
void Td::on_request(uint64 id, td_api::createBusinessChatLink &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
business_manager_->create_business_chat_link(std::move(request.link_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setSupergroupUsername &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.username_);

View File

@ -1445,6 +1445,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getBusinessChatLinks &request);
void on_request(uint64 id, td_api::createBusinessChatLink &request);
void on_request(uint64 id, td_api::setSupergroupUsername &request);
void on_request(uint64 id, td_api::toggleSupergroupUsernameIsActive &request);

View File

@ -6171,6 +6171,12 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::deleteBusinessConnectedBot>(bot_user_id));
} else if (op == "gbcl") {
send_request(td_api::make_object<td_api::getBusinessChatLinks>());
} else if (op == "cbcl") {
string text;
string title;
get_args(args, text, title);
send_request(td_api::make_object<td_api::createBusinessChatLink>(
td_api::make_object<td_api::inputBusinessChatLink>(as_formatted_text(text), title)));
} else if (op == "gbc") {
send_request(td_api::make_object<td_api::getBusinessConnection>(args.empty() ? business_connection_id_ : args));
} else if (op == "sco") {