tgbot/types/definitions/message/reply.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/// Contains information about a message or a story that is being replied to.
33#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
34pub enum ReplyTo {
35 /// The original message.
36 ///
37 /// Note that the Message object in this field will not contain further
38 /// `reply_to` fields even if it itself is a reply.
39 #[serde(rename = "reply_to_message")]
40 Message(Box<Message>),
41 /// The original story.
42 #[serde(rename = "reply_to_story")]
43 Story(Story),
44}
45
46impl From<Message> for ReplyTo {
47 fn from(value: Message) -> Self {
48 Self::Message(Box::new(value))
49 }
50}
51
52impl From<Story> for ReplyTo {
53 fn from(value: Story) -> Self {
54 Self::Story(value)
55 }
56}
57
58/// Contains information about a message that is being replied to, which may come from another chat or forum topic.
59#[serde_with::skip_serializing_none]
60#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
61pub struct ExternalReplyInfo {
62 /// Origin of the message replied to by the given message.
63 pub origin: MessageOrigin,
64 /// Chat the original message belongs to.
65 ///
66 /// Available only if the chat is a supergroup or a channel.
67 pub chat: Option<Chat>,
68 /// Whether the message media is covered by a spoiler animation.
69 pub has_media_spoiler: Option<bool>,
70 /// Options used for link preview generation for the original message, if it is a text message.
71 pub link_preview_options: Option<LinkPreviewOptions>,
72 /// Unique message identifier inside the original chat.
73 ///
74 /// Available only if the original chat is a supergroup or a channel.
75 pub message_id: Option<Integer>,
76
77 /// Contains data of the message.
78 #[serde(flatten)]
79 pub data: ExternalReplyData,
80}
81
82impl ExternalReplyInfo {
83 /// Creates a new `ExternalReplyInfo`.
84 ///
85 /// # Arguments
86 ///
87 /// * `data` - Data of the message.
88 /// * `origin` - Origin of the message.
89 pub fn new<A, B>(data: A, origin: B) -> Self
90 where
91 A: Into<ExternalReplyData>,
92 B: Into<MessageOrigin>,
93 {
94 Self {
95 origin: origin.into(),
96 chat: None,
97 has_media_spoiler: None,
98 link_preview_options: None,
99 message_id: None,
100 data: data.into(),
101 }
102 }
103
104 /// Sets a new chat.
105 ///
106 /// # Arguments
107 ///
108 /// * `value` - Chat the original message belongs to.
109 pub fn with_chat<T>(mut self, value: T) -> Self
110 where
111 T: Into<Chat>,
112 {
113 self.chat = Some(value.into());
114 self
115 }
116
117 /// Sets a new value for the `has_media_spoiler` flag.
118 ///
119 /// # Arguments
120 ///
121 /// * `value` - Whether the message media is covered by a spoiler animation.
122 pub fn with_has_media_spoiler(mut self, value: bool) -> Self {
123 self.has_media_spoiler = Some(value);
124 self
125 }
126
127 /// Sets new link preview options.
128 ///
129 /// # Arguments
130 ///
131 /// * `value` - Options used for link preview generation for the original message, if it is a text message.
132 pub fn with_link_preview_options(mut self, value: LinkPreviewOptions) -> Self {
133 self.link_preview_options = Some(value);
134 self
135 }
136
137 /// Sets a new message ID.
138 ///
139 /// # Arguments
140 ///
141 /// * `value` - Unique message identifier inside the original chat.
142 pub fn with_message_id(mut self, value: Integer) -> Self {
143 self.message_id = Some(value);
144 self
145 }
146}
147
148/// Contains data of an external reply info.
149#[derive(Clone, Debug, Deserialize, derive_more::From, PartialEq, Serialize)]
150#[serde(rename_all = "snake_case")]
151pub enum ExternalReplyData {
152 /// Message is an animation, information about the animation.
153 Animation(Animation),
154 /// Message is an audio file, information about the file.
155 Audio(Audio),
156 /// Message is a checklist
157 Checklist(Checklist),
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}