Add td_api::updateBusinessConnection.

This commit is contained in:
levlam 2024-03-07 17:18:11 +03:00
parent c54e2429b0
commit 74cf61d401
4 changed files with 92 additions and 1 deletions

View File

@ -4213,6 +4213,15 @@ speechRecognitionResultText text:string = SpeechRecognitionResult;
speechRecognitionResultError error:error = SpeechRecognitionResult;
//@description Describes a connection of the bot with a business account
//@id Unique identifier of the connection
//@user_id Identifier of the business user that created the connection
//@date Point in time (Unix timestamp) when the connection was established
//@can_reply True, if the bot can send messages to the connected user; false otherwise
//@is_disabled True, if the connection is disabled; false otherwise
businessConnection id:string user_id:int53 date:int32 can_reply:Bool is_disabled:Bool = BusinessConnection;
//@description Describes a color to highlight a bot added to attachment menu @light_color Color in the RGB24 format for light themes @dark_color Color in the RGB24 format for dark themes
attachmentMenuBotColor light_color:int32 dark_color:int32 = AttachmentMenuBotColor;
@ -6923,6 +6932,9 @@ updateAddChatMembersPrivacyForbidden chat_id:int53 user_ids:vector<int53> = Upda
//@description Autosave settings for some type of chats were updated @scope Type of chats for which autosave settings were updated @settings The new autosave settings; may be null if the settings are reset to default
updateAutosaveSettings scope:AutosaveSettingsScope settings:scopeAutosaveSettings = Update;
//@description A business connection has changed; for bots only @connection New data about the connection
updateBusinessConnection connection:businessConnection = Update;
//@description A new incoming inline query; for bots only
//@id Unique query identifier
//@sender_user_id Identifier of the user who sent the query

View File

@ -6,13 +6,76 @@
//
#include "td/telegram/BusinessConnectionManager.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/net/DcId.h"
#include "td/telegram/Td.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
#include "td/utils/logging.h"
namespace td {
BusinessConnectionManager::BusinessConnectionManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
struct BusinessConnectionManager::BusinessConnection {
string connection_id_;
UserId user_id_;
DcId dc_id_;
int32 connection_date_ = 0;
bool can_reply_ = false;
bool is_disabled_ = false;
explicit BusinessConnection(const telegram_api::object_ptr<telegram_api::botBusinessConnection> &connection)
: connection_id_(connection->connection_id_)
, user_id_(connection->user_id_)
, dc_id_(DcId::create(connection->dc_id_))
, connection_date_(connection->date_)
, can_reply_(connection->can_reply_)
, is_disabled_(connection->disabled_) {
}
BusinessConnection(const BusinessConnection &) = delete;
BusinessConnection &operator=(const BusinessConnection &) = delete;
BusinessConnection(BusinessConnection &&) = delete;
BusinessConnection &operator=(BusinessConnection &&) = delete;
~BusinessConnection() = default;
bool is_valid() const {
return !connection_id_.empty() && user_id_.is_valid() && !dc_id_.is_empty() && connection_date_ > 0;
}
td_api::object_ptr<td_api::businessConnection> get_business_connection_object(Td *td) const {
return td_api::make_object<td_api::businessConnection>(
connection_id_, td->contacts_manager_->get_user_id_object(user_id_, "businessConnection"), connection_date_,
can_reply_, is_disabled_);
}
};
BusinessConnectionManager::BusinessConnectionManager(Td *td, ActorShared<> parent)
: td_(td), parent_(std::move(parent)) {
}
BusinessConnectionManager::~BusinessConnectionManager() = default;
void BusinessConnectionManager::tear_down() {
parent_.reset();
}
void BusinessConnectionManager::on_update_bot_business_connect(
telegram_api::object_ptr<telegram_api::botBusinessConnection> &&connection) {
CHECK(connection != nullptr);
auto business_connection = make_unique<BusinessConnection>(connection);
if (!business_connection->is_valid()) {
LOG(ERROR) << "Receive invalid " << to_string(connection);
return;
}
auto &stored_connection = business_connections_[business_connection->connection_id_];
stored_connection = std::move(business_connection);
send_closure(
G()->td(), &Td::send_update,
td_api::make_object<td_api::updateBusinessConnection>(stored_connection->get_business_connection_object(td_)));
}
} // namespace td

View File

@ -6,9 +6,12 @@
//
#pragma once
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
#include "td/utils/common.h"
#include "td/utils/WaitFreeHashMap.h"
namespace td {
@ -17,8 +20,19 @@ class Td;
class BusinessConnectionManager final : public Actor {
public:
BusinessConnectionManager(Td *td, ActorShared<> parent);
BusinessConnectionManager(const BusinessConnectionManager &) = delete;
BusinessConnectionManager &operator=(const BusinessConnectionManager &) = delete;
BusinessConnectionManager(BusinessConnectionManager &&) = delete;
BusinessConnectionManager &operator=(BusinessConnectionManager &&) = delete;
~BusinessConnectionManager() final;
void on_update_bot_business_connect(telegram_api::object_ptr<telegram_api::botBusinessConnection> &&connection);
private:
struct BusinessConnection;
WaitFreeHashMap<string, unique_ptr<BusinessConnection>> business_connections_;
void tear_down() final;
Td *td_;

View File

@ -12,6 +12,7 @@
#include "td/telegram/AuthManager.h"
#include "td/telegram/AutosaveManager.h"
#include "td/telegram/BoostManager.h"
#include "td/telegram/BusinessConnectionManager.h"
#include "td/telegram/CallbackQueriesManager.h"
#include "td/telegram/CallManager.h"
#include "td/telegram/ChannelId.h"
@ -3089,6 +3090,7 @@ void UpdatesManager::process_qts_update(tl_object_ptr<telegram_api::Update> &&up
}
case telegram_api::updateBotBusinessConnect::ID: {
auto update = move_tl_object_as<telegram_api::updateBotBusinessConnect>(update_ptr);
td_->business_connection_manager_->on_update_bot_business_connect(std::move(update->connection_));
break;
}
case telegram_api::updateBotNewBusinessMessage::ID: {