Support Away messages sent only when the user is offline.

This commit is contained in:
levlam 2024-03-01 14:44:42 +03:00
parent 00e9793f09
commit 60ee05aef7
7 changed files with 32 additions and 22 deletions

View File

@ -578,8 +578,8 @@ chatLocation location:location address:string = ChatLocation;
//@class BusinessAwayMessageSchedule @description Describes conditions for sending of away messages by a Telegram Business account
//@description Send away messages if the account was online more than 10 minutes
businessAwayMessageScheduleOffline = BusinessAwayMessageSchedule;
//@description Send away messages always
businessAwayMessageScheduleAlways = BusinessAwayMessageSchedule;
//@description Send away messages outside of the business opening hours
businessAwayMessageScheduleOutsideOfOpeningHours = BusinessAwayMessageSchedule;
@ -606,7 +606,8 @@ businessRecipients chat_ids:vector<int53> select_existing_chats:Bool select_new_
//@shortcut_id Unique quick reply shortcut identifier for the away messages
//@recipients Chosen recipients of the away messages
//@schedule Settings used to check whether the current user is away
businessAwayMessageSettings shortcut_id:int32 recipients:businessRecipients schedule:BusinessAwayMessageSchedule = BusinessAwayMessageSettings;
//@offline_only True, if the messages must not be sent if the account was online in the last 10 minutes
businessAwayMessageSettings shortcut_id:int32 recipients:businessRecipients schedule:BusinessAwayMessageSchedule offline_only:Bool = BusinessAwayMessageSettings;
//@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

View File

@ -23,6 +23,7 @@ BusinessAwayMessage::BusinessAwayMessage(telegram_api::object_ptr<telegram_api::
shortcut_id_ = QuickReplyShortcutId(away_message->shortcut_id_);
recipients_ = BusinessRecipients(std::move(away_message->recipients_));
schedule_ = BusinessAwayMessageSchedule(std::move(away_message->schedule_));
offline_only_ = away_message->offline_only_;
}
BusinessAwayMessage::BusinessAwayMessage(td_api::object_ptr<td_api::businessAwayMessageSettings> away_message) {
@ -32,6 +33,7 @@ BusinessAwayMessage::BusinessAwayMessage(td_api::object_ptr<td_api::businessAway
shortcut_id_ = QuickReplyShortcutId(away_message->shortcut_id_);
recipients_ = BusinessRecipients(std::move(away_message->recipients_));
schedule_ = BusinessAwayMessageSchedule(std::move(away_message->schedule_));
offline_only_ = away_message->offline_only_;
}
td_api::object_ptr<td_api::businessAwayMessageSettings> BusinessAwayMessage::get_business_away_message_settings_object(
@ -41,24 +43,28 @@ td_api::object_ptr<td_api::businessAwayMessageSettings> BusinessAwayMessage::get
}
return td_api::make_object<td_api::businessAwayMessageSettings>(
shortcut_id_.get(), recipients_.get_business_recipients_object(td),
schedule_.get_business_away_message_schedule_object());
schedule_.get_business_away_message_schedule_object(), offline_only_);
}
telegram_api::object_ptr<telegram_api::inputBusinessAwayMessage> BusinessAwayMessage::get_input_business_away_message(
Td *td) const {
int32 flags = 0;
if (offline_only_) {
flags |= telegram_api::inputBusinessAwayMessage::OFFLINE_ONLY_MASK;
}
return telegram_api::make_object<telegram_api::inputBusinessAwayMessage>(
flags, false /*ignored*/, shortcut_id_.get(), schedule_.get_input_business_away_message_schedule(),
recipients_.get_input_business_recipients(td));
}
bool operator==(const BusinessAwayMessage &lhs, const BusinessAwayMessage &rhs) {
return lhs.shortcut_id_ == rhs.shortcut_id_ && lhs.recipients_ == rhs.recipients_ && lhs.schedule_ == rhs.schedule_;
return lhs.shortcut_id_ == rhs.shortcut_id_ && lhs.recipients_ == rhs.recipients_ && lhs.schedule_ == rhs.schedule_ &&
lhs.offline_only_ == rhs.offline_only_;
}
StringBuilder &operator<<(StringBuilder &string_builder, const BusinessAwayMessage &away_message) {
return string_builder << "away message " << away_message.shortcut_id_ << ' ' << away_message.recipients_ << ' '
<< away_message.schedule_;
<< away_message.schedule_ << (away_message.offline_only_ ? " only offline" : "");
}
} // namespace td

View File

