From 3d43bbb80d112f8d237ef2f1735dab0a97206538 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 26 Feb 2024 19:09:58 +0300 Subject: [PATCH] Add td_api::businessGreetingMessageSettings. --- CMakeLists.txt | 3 ++ SplitSource.php | 1 + td/generate/scheme/td_api.tl | 6 +++ td/telegram/BusinessGreetingMessage.cpp | 64 +++++++++++++++++++++++++ td/telegram/BusinessGreetingMessage.h | 63 ++++++++++++++++++++++++ td/telegram/BusinessGreetingMessage.hpp | 35 ++++++++++++++ td/telegram/BusinessRecipients.h | 2 + 7 files changed, 174 insertions(+) create mode 100644 td/telegram/BusinessGreetingMessage.cpp create mode 100644 td/telegram/BusinessGreetingMessage.h create mode 100644 td/telegram/BusinessGreetingMessage.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bd25801f..4b1f26f89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -301,6 +301,7 @@ set(TDLIB_SOURCE td/telegram/BotCommandScope.cpp td/telegram/BotInfoManager.cpp td/telegram/BotMenuButton.cpp + td/telegram/BusinessGreetingMessage.cpp td/telegram/BusinessRecipients.cpp td/telegram/BusinessWorkHours.cpp td/telegram/CallActor.cpp @@ -581,6 +582,7 @@ set(TDLIB_SOURCE td/telegram/BotCommandScope.h td/telegram/BotInfoManager.h td/telegram/BotMenuButton.h + td/telegram/BusinessGreetingMessage.h td/telegram/BusinessRecipients.h td/telegram/BusinessWorkHours.h td/telegram/CallActor.h @@ -881,6 +883,7 @@ set(TDLIB_SOURCE td/telegram/AuthManager.hpp td/telegram/BackgroundInfo.hpp td/telegram/BackgroundType.hpp + td/telegram/BusinessGreetingMessage.hpp td/telegram/BusinessRecipients.hpp td/telegram/BusinessWorkHours.hpp td/telegram/ChatReactions.hpp diff --git a/SplitSource.php b/SplitSource.php index 1c6f033fe..5d83e5d74 100644 --- a/SplitSource.php +++ b/SplitSource.php @@ -309,6 +309,7 @@ function split_file($file, $chunks, $undo) { 'BotMenuButton|[a-z_]*_menu_button' => 'BotMenuButton', 'boost_manager[_(-](?![.]get[(][)])|BoostManager' => 'BoostManager', 'bot_info_manager[_(-](?![.]get[(][)])|BotInfoManager' => 'BotInfoManager', + 'BusinessGreetingMessage' => 'BusinessGreetingMessage', 'BusinessRecipients' => 'BusinessRecipients', 'BusinessWorkHours' => 'BusinessWorkHours', 'callback_queries_manager[_(-](?![.]get[(][)])|CallbackQueriesManager' => 'CallbackQueriesManager', diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 2f925854e..28b4118c2 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -588,6 +588,12 @@ businessLocation location:location address:string = BusinessLocation; //@exclude_selected If true, then all private chats except the selected are chosen. Otherwise, only the selected chats are chosen businessRecipients chat_ids:vector select_existing_chats:Bool select_new_chats:Bool select_contacts:Bool select_non_contacts:Bool exclude_selected:Bool = BusinessRecipients; +//@description Describes settings for greeting messages that are automatically sent by a Telegram Business account as response to incoming messages in an inactive private chat +//@shortcut_id Unique quick reply shortcut identifier for the greeting messages +//@recipients Chosen recipients of the greeting messages +//@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 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 diff --git a/td/telegram/BusinessGreetingMessage.cpp b/td/telegram/BusinessGreetingMessage.cpp new file mode 100644 index 000000000..f0735e753 --- /dev/null +++ b/td/telegram/BusinessGreetingMessage.cpp @@ -0,0 +1,64 @@ +// +// 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/BusinessGreetingMessage.h" + +#include "td/telegram/ContactsManager.h" +#include "td/telegram/DialogId.h" +#include "td/telegram/DialogManager.h" +#include "td/telegram/Td.h" + +#include "td/utils/algorithm.h" + +namespace td { + +BusinessGreetingMessage::BusinessGreetingMessage( + telegram_api::object_ptr greeting_message) + : shortcut_id_(greeting_message->shortcut_id_) + , recipients_(std::move(greeting_message->recipients_)) + , inactivity_days_(clamp(greeting_message->no_activity_days_ / 7 * 7, 7, 28)) { +} + +BusinessGreetingMessage::BusinessGreetingMessage( + td_api::object_ptr greeting_message) { + if (greeting_message == nullptr) { + return; + } + auto inactivity_days = greeting_message->inactivity_days_; + if (inactivity_days < 7 || inactivity_days > 28 || inactivity_days % 7 != 0) { + return; + } + shortcut_id_ = QuickReplyShortcutId(greeting_message->shortcut_id_); + recipients_ = BusinessRecipients(std::move(greeting_message->recipients_)); + inactivity_days_ = inactivity_days; +} + +td_api::object_ptr +BusinessGreetingMessage::get_business_greeting_message_settings_object(Td *td) const { + if (!is_valid()) { + return nullptr; + } + return td_api::make_object( + shortcut_id_.get(), recipients_.get_business_recipients_object(td), inactivity_days_); +} + +telegram_api::object_ptr +BusinessGreetingMessage::get_input_business_greeting_message(Td *td) const { + return telegram_api::make_object( + shortcut_id_.get(), recipients_.get_input_business_recipients(td), inactivity_days_); +} + +bool operator==(const BusinessGreetingMessage &lhs, const BusinessGreetingMessage &rhs) { + return lhs.shortcut_id_ == rhs.shortcut_id_ && lhs.recipients_ == rhs.recipients_ && + lhs.inactivity_days_ == rhs.inactivity_days_; +} + +StringBuilder &operator<<(StringBuilder &string_builder, const BusinessGreetingMessage &greeting_message) { + return string_builder << "greeting message " << greeting_message.shortcut_id_ << ' ' << greeting_message.recipients_ + << " after " << greeting_message.inactivity_days_ << " inactivity days"; +} + +} // namespace td diff --git a/td/telegram/BusinessGreetingMessage.h b/td/telegram/BusinessGreetingMessage.h new file mode 100644 index 000000000..475954ae0 --- /dev/null +++ b/td/telegram/BusinessGreetingMessage.h @@ -0,0 +1,63 @@ +// +// 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/QuickReplyShortcutId.h" +#include "td/telegram/td_api.h" +#include "td/telegram/telegram_api.h" + +#include "td/utils/common.h" +#include "td/utils/StringBuilder.h" + +namespace td { + +class Td; + +class BusinessGreetingMessage { + public: + BusinessGreetingMessage() = default; + + explicit BusinessGreetingMessage(telegram_api::object_ptr greeting_message); + + explicit BusinessGreetingMessage(td_api::object_ptr greeting_message); + + td_api::object_ptr get_business_greeting_message_settings_object( + Td *td) const; + + telegram_api::object_ptr get_input_business_greeting_message( + Td *td) const; + + bool is_valid() const { + return shortcut_id_.is_server(); + } + + template + void store(StorerT &storer) const; + + template + void parse(ParserT &parser); + + private: + QuickReplyShortcutId shortcut_id_; + BusinessRecipients recipients_; + int32 inactivity_days_ = 0; + + friend bool operator==(const BusinessGreetingMessage &lhs, const BusinessGreetingMessage &rhs); + + friend StringBuilder &operator<<(StringBuilder &string_builder, const BusinessGreetingMessage &greeting_message); +}; + +bool operator==(const BusinessGreetingMessage &lhs, const BusinessGreetingMessage &rhs); + +inline bool operator!=(const BusinessGreetingMessage &lhs, const BusinessGreetingMessage &rhs) { + return !(lhs == rhs); +} + +StringBuilder &operator<<(StringBuilder &string_builder, const BusinessGreetingMessage &greeting_message); + +} // namespace td diff --git a/td/telegram/BusinessGreetingMessage.hpp b/td/telegram/BusinessGreetingMessage.hpp new file mode 100644 index 000000000..10057fd1e --- /dev/null +++ b/td/telegram/BusinessGreetingMessage.hpp @@ -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/BusinessGreetingMessage.h" +#include "td/telegram/BusinessRecipients.hpp" + +#include "td/utils/common.h" +#include "td/utils/tl_helpers.h" + +namespace td { + +template +void BusinessGreetingMessage::store(StorerT &storer) const { + BEGIN_STORE_FLAGS(); + END_STORE_FLAGS(); + td::store(shortcut_id_, storer); + td::store(recipients_, storer); + td::store(inactivity_days_, storer); +} + +template +void BusinessGreetingMessage::parse(ParserT &parser) { + BEGIN_PARSE_FLAGS(); + END_PARSE_FLAGS(); + td::parse(shortcut_id_, parser); + td::parse(recipients_, parser); + td::parse(inactivity_days_, parser); +} + +} // namespace td diff --git a/td/telegram/BusinessRecipients.h b/td/telegram/BusinessRecipients.h index 530bc5a4b..2141bb8b7 100644 --- a/td/telegram/BusinessRecipients.h +++ b/td/telegram/BusinessRecipients.h @@ -19,6 +19,8 @@ class Td; class BusinessRecipients { public: + BusinessRecipients() = default; + explicit BusinessRecipients(telegram_api::object_ptr recipients); explicit BusinessRecipients(td_api::object_ptr recipients);