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