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