@ -49,6 +49,7 @@ class BusinessAwayMessage {
QuickReplyShortcutId shortcut_id_;
BusinessRecipients recipients_;
BusinessAwayMessageSchedule schedule_;
bool offline_only_ = false;
friend bool operator==(const BusinessAwayMessage &lhs, const BusinessAwayMessage &rhs);

View File

@ -18,6 +18,7 @@ namespace td {
template <class StorerT>
void BusinessAwayMessage::store(StorerT &storer) const {
BEGIN_STORE_FLAGS();
STORE_FLAG(offline_only_);
END_STORE_FLAGS();
td::store(shortcut_id_, storer);
td::store(recipients_, storer);
@ -27,6 +28,7 @@ void BusinessAwayMessage::store(StorerT &storer) const {
template <class ParserT>
void BusinessAwayMessage::parse(ParserT &parser) {
BEGIN_PARSE_FLAGS();
PARSE_FLAG(offline_only_);
END_PARSE_FLAGS();
td::parse(shortcut_id_, parser);
td::parse(recipients_, parser);

View File

@ -13,7 +13,7 @@ BusinessAwayMessageSchedule::BusinessAwayMessageSchedule(
CHECK(schedule != nullptr);
switch (schedule->get_id()) {
case telegram_api::businessAwayMessageScheduleAlways::ID:
type_ = Type::Offline;
type_ = Type::Always;
break;
case telegram_api::businessAwayMessageScheduleOutsideWorkHours::ID:
type_ = Type::OutsideOfWorkHours;
@ -36,8 +36,8 @@ BusinessAwayMessageSchedule::BusinessAwayMessageSchedule(
return;
}
switch (schedule->get_id()) {
case td_api::businessAwayMessageScheduleOffline::ID:
type_ = Type::Offline;
case td_api::businessAwayMessageScheduleAlways::ID:
type_ = Type::Always;
break;
case td_api::businessAwayMessageScheduleOutsideOfOpeningHours::ID:
type_ = Type::OutsideOfWorkHours;
@ -57,8 +57,8 @@ BusinessAwayMessageSchedule::BusinessAwayMessageSchedule(
td_api::object_ptr<td_api::BusinessAwayMessageSchedule>
BusinessAwayMessageSchedule::get_business_away_message_schedule_object() const {
switch (type_) {
case Type::Offline:
return td_api::make_object<td_api::businessAwayMessageScheduleOffline>();
case Type::Always:
return td_api::make_object<td_api::businessAwayMessageScheduleAlways>();
case Type::OutsideOfWorkHours:
return td_api::make_object<td_api::businessAwayMessageScheduleOutsideOfOpeningHours>();
case Type::Custom:
@ -72,7 +72,7 @@ BusinessAwayMessageSchedule::get_business_away_message_schedule_object() const {
telegram_api::object_ptr<telegram_api::BusinessAwayMessageSchedule>
BusinessAwayMessageSchedule::get_input_business_away_message_schedule() const {
switch (type_) {
case Type::Offline:
case Type::Always:
return telegram_api::make_object<telegram_api::businessAwayMessageScheduleAlways>();
case Type::OutsideOfWorkHours:
return telegram_api::make_object<telegram_api::businessAwayMessageScheduleOutsideWorkHours>();
@ -90,10 +90,10 @@ bool operator==(const BusinessAwayMessageSchedule &lhs, const BusinessAwayMessag
StringBuilder &operator<<(StringBuilder &string_builder, const BusinessAwayMessageSchedule &schedule) {
switch (schedule.type_) {
case BusinessAwayMessageSchedule::Type::Offline:
return string_builder << "sent offline";
case BusinessAwayMessageSchedule::Type::Always:
return string_builder << "sent always";
case BusinessAwayMessageSchedule::Type::OutsideOfWorkHours:
return string_builder << "sent outside of work hours";
return string_builder << "sent outside of opening hours";
case BusinessAwayMessageSchedule::Type::Custom:
return string_builder << "sent from " << schedule.start_date_ << " to " << schedule.end_date_;
default:

View File

@ -33,8 +33,8 @@ class BusinessAwayMessageSchedule {
void parse(ParserT &parser);
private:
enum class Type : int32 { Offline, OutsideOfWorkHours, Custom };
Type type_ = Type::Offline;
enum class Type : int32 { Always, OutsideOfWorkHours, Custom };
Type type_ = Type::Always;
int32 start_date_ = 0;
int32 end_date_ = 0;

View File

@ -5984,7 +5984,7 @@ class CliClient final : public Actor {
rand_bool(), rand_bool(), rand_bool()),
inactivity_days)));
}
} else if (op == "sbams") {
} else if (op == "sbams" || op == "sbamso") {
ShortcutId shortcut_id;
string chat_ids;
string schedule;
@ -5993,9 +5993,9 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::setBusinessAwayMessageSettings>(nullptr));
} else {
td_api::object_ptr<td_api::BusinessAwayMessageSchedule> schedule_object;
if (schedule[0] == 'o') {
schedule_object = td_api::make_object<td_api::businessAwayMessageScheduleOffline>();
} else if (schedule[0] == 'h') {
if (schedule[0] == 'a') {
schedule_object = td_api::make_object<td_api::businessAwayMessageScheduleAlways>();
} else if (schedule[0] == 'o') {
schedule_object = td_api::make_object<td_api::businessAwayMessageScheduleOutsideOfOpeningHours>();
} else {
auto start_date = to_integer<int32>(schedule);
@ -6007,7 +6007,7 @@ class CliClient final : public Actor {
shortcut_id,
td_api::make_object<td_api::businessRecipients>(as_chat_ids(chat_ids), rand_bool(), rand_bool(),
rand_bool(), rand_bool(), rand_bool()),
std::move(schedule_object))));
std::move(schedule_object), op == "sbamso")));
}
} else if (op == "sco") {
SearchQuery query;