Add class BusinessConnectedBot.

This commit is contained in:
levlam 2024-03-04 16:06:36 +03:00
parent fbc738c8df
commit a629700b3c
6 changed files with 150 additions and 0 deletions

View File

@ -303,6 +303,7 @@ set(TDLIB_SOURCE
td/telegram/BotMenuButton.cpp
td/telegram/BusinessAwayMessage.cpp
td/telegram/BusinessAwayMessageSchedule.cpp
td/telegram/BusinessConnectedBot.cpp
td/telegram/BusinessGreetingMessage.cpp
td/telegram/BusinessInfo.cpp
td/telegram/BusinessRecipients.cpp
@ -587,6 +588,7 @@ set(TDLIB_SOURCE
td/telegram/BotMenuButton.h
td/telegram/BusinessAwayMessage.h
td/telegram/BusinessAwayMessageSchedule.h
td/telegram/BusinessConnectedBot.h
td/telegram/BusinessGreetingMessage.h
td/telegram/BusinessInfo.h
td/telegram/BusinessRecipients.h
@ -892,6 +894,7 @@ set(TDLIB_SOURCE
td/telegram/BackgroundType.hpp
td/telegram/BusinessAwayMessage.hpp
td/telegram/BusinessAwayMessageSchedule.hpp
td/telegram/BusinessConnectedBot.hpp
td/telegram/BusinessGreetingMessage.hpp
td/telegram/BusinessInfo.hpp
td/telegram/BusinessRecipients.hpp

View File

@ -310,6 +310,7 @@ function split_file($file, $chunks, $undo) {
'boost_manager[_(-](?![.]get[(][)])|BoostManager' => 'BoostManager',
'bot_info_manager[_(-](?![.]get[(][)])|BotInfoManager' => 'BotInfoManager',
'BusinessAwayMessage' => 'BusinessAwayMessage',
'BusinessConnectedBot' => 'BusinessConnectedBot',
'BusinessGreetingMessage' => 'BusinessGreetingMessage',
'BusinessInfo|business_info' => 'BusinessInfo',
'BusinessRecipients' => 'BusinessRecipients',

View File

@ -615,6 +615,12 @@ businessAwayMessageSettings shortcut_id:int32 recipients:businessRecipients sche
//@inactivity_days The number of days after which a chat will be considered as inactive; currently, must be on of 7, 14, 21, or 28
businessGreetingMessageSettings shortcut_id:int32 recipients:businessRecipients inactivity_days:int32 = BusinessGreetingMessageSettings;
//@description Describes a bot connected to a business account
//@bot_user_id User identifier of the bot
//@recipients Private chats that will be accessible to the bot
//@can_reply True, if the bot can send messages to the private chats; false otherwise
businessConnectedBot bot_user_id:int53 recipients:businessRecipients can_reply:Bool = BusinessConnectedBot;
//@description Describes an interval of time when the business is open
//@start_minute The first minute of the interval since start of the week; 0-7*24*60
//@end_minute The first minute after the end of the interval since start of the week; 1-8*24*60

View File

@ -0,0 +1,46 @@
//
// 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)
//
#include "td/telegram/BusinessConnectedBot.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Td.h"
namespace td {
BusinessConnectedBot::BusinessConnectedBot(telegram_api::object_ptr<telegram_api::connectedBot> connected_bot) {
CHECK(connected_bot != nullptr);
user_id_ = UserId(connected_bot->bot_id_);
recipients_ = BusinessRecipients(std::move(connected_bot->recipients_));
can_reply_ = connected_bot->can_reply_;
}
BusinessConnectedBot::BusinessConnectedBot(td_api::object_ptr<td_api::businessConnectedBot> connected_bot) {
if (connected_bot == nullptr) {
return;
}
user_id_ = UserId(connected_bot->bot_user_id_);
recipients_ = BusinessRecipients(std::move(connected_bot->recipients_));
can_reply_ = connected_bot->can_reply_;
}
td_api::object_ptr<td_api::businessConnectedBot> BusinessConnectedBot::get_business_connected_bot_object(Td *td) const {
CHECK(is_valid());
return td_api::make_object<td_api::businessConnectedBot>(
td->contacts_manager_->get_user_id_object(user_id_, "businessConnectedBot"),
recipients_.get_business_recipients_object(td), can_reply_);
}
bool operator==(const BusinessConnectedBot &lhs, const BusinessConnectedBot &rhs) {
return lhs.user_id_ == rhs.user_id_ && lhs.recipients_ == rhs.recipients_ && lhs.can_reply_ == rhs.can_reply_;
}
StringBuilder &operator<<(StringBuilder &string_builder, const BusinessConnectedBot &connected_bot) {
return string_builder << "coneected bot " << connected_bot.user_id_ << ' ' << connected_bot.recipients_ << ' '
<< (connected_bot.can_reply_ ? " that can reply" : " read-only");
}
} // namespace td

View File

@ -0,0 +1,59 @@
//
// 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/BusinessRecipients.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h"
#include "td/utils/common.h"
#include "td/utils/StringBuilder.h"
namespace td {
class Td;
class BusinessConnectedBot {
public:
BusinessConnectedBot() = default;
explicit BusinessConnectedBot(telegram_api::object_ptr<telegram_api::connectedBot> connected_bot);
explicit BusinessConnectedBot(td_api::object_ptr<td_api::businessConnectedBot> connected_bot);
td_api::object_ptr<td_api::businessConnectedBot> get_business_connected_bot_object(Td *td) const;
bool is_valid() const {
return user_id_.is_valid();
}
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
private:
UserId user_id_;
BusinessRecipients recipients_;
bool can_reply_ = false;
friend bool operator==(const BusinessConnectedBot &lhs, const BusinessConnectedBot &rhs);
friend StringBuilder &operator<<(StringBuilder &string_builder, const BusinessConnectedBot &connected_bot);
};
bool operator==(const BusinessConnectedBot &lhs, const BusinessConnectedBot &rhs);
inline bool operator!=(const BusinessConnectedBot &lhs, const BusinessConnectedBot &rhs) {
return !(lhs == rhs);
}
StringBuilder &operator<<(StringBuilder &string_builder, const BusinessConnectedBot &connected_bot);
} // namespace td

View File

@ -0,0 +1,35 @@
//
// 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/BusinessConnectedBot.h"
#include "td/telegram/BusinessRecipients.hpp"
#include "td/utils/common.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
void BusinessConnectedBot::store(StorerT &storer) const {
BEGIN_STORE_FLAGS();
STORE_FLAG(can_reply_);
END_STORE_FLAGS();
td::store(user_id_, storer);
td::store(recipients_, storer);
}
template <class ParserT>
void BusinessConnectedBot::parse(ParserT &parser) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(can_reply_);
END_PARSE_FLAGS();
td::parse(user_id_, parser);
td::parse(recipients_, parser);
}
} // namespace td