diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 750700e8..1b2fc016 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -5,15 +5,15 @@ use serde::{Deserialize, Serialize}; use url::Url; use crate::types::{ - Animation, Audio, BareChatId, Chat, ChatId, ChatShared, Contact, Dice, Document, - ExternalReplyInfo, ForumTopicClosed, ForumTopicCreated, ForumTopicEdited, ForumTopicReopened, - Game, GeneralForumTopicHidden, GeneralForumTopicUnhidden, Giveaway, GiveawayCompleted, - GiveawayCreated, GiveawayWinners, InlineKeyboardMarkup, Invoice, LinkPreviewOptions, Location, - MaybeInaccessibleMessage, MessageAutoDeleteTimerChanged, MessageEntity, MessageEntityRef, - MessageId, MessageOrigin, PassportData, PhotoSize, Poll, ProximityAlertTriggered, Sticker, - Story, SuccessfulPayment, TextQuote, ThreadId, True, User, UsersShared, Venue, Video, - VideoChatEnded, VideoChatParticipantsInvited, VideoChatScheduled, VideoChatStarted, VideoNote, - Voice, WebAppData, WriteAccessAllowed, + Animation, Audio, BareChatId, Chat, ChatBoostAdded, ChatId, ChatShared, Contact, Dice, + Document, ExternalReplyInfo, ForumTopicClosed, ForumTopicCreated, ForumTopicEdited, + ForumTopicReopened, Game, GeneralForumTopicHidden, GeneralForumTopicUnhidden, Giveaway, + GiveawayCompleted, GiveawayCreated, GiveawayWinners, InlineKeyboardMarkup, Invoice, + LinkPreviewOptions, Location, MaybeInaccessibleMessage, MessageAutoDeleteTimerChanged, + MessageEntity, MessageEntityRef, MessageId, MessageOrigin, PassportData, PhotoSize, Poll, + ProximityAlertTriggered, Sticker, Story, SuccessfulPayment, TextQuote, ThreadId, True, User, + UsersShared, Venue, Video, VideoChatEnded, VideoChatParticipantsInvited, VideoChatScheduled, + VideoChatStarted, VideoNote, Voice, WebAppData, WriteAccessAllowed, }; /// This object represents a message. @@ -84,6 +84,7 @@ pub enum MessageKind { PassportData(MessagePassportData), Dice(MessageDice), ProximityAlertTriggered(MessageProximityAlertTriggered), + ChatBoostAdded(MessageChatBoostAdded), ForumTopicCreated(MessageForumTopicCreated), ForumTopicEdited(MessageForumTopicEdited), ForumTopicClosed(MessageForumTopicClosed), @@ -553,6 +554,13 @@ pub struct MessageProximityAlertTriggered { pub proximity_alert_triggered: ProximityAlertTriggered, } +#[serde_with::skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct MessageChatBoostAdded { + /// Service message. User boosted the chat. + pub boost_added: ChatBoostAdded, +} + #[serde_with::skip_serializing_none] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct MessageWriteAccessAllowed { @@ -696,8 +704,8 @@ mod getters { }; use super::{ - MessageForumTopicClosed, MessageForumTopicCreated, MessageForumTopicEdited, - MessageForumTopicReopened, MessageGeneralForumTopicHidden, + MessageChatBoostAdded, MessageForumTopicClosed, MessageForumTopicCreated, + MessageForumTopicEdited, MessageForumTopicReopened, MessageGeneralForumTopicHidden, MessageGeneralForumTopicUnhidden, MessageGiveaway, MessageGiveawayCompleted, MessageGiveawayCreated, MessageGiveawayWinners, MessageMessageAutoDeleteTimerChanged, MessageVideoChatEnded, MessageVideoChatScheduled, MessageVideoChatStarted, @@ -1367,6 +1375,14 @@ mod getters { } } + #[must_use] + pub fn boost_added(&self) -> Option<&types::ChatBoostAdded> { + match &self.kind { + ChatBoostAdded(MessageChatBoostAdded { boost_added }) => Some(boost_added), + _ => None, + } + } + #[must_use] pub fn forum_topic_created(&self) -> Option<&types::ForumTopicCreated> { match &self.kind { @@ -2675,4 +2691,30 @@ mod tests { } ) } + + #[test] + fn chat_boost_added() { + let json = r#"{ + "message_id": 28, + "sender_chat": { + "id": -1002236736395, + "title": "Test", + "type": "channel" + }, + "chat": { + "id": -1002236736395, + "title": "Test", + "type": "channel" + }, + "date": 1721162702, + "boost_added": { + "boost_count": 4 + } + }"#; + let message: Message = from_str(json).unwrap(); + assert_eq!( + message.boost_added().expect("Failed to get ChatBoostAdded from Message!"), + &ChatBoostAdded { boost_count: 4 } + ) + } } diff --git a/crates/teloxide/src/dispatching/filter_ext.rs b/crates/teloxide/src/dispatching/filter_ext.rs index 1f7394e3..b6c0862a 100644 --- a/crates/teloxide/src/dispatching/filter_ext.rs +++ b/crates/teloxide/src/dispatching/filter_ext.rs @@ -114,6 +114,7 @@ define_message_ext! { (filter_passport_data, Message::passport_data), (filter_dice, Message::dice), (filter_proximity_alert_triggered, Message::proximity_alert_triggered), + (filter_boost_added, Message::boost_added), (filter_forum_topic_created, Message::forum_topic_created), (filter_forum_topic_edited, Message::forum_topic_edited), (filter_forum_topic_closed, Message::forum_topic_closed),