diff --git a/crates/teloxide-core/src/types.rs b/crates/teloxide-core/src/types.rs index 827fbc3e..707eb90f 100644 --- a/crates/teloxide-core/src/types.rs +++ b/crates/teloxide-core/src/types.rs @@ -114,6 +114,7 @@ pub use story::*; pub use successful_payment::*; pub use switch_inline_query_chosen_chat::*; pub use target_message::*; +pub use text_quote::*; pub use thread_id::*; pub use unit_false::*; pub use unit_true::*; @@ -221,6 +222,7 @@ mod story; mod successful_payment; mod switch_inline_query_chosen_chat; mod target_message; +mod text_quote; mod thread_id; mod unit_false; mod unit_true; diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index 48cde3c6..ccbacbe5 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -10,9 +10,9 @@ use crate::types::{ GeneralForumTopicHidden, GeneralForumTopicUnhidden, InlineKeyboardMarkup, Invoice, Location, MaybeInaccessibleMessage, MessageAutoDeleteTimerChanged, MessageEntity, MessageEntityRef, MessageId, MessageOrigin, PassportData, PhotoSize, Poll, ProximityAlertTriggered, Sticker, - Story, SuccessfulPayment, ThreadId, True, User, UsersShared, Venue, Video, VideoChatEnded, - VideoChatParticipantsInvited, VideoChatScheduled, VideoChatStarted, VideoNote, Voice, - WebAppData, WriteAccessAllowed, + Story, SuccessfulPayment, TextQuote, ThreadId, True, User, UsersShared, Venue, Video, + VideoChatEnded, VideoChatParticipantsInvited, VideoChatScheduled, VideoChatStarted, VideoNote, + Voice, WebAppData, WriteAccessAllowed, }; /// This object represents a message. @@ -110,6 +110,10 @@ pub struct MessageCommon { /// itself is a reply. pub reply_to_message: Option>, + /// For replies that quote part of the original message, the quoted part of + /// the message + pub quote: Option, + /// Date the message was last edited in Unix time. #[serde(default, with = "crate::types::serde_opt_date_from_unix_timestamp")] pub edit_date: Option>, @@ -637,7 +641,7 @@ mod getters { MessageLeftChatMember, MessageNewChatMembers, MessageNewChatPhoto, MessageNewChatTitle, MessageOrigin, MessagePassportData, MessagePinned, MessageProximityAlertTriggered, MessageSuccessfulPayment, MessageSupergroupChatCreated, MessageUsersShared, - MessageVideoChatParticipantsInvited, PhotoSize, User, + MessageVideoChatParticipantsInvited, PhotoSize, TextQuote, User, }; use super::{ @@ -686,6 +690,14 @@ mod getters { } } + #[must_use] + pub fn quote(&self) -> Option<&TextQuote> { + match &self.kind { + Common(MessageCommon { quote, .. }) => quote.as_ref(), + _ => None, + } + } + #[must_use] pub fn forward_date(&self) -> Option> { self.forward_origin().map(|f| f.date()) diff --git a/crates/teloxide-core/src/types/text_quote.rs b/crates/teloxide-core/src/types/text_quote.rs new file mode 100644 index 00000000..eda8811e --- /dev/null +++ b/crates/teloxide-core/src/types/text_quote.rs @@ -0,0 +1,24 @@ +use serde::{Deserialize, Serialize}; + +use crate::types::MessageEntity; + +/// This object contains information about the quoted part of a message that is +/// replied to by the given message. +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct TextQuote { + /// Text of the quoted part of a message that is replied to by the given + /// message + pub text: String, + /// Special entities that appear in the quote. Currently, only _bold_, + /// _italic_, _underline_, _strikethrough_, _spoiler_, and + /// _custom_emoji_ entities are kept in quotes. + #[serde(default)] + pub entities: Vec, + /// Approximate quote position in the original message in UTF-16 code units + /// as specified by the sender + pub position: u32, + /// True, if the quote was chosen manually by the message sender. Otherwise, + /// the quote was added automatically by the server. + #[serde(default)] + pub is_manual: bool, +} diff --git a/crates/teloxide-core/src/types/update.rs b/crates/teloxide-core/src/types/update.rs index 66906ead..e3e3e14c 100644 --- a/crates/teloxide-core/src/types/update.rs +++ b/crates/teloxide-core/src/types/update.rs @@ -456,6 +456,7 @@ mod test { }), reply_to_message: None, forward_origin: None, + quote: None, edit_date: None, media_kind: MediaKind::Text(MediaText { text: String::from("hello there"),