tgbot/types/message/data/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;

use self::raw::*;
use crate::types::{
    Animation,
    Audio,
    ChatBackground,
    Contact,
    Dice,
    Document,
    ForumTopicIconColor,
    Game,
    Giveaway,
    GiveawayCompleted,
    GiveawayCreated,
    GiveawayWinners,
    Integer,
    Invoice,
    Location,
    MaybeInaccessibleMessage,
    PaidMediaInfo,
    PassportData,
    PhotoSize,
    Poll,
    RefundedPayment,
    SharedUser,
    Sticker,
    Story,
    SuccessfulPayment,
    Text,
    User,
    Venue,
    Video,
    VideoNote,
    Voice,
    WebAppData,
};

#[cfg(test)]
mod tests;

mod raw;

/// Represents a message data.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
#[allow(clippy::large_enum_variant)]
#[serde(rename_all = "snake_case")]
pub enum MessageData {
    /// Information about the animation.
    Animation(Animation),
    /// Auto-delete timer settings changed.
    #[serde(rename = "message_auto_delete_timer_changed")]
    AutoDeleteTimerChanged(MessageDataAutoDeleteTimer),
    /// Service message: user boosted the chat.
    ///
    /// Contains a number of boosts added by the user.
    #[serde(
        deserialize_with = "RawDataBoostAdded::deserialize_value",
        serialize_with = "RawDataBoostAdded::serialize_value"
    )]
    BoostAdded(Integer),
    /// The channel has been created.
    ///
    /// This field can‘t be received in a message coming through updates,
    /// because bot can’t be a member of a channel when it is created.
    /// It can only be found in the `reply_to` field of the [`crate::types::Message`] struct
    /// if someone replies to a very first message in a channel.
    #[serde(
        deserialize_with = "RawDataFlag::deserialize_value",
        serialize_with = "RawDataFlag::serialize_value"
    )]
    ChannelChatCreated,
    /// Chat background set.
    ChatBackgroundSet(ChatBackground),
    /// A chat was shared with the bot.
    ChatShared(MessageDataChatShared),
    /// The domain name of the website on which the user has logged in.
    ConnectedWebsite(String),
    /// Information about the shared contact.
    Contact(Contact),
    /// The chat photo was deleted.
    #[serde(
        deserialize_with = "RawDataFlag::deserialize_value",
        serialize_with = "RawDataFlag::serialize_value"
    )]
    DeleteChatPhoto,
    /// A dice with a random value.
    Dice(Dice),
    /// Forum topic closed.
    #[serde(
        deserialize_with = "RawDataEmpty::deserialize_value",
        serialize_with = "RawDataEmpty::serialize_value"
    )]
    ForumTopicClosed,
    /// Forum topic created.
    ForumTopicCreated(MessageDataForumTopicCreated),
    /// Forum topic edited.
    ForumTopicEdited(MessageDataForumTopicEdited),
    /// Forum topic reopened.
    #[serde(
        deserialize_with = "RawDataEmpty::deserialize_value",
        serialize_with = "RawDataEmpty::serialize_value"
    )]
    ForumTopicReopened,
    /// Information about the game.
    Game(Game),
    /// The 'General' forum topic hidden.
    #[serde(
        deserialize_with = "RawDataEmpty::deserialize_value",
        serialize_with = "RawDataEmpty::serialize_value"
    )]
    GeneralForumTopicHidden,
    /// The 'General' forum topic unhidden.
    #[serde(
        deserialize_with = "RawDataEmpty::deserialize_value",
        serialize_with = "RawDataEmpty::serialize_value"
    )]
    GeneralForumTopicUnhidden,
    /// A scheduled giveaway.
    Giveaway(Giveaway),
    /// Service message: a scheduled giveaway was created.
    GiveawayCreated(GiveawayCreated),
    /// Service message: a giveaway without public winners was completed.
    GiveawayCompleted(GiveawayCompleted),
    /// A giveaway with public winners was completed.
    GiveawayWinners(GiveawayWinners),
    /// The group has been created.
    #[serde(
        deserialize_with = "RawDataFlag::deserialize_value",
        serialize_with = "RawDataFlag::serialize_value"
    )]
    GroupChatCreated,
    /// Information about the invoice for a payment.
    Invoice(Invoice),
    /// A member was removed from the group.
    ///
    /// This member may be the bot itself.
    LeftChatMember(User),
    /// Information about the shared location.
    Location(Location),
    /// The supergroup has been migrated from a group with the specified identifier.
    MigrateFromChatId(Integer),
    /// The group has been migrated to a supergroup with the specified identifier.
    MigrateToChatId(Integer),
    /// New members that were added to the group or supergroup.
    ///
    /// The bot itself may be one of these members.
    NewChatMembers(Vec<User>),
    /// A chat photo was change to this value.
    NewChatPhoto(Vec<PhotoSize>),
    /// A chat title was changed to this value.
    NewChatTitle(String),
    /// Message contains paid media; information about the paid media.
    PaidMedia(PaidMediaInfo),
    /// Telegram Passport data.
    PassportData(PassportData),
    /// Specified message was pinned.
    ///
    /// Note that the Message object in variant will not contain
    /// further `reply_to` field even if it is itself a reply.
    PinnedMessage(MaybeInaccessibleMessage),
    /// Information about the native poll.
    Poll(Poll),
    /// A user in the chat triggered another user's proximity alert while sharing Live Location.
    ProximityAlertTriggered(MessageDataProximityAlert),
    /// A service message about a refunded payment, information about the payment.
    RefundedPayment(RefundedPayment),
    /// Information about the sticker.
    Sticker(Sticker),
    /// A forwarded story.
    Story(Story),
    /// Information about the successful payment.
    SuccessfulPayment(SuccessfulPayment),
    /// The supergroup has been created.
    ///
    /// This field can‘t be received in a message coming through updates,
    /// because bot can’t be a member of a supergroup when it is created
    /// It can only be found in the `reply_to` field of the [`crate::types::Message`] struct
    /// if someone replies to a very first message
    /// in a directly created supergroup.
    #[serde(
        deserialize_with = "RawDataFlag::deserialize_value",
        serialize_with = "RawDataFlag::serialize_value"
    )]
    SupergroupChatCreated,
    /// A user was shared with the bot.
    UsersShared(MessageDataUsersShared),
    /// Information about the venue.
    Venue(Venue),
    /// Information about the video note.
    VideoNote(VideoNote),
    /// A video chat ended in the chat.
    VideoChatEnded(MessageDataVideoChatEnded),
    /// New members invited to a video chat.
    VideoChatParticipantsInvited(MessageDataVideoChatParticipantsInvited),
    /// A video chat scheduled in the chat.
    VideoChatScheduled(MessageDataVideoChatScheduled),
    /// A video chat started in the chat.
    #[serde(
        deserialize_with = "RawDataEmpty::deserialize_value",
        serialize_with = "RawDataEmpty::serialize_value"
    )]
    VideoChatStarted,
    /// Data sent by a Web App.
    WebAppData(WebAppData),
    /// The user allowed the bot to write messages
    /// after adding it to the attachment or side menu,
    /// launching a Web App from a link,
    /// or accepting an explicit request from a Web App
    /// sent by the method `requestWriteAccess`.
    WriteAccessAllowed(MessageDataWriteAccess),
    /// Describes the audio.
    #[serde(untagged)]
    Audio(MessageDataAudio),
    /// Describes the document.
    #[serde(untagged)]
    Document(MessageDataDocument),
    /// Available sizes of the photo.
    #[serde(untagged)]
    Photo(MessageDataPhoto),
    /// The actual UTF-8 text of the message; 0-4096 characters.
    #[serde(
        deserialize_with = "RawDataText::deserialize_value",
        serialize_with = "RawDataText::serialize_value",
        untagged
    )]
    Text(Text),
    /// Describes the video.
    #[serde(untagged)]
    Video(MessageDataVideo),
    /// Describes the voice.
    #[serde(untagged)]
    Voice(MessageDataVoice),
    /// Contains arbitrary data for future variants.
    #[serde(untagged)]
    Unknown(JsonValue),
}

