tgbot/types/message/data/
mod.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value as JsonValue;
3
4use self::raw::*;
5use crate::types::{
6    Animation,
7    Audio,
8    ChatBackground,
9    Checklist,
10    ChecklistTasksAdded,
11    ChecklistTasksDone,
12    Contact,
13    Dice,
14    Document,
15    ForumTopicIconColor,
16    Game,
17    GiftInfo,
18    Giveaway,
19    GiveawayCompleted,
20    GiveawayCreated,
21    GiveawayWinners,
22    Integer,
23    Invoice,
24    Location,
25    MaybeInaccessibleMessage,
26    PaidMediaInfo,
27    PassportData,
28    PhotoSize,
29    Poll,
30    RefundedPayment,
31    SharedUser,
32    Sticker,
33    Story,
34    SuccessfulPayment,
35    Text,
36    UniqueGiftInfo,
37    User,
38    Venue,
39    Video,
40    VideoNote,
41    Voice,
42    WebAppData,
43};
44
45#[cfg(test)]
46mod tests;
47
48mod raw;
49
50/// Represents a message data.
51#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
52#[allow(clippy::large_enum_variant)]
53#[serde(rename_all = "snake_case")]
54pub enum MessageData {
55    /// Information about the animation.
56    Animation(Animation),
57    /// Auto-delete timer settings changed.
58    #[serde(rename = "message_auto_delete_timer_changed")]
59    AutoDeleteTimerChanged(MessageDataAutoDeleteTimer),
60    /// Service message: user boosted the chat.
61    ///
62    /// Contains a number of boosts added by the user.
63    #[serde(
64        deserialize_with = "RawDataBoostAdded::deserialize_value",
65        serialize_with = "RawDataBoostAdded::serialize_value"
66    )]
67    BoostAdded(Integer),
68    /// The channel has been created.
69    ///
70    /// This field can‘t be received in a message coming through updates,
71    /// because bot can’t be a member of a channel when it is created.
72    /// It can only be found in the `reply_to` field of the [`crate::types::Message`] struct
73    /// if someone replies to a very first message in a channel.
74    #[serde(
75        deserialize_with = "RawDataFlag::deserialize_value",
76        serialize_with = "RawDataFlag::serialize_value"
77    )]
78    ChannelChatCreated,
79    /// Chat background set.
80    ChatBackgroundSet(ChatBackground),
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    #[serde(
95        deserialize_with = "RawDataFlag::deserialize_value",
96        serialize_with = "RawDataFlag::serialize_value"
97    )]
98    DeleteChatPhoto,
99    /// A dice with a random value.
100    Dice(Dice),
101    /// The price for paid messages in the corresponding direct messages chat of a channel has changed.
102    DirectMessagePriceChanged(MessageDataDirectMessagePriceChanged),
103    /// Forum topic closed.
104    #[serde(
105        deserialize_with = "RawDataEmpty::deserialize_value",
106        serialize_with = "RawDataEmpty::serialize_value"
107    )]
108    ForumTopicClosed,
109    /// Forum topic created.
110    ForumTopicCreated(MessageDataForumTopicCreated),
111    /// Forum topic edited.
112    ForumTopicEdited(MessageDataForumTopicEdited),
113    /// Forum topic reopened.
114    #[serde(
115        deserialize_with = "RawDataEmpty::deserialize_value",
116        serialize_with = "RawDataEmpty::serialize_value"
117    )]
118    ForumTopicReopened,
119    /// Information about the game.
120    Game(Game),
121    /// A service message about a sent or received regular gift.
122    Gift(GiftInfo),
123    /// The 'General' forum topic hidden.
124    #[serde(
125        deserialize_with = "RawDataEmpty::deserialize_value",
126        serialize_with = "RawDataEmpty::serialize_value"
127    )]
128    GeneralForumTopicHidden,
129    /// The 'General' forum topic unhidden.
130    #[serde(
131        deserialize_with = "RawDataEmpty::deserialize_value",
132        serialize_with = "RawDataEmpty::serialize_value"
133    )]
134    GeneralForumTopicUnhidden,
135    /// A scheduled giveaway.
136    Giveaway(Giveaway),
137    /// Service message: a scheduled giveaway was created.
138    GiveawayCreated(GiveawayCreated),
139    /// Service message: a giveaway without public winners was completed.
140    GiveawayCompleted(GiveawayCompleted),
141    /// A giveaway with public winners was completed.
142    GiveawayWinners(GiveawayWinners),
143    /// The group has been created.
144    #[serde(
145        deserialize_with = "RawDataFlag::deserialize_value",
146        serialize_with = "RawDataFlag::serialize_value"
147    )]
148    GroupChatCreated,
149    /// Information about the invoice for a payment.
150    Invoice(Invoice),
151    /// A member was removed from the group.
152    ///
153    /// This member may be the bot itself.
154    LeftChatMember(User),
155    /// Information about the shared location.
156    Location(Location),
157    /// The supergroup has been migrated from a group with the specified identifier.
158    MigrateFromChatId(Integer),
159    /// The group has been migrated to a supergroup with the specified identifier.
160    MigrateToChatId(Integer),
161    /// New members that were added to the group or supergroup.
162    ///
163    /// The bot itself may be one of these members.
164    NewChatMembers(Vec<User>),
165    /// A chat photo was change to this value.
166    NewChatPhoto(Vec<PhotoSize>),
167    /// A chat title was changed to this value.
168    NewChatTitle(String),
169    /// Message contains paid media; information about the paid media.
170    PaidMedia(PaidMediaInfo),
171    /// A service message about the changed price for paid messages.
172    PaidMessagePriceChanged(MessageDataPaidMessagePriceChanged),
173    /// Telegram Passport data.
174    PassportData(PassportData),
175    /// Specified message was pinned.
176    ///
177    /// Note that the Message object in variant will not contain
178    /// further `reply_to` field even if it is itself a reply.
179    PinnedMessage(MaybeInaccessibleMessage),
180    /// Information about the native poll.
181    Poll(Poll),
182    /// A user in the chat triggered another user's proximity alert while sharing Live Location.
183    ProximityAlertTriggered(MessageDataProximityAlert),
184    /// A service message about a refunded payment, information about the payment.
185    RefundedPayment(RefundedPayment),
186    /// Information about the sticker.
187    Sticker(Sticker),
188    /// A forwarded story.
189    Story(Story),
190    /// Information about the successful payment.
191    SuccessfulPayment(SuccessfulPayment),
192    /// The supergroup has been created.
193    ///
194    /// This field can‘t be received in a message coming through updates,
195    /// because bot can’t be a member of a supergroup when it is created
196    /// It can only be found in the `reply_to` field of the [`crate::types::Message`] struct
197    /// if someone replies to a very first message
198    /// in a directly created supergroup.
199    #[serde(
200        deserialize_with = "RawDataFlag::deserialize_value",
201        serialize_with = "RawDataFlag::serialize_value"
202    )]
203    SupergroupChatCreated,
204    /// A service message about a sent or received unique gift.
205    UniqueGift(UniqueGiftInfo),
206    /// A user was shared with the bot.
207    UsersShared(MessageDataUsersShared),
208    /// Information about the venue.
209    Venue(Venue),
210    /// Information about the video note.
211    VideoNote(VideoNote),
212    /// A video chat ended in the chat.
213    VideoChatEnded(MessageDataVideoChatEnded),
214    /// New members invited to a video chat.
215    VideoChatParticipantsInvited(MessageDataVideoChatParticipantsInvited),
216    /// A video chat scheduled in the chat.
217    VideoChatScheduled(MessageDataVideoChatScheduled),
218    /// A video chat started in the chat.
219    #[serde(
220        deserialize_with = "RawDataEmpty::deserialize_value",
221        serialize_with = "RawDataEmpty::serialize_value"
222    )]
223    VideoChatStarted,
224    /// Data sent by a Web App.
225    WebAppData(WebAppData),
226    /// The user allowed the bot to write messages
227    /// after adding it to the attachment or side menu,
228    /// launching a Web App from a link,
229    /// or accepting an explicit request from a Web App
230    /// sent by the method `requestWriteAccess`.
231    WriteAccessAllowed(MessageDataWriteAccess),
232    /// Describes the audio.
233    #[serde(untagged)]
234    Audio(MessageDataAudio),
235    /// Describes the document.
236    #[serde(untagged)]
237    Document(MessageDataDocument),
238    /// Available sizes of the photo.
239    #[serde(untagged)]
240    Photo(MessageDataPhoto),
241    /// The actual UTF-8 text of the message; 0-4096 characters.
242    #[serde(
243        deserialize_with = "RawDataText::deserialize_value",
244        serialize_with = "RawDataText::serialize_value",
245        untagged
246    )]
247    Text(Text),
248    /// Describes the video.
249    #[serde(untagged)]
250    Video(MessageDataVideo),
251    /// Describes the voice.
252    #[serde(untagged)]
253    Voice(MessageDataVoice),
254    /// Contains arbitrary data for future variants.
255    #[serde(untagged)]
256    Unknown(JsonValue),
257}
258
259/// Represents a service message about a change in auto-delete timer settings.
260#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
261pub struct MessageDataAutoDeleteTimer {
262    /// New auto-delete time for messages in the chat; in seconds.
263    #[serde(rename = "message_auto_delete_time")]
264    pub time: Integer,
265}
266
267impl MessageDataAutoDeleteTimer {
268    /// Creates a new `MessageDataAutoDeleteTimer`.
269    ///
270    /// # Arguments
271    ///
272    /// * `time` - Time in seconds.
273    pub fn new(time: Integer) -> Self {
274        Self { time }
275    }
276}
277
278/// Represents an audio message data.
279#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
280#[serde_with::skip_serializing_none]
281pub struct MessageDataAudio {
282    /// Audio data.
283    #[serde(rename = "audio")]
284    pub data: Audio,
285    /// Audio caption.
286    #[serde(
287        flatten,
288        deserialize_with = "RawCaption::deserialize_value",
289        serialize_with = "RawCaption::serialize_value"
290    )]
291    pub caption: Option<Text>,
292}
293
294impl From<Audio> for MessageDataAudio {
295    fn from(value: Audio) -> Self {
296        Self {
297            data: value,
298            caption: None,
299        }
300    }
301}
302
303impl MessageDataAudio {
304    /// Sets a new caption.
305    ///
306    /// # Arguments
307    ///
308    /// * `value` - Caption; 0-1024 characters.
309    pub fn with_caption<T>(mut self, value: T) -> Self
310    where
311        T: Into<Text>,
312    {
313        self.caption = Some(value.into());
314        self
315    }
316}
317
318/// Represents an information about the chat
319/// whose identifier was shared with the bot
320/// using a [`crate::types::KeyboardButtonRequestChat`] button.
321#[serde_with::skip_serializing_none]
322#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
323pub struct MessageDataChatShared {
324    /// Identifier of the shared chat.
325    ///
326    /// The bot may not have access to the chat and could be unable to use this identifier,
327    /// unless the chat is already known to the bot by some other means.
328    pub chat_id: Integer,
329    /// Identifier of the request.
330    pub request_id: Integer,
331    /// Available sizes of the chat photo, if the photo was requested by the bot.
332    pub photo: Option<Vec<PhotoSize>>,
333    /// Title of the chat, if the title was requested by the bot.
334    pub title: Option<String>,
335    /// Username of the chat, if the username was requested by the bot and available.
336    pub username: Option<String>,
337}
338
339impl MessageDataChatShared {
340    /// Creates a new `MessageDataChatShared`.
341    ///
342    /// # Arguments
343    ///
344    /// * `chat_id` - Identifier of the shared chat.
345    /// * `request_id` - Identifier of the request.
346    pub fn new(chat_id: Integer, request_id: Integer) -> Self {
347        Self {
348            chat_id,
349            request_id,
350            title: None,
351            username: None,
352            photo: None,
353        }
354    }
355
356    /// Sets a new photo.
357    ///
358    /// # Arguments
359    ///
360    /// * `value` - Available sizes of the chat photo.
361    pub fn with_photo<T>(mut self, value: T) -> Self
362    where
363        T: IntoIterator<Item = PhotoSize>,
364    {
365        self.photo = Some(value.into_iter().collect());
366        self
367    }
368
369    /// Sets a new title.
370    ///
371    /// # Arguments
372    ///
373    /// * `value` - Title.
374    pub fn with_title<T>(mut self, value: T) -> Self
375    where
376        T: Into<String>,
377    {
378        self.title = Some(value.into());
379        self
380    }
381
382    /// Sets a new username.
383    ///
384    /// # Arguments
385    ///
386    /// * `value` - Username.
387    pub fn with_username<T>(mut self, value: T) -> Self
388    where
389        T: Into<String>,
390    {
391        self.username = Some(value.into());
392        self
393    }
394}
395
396/// Represents an document message data.
397#[serde_with::skip_serializing_none]
398#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
399pub struct MessageDataDocument {
400    /// Document data.
401    #[serde(rename = "document")]
402    pub data: Document,
403    /// Document caption.
404    #[serde(
405        flatten,
406        deserialize_with = "RawCaption::deserialize_value",
407        serialize_with = "RawCaption::serialize_value"
408    )]
409    pub caption: Option<Text>,
410}
411
412impl From<Document> for MessageDataDocument {
413    fn from(value: Document) -> Self {
414        Self {
415            data: value,
416            caption: None,
417        }
418    }
419}
420
421impl MessageDataDocument {
422    /// Sets a new caption.
423    ///
424    /// # Arguments
425    ///
426    /// * `value` - Caption; 0-1024 characters.
427    pub fn with_caption<T>(mut self, value: T) -> Self
428    where
429        T: Into<Text>,
430    {
431        self.caption = Some(value.into());
432        self
433    }
434}
435
436/// Represents a service message about a new forum topic created in the chat.
437#[serde_with::skip_serializing_none]
438#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
439pub struct MessageDataForumTopicCreated {
440    /// Color of the icon of the topic.
441    pub icon_color: ForumTopicIconColor,
442    /// Name of the topic.
443    pub name: String,
444    /// Unique identifier of the custom emoji shown as the topic icon.
445    pub icon_custom_emoji_id: Option<String>,
446}
447
448impl MessageDataForumTopicCreated {
449    /// Creates a new `MessageDataForumTopicCreated`.
450    ///
451    /// # Arguments
452    ///
453    /// * `icon_color` - Color of the icon.
454    /// * `name` - Name of the topic.
455    pub fn new<A, B>(icon_color: A, name: B) -> Self
456    where
457        A: Into<ForumTopicIconColor>,
458        B: Into<String>,
459    {
460        Self {
461            icon_color: icon_color.into(),
462            name: name.into(),
463            icon_custom_emoji_id: None,
464        }
465    }
466
467    /// Sets a new icon custom emoji ID.
468    ///
469    /// # Arguments
470    ///
471    /// * `value` - Emoji ID.
472    pub fn with_icon_custom_emoji_id<T>(mut self, value: T) -> Self
473    where
474        T: Into<String>,
475    {
476        self.icon_custom_emoji_id = Some(value.into());
477        self
478    }
479}
480
481/// Represents a service message about an edited forum topic.
482#[serde_with::skip_serializing_none]
483#[derive(Clone, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
484pub struct MessageDataForumTopicEdited {
485    /// New name, if it was edited.
486    pub name: Option<String>,
487    /// New identifier of the custom emoji shown as the topic icon,
488    /// if it was edited; an empty string if the icon was removed.
489    pub icon_custom_emoji_id: Option<String>,
490}
491
492impl MessageDataForumTopicEdited {
493    /// Sets a new name.
494    ///
495    /// # Arguments
496    ///
497    /// * `value` - The name of the topic.
498    pub fn with_name<T>(mut self, value: T) -> Self
499    where
500        T: Into<String>,
501    {
502        self.name = Some(value.into());
503        self
504    }
505
506    /// Sets a new icon custom emoji ID.
507    ///
508    /// # Arguments
509    ///
510    /// * `value` - Emoji ID.
511    pub fn with_icon_custom_emoji_id<T>(mut self, value: T) -> Self
512    where
513        T: Into<String>,
514    {
515        self.icon_custom_emoji_id = Some(value.into());
516        self
517    }
518}
519
520/// Describes a service message about a change in the price of paid messages within a chat.
521#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
522pub struct MessageDataPaidMessagePriceChanged {
523    /// The new number of Telegram Stars
524    /// that must be paid by non-administrator users of the supergroup chat for each sent message.
525    pub paid_message_star_count: Integer,
526}
527
528/// Describes a service message about a change in the price of direct messages sent to a channel chat.
529#[serde_with::skip_serializing_none]
530#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
531pub struct MessageDataDirectMessagePriceChanged {
532    /// Whether the direct messages are enabled for the channel chat.
533    pub are_direct_messages_enabled: bool,
534    /// The new number of Telegram Stars that must be paid by users for each direct message sent to the channel.
535    ///
536    /// Does not apply to users who have been exempted by administrators.
537    /// Defaults to 0.
538    pub direct_message_star_count: Option<Integer>,
539}
540
541impl MessageDataDirectMessagePriceChanged {
542    /// Creates a new `MessageDataDirectMessagePriceChanged`.
543    ///
544    /// # Arguments
545    ///
546    /// * `are_direct_messages_enabled` - Whether the direct messages are enabled for the channel chat.
547    pub fn new(are_direct_messages_enabled: bool) -> Self {
548        Self {
549            are_direct_messages_enabled,
550            direct_message_star_count: None,
551        }
552    }
553
554    /// Sets a new direct message star count.
555    ///
556    /// # Arguments
557    ///
558    /// * `value` - The new number of Telegram Stars.
559    pub fn with_direct_message_star_count(mut self, value: Integer) -> Self {
560        self.direct_message_star_count = Some(value);
561        self
562    }
563}
564
565/// Represents a list of available sizes of the photo.
566#[serde_with::skip_serializing_none]
567#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
568pub struct MessageDataPhoto {
569    /// Photo sizes.
570    #[serde(rename = "photo")]
571    pub data: Vec<PhotoSize>,
572    /// Photo caption.
573    #[serde(
574        flatten,
575        deserialize_with = "RawCaption::deserialize_value",
576        serialize_with = "RawCaption::serialize_value"
577    )]
578    pub caption: Option<Text>,
579}
580
581impl<T> From<T> for MessageDataPhoto
582where
583    T: IntoIterator<Item = PhotoSize>,
584{
585    fn from(value: T) -> Self {
586        Self {
587            data: value.into_iter().collect(),
588            caption: None,
589        }
590    }
591}
592
593impl MessageDataPhoto {
594    /// Sets a new caption.
595    ///
596    /// # Arguments
597    ///
598    /// * `value` - Caption; 0-1024 characters.
599    pub fn with_caption<T>(mut self, value: T) -> Self
600    where
601        T: Into<Text>,
602    {
603        self.caption = Some(value.into());
604        self
605    }
606}
607
608/// Represents a content of a service message,
609/// sent whenever a user in the chat triggers
610/// a proximity alert set by another user.
611#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
612pub struct MessageDataProximityAlert {
613    /// The distance between the users.
614    pub distance: Integer,
615    /// User that triggered the alert.
616    pub traveler: User,
617    /// User that set the alert.
618    pub watcher: User,
619}
620
621impl MessageDataProximityAlert {
622    /// Creates a new `MessageDataProximityAlert`.
623    ///
624    /// # Arguments
625    ///
626    /// * `distance` - Distance between users.
627    /// * `traveler` - User that triggered the alert.
628    /// * `watcher` - User that set the alert.
629    pub fn new(distance: Integer, traveler: User, watcher: User) -> Self {
630        Self {
631            distance,
632            traveler,
633            watcher,
634        }
635    }
636}
637
638/// Contains information about the users
639/// whose identifiers were shared with the bot
640/// using a [`crate::types::KeyboardButton::with_request_users`] button.
641#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
642pub struct MessageDataUsersShared {
643    /// Identifier of the request.
644    pub request_id: Integer,
645    /// Information about users shared with the bot.
646    pub users: Vec<SharedUser>,
647}
648
649impl MessageDataUsersShared {
650    /// Creates a new `MessageDataUsersShared`.
651    ///
652    /// # Arguments
653    ///
654    /// * `request_id` - Identifier of the request.
655    /// * `users` - Information about users shared with the bot.
656    pub fn new<T>(request_id: Integer, users: T) -> Self
657    where
658        T: IntoIterator<Item = SharedUser>,
659    {
660        Self {
661            request_id,
662            users: users.into_iter().collect(),
663        }
664    }
665}
666
667/// Represents a video message data.
668#[serde_with::skip_serializing_none]
669#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
670pub struct MessageDataVideo {
671    /// Video data.
672    #[serde(rename = "video")]
673    pub data: Video,
674    /// Video caption.
675    #[serde(
676        flatten,
677        deserialize_with = "RawCaption::deserialize_value",
678        serialize_with = "RawCaption::serialize_value"
679    )]
680    pub caption: Option<Text>,
681}
682
683impl From<Video> for MessageDataVideo {
684    fn from(value: Video) -> Self {
685        Self {
686            data: value,
687            caption: None,
688        }
689    }
690}
691
692impl MessageDataVideo {
693    /// Sets a new caption.
694    ///
695    /// # Arguments
696    ///
697    /// * `value` - Caption; 0-1024 characters.
698    pub fn with_caption<T>(mut self, value: T) -> Self
699    where
700        T: Into<Text>,
701    {
702        self.caption = Some(value.into());
703        self
704    }
705}
706
707/// Represents a service message about a video chat ended in the chat.
708#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
709pub struct MessageDataVideoChatEnded {
710    /// Video chat duration; in seconds.
711    pub duration: Integer,
712}
713
714impl MessageDataVideoChatEnded {
715    /// Creates a new `MessageDataVideoChatEnded`.
716    ///
717    /// # Arguments
718    ///
719    /// * `duration` - Video chat duration; in seconds.
720    pub fn new(duration: Integer) -> Self {
721        Self { duration }
722    }
723}
724
725/// A service message about new members invited to a video chat.
726#[serde_with::skip_serializing_none]
727#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
728pub struct MessageDataVideoChatParticipantsInvited {
729    /// New members that were invited to the voice chat.
730    pub users: Option<Vec<User>>,
731}
732
733impl<T> From<T> for MessageDataVideoChatParticipantsInvited
734where
735    T: IntoIterator<Item = User>,
736{
737    fn from(value: T) -> Self {
738        Self::default().with_users(value)
739    }
740}
741
742impl MessageDataVideoChatParticipantsInvited {
743    /// Sets a new list of users.
744    ///
745    /// # Arguments
746    ///
747    /// * `value` - New members that were invited to the voice chat.
748    pub fn with_users<T>(mut self, value: T) -> Self
749    where
750        T: IntoIterator<Item = User>,
751    {
752        self.users = Some(value.into_iter().collect());
753        self
754    }
755}
756
757/// A service message about a video chat scheduled in the chat.
758#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
759pub struct MessageDataVideoChatScheduled {
760    /// Point in time (Unix timestamp) when the video chat
761    /// is supposed to be started by a chat administrator.
762    pub start_date: Integer,
763}
764
765impl MessageDataVideoChatScheduled {
766    /// Creates a new `MessageDataVideoChatScheduled`
767    ///
768    /// # Arguments
769    ///
770    /// * `start_date` - Point in time (Unix timestamp).
771    pub fn new(start_date: Integer) -> Self {
772        Self { start_date }
773    }
774}
775
776/// Message is a voice message, information about the file.
777#[serde_with::skip_serializing_none]
778#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
779pub struct MessageDataVoice {
780    /// Voice data.
781    #[serde(rename = "voice")]
782    pub data: Voice,
783    /// Voice caption.
784    #[serde(
785        flatten,
786        deserialize_with = "RawCaption::deserialize_value",
787        serialize_with = "RawCaption::serialize_value"
788    )]
789    pub caption: Option<Text>,
790}
791
792impl From<Voice> for MessageDataVoice {
793    fn from(value: Voice) -> Self {
794        Self {
795            data: value,
796            caption: None,
797        }
798    }
799}
800
801impl MessageDataVoice {
802    /// Sets a new caption.
803    ///
804    /// # Arguments
805    ///
806    /// * `value` - Caption; 0-1024 characters.
807    pub fn with_caption<T>(mut self, value: T) -> Self
808    where
809        T: Into<Text>,
810    {
811        self.caption = Some(value.into());
812        self
813    }
814}
815
816/// Represents a service message about a user allowing a bot to write messages
817/// after adding it to the attachment menu,
818/// launching a Web App from a link,
819/// or accepting an explicit request from a Web App
820/// sent by the method `requestWriteAccess`.
821#[serde_with::skip_serializing_none]
822#[derive(Clone, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
823pub struct MessageDataWriteAccess {
824    /// Indicates whether access was granted when the bot was added to the attachment or side menu.
825    pub from_attachment_menu: Option<bool>,
826    /// Indicates whether access was granted after the user accepted an explicit request
827    /// from a Web App sent by the method `requestWriteAccess`.
828    pub from_request: Option<bool>,
829    /// Name of the Web App,
830    /// if the access was granted when the Web App was launched from a link.
831    pub web_app_name: Option<String>,
832}
833
834impl MessageDataWriteAccess {
835    /// Sets a new value of the `from_attachment_menu` flag.
836    ///
837    /// * `value` - Indicates whether access was granted
838    ///   when the bot was added to the attachment
839    ///   or side menu.
840    pub fn with_from_attachment_menu(mut self, value: bool) -> Self {
841        self.from_attachment_menu = Some(value);
842        self
843    }
844
845    /// Sets a new value of the `from_request` flag.
846    ///
847    /// * `value` - Indicates whether access was granted after the user accepted an explicit request
848    ///   from a Web App sent by the method `requestWriteAccess`.
849    pub fn with_from_request(mut self, value: bool) -> Self {
850        self.from_request = Some(value);
851        self
852    }
853
854    /// Sets a new name of the Web App.
855    ///
856    /// # Arguments
857    ///
858    /// * `value` - Name of the Web App.
859    pub fn with_web_app_name<T>(mut self, value: T) -> Self
860    where
861        T: Into<String>,
862    {
863        self.web_app_name = Some(value.into());
864        self
865    }
866}