Skip to content

Commit

Permalink
Add service message ChatBoostAdded
Browse files Browse the repository at this point in the history
  • Loading branch information
Desiders committed Feb 27, 2024
1 parent 93e7881 commit d414121
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
6 changes: 5 additions & 1 deletion telers/src/enums/content_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ pub enum ContentType {
PassportData,
#[strum(serialize = "proximity_alert_triggered")]
ProximityAlertTriggered,
#[strum(serialize = "chat_boost_added")]
ChatBoostAdded,
#[strum(serialize = "forum_topic_created")]
ForumTopicCreated,
#[strum(serialize = "forum_topic_edited")]
Expand Down Expand Up @@ -113,7 +115,7 @@ pub enum ContentType {

impl ContentType {
#[must_use]
pub const fn all() -> [ContentType; 51] {
pub const fn all() -> [ContentType; 52] {
[
ContentType::Text,
ContentType::Animation,
Expand Down Expand Up @@ -151,6 +153,7 @@ impl ContentType {
ContentType::WriteAccessAllowed,
ContentType::PassportData,
ContentType::ProximityAlertTriggered,
ContentType::ChatBoostAdded,
ContentType::ForumTopicCreated,
ContentType::ForumTopicEdited,
ContentType::ForumTopicClosed,
Expand Down Expand Up @@ -227,6 +230,7 @@ impl From<&Message> for ContentType {
Message::WriteAccessAllowed(_) => ContentType::WriteAccessAllowed,
Message::PassportData(_) => ContentType::PassportData,
Message::ProximityAlertTriggered(_) => ContentType::ProximityAlertTriggered,
Message::ChatBoostAdded(_) => ContentType::ChatBoostAdded,
Message::ForumTopicCreated(_) => ContentType::ForumTopicCreated,
Message::ForumTopicEdited(_) => ContentType::ForumTopicEdited,
Message::ForumTopicClosed(_) => ContentType::ForumTopicClosed,
Expand Down
2 changes: 2 additions & 0 deletions telers/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub mod callback_query;
pub mod chat;
pub mod chat_administrator_rights;
pub mod chat_boost;
pub mod chat_boost_added;
pub mod chat_boost_removed;
pub mod chat_boost_source;
pub mod chat_boost_source_gift_code;
Expand Down Expand Up @@ -245,6 +246,7 @@ pub use chat::{
};
pub use chat_administrator_rights::ChatAdministratorRights;
pub use chat_boost::ChatBoost;
pub use chat_boost_added::ChatBoostAdded;
pub use chat_boost_removed::ChatBoostRemoved;
pub use chat_boost_source::ChatBoostSource;
pub use chat_boost_source_gift_code::ChatBoostSourceGiftCode;
Expand Down
10 changes: 10 additions & 0 deletions telers/src/types/chat_boost_added.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use serde::Deserialize;

/// This object represents a service message about a user boosting a chat.
/// # Documentation
/// <https://core.telegram.org/bots/api#chatboostadded>
#[derive(Debug, Clone, Hash, PartialEq, Eq, Deserialize)]
pub struct ChatBoostAdded {
/// Number of boosts added by the user
pub boost_count: i64,
}
57 changes: 57 additions & 0 deletions telers/src/types/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub enum Message {
WriteAccessAllowed(Box<WriteAccessAllowed>),
PassportData(Box<PassportData>),
ProximityAlertTriggered(Box<ProximityAlertTriggered>),
ChatBoostAdded(Box<ChatBoostAdded>),
ForumTopicCreated(Box<ForumTopicCreated>),
ForumTopicEdited(Box<ForumTopicEdited>),
ForumTopicClosed(Box<ForumTopicClosed>),
Expand Down Expand Up @@ -1217,6 +1218,21 @@ pub struct ProximityAlertTriggered {
pub triggered: types::ProximityAlertTriggered,
}

#[derive(Debug, Clone, PartialEq, Deserialize, FromEvent)]
#[event(try_from = Update)]
pub struct ChatBoostAdded {
/// Unique message identifier inside this chat
#[serde(rename = "message_id")]
pub id: i64,
/// Date the message was sent in Unix time
pub date: i64,
/// Conversation the message belongs to
pub chat: Chat,
/// Service message: user boosted the chat
#[serde(rename = "boost_added")]
pub added: types::ChatBoostAdded,
}

#[derive(Debug, Clone, PartialEq, Deserialize, FromEvent)]
#[event(try_from = Update)]
pub struct ForumTopicCreated {
Expand Down Expand Up @@ -1595,6 +1611,7 @@ impl Message {
Message::WriteAccessAllowed(message) => message.id,
Message::PassportData(message) => message.id,
Message::ProximityAlertTriggered(message) => message.id,
Message::ChatBoostAdded(message) => message.id,
Message::ForumTopicCreated(message) => message.id,
Message::ForumTopicEdited(message) => message.id,
Message::ForumTopicClosed(message) => message.id,
Expand Down Expand Up @@ -1688,6 +1705,7 @@ impl Message {
Message::WriteAccessAllowed(message) => message.date,
Message::PassportData(message) => message.date,
Message::ProximityAlertTriggered(message) => message.date,
Message::ChatBoostAdded(message) => message.date,
Message::ForumTopicCreated(message) => message.date,
Message::ForumTopicEdited(message) => message.date,
Message::ForumTopicClosed(message) => message.date,
Expand Down Expand Up @@ -1745,6 +1763,7 @@ impl Message {
Message::WriteAccessAllowed(message) => &message.chat,
Message::PassportData(message) => &message.chat,
Message::ProximityAlertTriggered(message) => &message.chat,
Message::ChatBoostAdded(message) => &message.chat,
Message::ForumTopicCreated(message) => &message.chat,
Message::ForumTopicEdited(message) => &message.chat,
Message::ForumTopicClosed(message) => &message.chat,
Expand Down Expand Up @@ -2435,6 +2454,14 @@ impl Message {
}
}

#[must_use]
pub const fn chat_boost_added(&self) -> Option<&types::ChatBoostAdded> {
match self {
Message::ChatBoostAdded(message) => Some(&message.added),
_ => None,
}
}

#[must_use]
pub const fn forum_topic_created(&self) -> Option<&types::ForumTopicCreated> {
match self {
Expand Down Expand Up @@ -2705,6 +2732,7 @@ impl_try_from_message!(SuccessfulPayment, SuccessfulPayment);
impl_try_from_message!(ConnectedWebsite, ConnectedWebsite);
impl_try_from_message!(PassportData, PassportData);
impl_try_from_message!(ProximityAlertTriggered, ProximityAlertTriggered);
impl_try_from_message!(ChatBoostAdded, ChatBoostAdded);
impl_try_from_message!(ForumTopicCreated, ForumTopicCreated);
impl_try_from_message!(ForumTopicEdited, ForumTopicEdited);
impl_try_from_message!(ForumTopicClosed, ForumTopicClosed);
Expand Down Expand Up @@ -2783,6 +2811,7 @@ impl_try_from_update!(SuccessfulPayment);
impl_try_from_update!(ConnectedWebsite);
impl_try_from_update!(PassportData);
impl_try_from_update!(ProximityAlertTriggered);
impl_try_from_update!(ChatBoostAdded);
impl_try_from_update!(ForumTopicCreated);
impl_try_from_update!(ForumTopicEdited);
impl_try_from_update!(ForumTopicClosed);
Expand Down Expand Up @@ -4017,6 +4046,34 @@ mod tests {
}
}

#[test]
fn deserialize_chat_boost_added() {
let jsons = [serde_json::json!({
"message_id": 1,
"date": 0,
"chat": {
"id": -1,
"title": "test",
"type": "channel",
},
"boost_added": {
"boost_count": 1,
},
})];

for json in jsons {
let message_kind = serde_json::from_value(json.clone()).unwrap();
let message: Message = serde_json::from_value(json).unwrap();

match message {
Message::ChatBoostAdded(message) => {
assert_eq!(message, message_kind);
}
_ => panic!("Unexpected message type: {message:?}"),
}
}
}

#[test]
fn deserialize_forum_topic_created() {
let jsons = [serde_json::json!({
Expand Down

0 comments on commit d414121

Please sign in to comment.