/// Represents a service message about a change in auto-delete timer settings.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct MessageDataAutoDeleteTimer {
    /// New auto-delete time for messages in the chat; in seconds.
    #[serde(rename = "message_auto_delete_time")]
    pub time: Integer,
}

impl MessageDataAutoDeleteTimer {
    /// Creates a new `MessageDataAutoDeleteTimer`.
    ///
    /// # Arguments
    ///
    /// * `time` - Time in seconds.
    pub fn new(time: Integer) -> Self {
        Self { time }
    }
}

/// Represents an audio message data.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct MessageDataAudio {
    /// Audio data.
    #[serde(rename = "audio")]
    pub data: Audio,
    /// Audio caption.
    #[serde(
        flatten,
        deserialize_with = "RawCaption::deserialize_value",
        serialize_with = "RawCaption::serialize_value",
        skip_serializing_if = "Option::is_none"
    )]
    pub caption: Option<Text>,
}

impl From<Audio> for MessageDataAudio {
    fn from(value: Audio) -> Self {
        Self {
            data: value,
            caption: None,
        }
    }
}

impl MessageDataAudio {
    /// Sets a new caption.
    ///
    /// # Arguments
    ///
    /// * `value` - Caption; 0-1024 characters.
    pub fn with_caption<T>(mut self, value: T) -> Self
    where
        T: Into<Text>,
    {
        self.caption = Some(value.into());
        self
    }
}

