// // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #pragma once #include "td/telegram/BusinessConnectionId.h" #include "td/telegram/DialogId.h" #include "td/telegram/files/FileId.h" #include "td/telegram/MessageEffectId.h" #include "td/telegram/MessageId.h" #include "td/telegram/MessageInputReplyTo.h" #include "td/telegram/net/DcId.h" #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" #include "td/actor/actor.h" #include "td/utils/common.h" #include "td/utils/FlatHashMap.h" #include "td/utils/Promise.h" #include "td/utils/Status.h" #include "td/utils/WaitFreeHashMap.h" #include namespace td { struct InputMessageContent; struct ReplyMarkup; 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; Status check_business_connection(const BusinessConnectionId &connection_id, DialogId dialog_id) const; DcId get_business_connection_dc_id(const BusinessConnectionId &connection_id) const; void on_update_bot_business_connect(telegram_api::object_ptr &&connection); void on_update_bot_new_business_message(const BusinessConnectionId &connection_id, telegram_api::object_ptr &&message, telegram_api::object_ptr &&reply_to_message); void on_update_bot_edit_business_message(const BusinessConnectionId &connection_id, telegram_api::object_ptr &&message, telegram_api::object_ptr &&reply_to_message); void on_update_bot_delete_business_messages(const BusinessConnectionId &connection_id, DialogId dialog_id, vector &&messages); void get_business_connection(const BusinessConnectionId &connection_id, Promise> &&promise); void send_message(BusinessConnectionId business_connection_id, DialogId dialog_id, td_api::object_ptr &&reply_to, bool disable_notification, bool protect_content, MessageEffectId effect_id, td_api::object_ptr &&reply_markup, td_api::object_ptr &&input_message_content, Promise> &&promise); void send_message_album(BusinessConnectionId business_connection_id, DialogId dialog_id, td_api::object_ptr &&reply_to, bool disable_notification, bool protect_content, MessageEffectId effect_id, vector> &&input_message_contents, Promise> &&promise); void edit_business_message_text(BusinessConnectionId business_connection_id, DialogId dialog_id, MessageId message_id, td_api::object_ptr &&reply_markup, td_api::object_ptr &&input_message_content, Promise> &&promise); void edit_business_message_live_location(BusinessConnectionId business_connection_id, DialogId dialog_id, MessageId message_id, td_api::object_ptr &&reply_markup, td_api::object_ptr &&input_location, int32 live_period, int32 heading, int32 proximity_alert_radius, Promise> &&promise); void edit_business_message_media(BusinessConnectionId business_connection_id, DialogId dialog_id, MessageId message_id, td_api::object_ptr &&reply_markup, td_api::object_ptr &&input_message_content, Promise> &&promise); void edit_business_message_caption(BusinessConnectionId business_connection_id, DialogId dialog_id, MessageId message_id, td_api::object_ptr &&reply_markup, td_api::object_ptr &&input_caption, bool invert_media, Promise> &&promise); void edit_business_message_reply_markup(BusinessConnectionId business_connection_id, DialogId dialog_id, MessageId message_id, td_api::object_ptr &&reply_markup, Promise> &&promise); void stop_poll(BusinessConnectionId business_connection_id, DialogId dialog_id, MessageId message_id, td_api::object_ptr &&reply_markup, Promise> &&promise); void get_current_state(vector> &updates) const; private: struct BusinessConnection; struct PendingMessage; class SendBusinessMessageQuery; class SendBusinessMediaQuery; class SendBusinessMultiMediaQuery; class UploadBusinessMediaQuery; class UploadMediaCallback; class UploadThumbnailCallback; class EditBusinessMessageQuery; class StopBusinessPollQuery; struct UploadMediaResult { unique_ptr message_; telegram_api::object_ptr input_media_; }; struct BeingUploadedMedia { unique_ptr message_; telegram_api::object_ptr input_file_; Promise promise_; }; struct MediaGroupSendRequest { size_t finished_count_ = 0; vector> upload_results_; Promise> promise_; }; void tear_down() final; Status check_business_message_id(MessageId message_id) const; void on_get_business_connection(const BusinessConnectionId &connection_id, Result> r_updates); MessageInputReplyTo create_business_message_input_reply_to( td_api::object_ptr &&reply_to); Result process_input_message_content( td_api::object_ptr &&input_message_content); unique_ptr create_business_message_to_send(BusinessConnectionId business_connection_id, DialogId dialog_id, MessageInputReplyTo &&input_reply_to, bool disable_notification, bool protect_content, MessageEffectId effect_id, unique_ptr &&reply_markup, InputMessageContent &&input_content) const; void do_send_message(unique_ptr &&message, Promise> &&promise); void process_sent_business_message(telegram_api::object_ptr &&updates_ptr, Promise> &&promise); static FileId get_message_file_id(const unique_ptr &message); FileId get_message_thumbnail_file_id(const unique_ptr &message, FileId file_id) const; void upload_media(unique_ptr &&message, Promise &&promise, vector bad_parts = {}); void complete_send_media(unique_ptr &&message, telegram_api::object_ptr &&input_media, Promise> &&promise); void on_upload_media(FileId file_id, telegram_api::object_ptr input_file); void on_upload_media_error(FileId file_id, Status status); void on_upload_thumbnail(FileId thumbnail_file_id, telegram_api::object_ptr thumbnail_input_file); void do_upload_media(BeingUploadedMedia &&being_uploaded_media, telegram_api::object_ptr input_thumbnail); void complete_upload_media(unique_ptr &&message, telegram_api::object_ptr &&media, Promise &&promise); int64 generate_new_media_album_id(); void on_upload_message_album_media(int64 request_id, size_t media_pos, Result &&result); void process_sent_business_message_album(telegram_api::object_ptr &&updates_ptr, Promise> &&promise); void do_edit_business_message_media(Result &&result, Promise> &&promise); td_api::object_ptr get_update_business_connection( const BusinessConnection *connection) const; WaitFreeHashMap, BusinessConnectionIdHash> business_connections_; FlatHashMap>>, BusinessConnectionIdHash> get_business_connection_queries_; int64 current_media_group_send_request_id_ = 0; FlatHashMap media_group_send_requests_; std::shared_ptr upload_media_callback_; std::shared_ptr upload_thumbnail_callback_; FlatHashMap being_uploaded_files_; FlatHashMap being_uploaded_thumbnails_; Td *td_; ActorShared<> parent_; }; } // namespace td