mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Add ChatBoostAdded
variant to MessageKind
enum
also add `boost_added` getter to `Message` struct and `filter_boost_added` filter to `MessageFilterExt`
This commit is contained in:
parent
02d7a3cd2e
commit
109454ed84
2 changed files with 54 additions and 11 deletions
|
@ -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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in a new issue