/// Represents an information about the chat
/// whose identifier was shared with the bot
/// using a [`crate::types::KeyboardButtonRequestChat`] button.
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct MessageDataChatShared {
    /// Identifier of the shared chat.
    ///
    /// The bot may not have access to the chat and could be unable to use this identifier,
    /// unless the chat is already known to the bot by some other means.
    pub chat_id: Integer,
    /// Identifier of the request.
    pub request_id: Integer,
    /// Available sizes of the chat photo, if the photo was requested by the bot.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub photo: Option<Vec<PhotoSize>>,
    /// Title of the chat, if the title was requested by the bot.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: Option<String>,
    /// Username of the chat, if the username was requested by the bot and available.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub username: Option<String>,
}

impl MessageDataChatShared {
    /// Creates a new `MessageDataChatShared`.
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Identifier of the shared chat.
    /// * `request_id` - Identifier of the request.
    pub fn new(chat_id: Integer, request_id: Integer) -> Self {
        Self {
            chat_id,
            request_id,
            title: None,
            username: None,
            photo: None,
        }
    }

    /// Sets a new photo.
    ///
    /// # Arguments
    ///
    /// * `value` - Available sizes of the chat photo.
    pub fn with_photo<T>(mut self, value: T) -> Self
    where
        T: IntoIterator<Item = PhotoSize>,
    {
        self.photo = Some(value.into_iter().collect());
        self
    }

    /// Sets a new title.
    ///
    /// # Arguments
    ///
    /// * `value` - Title.
    pub fn with_title<T>(mut self, value: T) -> Self
    where
        T: Into<String>,
    {
        self.title = Some(value.into());
        self
    }

    /// Sets a new username.
    ///
    /// # Arguments
    ///
    /// * `value` - Username.
    pub fn with_username<T>(mut self, value: T) -> Self
    where
        T: Into<String>,
    {
        self.username = Some(value.into());
        self
    }
}

/// Represents an document message data.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct MessageDataDocument {
    /// Document data.
    #[serde(rename = "document")]
    pub data: Document,
    /// Document caption.
    #[serde(
        flatten,
        deserialize_with = "RawCaption::deserialize_value",
        serialize_with = "RawCaption::serialize_value",
        skip_serializing_if = "Option::is_none"
    )]
    pub caption: Option<Text>,
}

impl From<Document> for MessageDataDocument {
    fn from(value: Document) -> Self {
        Self {
            data: value,
            caption: None,
        }
    }
}

impl MessageDataDocument {
    /// Sets a new caption.
    ///
    /// # Arguments
    ///
    /// * `value` - Caption; 0-1024 characters.
    pub fn with_caption<T>(mut self, value: T) -> Self
    where
        T: Into<Text>,
    {
        self.caption = Some(value.into());
        self
    }
}

/// Represents a service message about a new forum topic created in the chat.
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct MessageDataForumTopicCreated {
    /// Color of the icon of the topic.
    pub icon_color: ForumTopicIconColor,
    /// Name of the topic.
    pub name: String,
    /// Unique identifier of the custom emoji shown as the topic icon.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub icon_custom_emoji_id: Option<String>,
}

impl MessageDataForumTopicCreated {
    /// Creates a new `MessageDataForumTopicCreated`.
    ///
    /// # Arguments
    ///
    /// * `icon_color` - Color of the icon.
    /// * `name` - Name of the topic.
    pub fn new<A, B>(icon_color: A, name: B) -> Self
    where
        A: Into<ForumTopicIconColor>,
        B: Into<String>,
    {
        Self {
            icon_color: icon_color.into(),
            name: name.into(),
            icon_custom_emoji_id: None,
        }
    }

