tgbot/types/message/reply/
mod.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4use crate::types::{
5    Animation,
6    Audio,
7    Chat,
8    Checklist,
9    Contact,
10    Dice,
11    Document,
12    Game,
13    Giveaway,
14    GiveawayWinners,
15    Integer,
16    Invoice,
17    LinkPreviewOptions,
18    Location,
19    Message,
20    MessageOrigin,
21    PaidMediaInfo,
22    PhotoSize,
23    Poll,
24    Sticker,
25    Story,
26    Venue,
27    Video,
28    VideoNote,
29    Voice,
30};
31
32#[cfg(test)]
33mod tests;
34
35/// Contains information about a message or a story that is being replied to.
36#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
37pub enum ReplyTo {
38    /// The original message.
39    ///
40    /// Note that the Message object in this field will not contain further
41    /// `reply_to` fields even if it itself is a reply.
42    #[serde(rename = "reply_to_message")]
43    Message(Box<Message>),
44    /// The original story.
45    #[serde(rename = "reply_to_story")]
46    Story(Story),
47}
48
49impl From<Message> for ReplyTo {
50    fn from(value: Message) -> Self {
51        Self::Message(Box::new(value))
52    }
53}
54
55impl From<Story> for ReplyTo {
56    fn from(value: Story) -> Self {
57        Self::Story(value)
58    }
59}
60
61/// Contains information about a message that is being replied to, which may come from another chat or forum topic.
62#[serde_with::skip_serializing_none]
63#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
64pub struct ExternalReplyInfo {
65    /// Origin of the message replied to by the given message.
66    pub origin: MessageOrigin,
67    /// Chat the original message belongs to.
68    ///
69    /// Available only if the chat is a supergroup or a channel.
70    pub chat: Option<Chat>,
71    /// Whether the message media is covered by a spoiler animation.
72    pub has_media_spoiler: Option<bool>,
73    /// Options used for link preview generation for the original message, if it is a text message.
74    pub link_preview_options: Option<LinkPreviewOptions>,
75    /// Unique message identifier inside the original chat.
76    ///
77    /// Available only if the original chat is a supergroup or a channel.
78    pub message_id: Option<Integer>,
79
80    /// Contains data of the message.
81    #[serde(flatten)]
82    pub data: ExternalReplyData,
83}
84
85impl ExternalReplyInfo {
86    /// Creates a new `ExternalReplyInfo`.
87    ///
88    /// # Arguments
89    ///
90    /// * `data` - Data of the message.
91    /// * `origin` - Origin of the message.
92    pub fn new<A, B>(data: A, origin: B) -> Self
93    where
94        A: Into<ExternalReplyData>,
95        B: Into<MessageOrigin>,
96    {
97        Self {
98            origin: origin.into(),
99            chat: None,
100            has_media_spoiler: None,
101            link_preview_options: None,
102            message_id: None,
103            data: data.into(),
104        }
105    }
106
107    /// Sets a new chat.
108    ///
109    /// # Arguments
110    ///
111    /// * `value` - Chat the original message belongs to.
112    pub fn with_chat<T>(mut self, value: T) -> Self
113    where
114        T: Into<Chat>,
115    {
116        self.chat = Some(value.into());
117        self
118    }
119
120    /// Sets a new value for the `has_media_spoiler` flag.
121    ///
122    /// # Arguments
123    ///
124    /// * `value` - Whether the message media is covered by a spoiler animation.
125    pub fn with_has_media_spoiler(mut self, value: bool) -> Self {
126        self.has_media_spoiler = Some(value);
127        self
128    }
129
130    /// Sets new link preview options.
131    ///
132    /// # Arguments
133    ///
134    /// * `value` - Options used for link preview generation for the original message, if it is a text message.
135    pub fn with_link_preview_options(mut self, value: LinkPreviewOptions) -> Self {
136        self.link_preview_options = Some(value);
137        self
138    }
139
140    /// Sets a new message ID.
141    ///
142    /// # Arguments
143    ///
144    /// * `value` - Unique message identifier inside the original chat.
145    pub fn with_message_id(mut self, value: Integer) -> Self {
146        self.message_id = Some(value);
147        self
148    }
149}
150
151/// Contains data of an external reply info.
152#[derive(Clone, Debug, Deserialize, derive_more::From, PartialEq, Serialize)]
153#[serde(rename_all = "snake_case")]
154pub enum ExternalReplyData {
155    /// Message is an animation, information about the animation.
156    Animation(Animation),
157    /// Message is an audio file, information about the file.
158    Audio(Audio),
159    /// Message is a checklist
160    Checklist(Checklist),
161    /// Message is a shared contact, information about the contact.
162    Contact(Contact),
163    /// Message is a dice with random value.
164    Dice(Dice),
165    /// Message is a general file, information about the file.
166    Document(Document),
167    /// Message is a game, information about the game.
168    Game(Game),
169    /// Message is a scheduled giveaway, information about the giveaway.
170    Giveaway(Giveaway),
171    /// A giveaway with public winners was completed.
172    GiveawayWinners(GiveawayWinners),
173    /// Message is an invoice for a payment, information about the invoice.
174    Invoice(Invoice),
175    /// Message is a shared location, information about the location.
176    Location(Location),
177    /// Message contains paid media, information about the paid media.
178    PaidMedia(PaidMediaInfo),
179    /// Message is a photo, available sizes of the photo.
180    Photo(Vec<PhotoSize>),
181    /// Message is a native poll, information about the poll.
182    Poll(Poll),
183    /// Message is a sticker, information about the sticker.
184    Sticker(Sticker),
185    /// Message is a forwarded story.
186    Story(Story),
187    /// Message is a venue, information about the venue.
188    Venue(Venue),
189    /// Message is a video, information about the video.
190    Video(Video),
191    /// Message is a video note, information about the video message.
192    VideoNote(VideoNote),
193    /// Message is a voice message, information about the file.
194    Voice(Voice),
195    /// Contains arbitrary data for future variants.
196    #[serde(untagged)]
197    Unknown(Value),
198}