apid_telegram_bot/types/message/message.rs
1use serde::{Deserialize, Serialize};
2
3use crate::types::{
4    Animation, Chat, Contact, Dice, Game, Location, MessageAutoDeleteTimerChanged, MessageEntity,
5    PhotoSize, Poll, True, User, VideoChatEnded, VideoChatParticipantsInvited, VideoChatScheduled,
6    VideoChatStarted, WebAppData,
7};
8
9/// This object represents a message.
10#[derive(Debug, PartialEq, Serialize, Deserialize)]
11pub struct Message {
12    /// Unique message identifier inside this chat
13    pub message_id: i32,
14
15    /// Sender of the message; empty for messages sent to channels.
16    /// For backward compatibility, the field contains a fake sender user in non-channel chats,
17    /// if the message was sent on behalf of a chat.
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub from: Option<User>,
20
21    /// Sender of the message, sent on behalf of a chat.
22    /// For example,
23    /// the channel itself for channel posts,
24    /// the supergroup itself for messages from anonymous group administrators,
25    /// the linked channel for messages automatically forwarded to the discussion group.
26    /// For backward compatibility, the field *from* contains a fake sender user in non-channel chats,
27    /// if the message was sent on behalf of a chat.
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub sender_chat: Option<Chat>,
30
31    /// Date the message was sent in Unix time
32    pub date: i32,
33
34    /// Conversation the message belongs to
35    pub chat: Chat,
36
37    /// For forwarded messages, sender of the original message
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub forward_from: Option<User>,
40
41    /// For messages forwarded from channels or from anonymous administrators, information about the original sender chat
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub forward_from_chat: Option<Chat>,
44
45    /// For messages forwarded from channels, identifier of the original message in the channel
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub forward_from_message_id: Option<i32>,
48
49    /// For forwarded messages that were originally sent in channels or by an anonymous chat administrator, signature of the message sender if present
50    #[serde(skip_serializing_if = "Option::is_none")]
51    pub forward_signature: Option<String>,
52
53    /// Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub forward_sender_name: Option<String>,
56
57    /// For forwarded messages, date the original message was sent in Unix time
58    #[serde(skip_serializing_if = "Option::is_none")]
59    pub forward_date: Option<i32>,
60
61    /// True, if the message is a channel post that was automatically forwarded to the connected discussion group
62    #[serde(default, skip_serializing_if = "crate::util::is_false")]
63    pub is_automatic_forward: bool,
64
65    /// For replies, the original message.
66    /// Note that the Message object in this field will not contain further *reply_to_message* fields even if it itself is a reply.
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub reply_to_message: Option<Box<Message>>,
69
70    /// Bot through which the message was sent
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub via_bot: Option<User>,
73
74    /// Date the message was last edited in Unix time
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub edit_date: Option<i32>,
77
78    /// True, if the message can't be forwarded
79    #[serde(default, skip_serializing_if = "crate::util::is_false")]
80    pub has_protected_content: bool,
81
82    /// The unique identifier of a media message group this message belongs to
83    #[serde(skip_serializing_if = "Option::is_none")]
84    pub media_group_id: Option<String>,
85
86    /// Signature of the post author for messages in channels, or the custom title of an anonymous group administrator
87    #[serde(skip_serializing_if = "Option::is_none")]
88    pub author_signature: Option<String>,
89
90    /// The content of the message
91    #[serde(flatten)]
92    pub content: MessageContent,
93
94    /// Service message: data sent by a Web App
95    #[serde(skip_serializing_if = "Option::is_none")]
96    pub web_app_data: Option<WebAppData>,
97
98    /// Inline keyboard attached to the message.
99    /// `login_url` buttons are represented as ordinary `url` buttons.
100    #[serde(skip_serializing_if = "Option::is_none")]
101    pub reply_markup: Option<InlineKeyboardMarkup>,
102}
103
104/// The object representing message content
105#[derive(Debug, PartialEq, Serialize, Deserialize)]
106#[serde(untagged)]
107pub enum MessageContent {
108    /// Message is a text message
109    Text {
110        /// For text messages, the actual UTF-8 text of the message
111        text: String,
112        /// For text messages, special entities like usernames, URLs, bot commands, etc.
113        /// that appear in the text
114        #[serde(default, skip_serializing_if = "Vec::is_empty")]
115        entities: Vec<MessageEntity>,
116    },
117
118    /// Message is an animation
119    Animation {
120        /// Message is an animation, information about the animation.
121        /// For backward compatibility, when this field is set, the *document* field will also be set
122        animation: Animation,
123
124        /// Message is a general file, information about the file
125        document: Document,
126
127        /// Caption for the animation, audio, document, photo, video or voice
128        #[serde(flatten, skip_serializing_if = "Option::is_none")]
129        caption: Option<Caption>,
130    },
131
132    /// Message is an audio file
133    Audio {
134        /// Message is an audio file, information about the file
135        audio: Audio,
136
137        /// Caption for the animation, audio, document, photo, video or voice
138        #[serde(flatten, skip_serializing_if = "Option::is_none")]
139        caption: Option<Caption>,
140    },
141
142    /// Message is a general file
143    Document {
144        /// Message is a general file, information about the file
145        document: Document,
146
147        /// Caption for the animation, audio, document, photo, video or voice
148        #[serde(flatten, skip_serializing_if = "Option::is_none")]
149        caption: Option<Caption>,
150    },
151
152    /// Message is a photo
153    Photo {
154        /// Message is a photo, available sizes of the photo
155        photo: Vec<PhotoSize>,
156
157        /// Caption for the animation, audio, document, photo, video or voice
158        #[serde(flatten, skip_serializing_if = "Option::is_none")]
159        caption: Option<Caption>,
160    },
161
162    /// Message is a sticker
163    Sticker { sticker: Sticker },
164
165    /// Message is a video
166    Video {
167        /// Message is a video, information about the video
168        video: Video,
169
170        /// Caption for the animation, audio, document, photo, video or voice
171        #[serde(flatten, skip_serializing_if = "Option::is_none")]
172        caption: Option<Caption>,
173    },
174
175    /// Message is a [video note](https://telegram.org/blog/video-messages-and-telescope)
176    VideoNote { video_note: VideoNote },
177
178    /// Message is a voice message
179    Voice {
180        /// Message is a voice message, information about the file
181        voice: Voice,
182
183        /// Caption for the animation, audio, document, photo, video or voice
184        #[serde(flatten, skip_serializing_if = "Option::is_none")]
185        caption: Option<Caption>,
186    },
187
188    /// Message is a shared contact
189    Contact { contact: Contact },
190
191    /// Message is a dice with random value
192    Dice { dice: Dice },
193
194    /// Message is a game.
195    /// [More about games »](https://core.telegram.org/bots/api#games)
196    Game { game: Game },
197
198    /// Message is a native poll
199    Poll { poll: Poll },
200
201    /// Message is a venue.
202    Venue {
203        /// Message is a venue, information about the venue.
204        /// For backward compatibility, when this field is set, the *location* field will also be set
205        venue: Venue,
206
207        /// information about the location
208        location: Location,
209    },
210
211    /// Message is a shared location
212    Location { location: Location },
213
214    NewChatMembers {
215        /// New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)
216        new_chat_members: Vec<User>,
217    },
218
219    LeftChatMember {
220        /// A member was removed from the group, information about them (this member may be the bot itself)
221        left_chat_member: User,
222    },
223
224    NewChatTitle {
225        /// A chat title was changed to this value
226        new_chat_title: String,
227    },
228
229    NewChatPhoto {
230        /// A chat photo was change to this value
231        new_chat_photo: Vec<PhotoSize>,
232    },
233
234    /// Service message: the chat photo was deleted
235    DeleteChatPhoto {
236        /// Service message: the chat photo was deleted
237        delete_chat_photo: True,
238    },
239
240    /// Service message: the group has been created
241    GroupChatCreated {
242        /// Service message: the group has been created
243        group_chat_created: True,
244    },
245
246    /// Service message: the supergroup has been created.
247    /// This field can't be received in a message coming through updates,
248    /// because bot can't be a member of a supergroup when it is created.
249    /// It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup.
250    SupergroupChatCreated {
251        /// Service message: the supergroup has been created.
252        /// This field can't be received in a message coming through updates,
253        /// because bot can't be a member of a supergroup when it is created.
254        /// It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup.
255        supergroup_chat_created: True,
256    },
257
258    /// Service message: the channel has been created.
259    /// This field can't be received in a message coming through updates,
260    /// because bot can't be a member of a channel when it is created.
261    /// It can only be found in reply_to_message if someone replies to a very first message in a channel.
262    ChannelChatCreated {
263        /// Service message: the channel has been created.
264        /// This field can't be received in a message coming through updates,
265        /// because bot can't be a member of a channel when it is created.
266        /// It can only be found in reply_to_message if someone replies to a very first message in a channel.
267        channel_chat_created: True,
268    },
269
270    /// Service message: auto-delete timer settings changed in the chat
271    MessageAutoDeleteTimerChanged {
272        /// Service message: auto-delete timer settings changed in the chat
273        message_auto_delete_timer_changed: MessageAutoDeleteTimerChanged,
274    },
275
276    /// The group has been migrated to a supergroup with the specified identifier.
277    /// This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it.
278    /// But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier.
279    MigrateToChatId {
280        /// The group has been migrated to a supergroup with the specified identifier.
281        /// This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it.
282        /// But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier.
283        migrate_to_chat_id: i64,
284    },
285
286    /// The supergroup has been migrated from a group with the specified identifier.
287    /// This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it.
288    /// But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier.
289    MigrateFromChatId {
290        /// The supergroup has been migrated from a group with the specified identifier.
291        /// This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it.
292        /// But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier.
293        migrate_from_chat_id: i64,
294    },
295
296    /// Specified message was pinned.
297    /// Note that the Message object in this field will not contain further *reply_to_message* fields even if it is itself a reply.
298    PinnedMessage {
299        /// Specified message was pinned.
300        /// Note that the Message object in this field will not contain further *reply_to_message* fields even if it is itself a reply.
301        pinned_message: Box<Message>,
302    },
303
304    /// Message is an invoice for a [payment](https://core.telegram.org/bots/api#payments), information about the invoice.
305    /// [More about payments »](https://core.telegram.org/bots/api#payments)
306    Invoice {
307        /// Message is an invoice for a [payment](https://core.telegram.org/bots/api#payments), information about the invoice.
308        /// [More about payments »](https://core.telegram.org/bots/api#payments)
309        invoice: Invoice,
310    },
311
312    /// Message is a service message about a successful payment, information about the payment.
313    /// [More about payments »](https://core.telegram.org/bots/api#payments)
314    SuccessfulPayment {
315        /// Message is a service message about a successful payment, information about the payment.
316        /// [More about payments »](https://core.telegram.org/bots/api#payments)
317        successful_payment: SuccessfulPayment,
318    },
319
320    Login {
321        /// The domain name of the website on which the user has logged in.
322        /// [More about Telegram Login »](https://core.telegram.org/widgets/login)
323        connected_website: String,
324
325        /// Telegram Passport data
326        passport_data: PassportData,
327    },
328
329    /// Service message.
330    /// A user in the chat triggered another user's proximity alert while sharing Live Location.
331    ProximityAlertTriggered {
332        /// Service message.
333        /// A user in the chat triggered another user's proximity alert while sharing Live Location.
334        proximity_alert_triggered: ProximityAlertTriggered,
335    },
336
337    /// Service message: video chat scheduled
338    VideoChatScheduled {
339        /// Service message: video chat scheduled
340        video_chat_scheduled: VideoChatScheduled,
341    },
342
343    /// Service message: video chat started
344    VideoChatStarted {
345        /// Service message: video chat started
346        video_chat_started: VideoChatStarted,
347    },
348
349    /// Service message: video chat ended
350    VideoChatEnded {
351        /// Service message: video chat ended
352        video_chat_ended: VideoChatEnded,
353    },
354
355    /// Service message: new participants invited to a video chat
356    VideoChatParticipantsInvited {
357        /// Service message: new participants invited to a video chat
358        video_chat_participants_invited: VideoChatParticipantsInvited,
359    },
360}
361
362#[derive(Debug, PartialEq, Serialize, Deserialize)]
363pub struct Audio {
364    // TODO:
365    __never_happen: String,
366}
367
368#[derive(Debug, PartialEq, Serialize, Deserialize)]
369pub struct Document {
370    // TODO:
371    __never_happen: String,
372}
373
374#[derive(Debug, PartialEq, Serialize, Deserialize)]
375pub struct Sticker {
376    // TODO:
377    __never_happen: String,
378}
379
380#[derive(Debug, PartialEq, Serialize, Deserialize)]
381pub struct Video {
382    // TODO:
383    __never_happen: String,
384}
385
386#[derive(Debug, PartialEq, Serialize, Deserialize)]
387pub struct VideoNote {
388    // TODO:
389    __never_happen: String,
390}
391
392#[derive(Debug, PartialEq, Serialize, Deserialize)]
393pub struct Voice {
394    // TODO:
395    __never_happen: String,
396}
397
398#[derive(Debug, PartialEq, Serialize, Deserialize)]
399pub struct Venue {
400    // TODO:
401    __never_happen: String,
402}
403
404#[derive(Debug, PartialEq, Serialize, Deserialize)]
405pub struct Invoice {
406    // TODO:
407    __never_happen: String,
408}
409
410#[derive(Debug, PartialEq, Serialize, Deserialize)]
411pub struct SuccessfulPayment {
412    // TODO:
413    __never_happen: String,
414}
415
416#[derive(Debug, PartialEq, Serialize, Deserialize)]
417pub struct PassportData {
418    // TODO:
419    __never_happen: String,
420}
421
422#[derive(Debug, PartialEq, Serialize, Deserialize)]
423pub struct ProximityAlertTriggered {
424    // TODO:
425    __never_happen: String,
426}
427
428#[derive(Debug, PartialEq, Serialize, Deserialize)]
429pub struct InlineKeyboardMarkup {
430    // TODO:
431    __never_happen: String,
432}
433
434/// Caption for the animation, audio, document, photo, video or voice
435#[derive(Debug, PartialEq, Serialize, Deserialize)]
436pub struct Caption {
437    /// Caption text
438    #[serde(rename = "caption")]
439    pub text: String,
440
441    /// For messages with a caption, special entities like usernames, URLs, bot commands, etc.
442    /// that appear in the caption
443    #[serde(default, skip_serializing_if = "Vec::is_empty")]
444    pub caption_entities: Vec<MessageEntity>,
445}