    /// Sets a new icon custom emoji ID.
    ///
    /// # Arguments
    ///
    /// * `value` - Emoji ID.
    pub fn with_icon_custom_emoji_id<T>(mut self, value: T) -> Self
    where
        T: Into<String>,
    {
        self.icon_custom_emoji_id = Some(value.into());
        self
    }
}

/// Represents a service message about an edited forum topic.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct MessageDataForumTopicEdited {
    /// New name, if it was edited.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// New identifier of the custom emoji shown as the topic icon,
    /// if it was edited; an empty string if the icon was removed.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub icon_custom_emoji_id: Option<String>,
}

impl MessageDataForumTopicEdited {
    /// Sets a new name.
    ///
    /// # Arguments
    ///
    /// * `value` - The name of the topic.
    pub fn with_name<T>(mut self, value: T) -> Self
    where
        T: Into<String>,
    {
        self.name = Some(value.into());
        self
    }

    /// Sets a new icon custom emoji ID.
    ///
    /// # Arguments
    ///
    /// * `value` - Emoji ID.
    pub fn with_icon_custom_emoji_id<T>(mut self, value: T) -> Self
    where
        T: Into<String>,
    {
        self.icon_custom_emoji_id = Some(value.into());
        self
    }
}

/// Represents a list of available sizes of the photo.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct MessageDataPhoto {
    /// Photo sizes.
    #[serde(rename = "photo")]
    pub data: Vec<PhotoSize>,
    /// Photo caption.
    #[serde(
        flatten,
        deserialize_with = "RawCaption::deserialize_value",
        serialize_with = "RawCaption::serialize_value",
        skip_serializing_if = "Option::is_none"
    )]
    pub caption: Option<Text>,
}

impl<T> From<T> for MessageDataPhoto
where
    T: IntoIterator<Item = PhotoSize>,
{
    fn from(value: T) -> Self {
        Self {
            data: value.into_iter().collect(),
            caption: None,
        }
    }
}

impl MessageDataPhoto {
    /// Sets a new caption.
    ///
    /// # Arguments
    ///
    /// * `value` - Caption; 0-1024 characters.
    pub fn with_caption<T>(mut self, value: T) -> Self
    where
        T: Into<Text>,
    {
        self.caption = Some(value.into());
        self
    }
}

/// Represents a content of a service message,
/// sent whenever a user in the chat triggers
/// a proximity alert set by another user.
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct MessageDataProximityAlert {
    /// The distance between the users.
    pub distance: Integer,
    /// User that triggered the alert.
    pub traveler: User,
    /// User that set the alert.
    pub watcher: User,
}

impl MessageDataProximityAlert {
    /// Creates a new `MessageDataProximityAlert`.
    ///
    /// # Arguments
    ///
    /// * `distance` - Distance between users.
    /// * `traveler` - User that triggered the alert.
    /// * `watcher` - User that set the alert.
    pub fn new(distance: Integer, traveler: User, watcher: User) -> Self {
        Self {
            distance,
            traveler,
            watcher,
        }
    }
}

/// Contains information about the users
/// whose identifiers were shared with the bot
/// using a [`crate::types::KeyboardButton::with_request_users`] button.
#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct MessageDataUsersShared {
    /// Identifier of the request.
    pub request_id: Integer,
    /// Information about users shared with the bot.
    pub users: Vec<SharedUser>,
}

impl MessageDataUsersShared {
    /// Creates a new `MessageDataUsersShared`.
    ///
    /// # Arguments
    ///
    /// * `request_id` - Identifier of the request.
    /// * `users` - Information about users shared with the bot.
    pub fn new<T>(request_id: Integer, users: T) -> Self
    where
        T: IntoIterator<Item = SharedUser>,
    {
        Self {
            request_id,
            users: users.into_iter().collect(),
        }
    }
}

/// Represents a video message data.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct MessageDataVideo {
    /// Video data.
    #[serde(rename = "video")]
    pub data: Video,
    /// Video caption.
    #[serde(
        flatten,
        deserialize_with = "RawCaption::deserialize_value",
        serialize_with = "RawCaption::serialize_value",
        skip_serializing_if = "Option::is_none"
    )]
    pub caption: Option<Text>,
}

impl From<Video> for MessageDataVideo {
    fn from(value: Video) -> Self {
        Self {
            data: value,
            caption: None,
        }
    }
}

impl MessageDataVideo {
    /// Sets a new caption.
    ///
    /// # Arguments
    ///
    /// * `value` - Caption; 0-1024 characters.
    pub fn with_caption<T>(mut self, value: T) -> Self
    where
        T: Into<Text>,
    {
        self.caption = Some(value.into());
        self
    }
}

