Add td_api::setBusinessConnectedBot.

This commit is contained in:
levlam 2024-03-04 17:59:29 +03:00
parent 5c764d1716
commit 84ecc89d20
7 changed files with 78 additions and 1 deletions

View File

@ -9405,9 +9405,12 @@ resendChangePhoneNumberCode = AuthenticationCodeInfo;
checkChangePhoneNumberCode code:string = Ok;
//@description Returns the business bot connected to the current user account. Returns a 404 error if there is no connected bot
//@description Returns the business bot that is connected to the current user account. Returns a 404 error if there is no connected bot
getBusinessConnectedBot = BusinessConnectedBot;
//@description Adds or changes business bot that is connected to the current user account @bot Connection settings for the bot
setBusinessConnectedBot bot:businessConnectedBot = Ok;
//@description Returns an HTTPS link, which can be used to get information about the current user
getUserLink = UserLink;

View File

@ -32,6 +32,18 @@ class BusinessConnectedBot {
return user_id_.is_valid();
}
UserId get_user_id() const {
return user_id_;
}
const BusinessRecipients &get_recipients() const {
return recipients_;
}
bool get_can_reply() const {
return can_reply_;
}
template <class StorerT>
void store(StorerT &storer) const;

View File

@ -15,6 +15,7 @@
#include "td/telegram/Global.h"
#include "td/telegram/Td.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/UpdatesManager.h"
#include "td/utils/buffer.h"
#include "td/utils/Status.h"
@ -61,6 +62,40 @@ class GetConnectedBotsQuery final : public Td::ResultHandler {
}
};
class UpdateConnectedBotQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit UpdateConnectedBotQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(const BusinessConnectedBot &bot, telegram_api::object_ptr<telegram_api::InputUser> &&input_user) {
int32 flags = 0;
if (bot.get_can_reply()) {
flags |= telegram_api::account_updateConnectedBot::CAN_REPLY_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::account_updateConnectedBot(flags, false /*ignored*/, false /*ignored*/, std::move(input_user),
bot.get_recipients().get_input_business_recipients(td_)),
{{"me"}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::account_updateConnectedBot>(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 UpdateConnectedBotQuery: " << to_string(ptr);
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class UpdateBusinessLocationQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
DialogLocation location_;
@ -215,6 +250,16 @@ void BusinessManager::get_business_connected_bot(Promise<td_api::object_ptr<td_a
td_->create_handler<GetConnectedBotsQuery>(std::move(promise))->send();
}
void BusinessManager::set_business_connected_bot(td_api::object_ptr<td_api::businessConnectedBot> &&bot,
Promise<Unit> &&promise) {
if (bot == nullptr) {
return promise.set_error(Status::Error(400, "Bot must be non-empty"));
}
BusinessConnectedBot connected_bot(std::move(bot));
TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(connected_bot.get_user_id()));
td_->create_handler<UpdateConnectedBotQuery>(std::move(promise))->send(connected_bot, std::move(input_user));
}
void BusinessManager::set_business_location(DialogLocation &&location, Promise<Unit> &&promise) {
td_->create_handler<UpdateBusinessLocationQuery>(std::move(promise))->send(std::move(location));
}

View File

@ -27,6 +27,8 @@ class BusinessManager final : public Actor {
void get_business_connected_bot(Promise<td_api::object_ptr<td_api::businessConnectedBot>> &&promise);
void set_business_connected_bot(td_api::object_ptr<td_api::businessConnectedBot> &&bot, Promise<Unit> &&promise);
void set_business_location(DialogLocation &&location, Promise<Unit> &&promise);
void set_business_work_hours(BusinessWorkHours &&work_hours, Promise<Unit> &&promise);

View File

@ -7868,6 +7868,12 @@ void Td::on_request(uint64 id, const td_api::getBusinessConnectedBot &request) {
business_manager_->get_business_connected_bot(std::move(promise));
}
void Td::on_request(uint64 id, td_api::setBusinessConnectedBot &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
business_manager_->set_business_connected_bot(std::move(request.bot_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setSupergroupUsername &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.username_);

View File

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

View File

@ -6021,6 +6021,13 @@ class CliClient final : public Actor {
}
} else if (op == "gbcb") {
send_request(td_api::make_object<td_api::getBusinessConnectedBot>());
} else if (op == "sbcb") {
UserId bot_user_id;
string chat_ids;
bool can_reply = false;
get_args(args, bot_user_id, chat_ids, can_reply);
send_request(td_api::make_object<td_api::setBusinessConnectedBot>(
td_api::make_object<td_api::businessConnectedBot>(bot_user_id, as_business_recipients(chat_ids), can_reply)));
} else if (op == "sco") {
SearchQuery query;
get_args(args, query);