Skip to main content

tgbot/types/definitions/message/data/
mod.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value as JsonValue;
3
4use crate::types::{
5    Animation,
6    Audio,
7    ChatBackground,
8    Checklist,
9    ChecklistTasksAdded,
10    ChecklistTasksDone,
11    Contact,
12    Dice,
13    Document,
14    ForumTopicIconColor,
15    Game,
16    GiftInfo,
17    Giveaway,
18    GiveawayCompleted,
19    GiveawayCreated,
20    GiveawayWinners,
21    Integer,
22    Invoice,
23    LivePhoto,
24    Location,
25    MaybeInaccessibleMessage,
26    PaidMediaInfo,
27    PassportData,
28    PhotoSize,
29    Poll,
30    RefundedPayment,
31    RichMessage,
32    SharedUser,
33    Sticker,
34    Story,
35    SuccessfulPayment,
36    SuggestedPostApprovalFailed,
37    SuggestedPostApproved,
38    SuggestedPostDeclined,
39    SuggestedPostPaid,
40    SuggestedPostRefunded,
41    Text,
42    TextEntities,
43    True,
44    UniqueGiftInfo,
45    User,
46    Venue,
47    Video,
48    VideoNote,
49    Voice,
50    WebAppData,
51};
52
53/// Represents a message data.
54#[derive(Clone, Debug, Deserialize, Serialize)]
55#[serde(from = "RawMessageData", into = "RawMessageData")]
56pub enum MessageData {
57    /// Information about the animation.
58    Animation(Animation),
59    /// Auto-delete timer settings changed.
60    AutoDeleteTimerChanged(MessageDataAutoDeleteTimer),
61    /// Service message: user boosted the chat.
62    ///
63    /// Contains a number of boosts added by the user.
64    BoostAdded(Integer),
65    /// The channel has been created.
66    ///
67    /// This field can‘t be received in a message coming through updates,
68    /// because bot can’t be a member of a channel when it is created.
69    /// It can only be found in the `reply_to` field of the [`crate::types::Message`] struct
70    /// if someone replies to a very first message in a channel.
71    ChannelChatCreated,
72    /// Chat background set.
73    ChatBackgroundSet(ChatBackground),
74    /// Describes a service message about an ownership change in the chat.
75    ChatOwnerChanged(User),
76    /// Describes a service message about the chat owner leaving the chat.
77    ///
78    /// Optional user is the user which will be the new owner of the chat
79    /// if the previous owner does not return to the chat.
80    ChatOwnerLeft(Option<User>),
81    /// A chat was shared with the bot.
82    ChatShared(MessageDataChatShared),
83    /// Message is a checklist.
84    Checklist(Checklist),
85    /// Tasks were added to a checklist.
86    ChecklistTasksAdded(ChecklistTasksAdded),
87    /// Some tasks in a checklist were marked as done or not done.
88    ChecklistTasksDone(ChecklistTasksDone),
89    /// The domain name of the website on which the user has logged in.
90    ConnectedWebsite(String),
91    /// Information about the shared contact.
92    Contact(Contact),
93    /// The chat photo was deleted.
94    DeleteChatPhoto,
95    /// A dice with a random value.
96    Dice(Dice),
97    /// The price for paid messages in the corresponding direct messages chat of a channel has changed.
98    DirectMessagePriceChanged(MessageDataDirectMessagePriceChanged),
99    /// Forum topic closed.
100    ForumTopicClosed,
101    /// Forum topic created.
102    ForumTopicCreated(MessageDataForumTopicCreated),
103    /// Forum topic edited.
104    ForumTopicEdited(MessageDataForumTopicEdited),
105    /// Forum topic reopened.
106    ForumTopicReopened,
107    /// Information about the game.
108    Game(Game),
109    /// A service message about a sent or received regular gift.
110    Gift(GiftInfo),
111    /// A service message about upgrade of a gift was purchased after the gift was sent.
112    GiftUpgradeSent(GiftInfo),
113    /// The 'General' forum topic hidden.
114    GeneralForumTopicHidden,
115    /// The 'General' forum topic unhidden.
116    GeneralForumTopicUnhidden,
117    /// A scheduled giveaway.
118    Giveaway(Giveaway),
119    /// Service message: a scheduled giveaway was created.
120    GiveawayCreated(GiveawayCreated),
121    /// Service message: a giveaway without public winners was completed.
122    GiveawayCompleted(GiveawayCompleted),
123    /// A giveaway with public winners was completed.
124    GiveawayWinners(GiveawayWinners),
125    /// The group has been created.
126    GroupChatCreated,
127    /// Information about the invoice for a payment.
128    Invoice(Invoice),
129    /// Information about the live photo.
130    LivePhoto(LivePhoto),
131    /// A member was removed from the group.
132    ///
133    /// This member may be the bot itself.
134    LeftChatMember(User),
135    /// Information about the shared location.
136    Location(Location),
137    /// User created a bot that will be managed by the current bot.
138    ManagedBotCreated(MessageDataManagedBotCreated),
139    /// The supergroup has been migrated from a group with the specified identifier.
140    MigrateFromChatId(Integer),
141    /// The group has been migrated to a supergroup with the specified identifier.
142    MigrateToChatId(Integer),
143    /// New members that were added to the group or supergroup.
144    ///
145    /// The bot itself may be one of these members.
146    NewChatMembers(Vec<User>),
147    /// A chat photo was change to this value.
148    NewChatPhoto(Vec<PhotoSize>),
149    /// A chat title was changed to this value.
150    NewChatTitle(String),
151    /// Message contains paid media; information about the paid media.
152    PaidMedia(PaidMediaInfo),
153    /// A service message about the changed price for paid messages.
154    PaidMessagePriceChanged(MessageDataPaidMessagePriceChanged),
155    /// Telegram Passport data.
156    PassportData(PassportData),
157    /// Specified message was pinned.
158    ///
159    /// Note that the Message object in variant will not contain
160    /// further `reply_to` field even if it is itself a reply.
161    PinnedMessage(MaybeInaccessibleMessage),
162    /// Information about the native poll.
163    Poll(Poll),
164    /// Answer option was added to a poll.
165    PollOptionAdded(MessageDataPollOptionAdded),
166    /// Answer option was deleted from a poll.
167    PollOptionDeleted(MessageDataPollOptionDeleted),
168    /// A user in the chat triggered another user's proximity alert while sharing Live Location.
169    ProximityAlertTriggered(MessageDataProximityAlert),
170    /// A service message about a refunded payment, information about the payment.
171    RefundedPayment(RefundedPayment),
172    /// Message is a rich formatted message.
173    RichMessage(RichMessage),
174    /// Information about the sticker.
175    Sticker(Sticker),
176    /// A forwarded story.
177    Story(Story),
178    /// Service message: a suggested post was approved.
179    SuggestedPostApproved(SuggestedPostApproved),
180    /// Service message: approval of a suggested post has failed.
181    SuggestedPostApprovalFailed(SuggestedPostApprovalFailed),
182    /// Service message: a suggested post was declined.
183    SuggestedPostDeclined(SuggestedPostDeclined),
184    /// Service message: payment for a suggested post was received.
185    SuggestedPostPaid(SuggestedPostPaid),
186    /// Service message: payment for a suggested post was refunded.
187    SuggestedPostRefunded(SuggestedPostRefunded),
188    /// Information about the successful payment.
189    SuccessfulPayment(SuccessfulPayment),
190    /// The supergroup has been created.
191    ///
192    /// This field can‘t be received in a message coming through updates,
193    /// because bot can’t be a member of a supergroup when it is created
194    /// It can only be found in the `reply_to` field of the [`crate::types::Message`] struct
195    /// if someone replies to a very first message
196    /// in a directly created supergroup.
197    SupergroupChatCreated,
198    /// A service message about a sent or received unique gift.
199    UniqueGift(Box<UniqueGiftInfo>),
200    /// A user was shared with the bot.
201    UsersShared(MessageDataUsersShared),
202    /// Information about the venue.
203    Venue(Venue),
204    /// Information about the video note.
205    VideoNote(VideoNote),
206    /// A video chat ended in the chat.
207    VideoChatEnded(MessageDataVideoChatEnded),
208    /// New members invited to a video chat.
209    VideoChatParticipantsInvited(MessageDataVideoChatParticipantsInvited),
210    /// A video chat scheduled in the chat.
211    VideoChatScheduled(MessageDataVideoChatScheduled),
212    /// A video chat started in the chat.
213    VideoChatStarted,
214    /// Data sent by a Web App.
215    WebAppData(WebAppData),
216    /// The user allowed the bot to write messages
217    /// after adding it to the attachment or side menu,
218    /// launching a Web App from a link,
219    /// or accepting an explicit request from a Web App
220    /// sent by the method `requestWriteAccess`.
221    WriteAccessAllowed(MessageDataWriteAccess),
222    /// Describes the audio.
223    Audio(MessageDataAudio),
224    /// Describes the document.
225    Document(MessageDataDocument),
226    /// Available sizes of the photo.
227    Photo(MessageDataPhoto),
228    /// The actual UTF-8 text of the message; 0-4096 characters.
229    Text(Text),
230    /// Describes the video.
231    Video(MessageDataVideo),
232    /// Describes the voice.
233    Voice(MessageDataVoice),
234    /// Contains arbitrary data for future variants.
235    Unknown(JsonValue),
236}
237
238impl From<Animation> for MessageData {
239    fn from(value: Animation) -> Self {
240        Self::Animation(value)
241    }
242}
243
244impl From<MessageDataAutoDeleteTimer> for MessageData {
245    fn from(value: MessageDataAutoDeleteTimer) -> Self {
246        Self::AutoDeleteTimerChanged(value)
247    }
248}
249
250impl From<ChatBackground> for MessageData {
251    fn from(value: ChatBackground) -> Self {
252        Self::ChatBackgroundSet(value)
253    }
254}
255
256impl From<MessageDataChatShared> for MessageData {
257    fn from(value: MessageDataChatShared) -> Self {
258        Self::ChatShared(value)
259    }
260}
261
262impl From<Checklist> for MessageData {
263    fn from(value: Checklist) -> Self {
264        Self::Checklist(value)
265    }
266}
267
268impl From<ChecklistTasksAdded> for MessageData {
269    fn from(value: ChecklistTasksAdded) -> Self {
270        Self::ChecklistTasksAdded(value)
271    }
272}
273
274impl From<ChecklistTasksDone> for MessageData {
275    fn from(value: ChecklistTasksDone) -> Self {
276        Self::ChecklistTasksDone(value)
277    }
278}
279
280impl From<Contact> for MessageData {
281    fn from(value: Contact) -> Self {
282        Self::Contact(value)
283    }
284}
285
286impl From<Dice> for MessageData {
287    fn from(value: Dice) -> Self {
288        Self::Dice(value)
289    }
290}
291
292impl From<MessageDataDirectMessagePriceChanged> for MessageData {
293    fn from(value: MessageDataDirectMessagePriceChanged) -> Self {
294        Self::DirectMessagePriceChanged(value)
295    }
296}
297
298impl From<MessageDataForumTopicCreated> for MessageData {
299    fn from(value: MessageDataForumTopicCreated) -> Self {
300        Self::ForumTopicCreated(value)
301    }
302}
303
304impl From<MessageDataForumTopicEdited> for MessageData {
305    fn from(value: MessageDataForumTopicEdited) -> Self {
306        Self::ForumTopicEdited(value)
307    }
308}
309
310impl From<Game> for MessageData {
311    fn from(value: Game) -> Self {
312        Self::Game(value)
313    }
314}
315
316impl From<Giveaway> for MessageData {
317    fn from(value: Giveaway) -> Self {
318        Self::Giveaway(value)
319    }
320}
321
322impl From<GiveawayCreated> for MessageData {
323    fn from(value: GiveawayCreated) -> Self {
324        Self::GiveawayCreated(value)
325    }
326}
327
328impl From<GiveawayCompleted> for MessageData {
329    fn from(value: GiveawayCompleted) -> Self {
330        Self::GiveawayCompleted(value)
331    }
332}
333
334impl From<GiveawayWinners> for MessageData {
335    fn from(value: GiveawayWinners) -> Self {
336        Self::GiveawayWinners(value)
337    }
338}
339
340impl From<Invoice> for MessageData {
341    fn from(value: Invoice) -> Self {
342        Self::Invoice(value)
343    }
344}
345
346impl From<LivePhoto> for MessageData {
347    fn from(value: LivePhoto) -> Self {
348        Self::LivePhoto(value)
349    }
350}
351
352impl From<Location> for MessageData {
353    fn from(value: Location) -> Self {
354        Self::Location(value)
355    }
356}
357
358impl From<MessageDataManagedBotCreated> for MessageData {
359    fn from(value: MessageDataManagedBotCreated) -> Self {
360        Self::ManagedBotCreated(value)
361    }
362}
363
364impl From<PaidMediaInfo> for MessageData {
365    fn from(value: PaidMediaInfo) -> Self {
366        Self::PaidMedia(value)
367    }
368}
369
370impl From<MessageDataPaidMessagePriceChanged> for MessageData {
371    fn from(value: MessageDataPaidMessagePriceChanged) -> Self {
372        Self::PaidMessagePriceChanged(value)
373    }
374}
375
376impl From<PassportData> for MessageData {
377    fn from(value: PassportData) -> Self {
378        Self::PassportData(value)
379    }
380}
381
382impl From<Poll> for MessageData {
383    fn from(value: Poll) -> Self {
384        Self::Poll(value)
385    }
386}
387
388impl From<MessageDataPollOptionAdded> for MessageData {
389    fn from(value: MessageDataPollOptionAdded) -> Self {
390        Self::PollOptionAdded(value)
391    }
392}
393
394impl From<MessageDataPollOptionDeleted> for MessageData {
395    fn from(value: MessageDataPollOptionDeleted) -> Self {
396        Self::PollOptionDeleted(value)
397    }
398}
399
400impl From<MessageDataProximityAlert> for MessageData {
401    fn from(value: MessageDataProximityAlert) -> Self {
402        Self::ProximityAlertTriggered(value)
403    }
404}
405
406impl From<RefundedPayment> for MessageData {
407    fn from(value: RefundedPayment) -> Self {
408        Self::RefundedPayment(value)
409    }
410}
411
412impl From<Sticker> for MessageData {
413    fn from(value: Sticker) -> Self {
414        Self::Sticker(value)
415    }
416}
417
418impl From<Story> for MessageData {
419    fn from(value: Story) -> Self {
420        Self::Story(value)
421    }
422}
423
424impl From<SuggestedPostApproved> for MessageData {
425    fn from(value: SuggestedPostApproved) -> Self {
426        Self::SuggestedPostApproved(value)
427    }
428}
429
430impl From<SuggestedPostApprovalFailed> for MessageData {
431    fn from(value: SuggestedPostApprovalFailed) -> Self {
432        Self::SuggestedPostApprovalFailed(value)
433    }
434}
435
436impl From<SuggestedPostDeclined> for MessageData {
437    fn from(value: SuggestedPostDeclined) -> Self {
438        Self::SuggestedPostDeclined(value)
439    }
440}
441
442impl From<SuggestedPostPaid> for MessageData {
443    fn from(value: SuggestedPostPaid) -> Self {
444        Self::SuggestedPostPaid(value)
445    }
446}
447
448impl From<SuggestedPostRefunded> for MessageData {
449    fn from(value: SuggestedPostRefunded) -> Self {
450        Self::SuggestedPostRefunded(value)
451    }
452}
453
454impl From<SuccessfulPayment> for MessageData {
455    fn from(value: SuccessfulPayment) -> Self {
456        Self::SuccessfulPayment(value)
457    }
458}
459
460impl From<UniqueGiftInfo> for MessageData {
461    fn from(value: UniqueGiftInfo) -> Self {
462        Self::UniqueGift(Box::new(value))
463    }
464}
465
466impl From<MessageDataUsersShared> for MessageData {
467    fn from(value: MessageDataUsersShared) -> Self {
468        Self::UsersShared(value)
469    }
470}
471
472impl From<Venue> for MessageData {
473    fn from(value: Venue) -> Self {
474        Self::Venue(value)
475    }
476}
477
478impl From<VideoNote> for MessageData {
479    fn from(value: VideoNote) -> Self {
480        Self::VideoNote(value)
481    }
482}
483
484impl From<MessageDataVideoChatEnded> for MessageData {
485    fn from(value: MessageDataVideoChatEnded) -> Self {
486        Self::VideoChatEnded(value)
487    }
488}
489
490impl From<MessageDataVideoChatParticipantsInvited> for MessageData {
491    fn from(value: MessageDataVideoChatParticipantsInvited) -> Self {
492        Self::VideoChatParticipantsInvited(value)
493    }
494}
495
496impl From<MessageDataVideoChatScheduled> for MessageData {
497    fn from(value: MessageDataVideoChatScheduled) -> Self {
498        Self::VideoChatScheduled(value)
499    }
500}
501
502impl From<WebAppData> for MessageData {
503    fn from(value: WebAppData) -> Self {
504        Self::WebAppData(value)
505    }
506}
507
508impl From<MessageDataWriteAccess> for MessageData {
509    fn from(value: MessageDataWriteAccess) -> Self {
510        Self::WriteAccessAllowed(value)
511    }
512}
513
514impl From<MessageDataAudio> for MessageData {
515    fn from(value: MessageDataAudio) -> Self {
516        Self::Audio(value)
517    }
518}
519
520impl From<MessageDataDocument> for MessageData {
521    fn from(value: MessageDataDocument) -> Self {
522        Self::Document(value)
523    }
524}
525
526impl From<MessageDataPhoto> for MessageData {
527    fn from(value: MessageDataPhoto) -> Self {
528        Self::Photo(value)
529    }
530}
531
532impl From<Text> for MessageData {
533    fn from(value: Text) -> Self {
534        Self::Text(value)
535    }
536}
537
538impl From<MessageDataVideo> for MessageData {
539    fn from(value: MessageDataVideo) -> Self {
540        Self::Video(value)
541    }
542}
543
544impl From<MessageDataVoice> for MessageData {
545    fn from(value: MessageDataVoice) -> Self {
546        Self::Voice(value)
547    }
548}
549
550/// Represents a service message about a change in auto-delete timer settings.
551#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
552pub struct MessageDataAutoDeleteTimer {
553    /// New auto-delete time for messages in the chat; in seconds.
554    #[serde(rename = "message_auto_delete_time")]
555    pub time: Integer,
556}
557
558impl MessageDataAutoDeleteTimer {
559    /// Creates a new `MessageDataAutoDeleteTimer`.
560    ///
561    /// # Arguments
562    ///
563    /// * `time` - Time in seconds.
564    pub fn new(time: Integer) -> Self {
565        Self { time }
566    }
567}
568
569/// Represents an audio message data.
570#[derive(Clone, Debug, PartialEq)]
571pub struct MessageDataAudio {
572    /// Audio data.
573    pub data: Audio,
574    /// Audio caption.
575    pub caption: Option<Text>,
576}
577
578impl From<Audio> for MessageDataAudio {
579    fn from(value: Audio) -> Self {
580        Self {
581            data: value,
582            caption: None,
583        }
584    }
585}
586
587impl MessageDataAudio {
588    /// Sets a new caption.
589    ///
590    /// # Arguments
591    ///
592    /// * `value` - Caption; 0-1024 characters.
593    pub fn with_caption<T>(mut self, value: T) -> Self
594    where
595        T: Into<Text>,
596    {
597        self.caption = Some(value.into());
598        self
599    }
600}
601
602/// Represents an information about the chat
603/// whose identifier was shared with the bot
604/// using a [`crate::types::KeyboardButtonRequestChat`] button.
605#[serde_with::skip_serializing_none]
606#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
607pub struct MessageDataChatShared {
608    /// Identifier of the shared chat.
609    ///
610    /// The bot may not have access to the chat and could be unable to use this identifier,
611    /// unless the chat is already known to the bot by some other means.
612    pub chat_id: Integer,
613    /// Identifier of the request.
614    pub request_id: Integer,
615    /// Available sizes of the chat photo, if the photo was requested by the bot.
616    pub photo: Option<Vec<PhotoSize>>,
617    /// Title of the chat, if the title was requested by the bot.
618    pub title: Option<String>,
619    /// Username of the chat, if the username was requested by the bot and available.
620    pub username: Option<String>,
621}
622
623impl MessageDataChatShared {
624    /// Creates a new `MessageDataChatShared`.
625    ///
626    /// # Arguments
627    ///
628    /// * `chat_id` - Identifier of the shared chat.
629    /// * `request_id` - Identifier of the request.
630    pub fn new(chat_id: Integer, request_id: Integer) -> Self {
631        Self {
632            chat_id,
633            request_id,
634            title: None,
635            username: None,
636            photo: None,
637        }
638    }
639
640    /// Sets a new photo.
641    ///
642    /// # Arguments
643    ///
644    /// * `value` - Available sizes of the chat photo.
645    pub fn with_photo<T>(mut self, value: T) -> Self
646    where
647        T: IntoIterator<Item = PhotoSize>,
648    {
649        self.photo = Some(value.into_iter().collect());
650        self
651    }
652
653    /// Sets a new title.
654    ///
655    /// # Arguments
656    ///
657    /// * `value` - Title.
658    pub fn with_title<T>(mut self, value: T) -> Self
659    where
660        T: Into<String>,
661    {
662        self.title = Some(value.into());
663        self
664    }
665
666    /// Sets a new username.
667    ///
668    /// # Arguments
669    ///
670    /// * `value` - Username.
671    pub fn with_username<T>(mut self, value: T) -> Self
672    where
673        T: Into<String>,
674    {
675        self.username = Some(value.into());
676        self
677    }
678}
679
680/// Represents an document message data.
681#[derive(Clone, Debug, PartialEq)]
682pub struct MessageDataDocument {
683    /// Document data.
684    pub data: Document,
685    /// Document caption.
686    pub caption: Option<Text>,
687}
688
689impl From<Document> for MessageDataDocument {
690    fn from(value: Document) -> Self {
691        Self {
692            data: value,
693            caption: None,
694        }
695    }
696}
697
698impl MessageDataDocument {
699    /// Sets a new caption.
700    ///
701    /// # Arguments
702    ///
703    /// * `value` - Caption; 0-1024 characters.
704    pub fn with_caption<T>(mut self, value: T) -> Self
705    where
706        T: Into<Text>,
707    {
708        self.caption = Some(value.into());
709        self
710    }
711}
712
713/// Represents a service message about a new forum topic created in the chat.
714#[serde_with::skip_serializing_none]
715#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
716pub struct MessageDataForumTopicCreated {
717    /// Color of the icon of the topic.
718    pub icon_color: ForumTopicIconColor,
719    /// Name of the topic.
720    pub name: String,
721    /// Unique identifier of the custom emoji shown as the topic icon.
722    pub icon_custom_emoji_id: Option<String>,
723    /// Whether the name of the topic wasn't specified explicitly by its creator
724    /// and likely needs to be changed by the bot.
725    pub is_name_implicit: Option<bool>,
726}
727
728impl MessageDataForumTopicCreated {
729    /// Creates a new `MessageDataForumTopicCreated`.
730    ///
731    /// # Arguments
732    ///
733    /// * `icon_color` - Color of the icon.
734    /// * `name` - Name of the topic.
735    pub fn new<A, B>(icon_color: A, name: B) -> Self
736    where
737        A: Into<ForumTopicIconColor>,
738        B: Into<String>,
739    {
740        Self {
741            icon_color: icon_color.into(),
742            name: name.into(),
743            icon_custom_emoji_id: None,
744            is_name_implicit: None,
745        }
746    }
747
748    /// Sets a new icon custom emoji ID.
749    ///
750    /// # Arguments
751    ///
752    /// * `value` - Emoji ID.
753    pub fn with_icon_custom_emoji_id<T>(mut self, value: T) -> Self
754    where
755        T: Into<String>,
756    {
757        self.icon_custom_emoji_id = Some(value.into());
758        self
759    }
760
761    /// Sets a new value for the `is_name_implicit` flag.
762    ///
763    /// # Arguments
764    ///
765    /// `value` - Whether the name of the topic wasn't specified explicitly by its creator.
766    pub fn with_is_name_implicit(mut self, value: bool) -> Self {
767        self.is_name_implicit = Some(value);
768        self
769    }
770}
771
772/// Represents a service message about an edited forum topic.
773#[serde_with::skip_serializing_none]
774#[derive(Clone, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
775pub struct MessageDataForumTopicEdited {
776    /// New name, if it was edited.
777    pub name: Option<String>,
778    /// New identifier of the custom emoji shown as the topic icon,
779    /// if it was edited; an empty string if the icon was removed.
780    pub icon_custom_emoji_id: Option<String>,
781}
782
783impl MessageDataForumTopicEdited {
784    /// Sets a new name.
785    ///
786    /// # Arguments
787    ///
788    /// * `value` - The name of the topic.
789    pub fn with_name<T>(mut self, value: T) -> Self
790    where
791        T: Into<String>,
792    {
793        self.name = Some(value.into());
794        self
795    }
796
797    /// Sets a new icon custom emoji ID.
798    ///
799    /// # Arguments
800    ///
801    /// * `value` - Emoji ID.
802    pub fn with_icon_custom_emoji_id<T>(mut self, value: T) -> Self
803    where
804        T: Into<String>,
805    {
806        self.icon_custom_emoji_id = Some(value.into());
807        self
808    }
809}
810
811/// Contains information about the bot that was created to be managed by the current bot.
812#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
813pub struct MessageDataManagedBotCreated {
814    /// Information about the bot.
815    pub user: User,
816}
817
818/// Describes a service message about a change in the price of paid messages within a chat.
819#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
820pub struct MessageDataPaidMessagePriceChanged {
821    /// The new number of Telegram Stars
822    /// that must be paid by non-administrator users of the supergroup chat for each sent message.
823    pub paid_message_star_count: Integer,
824}
825
826/// Describes a service message about a change in the price of direct messages sent to a channel chat.
827#[serde_with::skip_serializing_none]
828#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
829pub struct MessageDataDirectMessagePriceChanged {
830    /// Whether the direct messages are enabled for the channel chat.
831    pub are_direct_messages_enabled: bool,
832    /// The new number of Telegram Stars that must be paid by users for each direct message sent to the channel.
833    ///
834    /// Does not apply to users who have been exempted by administrators.
835    /// Defaults to 0.
836    pub direct_message_star_count: Option<Integer>,
837}
838
839impl MessageDataDirectMessagePriceChanged {
840    /// Creates a new `MessageDataDirectMessagePriceChanged`.
841    ///
842    /// # Arguments
843    ///
844    /// * `are_direct_messages_enabled` - Whether the direct messages are enabled for the channel chat.
845    pub fn new(are_direct_messages_enabled: bool) -> Self {
846        Self {
847            are_direct_messages_enabled,
848            direct_message_star_count: None,
849        }
850    }
851
852    /// Sets a new direct message star count.
853    ///
854    /// # Arguments
855    ///
856    /// * `value` - The new number of Telegram Stars.
857    pub fn with_direct_message_star_count(mut self, value: Integer) -> Self {
858        self.direct_message_star_count = Some(value);
859        self
860    }
861}
862
863/// Represents a list of available sizes of the photo.
864#[derive(Clone, Debug, PartialEq)]
865pub struct MessageDataPhoto {
866    /// Photo sizes.
867    pub data: Vec<PhotoSize>,
868    /// Photo caption.
869    pub caption: Option<Text>,
870}
871
872impl<T> From<T> for MessageDataPhoto
873where
874    T: IntoIterator<Item = PhotoSize>,
875{
876    fn from(value: T) -> Self {
877        Self {
878            data: value.into_iter().collect(),
879            caption: None,
880        }
881    }
882}
883
884impl MessageDataPhoto {
885    /// Sets a new caption.
886    ///
887    /// # Arguments
888    ///
889    /// * `value` - Caption; 0-1024 characters.
890    pub fn with_caption<T>(mut self, value: T) -> Self
891    where
892        T: Into<Text>,
893    {
894        self.caption = Some(value.into());
895        self
896    }
897}
898
899/// Describes a service message about an option added to a poll.
900#[derive(Clone, Debug)]
901pub struct MessageDataPollOptionAdded {
902    /// Unique identifier of the added option.
903    pub option_persistent_id: String,
904    /// Option text.
905    pub option: Text,
906    /// Message containing the poll to which the option was added, if known.
907    pub poll_message: Option<MaybeInaccessibleMessage>,
908}
909
910/// Desribes a service message about an option deleted from a poll.
911#[derive(Clone, Debug)]
912pub struct MessageDataPollOptionDeleted {
913    /// Unique identifier of the deleted option.
914    pub option_persistent_id: String,
915    /// Option text.
916    pub option: Text,
917    /// Message containing the poll from which the option was deleted, if known.
918    pub poll_message: Option<MaybeInaccessibleMessage>,
919}
920
921/// Represents a content of a service message,
922/// sent whenever a user in the chat triggers
923/// a proximity alert set by another user.
924#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
925pub struct MessageDataProximityAlert {
926    /// The distance between the users.
927    pub distance: Integer,
928    /// User that triggered the alert.
929    pub traveler: User,
930    /// User that set the alert.
931    pub watcher: User,
932}
933
934impl MessageDataProximityAlert {
935    /// Creates a new `MessageDataProximityAlert`.
936    ///
937    /// # Arguments
938    ///
939    /// * `distance` - Distance between users.
940    /// * `traveler` - User that triggered the alert.
941    /// * `watcher` - User that set the alert.
942    pub fn new(distance: Integer, traveler: User, watcher: User) -> Self {
943        Self {
944            distance,
945            traveler,
946            watcher,
947        }
948    }
949}
950
951/// Contains information about the users
952/// whose identifiers were shared with the bot
953/// using a [`crate::types::KeyboardButton::with_request_users`] button.
954#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
955pub struct MessageDataUsersShared {
956    /// Identifier of the request.
957    pub request_id: Integer,
958    /// Information about users shared with the bot.
959    pub users: Vec<SharedUser>,
960}
961
962impl MessageDataUsersShared {
963    /// Creates a new `MessageDataUsersShared`.
964    ///
965    /// # Arguments
966    ///
967    /// * `request_id` - Identifier of the request.
968    /// * `users` - Information about users shared with the bot.
969    pub fn new<T>(request_id: Integer, users: T) -> Self
970    where
971        T: IntoIterator<Item = SharedUser>,
972    {
973        Self {
974            request_id,
975            users: users.into_iter().collect(),
976        }
977    }
978}
979
980/// Represents a video message data.
981#[derive(Clone, Debug, PartialEq)]
982pub struct MessageDataVideo {
983    /// Video data.
984    pub data: Video,
985    /// Video caption.
986    pub caption: Option<Text>,
987}
988
989impl From<Video> for MessageDataVideo {
990    fn from(value: Video) -> Self {
991        Self {
992            data: value,
993            caption: None,
994        }
995    }
996}
997
998impl MessageDataVideo {
999    /// Sets a new caption.
1000    ///
1001    /// # Arguments
1002    ///
1003    /// * `value` - Caption; 0-1024 characters.
1004    pub fn with_caption<T>(mut self, value: T) -> Self
1005    where
1006        T: Into<Text>,
1007    {
1008        self.caption = Some(value.into());
1009        self
1010    }
1011}
1012
1013/// Represents a service message about a video chat ended in the chat.
1014#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1015pub struct MessageDataVideoChatEnded {
1016    /// Video chat duration; in seconds.
1017    pub duration: Integer,
1018}
1019
1020impl MessageDataVideoChatEnded {
1021    /// Creates a new `MessageDataVideoChatEnded`.
1022    ///
1023    /// # Arguments
1024    ///
1025    /// * `duration` - Video chat duration; in seconds.
1026    pub fn new(duration: Integer) -> Self {
1027        Self { duration }
1028    }
1029}
1030
1031/// A service message about new members invited to a video chat.
1032#[serde_with::skip_serializing_none]
1033#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
1034pub struct MessageDataVideoChatParticipantsInvited {
1035    /// New members that were invited to the voice chat.
1036    pub users: Option<Vec<User>>,
1037}
1038
1039impl<T> From<T> for MessageDataVideoChatParticipantsInvited
1040where
1041    T: IntoIterator<Item = User>,
1042{
1043    fn from(value: T) -> Self {
1044        Self::default().with_users(value)
1045    }
1046}
1047
1048impl MessageDataVideoChatParticipantsInvited {
1049    /// Sets a new list of users.
1050    ///
1051    /// # Arguments
1052    ///
1053    /// * `value` - New members that were invited to the voice chat.
1054    pub fn with_users<T>(mut self, value: T) -> Self
1055    where
1056        T: IntoIterator<Item = User>,
1057    {
1058        self.users = Some(value.into_iter().collect());
1059        self
1060    }
1061}
1062
1063/// A service message about a video chat scheduled in the chat.
1064#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1065pub struct MessageDataVideoChatScheduled {
1066    /// Point in time (Unix timestamp) when the video chat
1067    /// is supposed to be started by a chat administrator.
1068    pub start_date: Integer,
1069}
1070
1071impl MessageDataVideoChatScheduled {
1072    /// Creates a new `MessageDataVideoChatScheduled`
1073    ///
1074    /// # Arguments
1075    ///
1076    /// * `start_date` - Point in time (Unix timestamp).
1077    pub fn new(start_date: Integer) -> Self {
1078        Self { start_date }
1079    }
1080}
1081
1082/// Message is a voice message, information about the file.
1083#[derive(Clone, Debug, PartialEq)]
1084pub struct MessageDataVoice {
1085    /// Voice data.
1086    pub data: Voice,
1087    /// Voice caption.
1088    pub caption: Option<Text>,
1089}
1090
1091impl From<Voice> for MessageDataVoice {
1092    fn from(value: Voice) -> Self {
1093        Self {
1094            data: value,
1095            caption: None,
1096        }
1097    }
1098}
1099
1100impl MessageDataVoice {
1101    /// Sets a new caption.
1102    ///
1103    /// # Arguments
1104    ///
1105    /// * `value` - Caption; 0-1024 characters.
1106    pub fn with_caption<T>(mut self, value: T) -> Self
1107    where
1108        T: Into<Text>,
1109    {
1110        self.caption = Some(value.into());
1111        self
1112    }
1113}
1114
1115/// Represents a service message about a user allowing a bot to write messages
1116/// after adding it to the attachment menu,
1117/// launching a Web App from a link,
1118/// or accepting an explicit request from a Web App
1119/// sent by the method `requestWriteAccess`.
1120#[serde_with::skip_serializing_none]
1121#[derive(Clone, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
1122pub struct MessageDataWriteAccess {
1123    /// Indicates whether access was granted when the bot was added to the attachment or side menu.
1124    pub from_attachment_menu: Option<bool>,
1125    /// Indicates whether access was granted after the user accepted an explicit request
1126    /// from a Web App sent by the method `requestWriteAccess`.
1127    pub from_request: Option<bool>,
1128    /// Name of the Web App,
1129    /// if the access was granted when the Web App was launched from a link.
1130    pub web_app_name: Option<String>,
1131}
1132
1133impl MessageDataWriteAccess {
1134    /// Sets a new value of the `from_attachment_menu` flag.
1135    ///
1136    /// * `value` - Indicates whether access was granted
1137    ///   when the bot was added to the attachment
1138    ///   or side menu.
1139    pub fn with_from_attachment_menu(mut self, value: bool) -> Self {
1140        self.from_attachment_menu = Some(value);
1141        self
1142    }
1143
1144    /// Sets a new value of the `from_request` flag.
1145    ///
1146    /// * `value` - Indicates whether access was granted after the user accepted an explicit request
1147    ///   from a Web App sent by the method `requestWriteAccess`.
1148    pub fn with_from_request(mut self, value: bool) -> Self {
1149        self.from_request = Some(value);
1150        self
1151    }
1152
1153    /// Sets a new name of the Web App.
1154    ///
1155    /// # Arguments
1156    ///
1157    /// * `value` - Name of the Web App.
1158    pub fn with_web_app_name<T>(mut self, value: T) -> Self
1159    where
1160        T: Into<String>,
1161    {
1162        self.web_app_name = Some(value.into());
1163        self
1164    }
1165}
1166
1167/// Represents a message data.
1168#[serde_with::skip_serializing_none]
1169#[derive(Clone, Debug, Deserialize, Serialize)]
1170#[serde(rename_all = "snake_case")]
1171enum RawMessageData {
1172    Animation(Animation),
1173    #[serde(rename = "message_auto_delete_timer_changed")]
1174    AutoDeleteTimerChanged(MessageDataAutoDeleteTimer),
1175    BoostAdded {
1176        boost_count: Integer,
1177    },
1178    ChannelChatCreated(True),
1179    ChatBackgroundSet(ChatBackground),
1180    ChatOwnerChanged {
1181        new_owner: User,
1182    },
1183    ChatOwnerLeft {
1184        new_owner: Option<User>,
1185    },
1186    ChatShared(MessageDataChatShared),
1187    Checklist(Checklist),
1188    ChecklistTasksAdded(ChecklistTasksAdded),
1189    ChecklistTasksDone(ChecklistTasksDone),
1190    ConnectedWebsite(String),
1191    Contact(Contact),
1192    DeleteChatPhoto(True),
1193    Dice(Dice),
1194    DirectMessagePriceChanged(MessageDataDirectMessagePriceChanged),
1195    ForumTopicClosed {},
1196    ForumTopicCreated(MessageDataForumTopicCreated),
1197    ForumTopicEdited(MessageDataForumTopicEdited),
1198    ForumTopicReopened {},
1199    Game(Game),
1200    Gift(GiftInfo),
1201    GiftUpgradeSent(GiftInfo),
1202    GeneralForumTopicHidden {},
1203    GeneralForumTopicUnhidden {},
1204    Giveaway(Giveaway),
1205    GiveawayCreated(GiveawayCreated),
1206    GiveawayCompleted(GiveawayCompleted),
1207    GiveawayWinners(GiveawayWinners),
1208    GroupChatCreated(True),
1209    Invoice(Invoice),
1210    LeftChatMember(User),
1211    Location(Location),
1212    ManagedBotCreated(MessageDataManagedBotCreated),
1213    MigrateFromChatId(Integer),
1214    MigrateToChatId(Integer),
1215    NewChatMembers(Vec<User>),
1216    NewChatPhoto(Vec<PhotoSize>),
1217    NewChatTitle(String),
1218    PaidMedia(PaidMediaInfo),
1219    PaidMessagePriceChanged(MessageDataPaidMessagePriceChanged),
1220    PassportData(PassportData),
1221    PinnedMessage(MaybeInaccessibleMessage),
1222    Poll(Poll),
1223    PollOptionAdded {
1224        option_persistent_id: String,
1225        option_text: String,
1226        option_text_entities: Option<TextEntities>,
1227        poll_message: Option<MaybeInaccessibleMessage>,
1228    },
1229    PollOptionDeleted {
1230        option_persistent_id: String,
1231        option_text: String,
1232        option_text_entities: Option<TextEntities>,
1233        poll_message: Option<MaybeInaccessibleMessage>,
1234    },
1235    ProximityAlertTriggered(MessageDataProximityAlert),
1236    RefundedPayment(RefundedPayment),
1237    RichMessage(RichMessage),
1238    Sticker(Sticker),
1239    Story(Story),
1240    SuggestedPostApproved(SuggestedPostApproved),
1241    SuggestedPostApprovalFailed(SuggestedPostApprovalFailed),
1242    SuggestedPostDeclined(SuggestedPostDeclined),
1243    SuggestedPostPaid(SuggestedPostPaid),
1244    SuggestedPostRefunded(SuggestedPostRefunded),
1245    SuccessfulPayment(SuccessfulPayment),
1246    SupergroupChatCreated(True),
1247    UniqueGift(Box<UniqueGiftInfo>),
1248    UsersShared(MessageDataUsersShared),
1249    Venue(Venue),
1250    VideoNote(VideoNote),
1251    VideoChatEnded(MessageDataVideoChatEnded),
1252    VideoChatParticipantsInvited(MessageDataVideoChatParticipantsInvited),
1253    VideoChatScheduled(MessageDataVideoChatScheduled),
1254    VideoChatStarted {},
1255    WebAppData(WebAppData),
1256    WriteAccessAllowed(MessageDataWriteAccess),
1257    #[serde(untagged)]
1258    Audio {
1259        audio: Audio,
1260        caption: Option<String>,
1261        caption_entities: Option<TextEntities>,
1262    },
1263    #[serde(untagged)]
1264    Document {
1265        document: Document,
1266        caption: Option<String>,
1267        caption_entities: Option<TextEntities>,
1268    },
1269    /// When both photo and a live_photo are provided, the live_photo is ignored.
1270    /// Using untagged to parse the live_photo first
1271    #[serde(untagged)]
1272    LivePhoto {
1273        live_photo: LivePhoto,
1274    },
1275    #[serde(untagged)]
1276    Photo {
1277        photo: Vec<PhotoSize>,
1278        caption: Option<String>,
1279        caption_entities: Option<TextEntities>,
1280    },
1281    #[serde(untagged)]
1282    Text {
1283        text: String,
1284        entities: Option<TextEntities>,
1285    },
1286    #[serde(untagged)]
1287    Video {
1288        video: Video,
1289        caption: Option<String>,
1290        caption_entities: Option<TextEntities>,
1291    },
1292    #[serde(untagged)]
1293    Voice {
1294        voice: Voice,
1295        caption: Option<String>,
1296        caption_entities: Option<TextEntities>,
1297    },
1298    #[serde(untagged)]
1299    Unknown(JsonValue),
1300}
1301
1302impl From<RawMessageData> for MessageData {
1303    fn from(value: RawMessageData) -> Self {
1304        match value {
1305            RawMessageData::Animation(value) => Self::Animation(value),
1306            RawMessageData::AutoDeleteTimerChanged(value) => Self::AutoDeleteTimerChanged(value),
1307            RawMessageData::BoostAdded { boost_count } => Self::BoostAdded(boost_count),
1308            RawMessageData::ChannelChatCreated(True) => Self::ChannelChatCreated,
1309            RawMessageData::ChatBackgroundSet(value) => Self::ChatBackgroundSet(value),
1310            RawMessageData::ChatOwnerChanged { new_owner } => Self::ChatOwnerChanged(new_owner),
1311            RawMessageData::ChatOwnerLeft { new_owner } => Self::ChatOwnerLeft(new_owner),
1312            RawMessageData::ChatShared(value) => Self::ChatShared(value),
1313            RawMessageData::Checklist(value) => Self::Checklist(value),
1314            RawMessageData::ChecklistTasksAdded(value) => Self::ChecklistTasksAdded(value),
1315            RawMessageData::ChecklistTasksDone(value) => Self::ChecklistTasksDone(value),
1316            RawMessageData::ConnectedWebsite(value) => Self::ConnectedWebsite(value),
1317            RawMessageData::Contact(value) => Self::Contact(value),
1318            RawMessageData::DeleteChatPhoto(True) => Self::DeleteChatPhoto,
1319            RawMessageData::Dice(value) => Self::Dice(value),
1320            RawMessageData::DirectMessagePriceChanged(value) => Self::DirectMessagePriceChanged(value),
1321            RawMessageData::ForumTopicClosed {} => Self::ForumTopicClosed,
1322            RawMessageData::ForumTopicCreated(value) => Self::ForumTopicCreated(value),
1323            RawMessageData::ForumTopicEdited(value) => Self::ForumTopicEdited(value),
1324            RawMessageData::ForumTopicReopened {} => Self::ForumTopicReopened,
1325            RawMessageData::Game(value) => Self::Game(value),
1326            RawMessageData::Gift(value) => Self::Gift(value),
1327            RawMessageData::GiftUpgradeSent(value) => Self::GiftUpgradeSent(value),
1328            RawMessageData::GeneralForumTopicHidden {} => Self::GeneralForumTopicHidden,
1329            RawMessageData::GeneralForumTopicUnhidden {} => Self::GeneralForumTopicUnhidden,
1330            RawMessageData::Giveaway(value) => Self::Giveaway(value),
1331            RawMessageData::GiveawayCreated(value) => Self::GiveawayCreated(value),
1332            RawMessageData::GiveawayCompleted(value) => Self::GiveawayCompleted(value),
1333            RawMessageData::GiveawayWinners(value) => Self::GiveawayWinners(value),
1334            RawMessageData::GroupChatCreated(True) => Self::GroupChatCreated,
1335            RawMessageData::Invoice(value) => Self::Invoice(value),
1336            RawMessageData::LeftChatMember(value) => Self::LeftChatMember(value),
1337            RawMessageData::Location(value) => Self::Location(value),
1338            RawMessageData::ManagedBotCreated(value) => Self::ManagedBotCreated(value),
1339            RawMessageData::MigrateFromChatId(value) => Self::MigrateFromChatId(value),
1340            RawMessageData::MigrateToChatId(value) => Self::MigrateToChatId(value),
1341            RawMessageData::NewChatMembers(value) => Self::NewChatMembers(value),
1342            RawMessageData::NewChatPhoto(value) => Self::NewChatPhoto(value),
1343            RawMessageData::NewChatTitle(value) => Self::NewChatTitle(value),
1344            RawMessageData::PaidMedia(value) => Self::PaidMedia(value),
1345            RawMessageData::PaidMessagePriceChanged(value) => Self::PaidMessagePriceChanged(value),
1346            RawMessageData::PassportData(value) => Self::PassportData(value),
1347            RawMessageData::PinnedMessage(value) => Self::PinnedMessage(value),
1348            RawMessageData::Poll(value) => Self::Poll(value),
1349            RawMessageData::PollOptionAdded {
1350                option_persistent_id,
1351                option_text,
1352                option_text_entities,
1353                poll_message,
1354            } => Self::PollOptionAdded(MessageDataPollOptionAdded {
1355                option_persistent_id,
1356                option: Text {
1357                    data: option_text,
1358                    entities: option_text_entities,
1359                },
1360                poll_message,
1361            }),
1362            RawMessageData::PollOptionDeleted {
1363                option_persistent_id,
1364                option_text,
1365                option_text_entities,
1366                poll_message,
1367            } => Self::PollOptionDeleted(MessageDataPollOptionDeleted {
1368                option_persistent_id,
1369                option: Text {
1370                    data: option_text,
1371                    entities: option_text_entities,
1372                },
1373                poll_message,
1374            }),
1375            RawMessageData::ProximityAlertTriggered(value) => Self::ProximityAlertTriggered(value),
1376            RawMessageData::RefundedPayment(value) => Self::RefundedPayment(value),
1377            RawMessageData::RichMessage(value) => Self::RichMessage(value),
1378            RawMessageData::Sticker(value) => Self::Sticker(value),
1379            RawMessageData::Story(value) => Self::Story(value),
1380            RawMessageData::SuggestedPostApproved(value) => Self::SuggestedPostApproved(value),
1381            RawMessageData::SuggestedPostApprovalFailed(value) => Self::SuggestedPostApprovalFailed(value),
1382            RawMessageData::SuggestedPostDeclined(value) => Self::SuggestedPostDeclined(value),
1383            RawMessageData::SuggestedPostPaid(value) => Self::SuggestedPostPaid(value),
1384            RawMessageData::SuggestedPostRefunded(value) => Self::SuggestedPostRefunded(value),
1385            RawMessageData::SuccessfulPayment(value) => Self::SuccessfulPayment(value),
1386            RawMessageData::SupergroupChatCreated(True) => Self::SupergroupChatCreated,
1387            RawMessageData::UniqueGift(value) => Self::UniqueGift(value),
1388            RawMessageData::UsersShared(value) => Self::UsersShared(value),
1389            RawMessageData::Venue(value) => Self::Venue(value),
1390            RawMessageData::VideoNote(value) => Self::VideoNote(value),
1391            RawMessageData::VideoChatEnded(value) => Self::VideoChatEnded(value),
1392            RawMessageData::VideoChatParticipantsInvited(value) => Self::VideoChatParticipantsInvited(value),
1393            RawMessageData::VideoChatScheduled(value) => Self::VideoChatScheduled(value),
1394            RawMessageData::VideoChatStarted {} => Self::VideoChatStarted,
1395            RawMessageData::WebAppData(value) => Self::WebAppData(value),
1396            RawMessageData::WriteAccessAllowed(value) => Self::WriteAccessAllowed(value),
1397            RawMessageData::Audio {
1398                audio,
1399                caption,
1400                caption_entities,
1401            } => Self::Audio(MessageDataAudio {
1402                data: audio,
1403                caption: caption.map(|data| Text {
1404                    data,
1405                    entities: caption_entities,
1406                }),
1407            }),
1408            RawMessageData::Document {
1409                document,
1410                caption,
1411                caption_entities,
1412            } => Self::Document(MessageDataDocument {
1413                data: document,
1414                caption: caption.map(|data| Text {
1415                    data,
1416                    entities: caption_entities,
1417                }),
1418            }),
1419            RawMessageData::LivePhoto { live_photo } => Self::LivePhoto(live_photo),
1420            RawMessageData::Photo {
1421                photo,
1422                caption,
1423                caption_entities,
1424            } => Self::Photo(MessageDataPhoto {
1425                data: photo,
1426
1427                caption: caption.map(|data| Text {
1428                    data,
1429                    entities: caption_entities,
1430                }),
1431            }),
1432            RawMessageData::Text { text: data, entities } => Self::Text(Text { data, entities }),
1433            RawMessageData::Video {
1434                video,
1435                caption,
1436                caption_entities,
1437            } => Self::Video(MessageDataVideo {
1438                data: video,
1439
1440                caption: caption.map(|data| Text {
1441                    data,
1442                    entities: caption_entities,
1443                }),
1444            }),
1445            RawMessageData::Voice {
1446                voice,
1447                caption,
1448                caption_entities,
1449            } => Self::Voice(MessageDataVoice {
1450                data: voice,
1451
1452                caption: caption.map(|data| Text {
1453                    data,
1454                    entities: caption_entities,
1455                }),
1456            }),
1457            RawMessageData::Unknown(value) => Self::Unknown(value),
1458        }
1459    }
1460}
1461
1462impl From<MessageData> for RawMessageData {
1463    fn from(value: MessageData) -> Self {
1464        match value {
1465            MessageData::Animation(value) => Self::Animation(value),
1466            MessageData::AutoDeleteTimerChanged(value) => Self::AutoDeleteTimerChanged(value),
1467            MessageData::BoostAdded(boost_count) => Self::BoostAdded { boost_count },
1468            MessageData::ChannelChatCreated => Self::ChannelChatCreated(True),
1469            MessageData::ChatBackgroundSet(value) => Self::ChatBackgroundSet(value),
1470            MessageData::ChatOwnerChanged(new_owner) => Self::ChatOwnerChanged { new_owner },
1471            MessageData::ChatOwnerLeft(new_owner) => Self::ChatOwnerLeft { new_owner },
1472            MessageData::ChatShared(value) => Self::ChatShared(value),
1473            MessageData::Checklist(value) => Self::Checklist(value),
1474            MessageData::ChecklistTasksAdded(value) => Self::ChecklistTasksAdded(value),
1475            MessageData::ChecklistTasksDone(value) => Self::ChecklistTasksDone(value),
1476            MessageData::ConnectedWebsite(value) => Self::ConnectedWebsite(value),
1477            MessageData::Contact(value) => Self::Contact(value),
1478            MessageData::DeleteChatPhoto => Self::DeleteChatPhoto(True),
1479            MessageData::Dice(value) => Self::Dice(value),
1480            MessageData::DirectMessagePriceChanged(value) => Self::DirectMessagePriceChanged(value),
1481            MessageData::ForumTopicClosed => Self::ForumTopicClosed {},
1482            MessageData::ForumTopicCreated(value) => Self::ForumTopicCreated(value),
1483            MessageData::ForumTopicEdited(value) => Self::ForumTopicEdited(value),
1484            MessageData::ForumTopicReopened => Self::ForumTopicReopened {},
1485            MessageData::Game(value) => Self::Game(value),
1486            MessageData::Gift(value) => Self::Gift(value),
1487            MessageData::GiftUpgradeSent(value) => Self::GiftUpgradeSent(value),
1488            MessageData::GeneralForumTopicHidden => Self::GeneralForumTopicHidden {},
1489            MessageData::GeneralForumTopicUnhidden => Self::GeneralForumTopicUnhidden {},
1490            MessageData::Giveaway(value) => Self::Giveaway(value),
1491            MessageData::GiveawayCreated(value) => Self::GiveawayCreated(value),
1492            MessageData::GiveawayCompleted(value) => Self::GiveawayCompleted(value),
1493            MessageData::GiveawayWinners(value) => Self::GiveawayWinners(value),
1494            MessageData::GroupChatCreated => Self::GroupChatCreated(True),
1495            MessageData::Invoice(value) => Self::Invoice(value),
1496            MessageData::LeftChatMember(value) => Self::LeftChatMember(value),
1497            MessageData::Location(value) => Self::Location(value),
1498            MessageData::ManagedBotCreated(value) => Self::ManagedBotCreated(value),
1499            MessageData::MigrateFromChatId(value) => Self::MigrateFromChatId(value),
1500            MessageData::MigrateToChatId(value) => Self::MigrateToChatId(value),
1501            MessageData::NewChatMembers(value) => Self::NewChatMembers(value),
1502            MessageData::NewChatPhoto(value) => Self::NewChatPhoto(value),
1503            MessageData::NewChatTitle(value) => Self::NewChatTitle(value),
1504            MessageData::PaidMedia(value) => Self::PaidMedia(value),
1505            MessageData::PaidMessagePriceChanged(value) => Self::PaidMessagePriceChanged(value),
1506            MessageData::PassportData(value) => Self::PassportData(value),
1507            MessageData::PinnedMessage(value) => Self::PinnedMessage(value),
1508            MessageData::Poll(value) => Self::Poll(value),
1509            MessageData::PollOptionAdded(MessageDataPollOptionAdded {
1510                option_persistent_id,
1511                option,
1512                poll_message,
1513            }) => Self::PollOptionAdded {
1514                option_persistent_id,
1515                option_text: option.data,
1516                option_text_entities: option.entities,
1517                poll_message,
1518            },
1519            MessageData::PollOptionDeleted(MessageDataPollOptionDeleted {
1520                option_persistent_id,
1521                option,
1522                poll_message,
1523            }) => Self::PollOptionDeleted {
1524                option_persistent_id,
1525                option_text: option.data,
1526                option_text_entities: option.entities,
1527                poll_message,
1528            },
1529            MessageData::ProximityAlertTriggered(value) => Self::ProximityAlertTriggered(value),
1530            MessageData::RefundedPayment(value) => Self::RefundedPayment(value),
1531            MessageData::RichMessage(value) => Self::RichMessage(value),
1532            MessageData::Sticker(value) => Self::Sticker(value),
1533            MessageData::Story(value) => Self::Story(value),
1534            MessageData::SuggestedPostApproved(value) => Self::SuggestedPostApproved(value),
1535            MessageData::SuggestedPostApprovalFailed(value) => Self::SuggestedPostApprovalFailed(value),
1536            MessageData::SuggestedPostDeclined(value) => Self::SuggestedPostDeclined(value),
1537            MessageData::SuggestedPostPaid(value) => Self::SuggestedPostPaid(value),
1538            MessageData::SuggestedPostRefunded(value) => Self::SuggestedPostRefunded(value),
1539            MessageData::SuccessfulPayment(value) => Self::SuccessfulPayment(value),
1540            MessageData::SupergroupChatCreated => Self::SupergroupChatCreated(True),
1541            MessageData::UniqueGift(value) => Self::UniqueGift(value),
1542            MessageData::UsersShared(value) => Self::UsersShared(value),
1543            MessageData::Venue(value) => Self::Venue(value),
1544            MessageData::VideoNote(value) => Self::VideoNote(value),
1545            MessageData::VideoChatEnded(value) => Self::VideoChatEnded(value),
1546            MessageData::VideoChatParticipantsInvited(value) => Self::VideoChatParticipantsInvited(value),
1547            MessageData::VideoChatScheduled(value) => Self::VideoChatScheduled(value),
1548            MessageData::VideoChatStarted => Self::VideoChatStarted {},
1549            MessageData::WebAppData(value) => Self::WebAppData(value),
1550            MessageData::WriteAccessAllowed(value) => Self::WriteAccessAllowed(value),
1551            MessageData::Audio(value) => {
1552                let audio = value.data;
1553                let (caption, caption_entities) = value
1554                    .caption
1555                    .map(|x| (Some(x.data), x.entities))
1556                    .unwrap_or((None, None));
1557                Self::Audio {
1558                    audio,
1559                    caption,
1560                    caption_entities,
1561                }
1562            }
1563            MessageData::Document(value) => {
1564                let document = value.data;
1565                let (caption, caption_entities) = value
1566                    .caption
1567                    .map(|x| (Some(x.data), x.entities))
1568                    .unwrap_or((None, None));
1569                Self::Document {
1570                    document,
1571                    caption,
1572                    caption_entities,
1573                }
1574            }
1575            MessageData::LivePhoto(live_photo) => Self::LivePhoto { live_photo },
1576            MessageData::Photo(value) => {
1577                let photo = value.data;
1578                let (caption, caption_entities) = value
1579                    .caption
1580                    .map(|x| (Some(x.data), x.entities))
1581                    .unwrap_or((None, None));
1582                Self::Photo {
1583                    photo,
1584                    caption,
1585                    caption_entities,
1586                }
1587            }
1588            MessageData::Text(Text { data: text, entities }) => Self::Text { text, entities },
1589            MessageData::Video(value) => {
1590                let video = value.data;
1591                let (caption, caption_entities) = value
1592                    .caption
1593                    .map(|x| (Some(x.data), x.entities))
1594                    .unwrap_or((None, None));
1595                Self::Video {
1596                    video,
1597                    caption,
1598                    caption_entities,
1599                }
1600            }
1601            MessageData::Voice(value) => {
1602                let voice = value.data;
1603                let (caption, caption_entities) = value
1604                    .caption
1605                    .map(|x| (Some(x.data), x.entities))
1606                    .unwrap_or((None, None));
1607                Self::Voice {
1608                    voice,
1609                    caption,
1610                    caption_entities,
1611                }
1612            }
1613            MessageData::Unknown(value) => Self::Unknown(value),
1614        }
1615    }
1616}