/// Represents a service message about a video chat ended in the chat.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct MessageDataVideoChatEnded {
    /// Video chat duration; in seconds.
    pub duration: Integer,
}

impl MessageDataVideoChatEnded {
    /// Creates a new `MessageDataVideoChatEnded`.
    ///
    /// # Arguments
    ///
    /// * `duration` - Video chat duration; in seconds.
    pub fn new(duration: Integer) -> Self {
        Self { duration }
    }
}

/// A service message about new members invited to a video chat.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct MessageDataVideoChatParticipantsInvited {
    /// New members that were invited to the voice chat.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub users: Option<Vec<User>>,
}

impl<T> From<T> for MessageDataVideoChatParticipantsInvited
where
    T: IntoIterator<Item = User>,
{
    fn from(value: T) -> Self {
        Self::default().with_users(value)
    }
}

impl MessageDataVideoChatParticipantsInvited {
    /// Sets a new list of users.
    ///
    /// # Arguments
    ///
    /// * `value` - New members that were invited to the voice chat.
    pub fn with_users<T>(mut self, value: T) -> Self
    where
        T: IntoIterator<Item = User>,
    {
        self.users = Some(value.into_iter().collect());
        self
    }
}

/// A service message about a video chat scheduled in the chat.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct MessageDataVideoChatScheduled {
    /// Point in time (Unix timestamp) when the video chat
    /// is supposed to be started by a chat administrator.
    pub start_date: Integer,
}

impl MessageDataVideoChatScheduled {
    /// Creates a new `MessageDataVideoChatScheduled`
    ///
    /// # Arguments
    ///
    /// * `start_date` - Point in time (Unix timestamp).
    pub fn new(start_date: Integer) -> Self {
        Self { start_date }
    }
}

/// Message is a voice message, information about the file.
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct MessageDataVoice {
    /// Voice data.
    #[serde(rename = "voice")]
    pub data: Voice,
    /// Voice caption.
    #[serde(
        flatten,
        deserialize_with = "RawCaption::deserialize_value",
        serialize_with = "RawCaption::serialize_value",
        skip_serializing_if = "Option::is_none"
    )]
    pub caption: Option<Text>,
}

impl From<Voice> for MessageDataVoice {
    fn from(value: Voice) -> Self {
        Self {
            data: value,
            caption: None,
        }
    }
}

impl MessageDataVoice {
    /// Sets a new caption.
    ///
    /// # Arguments
    ///
    /// * `value` - Caption; 0-1024 characters.
    pub fn with_caption<T>(mut self, value: T) -> Self
    where
        T: Into<Text>,
    {
        self.caption = Some(value.into());
        self
    }
}

/// Represents a service message about a user allowing a bot to write messages
/// after adding it to the attachment menu,
/// launching a Web App from a link,
/// or accepting an explicit request from a Web App
/// sent by the method `requestWriteAccess`.
#[derive(Clone, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct MessageDataWriteAccess {
    /// Indicates whether access was granted when the bot was added to the attachment or side menu.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from_attachment_menu: Option<bool>,
    /// Indicates whether access was granted after the user accepted an explicit request
    /// from a Web App sent by the method `requestWriteAccess`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from_request: Option<bool>,
    /// Name of the Web App,
    /// if the access was granted when the Web App was launched from a link.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub web_app_name: Option<String>,
}

impl MessageDataWriteAccess {
    /// Sets a new value of the `from_attachment_menu` flag.
    ///
    /// * `value` - Indicates whether access was granted
    ///             when the bot was added to the attachment
    ///             or side menu.
    pub fn with_from_attachment_menu(mut self, value: bool) -> Self {
        self.from_attachment_menu = Some(value);
        self
    }

    /// Sets a new value of the `from_request` flag.
    ///
    /// * value - Indicates whether access was granted after the user accepted an explicit request
    ///           from a Web App sent by the method `requestWriteAccess`.
    pub fn with_from_request(mut self, value: bool) -> Self {
        self.from_request = Some(value);
        self
    }

    /// Sets a new name of the Web App.
    ///
    /// # Arguments
    ///
    /// * value - Name of the Web App.
    pub fn with_web_app_name<T>(mut self, value: T) -> Self
    where
        T: Into<String>,
    {
        self.web_app_name = Some(value.into());
        self
    }
}