telbot_types/
chat.rs

1use serde::{Deserialize, Serialize};
2
3use crate::file::{InputFile, InputFileVariant, InputMedia};
4use crate::markup::InlineKeyboardMarkup;
5use crate::message::{
6    ChatActionKind, DeleteMessage, EditMessageCaption, EditMessageMedia, EditMessageReplyMarkup,
7    EditMessageText, Location, Message, SendAnimation, SendAudio, SendChatAction, SendContact,
8    SendDice, SendDocument, SendLocation, SendMediaGroup, SendMessage, SendPhoto, SendPoll,
9    SendVenue, SendVideo, SendVideoNote, SendVoice, StopPoll,
10};
11use crate::user::User;
12use crate::{JsonMethod, TelegramMethod};
13
14/// This object represents a chat.
15#[derive(Debug, Deserialize)]
16pub struct Chat {
17    /// Unique identifier for this chat.
18    pub id: i64,
19    /// Type of chat.
20    #[serde(flatten)]
21    pub kind: ChatKind,
22    /// Title, for supergroups, channels and group chats
23    pub title: Option<String>,
24    /// Username, for private chats, supergroups and channels if available
25    pub username: Option<String>,
26    /// First name of the other party in a private chat
27    pub first_name: Option<String>,
28    /// Last name of the other party in a private chat
29    pub last_name: Option<String>,
30    /// Chat photo.
31    /// Returned only in getChat.
32    pub photo: Option<ChatPhoto>,
33    /// Bio of the other party in a private chat.
34    /// Returned only in getChat.
35    pub bio: Option<String>,
36    /// Description, for groups, supergroups and channel chats.
37    /// Returned only in getChat.
38    pub description: Option<String>,
39    /// Primary invite link, for groups, supergroups and channel chats.
40    /// Returned only in getChat.
41    pub invite_link: Option<String>,
42    /// The most recent pinned message (by sending date).
43    /// Returned only in getChat.
44    pub pinned_message: Option<Box<Message>>,
45    /// Default chat member permissions, for groups and supergroups.
46    /// Returned only in getChat.
47    pub permissions: Option<ChatPermissions>,
48    /// Default chat member permissions, for groups and supergroups.
49    /// Returned only in getChat.
50    pub slow_mode_delay: Option<i32>,
51    /// The time after which all messages sent to the chat will be automatically deleted; in seconds.
52    /// Returned only in getChat.
53    pub message_auto_delete_time: Option<i32>,
54    /// For supergroups, name of group sticker set.
55    /// Returned only in getChat.
56    pub sticker_set_name: Option<String>,
57    /// True, if the bot can change the group sticker set.
58    /// Returned only in getChat.
59    pub can_get_sticker_set: Option<bool>,
60    /// Unique identifier for the linked chat,
61    /// i.e. the discussion group identifier for a channel and vice versa;
62    /// for supergroups and channel chats.
63    /// Returned only in getChat.
64    pub linked_chat_id: Option<i32>,
65    /// For supergroups, the location to which the supergroup is connected.
66    /// Returned only in getChat.
67    pub location: Option<ChatLocation>,
68}
69
70impl Chat {
71    pub fn send_animation(&self, animation: impl Into<InputFileVariant>) -> SendAnimation {
72        SendAnimation::new(self.id, animation)
73    }
74
75    pub fn send_audio(&self, audio: impl Into<InputFileVariant>) -> SendAudio {
76        SendAudio::new(self.id, audio)
77    }
78
79    pub fn send_chat_action(&self, action: ChatActionKind) -> SendChatAction {
80        SendChatAction::new(self.id, action)
81    }
82
83    pub fn send_contact(
84        &self,
85        phone_number: impl Into<String>,
86        first_name: impl Into<String>,
87    ) -> SendContact {
88        SendContact::new(self.id, phone_number, first_name)
89    }
90
91    pub fn send_dice(&self) -> SendDice {
92        SendDice::new(self.id)
93    }
94
95    pub fn send_document(&self, document: impl Into<InputFileVariant>) -> SendDocument {
96        SendDocument::new(self.id, document)
97    }
98
99    pub fn send_location(
100        &self,
101        latitude: f32,
102        longitude: f32,
103        horizontal_accuracy: f32,
104    ) -> SendLocation {
105        SendLocation::new(self.id, latitude, longitude, horizontal_accuracy)
106    }
107
108    pub fn send_media_group(&self) -> SendMediaGroup {
109        SendMediaGroup::new(self.id)
110    }
111
112    pub fn send_message(&self, text: impl Into<String>) -> SendMessage {
113        SendMessage::new(self.id, text)
114    }
115
116    pub fn send_photo(&self, photo: impl Into<InputFileVariant>) -> SendPhoto {
117        SendPhoto::new(self.id, photo)
118    }
119
120    pub fn send_poll(&self, question: impl Into<String>, options: Vec<String>) -> SendPoll {
121        SendPoll::new_regular(self.id, question, options)
122    }
123
124    pub fn send_quiz(
125        &self,
126        question: impl Into<String>,
127        options: Vec<String>,
128        correct_option_id: u32,
129    ) -> SendPoll {
130        SendPoll::new_quiz(self.id, question, options, correct_option_id)
131    }
132
133    pub fn send_venue(
134        &self,
135        latitude: f32,
136        longitude: f32,
137        title: impl Into<String>,
138        address: impl Into<String>,
139    ) -> SendVenue {
140        SendVenue::new(self.id, latitude, longitude, title, address)
141    }
142
143    pub fn send_video(&self, video: impl Into<InputFileVariant>) -> SendVideo {
144        SendVideo::new(self.id, video)
145    }
146
147    pub fn send_video_note(&self, video_note: impl Into<InputFileVariant>) -> SendVideoNote {
148        SendVideoNote::new(self.id, video_note)
149    }
150
151    pub fn send_voice(&self, voice: impl Into<InputFileVariant>) -> SendVoice {
152        SendVoice::new(self.id, voice)
153    }
154
155    pub fn ban(&self, user_id: i64) -> BanChatMember {
156        BanChatMember::new(self.id, user_id)
157    }
158
159    pub fn unban(&self, user_id: i64) -> UnbanChatMember {
160        UnbanChatMember::new(self.id, user_id)
161    }
162
163    pub fn restrict(&self, user_id: i64, permissions: ChatPermissions) -> RestrictChatMember {
164        RestrictChatMember::new(self.id, user_id, permissions)
165    }
166
167    pub fn promote(&self, user_id: i64) -> PromoteChatMember {
168        PromoteChatMember::new(self.id, user_id)
169    }
170
171    pub fn set_administrator_title(
172        &self,
173        user_id: i64,
174        custom_title: impl Into<String>,
175    ) -> SetChatAdministratorCustomTitle {
176        SetChatAdministratorCustomTitle::new(self.id, user_id, custom_title)
177    }
178
179    pub fn set_permissions(&self, permissions: ChatPermissions) -> SetChatPermissions {
180        SetChatPermissions::new(self.id, permissions)
181    }
182
183    pub fn export_invite_link(&self) -> ExportChatInviteLink {
184        ExportChatInviteLink::new(self.id)
185    }
186
187    pub fn create_invite_link(&self) -> CreateChatInviteLink {
188        CreateChatInviteLink::new(self.id)
189    }
190
191    pub fn edit_invite_link(&self, invite_link: impl Into<String>) -> EditChatInviteLink {
192        EditChatInviteLink::new(self.id, invite_link)
193    }
194
195    pub fn revoke_invite_link(&self, invite_link: impl Into<String>) -> RevokeChatInviteLink {
196        RevokeChatInviteLink::new(self.id, invite_link)
197    }
198
199    pub fn approve_join(&self, user_id: i64) -> ApproveChatJoinRequest {
200        ApproveChatJoinRequest::new(self.id, user_id)
201    }
202
203    pub fn decline_join(&self, user_id: i64) -> DeclineChatJoinRequest {
204        DeclineChatJoinRequest::new(self.id, user_id)
205    }
206
207    pub fn set_photo(&self, photo: InputFile) -> SetChatPhoto {
208        SetChatPhoto::new(self.id, photo)
209    }
210
211    pub fn delete_photo(&self) -> DeleteChatPhoto {
212        DeleteChatPhoto::new(self.id)
213    }
214
215    pub fn set_title(&self, title: impl Into<String>) -> SetChatTitle {
216        SetChatTitle::new(self.id, title)
217    }
218
219    pub fn set_description(&self, description: impl Into<String>) -> SetChatDescription {
220        SetChatDescription::new(self.id, description)
221    }
222
223    pub fn remove_description(&self) -> SetChatDescription {
224        SetChatDescription::new_empty(self.id)
225    }
226
227    pub fn pin_message(&self, message_id: i64) -> PinChatMessage {
228        PinChatMessage::new(self.id, message_id)
229    }
230
231    pub fn unpin_message(&self, message_id: i64) -> UnpinChatMessage {
232        UnpinChatMessage::new(self.id, message_id)
233    }
234
235    pub fn unpin_latest_message(&self) -> UnpinChatMessage {
236        UnpinChatMessage::new_recent(self.id)
237    }
238
239    pub fn unpin_all_messages(&self) -> UnpinAllChatMessages {
240        UnpinAllChatMessages::new(self.id)
241    }
242
243    pub fn leave(&self) -> LeaveChat {
244        LeaveChat::new(self.id)
245    }
246
247    pub fn get_details(&self) -> GetChat {
248        GetChat::new(self.id)
249    }
250
251    pub fn get_administrators(&self) -> GetChatAdministrators {
252        GetChatAdministrators::new(self.id)
253    }
254
255    pub fn get_member_count(&self) -> GetChatMemberCount {
256        GetChatMemberCount::new(self.id)
257    }
258
259    pub fn get_member(&self, user_id: i64) -> GetChatMember {
260        GetChatMember::new(self.id, user_id)
261    }
262
263    pub fn set_sticker_set(&self, sticker_set_name: impl Into<String>) -> SetChatStickerSet {
264        SetChatStickerSet::new(self.id, sticker_set_name)
265    }
266
267    pub fn delete_sticker_set(&self) -> DeleteChatStickerSet {
268        DeleteChatStickerSet::new(self.id)
269    }
270
271    pub fn edit_text_of(&self, message_id: i64, text: impl Into<String>) -> EditMessageText {
272        EditMessageText::new(self.id, message_id, text)
273    }
274
275    pub fn remove_caption_of(&self, message_id: i64) -> EditMessageCaption {
276        EditMessageCaption::new_empty(self.id, message_id)
277    }
278
279    pub fn edit_caption_of(
280        &self,
281        message_id: i64,
282        caption: impl Into<String>,
283    ) -> EditMessageCaption {
284        EditMessageCaption::new(self.id, message_id, caption)
285    }
286
287    pub fn edit_media_of(&self, message_id: i64, media: impl Into<InputMedia>) -> EditMessageMedia {
288        EditMessageMedia::new(self.id, message_id, media)
289    }
290
291    pub fn remove_reply_markup_of(&self, message_id: i64) -> EditMessageReplyMarkup {
292        EditMessageReplyMarkup::new_empty(self.id, message_id)
293    }
294
295    pub fn edit_reply_markup_of(
296        &self,
297        message_id: i64,
298        reply_markup: impl Into<InlineKeyboardMarkup>,
299    ) -> EditMessageReplyMarkup {
300        EditMessageReplyMarkup::new(self.id, message_id, reply_markup)
301    }
302
303    pub fn stop_poll(&self, message_id: i64) -> StopPoll {
304        StopPoll::new(self.id, message_id)
305    }
306
307    pub fn delete_message(&self, message_id: i64) -> DeleteMessage {
308        DeleteMessage::new(self.id, message_id)
309    }
310}
311
312#[derive(Debug, Deserialize, PartialEq, Eq, Hash)]
313#[serde(rename_all = "snake_case", tag = "type")]
314pub enum ChatKind {
315    Private,
316    Group,
317    Supergroup,
318    Channel,
319}
320
321/// This object represents a chat photo.
322#[derive(Debug, Deserialize)]
323pub struct ChatPhoto {
324    /// File identifier of small (160x160) chat photo.
325    /// This file_id can be used only for photo download
326    /// and only for as long as the photo is not changed.
327    pub small_file_id: String,
328    /// Unique file identifier of small (160x160) chat photo,
329    /// which is supposed to be the same over time and for different bots.
330    /// Can't be used to download or reuse the file.
331    pub small_file_unique_id: String,
332    /// File identifier of big (640x640) chat photo.
333    /// This file_id can be used only for photo download
334    /// and only for as long as the photo is not changed.
335    pub big_file_id: String,
336    /// Unique file identifier of big (640x640) chat photo,
337    /// which is supposed to be the same over time and for different bots.
338    /// Can't be used to download or reuse the file.
339    pub big_file_unique_id: String,
340}
341
342#[derive(Debug, Deserialize)]
343pub struct ChatLocation {
344    /// The location to which the supergroup is connected.
345    /// Can't be a live location.
346    pub location: Location,
347    /// Location address; 1-64 characters, as defined by the chat owner
348    pub address: String,
349}
350
351/// Describes actions that a non-administrator user is allowed to take in a chat.
352#[derive(Debug, Clone, Serialize, Deserialize, Default)]
353pub struct ChatPermissions {
354    /// True, if the user is allowed to send text messages, contacts, locations and venues
355    #[serde(skip_serializing_if = "Option::is_none")]
356    pub can_send_messages: Option<bool>,
357    /// True, if the user is allowed to send audios, documents,
358    /// photos, videos, video notes and voice notes, implies can_send_messages
359    #[serde(skip_serializing_if = "Option::is_none")]
360    pub can_send_media_messages: Option<bool>,
361    /// True, if the user is allowed to send polls, implies can_send_messages
362    #[serde(skip_serializing_if = "Option::is_none")]
363    pub can_send_polls: Option<bool>,
364    /// True, if the user is allowed to send animations, games, stickers
365    /// and use inline bots, implies can_send_media_messages
366    #[serde(skip_serializing_if = "Option::is_none")]
367    pub can_send_other_messages: Option<bool>,
368    /// True, if the user is allowed to add web page previews to their messages,
369    /// implies can_send_media_messages
370    #[serde(skip_serializing_if = "Option::is_none")]
371    pub can_add_web_page_previews: Option<bool>,
372    /// True, if the user is allowed to change the chat title, photo and other settings.
373    /// Ignored in public supergroups
374    #[serde(skip_serializing_if = "Option::is_none")]
375    pub can_change_info: Option<bool>,
376    /// True, if the user is allowed to invite new users to the chat
377    #[serde(skip_serializing_if = "Option::is_none")]
378    pub can_invite_users: Option<bool>,
379    /// True, if the user is allowed to pin messages.
380    /// Ignored in public supergroups
381    #[serde(skip_serializing_if = "Option::is_none")]
382    pub can_pin_messages: Option<bool>,
383}
384
385impl ChatPermissions {
386    /// Create a new ChatPermissions object
387    pub fn new() -> Self {
388        Default::default()
389    }
390    /// Set can_send_messages to `true`
391    pub fn allow_send_messages(self) -> Self {
392        Self {
393            can_send_messages: Some(true),
394            ..self
395        }
396    }
397    /// Set can_send_media_messages to `true`
398    pub fn allow_send_media_messages(self) -> Self {
399        Self {
400            can_send_media_messages: Some(true),
401            ..self
402        }
403    }
404    /// Set can_send_polls to `true`
405    pub fn allow_send_polls(self) -> Self {
406        Self {
407            can_send_polls: Some(true),
408            ..self
409        }
410    }
411    /// Set can_send_other_messages to `true`
412    pub fn allow_send_other_messages(self) -> Self {
413        Self {
414            can_send_other_messages: Some(true),
415            ..self
416        }
417    }
418    /// Set can_add_web_page_previews to `true`
419    pub fn allow_add_web_page_previews(self) -> Self {
420        Self {
421            can_add_web_page_previews: Some(true),
422            ..self
423        }
424    }
425    /// Set can_change_info to `true`
426    pub fn allow_change_info(self) -> Self {
427        Self {
428            can_change_info: Some(true),
429            ..self
430        }
431    }
432    /// Set can_invite_users to `true`
433    pub fn allow_invite_users(self) -> Self {
434        Self {
435            can_invite_users: Some(true),
436            ..self
437        }
438    }
439    /// Set can_pin_messages to `true`
440    pub fn allow_pin_messages(self) -> Self {
441        Self {
442            can_pin_messages: Some(true),
443            ..self
444        }
445    }
446}
447
448#[derive(Debug, Deserialize)]
449#[serde(rename_all = "snake_case", tag = "status")]
450pub enum ChatMember {
451    /// Represents a [chat member](https://core.telegram.org/bots/api#chatmember)
452    /// that owns the chat and has all administrator privileges.
453    #[serde(rename = "creator")]
454    Owner {
455        /// Information about the user
456        user: User,
457        /// True, if the user's presence in the chat is hidden
458        is_anonymous: bool,
459        /// Custom title for this user
460        custom_title: Option<String>,
461    },
462    /// Represents a [chat member](https://core.telegram.org/bots/api#chatmember)
463    /// that has some additional privileges.
464    Administrator {
465        /// Information about the user
466        user: User,
467        /// True, if the bot is allowed to edit administrator privileges of that user
468        can_be_edited: bool,
469        /// True, if the user's presence in the chat is hidden
470        is_anonymous: bool,
471        /// True, if the administrator can access the chat event log, chat statistics,
472        /// message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode.
473        /// Implied by any other administrator privilege
474        can_manage_chat: bool,
475        /// True, if the administrator can delete messages of other users
476        can_delete_messages: bool,
477        /// True, if the administrator can manage voice chats
478        can_manage_voice_chats: bool,
479        /// True, if the administrator can restrict, ban or unban chat members
480        can_restrict_members: bool,
481        /// True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that he has promoted,
482        /// directly or indirectly (promoted by administrators that were appointed by the user)
483        can_promote_members: bool,
484        /// True, if the user is allowed to change the chat title, photo and other settings
485        can_change_info: bool,
486        /// True, if the user is allowed to invite new users to the chat
487        can_invite_users: bool,
488        /// True, if the administrator can post in the channel; channels only
489        can_post_messages: Option<bool>,
490        /// True, if the administrator can edit messages of other users and can pin messages; channels only
491        can_edit_messages: Option<bool>,
492        /// True, if the user is allowed to pin messages; groups and supergroups only
493        can_pin_messages: Option<bool>,
494        /// Custom title for this user
495        custom_title: Option<String>,
496    },
497    /// Represents a [chat member](https://core.telegram.org/bots/api#chatmember)
498    /// that has no additional privileges or restrictions.
499    Member {
500        /// Information about the user
501        user: User,
502    },
503    /// Represents a [chat member](https://core.telegram.org/bots/api#chatmember)
504    /// that is under certain restrictions in the chat. Supergroups only.
505    Restricted {
506        /// Information about the user
507        user: User,
508        /// True, if the user is a member of the chat at the moment of the request
509        is_member: bool,
510        /// True, if the user is allowed to change the chat title, photo and other settings
511        can_change_info: bool,
512        /// True, if the user is allowed to invite new users to the chat
513        can_invite_users: bool,
514        /// True, if the user is allowed to pin messages
515        can_pin_messages: bool,
516        /// True, if the user is allowed to send text messages, contacts, locations and venues
517        can_send_messages: bool,
518        /// True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes
519        can_send_media_messages: bool,
520        /// True, if the user is allowed to send polls
521        can_send_polls: bool,
522        /// True, if the user is allowed to send animations, games, stickers and use inline bots
523        can_send_other_messages: bool,
524        /// True, if the user is allowed to add web page previews to their messages
525        can_add_web_page_previews: bool,
526        /// Date when restrictions will be lifted for this user; unix time.
527        /// If 0, then the user is restricted forever
528        until_date: u64,
529    },
530    /// Represents a [chat member](https://core.telegram.org/bots/api#chatmember)
531    /// that isn't currently a member of the chat, but may join it themselves.
532    Left {
533        /// Information about the user
534        user: User,
535    },
536    /// Represents a [chat member](https://core.telegram.org/bots/api#chatmember)
537    /// that was banned in the chat and can't return to the chat or view chat messages.
538    #[serde(rename = "kicked")]
539    Banned {
540        /// Information about the user
541        user: User,
542        /// Date when restrictions will be lifted for this user; unix time.
543        /// If 0, then the user is banned forever
544        until_date: u64,
545    },
546}
547
548impl ChatMember {
549    pub fn user(&self) -> &User {
550        match self {
551            ChatMember::Owner { user, .. }
552            | ChatMember::Administrator { user, .. }
553            | ChatMember::Member { user }
554            | ChatMember::Restricted { user, .. }
555            | ChatMember::Left { user }
556            | ChatMember::Banned { user, .. } => user,
557        }
558    }
559
560    pub fn is_anonymous(&self) -> Option<bool> {
561        match self {
562            ChatMember::Owner { is_anonymous, .. }
563            | ChatMember::Administrator { is_anonymous, .. } => Some(*is_anonymous),
564            _ => None,
565        }
566    }
567
568    pub fn custom_title(&self) -> Option<&str> {
569        match self {
570            Self::Owner { custom_title, .. } | Self::Administrator { custom_title, .. } => {
571                custom_title.as_deref()
572            }
573            _ => None,
574        }
575    }
576
577    pub fn can_be_edited(&self) -> Option<bool> {
578        match self {
579            Self::Administrator { can_be_edited, .. } => Some(*can_be_edited),
580            _ => None,
581        }
582    }
583
584    pub fn can_manage_chat(&self) -> Option<bool> {
585        match self {
586            Self::Administrator {
587                can_manage_chat, ..
588            } => Some(*can_manage_chat),
589            _ => None,
590        }
591    }
592
593    pub fn can_delete_messages(&self) -> Option<bool> {
594        match self {
595            Self::Administrator {
596                can_delete_messages,
597                ..
598            } => Some(*can_delete_messages),
599            _ => None,
600        }
601    }
602
603    pub fn can_manage_voice_chats(&self) -> Option<bool> {
604        match self {
605            Self::Administrator {
606                can_manage_voice_chats,
607                ..
608            } => Some(*can_manage_voice_chats),
609            _ => None,
610        }
611    }
612
613    pub fn can_restrict_members(&self) -> Option<bool> {
614        match self {
615            Self::Administrator {
616                can_restrict_members,
617                ..
618            } => Some(*can_restrict_members),
619            _ => None,
620        }
621    }
622
623    pub fn can_promote_members(&self) -> Option<bool> {
624        match self {
625            Self::Administrator {
626                can_promote_members,
627                ..
628            } => Some(*can_promote_members),
629            _ => None,
630        }
631    }
632
633    pub fn can_change_info(&self) -> Option<bool> {
634        match self {
635            Self::Administrator {
636                can_change_info, ..
637            }
638            | Self::Restricted {
639                can_change_info, ..
640            } => Some(*can_change_info),
641            _ => None,
642        }
643    }
644
645    pub fn can_invite_users(&self) -> Option<bool> {
646        match self {
647            Self::Administrator {
648                can_invite_users, ..
649            }
650            | Self::Restricted {
651                can_invite_users, ..
652            } => Some(*can_invite_users),
653            _ => None,
654        }
655    }
656
657    pub fn can_edit_messages(&self) -> Option<bool> {
658        match self {
659            Self::Administrator {
660                can_edit_messages, ..
661            } => *can_edit_messages,
662            _ => None,
663        }
664    }
665
666    pub fn can_pin_messages(&self) -> Option<bool> {
667        match self {
668            Self::Administrator {
669                can_pin_messages, ..
670            } => *can_pin_messages,
671            Self::Restricted {
672                can_pin_messages, ..
673            } => Some(*can_pin_messages),
674            _ => None,
675        }
676    }
677
678    pub fn can_post_messages(&self) -> Option<bool> {
679        match self {
680            Self::Administrator {
681                can_post_messages, ..
682            } => *can_post_messages,
683            _ => None,
684        }
685    }
686
687    pub fn can_send_messages(&self) -> Option<bool> {
688        match self {
689            Self::Restricted {
690                can_send_messages, ..
691            } => Some(*can_send_messages),
692            _ => None,
693        }
694    }
695
696    pub fn can_send_media_messages(&self) -> Option<bool> {
697        match self {
698            Self::Restricted {
699                can_send_media_messages,
700                ..
701            } => Some(*can_send_media_messages),
702            _ => None,
703        }
704    }
705
706    pub fn can_send_polls(&self) -> Option<bool> {
707        match self {
708            Self::Restricted { can_send_polls, .. } => Some(*can_send_polls),
709            _ => None,
710        }
711    }
712
713    pub fn can_send_other_messages(&self) -> Option<bool> {
714        match self {
715            Self::Restricted {
716                can_send_other_messages,
717                ..
718            } => Some(*can_send_other_messages),
719            _ => None,
720        }
721    }
722
723    pub fn can_add_web_page_previews(&self) -> Option<bool> {
724        match self {
725            Self::Restricted {
726                can_add_web_page_previews,
727                ..
728            } => Some(*can_add_web_page_previews),
729            _ => None,
730        }
731    }
732
733    pub fn is_member(&self) -> bool {
734        match self {
735            Self::Owner { .. } | Self::Administrator { .. } | Self::Member { .. } => true,
736            Self::Restricted { is_member, .. } => *is_member,
737            ChatMember::Left { .. } | ChatMember::Banned { .. } => false,
738        }
739    }
740
741    pub fn banned_until(&self) -> Option<u64> {
742        match self {
743            Self::Banned { until_date, .. } => Some(*until_date),
744            _ => None,
745        }
746    }
747
748    pub fn restricted_until(&self) -> Option<u64> {
749        match self {
750            Self::Restricted { until_date, .. } => Some(*until_date),
751            _ => None,
752        }
753    }
754}
755
756/// Represents an invite link for a chat.
757#[derive(Debug, Deserialize)]
758pub struct ChatInviteLink {
759    /// The invite link.
760    /// If the link was created by another chat administrator,
761    /// then the second part of the link will be replaced with “…”.
762    pub invite_link: String,
763    /// Creator of the link
764    pub creator: User,
765    /// True, if the link is primary
766    pub is_primary: bool,
767    /// True, if the link is revoked
768    pub is_revoked: bool,
769    /// Point in time (Unix timestamp) when the link will expire or has been expired
770    pub expire_date: Option<u64>,
771    /// Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
772    pub member_limit: Option<u32>,
773}
774
775/// This object represents changes in the status of a chat member.
776#[derive(Debug, Deserialize)]
777pub struct ChatMemberUpdated {
778    /// Chat the user belongs to
779    pub chat: Chat,
780    /// Performer of the action, which resulted in the change
781    pub from: User,
782    /// Date the change was done in Unix time
783    pub date: u64,
784    /// Previous information about the chat member
785    pub old_chat_member: ChatMember,
786    /// New information about the chat member
787    pub new_chat_member: ChatMember,
788    /// Chat invite link, which was used by the user to join the chat;
789    /// for joining by invite link events only.
790    pub invite_link: Option<ChatInviteLink>,
791}
792
793/// Chat identifier
794#[derive(Clone, Serialize)]
795#[serde(untagged)]
796pub enum ChatId {
797    Id(i64),
798    Username(String),
799}
800
801impl From<i64> for ChatId {
802    fn from(id: i64) -> Self {
803        Self::Id(id)
804    }
805}
806
807impl From<String> for ChatId {
808    fn from(username: String) -> Self {
809        Self::Username(username)
810    }
811}
812
813impl From<&str> for ChatId {
814    fn from(username: &str) -> Self {
815        Self::Username(username.to_string())
816    }
817}
818
819/// Use this method to ban a user in a group, a supergroup or a channel.
820/// In the case of supergroups and channels, the user will not be able to return to the chat
821/// on their own using invite links, etc., unless unbanned first.
822/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
823/// Returns True on success.
824#[derive(Clone, Serialize)]
825pub struct BanChatMember {
826    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
827    pub chat_id: ChatId,
828    /// Unique identifier of the target user
829    pub user_id: i64,
830    /// Date when the user will be unbanned, unix time.
831    /// If user is banned for more than 366 days or less than 30 seconds from the current time
832    /// they are considered to be banned forever.
833    /// Applied for supergroups and channels only.
834    #[serde(skip_serializing_if = "Option::is_none")]
835    pub until_date: Option<u64>,
836    /// Pass _True_ to delete all messages from the chat for the user that is being removed.
837    /// If _False_, the user will be able to see messages in the group that were sent before the user was removed.
838    /// Always _True_ for supergroups and channels.
839    #[serde(skip_serializing_if = "Option::is_none")]
840    pub revoke_messages: Option<bool>,
841}
842
843impl BanChatMember {
844    /// Create a new banChatMember request
845    pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
846        Self {
847            chat_id: chat_id.into(),
848            user_id,
849            until_date: None,
850            revoke_messages: None,
851        }
852    }
853
854    /// Set the date at which the user will be unbanned
855    pub fn until_date(self, date: u64) -> Self {
856        Self {
857            until_date: Some(date),
858            ..self
859        }
860    }
861
862    /// Set revoke_messages to `true`
863    pub fn revoke_messages(self) -> Self {
864        Self {
865            revoke_messages: Some(true),
866            ..self
867        }
868    }
869}
870
871impl TelegramMethod for BanChatMember {
872    type Response = bool;
873
874    fn name() -> &'static str {
875        "banChatMember"
876    }
877}
878
879impl JsonMethod for BanChatMember {}
880
881/// Use this method to unban a previously banned user in a supergroup or channel.
882/// The user will **not** return to the group or channel automatically, but will be able to join via link, etc.
883/// The bot must be an administrator for this to work.
884/// By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it.
885/// So if the user is a member of the chat they will also be **removed** from the chat.
886/// If you don't want this, use the parameter *only_if_banned*.
887/// Returns _True_ on success.
888#[derive(Clone, Serialize)]
889pub struct UnbanChatMember {
890    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
891    pub chat_id: ChatId,
892    /// Unique identifier of the target user
893    pub user_id: i64,
894    /// Do nothing if the user is not banned
895    #[serde(skip_serializing_if = "Option::is_none")]
896    pub only_if_banned: Option<bool>,
897}
898
899impl UnbanChatMember {
900    /// Create a new unbanChatMember request
901    pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
902        Self {
903            chat_id: chat_id.into(),
904            user_id,
905            only_if_banned: None,
906        }
907    }
908
909    /// Set only_if_banned to `true`
910    pub fn only_if_banned(self) -> Self {
911        Self {
912            only_if_banned: Some(true),
913            ..self
914        }
915    }
916}
917
918impl TelegramMethod for UnbanChatMember {
919    type Response = bool;
920
921    fn name() -> &'static str {
922        "unbanChatMember"
923    }
924}
925
926impl JsonMethod for UnbanChatMember {}
927
928/// Use this method to restrict a user in a supergroup.
929/// The bot must be an administrator in the supergroup for this to work and must have the appropriate administrator rights.
930/// Pass *True* for all permissions to lift restrictions from a user.
931/// Returns *True* on success.
932#[derive(Clone, Serialize)]
933pub struct RestrictChatMember {
934    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
935    pub chat_id: ChatId,
936    /// Unique identifier of the target user
937    pub user_id: i64,
938    /// A JSON-serialized object for new user permissions
939    pub permissions: ChatPermissions,
940    /// Date when restrictions will be lifted for the user, unix time.
941    /// If user is restricted for more than 366 days or less than 30 seconds from the current time,
942    /// they are considered to be restricted forever
943    #[serde(skip_serializing_if = "Option::is_none")]
944    pub until_date: Option<u64>,
945}
946
947impl RestrictChatMember {
948    /// Create a new restrictChatMember request
949    pub fn new(chat_id: impl Into<ChatId>, user_id: i64, permissions: ChatPermissions) -> Self {
950        Self {
951            chat_id: chat_id.into(),
952            user_id,
953            permissions,
954            until_date: None,
955        }
956    }
957
958    /// Set the date at which the restriction wil be lifted
959    pub fn until_date(self, date: u64) -> Self {
960        Self {
961            until_date: Some(date),
962            ..self
963        }
964    }
965}
966
967impl TelegramMethod for RestrictChatMember {
968    type Response = bool;
969
970    fn name() -> &'static str {
971        "restrictChatMember"
972    }
973}
974
975impl JsonMethod for RestrictChatMember {}
976
977/// Use this method to promote or demote a user in a supergroup or a channel.
978/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
979/// Pass _False_ for all boolean parameters to demote a user.
980/// Returns _True_ on success.
981#[derive(Clone, Serialize)]
982pub struct PromoteChatMember {
983    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
984    pub chat_id: ChatId,
985    /// Unique identifier of the target user
986    pub user_id: i64,
987    /// Pass _True_, if the administrator's presence in the chat is hidden
988    #[serde(skip_serializing_if = "Option::is_none")]
989    pub is_anonymous: Option<bool>,
990    /// Pass _True_, if the administrator can access the chat event log, chat statistics, message statistics in channels,
991    /// see channel members, see anonymous administrators in supergroups and ignore slow mode.
992    /// Implied by any other administrator privilege
993    #[serde(skip_serializing_if = "Option::is_none")]
994    pub can_manage_chat: Option<bool>,
995    /// Pass _True_, if the administrator can delete messages of other users
996    #[serde(skip_serializing_if = "Option::is_none")]
997    pub can_delete_messages: Option<bool>,
998    /// Pass _True_, if the administrator can manage voice chats
999    #[serde(skip_serializing_if = "Option::is_none")]
1000    pub can_manage_voice_chats: Option<bool>,
1001    /// Pass _True_, if the administrator can restrict, ban or unban chat members
1002    #[serde(skip_serializing_if = "Option::is_none")]
1003    pub can_restrict_members: Option<bool>,
1004    /// Pass _True_, if the administrator can add new administrators with a subset of their own privileges or demote administrators that he has promoted,
1005    /// directly or indirectly (promoted by administrators that were appointed by him)
1006    #[serde(skip_serializing_if = "Option::is_none")]
1007    pub can_promote_members: Option<bool>,
1008    /// Pass _True_, if the administrator can change chat title, photo and other settings
1009    #[serde(skip_serializing_if = "Option::is_none")]
1010    pub can_change_info: Option<bool>,
1011    /// Pass _True_, if the administrator can invite new users to the chat
1012    #[serde(skip_serializing_if = "Option::is_none")]
1013    pub can_invite_users: Option<bool>,
1014    /// Pass _True_, if the administrator can create channel posts, channels only
1015    #[serde(skip_serializing_if = "Option::is_none")]
1016    pub can_post_messages: Option<bool>,
1017    /// Pass _True_, if the administrator can edit messages of other users and can pin messages, channels only
1018    #[serde(skip_serializing_if = "Option::is_none")]
1019    pub can_edit_messages: Option<bool>,
1020    /// Pass _True_, if the administrator can pin messages, supergroups only
1021    #[serde(skip_serializing_if = "Option::is_none")]
1022    pub can_pin_messages: Option<bool>,
1023}
1024
1025impl PromoteChatMember {
1026    /// Create a new promoteChatMember request
1027    pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
1028        Self {
1029            chat_id: chat_id.into(),
1030            user_id,
1031            is_anonymous: None,
1032            can_manage_chat: None,
1033            can_delete_messages: None,
1034            can_manage_voice_chats: None,
1035            can_restrict_members: None,
1036            can_promote_members: None,
1037            can_change_info: None,
1038            can_invite_users: None,
1039            can_post_messages: None,
1040            can_edit_messages: None,
1041            can_pin_messages: None,
1042        }
1043    }
1044
1045    /// Create a new promoteChatMember request that demotes the user
1046    ///
1047    /// It creates a new promoteChatMember request with all options disabled.
1048    pub fn demote(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
1049        Self {
1050            chat_id: chat_id.into(),
1051            user_id,
1052            is_anonymous: Some(false),
1053            can_manage_chat: Some(false),
1054            can_delete_messages: Some(false),
1055            can_manage_voice_chats: Some(false),
1056            can_restrict_members: Some(false),
1057            can_promote_members: Some(false),
1058            can_change_info: Some(false),
1059            can_invite_users: Some(false),
1060            can_post_messages: Some(false),
1061            can_edit_messages: Some(false),
1062            can_pin_messages: Some(false),
1063        }
1064    }
1065
1066    /// Set `is_anonymous` to `true`
1067    pub fn anonymous(self) -> Self {
1068        Self {
1069            is_anonymous: Some(true),
1070            ..self
1071        }
1072    }
1073
1074    /// Set `can_manage_chat` to `true`
1075    pub fn allow_manage_chat(self) -> Self {
1076        Self {
1077            can_manage_chat: Some(true),
1078            ..self
1079        }
1080    }
1081
1082    /// Set `can_delete_messages` to `true`
1083    pub fn allow_delete_messages(self) -> Self {
1084        Self {
1085            can_delete_messages: Some(true),
1086            ..self
1087        }
1088    }
1089
1090    /// Set `can_manage_voice_chats` to `true`
1091    pub fn allow_manage_voice_chats(self) -> Self {
1092        Self {
1093            can_manage_voice_chats: Some(true),
1094            ..self
1095        }
1096    }
1097
1098    /// Set `can_restrict_members` to `true`
1099    pub fn allow_restrict_members(self) -> Self {
1100        Self {
1101            can_restrict_members: Some(true),
1102            ..self
1103        }
1104    }
1105
1106    /// Set `can_promote_members` to `true`
1107    pub fn allow_promote_members(self) -> Self {
1108        Self {
1109            can_promote_members: Some(true),
1110            ..self
1111        }
1112    }
1113
1114    /// Set `can_change_info` to `true`
1115    pub fn allow_change_info(self) -> Self {
1116        Self {
1117            can_change_info: Some(true),
1118            ..self
1119        }
1120    }
1121
1122    /// Set `can_invite_users` to `true`
1123    pub fn allow_invite_users(self) -> Self {
1124        Self {
1125            can_invite_users: Some(true),
1126            ..self
1127        }
1128    }
1129
1130    /// Set `can_post_messages` to `true`
1131    pub fn allow_post_messages(self) -> Self {
1132        Self {
1133            can_post_messages: Some(true),
1134            ..self
1135        }
1136    }
1137
1138    /// Set `can_edit_messages` to `true`
1139    pub fn allow_edit_messages(self) -> Self {
1140        Self {
1141            can_edit_messages: Some(true),
1142            ..self
1143        }
1144    }
1145
1146    /// Set `can_pin_messages` to `true`
1147    pub fn allow_pin_messages(self) -> Self {
1148        Self {
1149            can_pin_messages: Some(true),
1150            ..self
1151        }
1152    }
1153}
1154
1155impl TelegramMethod for PromoteChatMember {
1156    type Response = bool;
1157
1158    fn name() -> &'static str {
1159        "promoteChatMember"
1160    }
1161}
1162
1163impl JsonMethod for PromoteChatMember {}
1164
1165/// Use this method to set a custom title for an administrator in a supergroup promoted by the bot.
1166/// Returns _True_ on success.
1167#[derive(Clone, Serialize)]
1168pub struct SetChatAdministratorCustomTitle {
1169    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
1170    pub chat_id: ChatId,
1171    /// Unique identifier of the target user
1172    pub user_id: i64,
1173    /// New custom title for the administrator; 0-16 characters, emoji are not allowed
1174    pub custom_title: String,
1175}
1176
1177impl SetChatAdministratorCustomTitle {
1178    /// Create a new setChatAdministratorCustomTitle request
1179    pub fn new(chat_id: impl Into<ChatId>, user_id: i64, custom_title: impl Into<String>) -> Self {
1180        Self {
1181            chat_id: chat_id.into(),
1182            user_id,
1183            custom_title: custom_title.into(),
1184        }
1185    }
1186}
1187
1188impl TelegramMethod for SetChatAdministratorCustomTitle {
1189    type Response = bool;
1190
1191    fn name() -> &'static str {
1192        "setChatAdministratorCustomTitle"
1193    }
1194}
1195
1196impl JsonMethod for SetChatAdministratorCustomTitle {}
1197
1198/// Use this method to set default chat permissions for all members.
1199/// The bot must be an administrator in the group or a supergroup for this to work and must have the *can_restrict_members* administrator rights.
1200/// Returns _True_ on success.
1201#[derive(Clone, Serialize)]
1202pub struct SetChatPermissions {
1203    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
1204    pub chat_id: ChatId,
1205    /// A JSON-serialized object for new user permissions
1206    pub permissions: ChatPermissions,
1207}
1208
1209impl SetChatPermissions {
1210    /// Create a new setChatPermissions request
1211    pub fn new(chat_id: impl Into<ChatId>, permissions: ChatPermissions) -> Self {
1212        Self {
1213            chat_id: chat_id.into(),
1214            permissions,
1215        }
1216    }
1217}
1218
1219impl TelegramMethod for SetChatPermissions {
1220    type Response = bool;
1221
1222    fn name() -> &'static str {
1223        "setChatPermissions"
1224    }
1225}
1226
1227impl JsonMethod for SetChatPermissions {}
1228
1229/// Use this method to generate a new primary invite link for a chat;
1230/// any previously generated primary link is revoked.
1231/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
1232/// Returns the new invite link as _String_ on success.
1233///
1234/// Note: Each administrator in a chat generates their own invite links.
1235/// Bots can't use invite links generated by other administrators.
1236/// If you want your bot to work with invite links,
1237/// it will need to generate its own link using [exportChatInviteLink](https://core.telegram.org/bots/api#exportchatinvitelink)
1238/// or by calling the [getChat](https://core.telegram.org/bots/api#getchat) method.
1239/// If your bot needs to generate a new primary invite link replacing its previous one,
1240/// use [exportChatInviteLink](https://core.telegram.org/bots/api#exportchatinvitelink) again.
1241#[derive(Clone, Serialize)]
1242pub struct ExportChatInviteLink {
1243    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
1244    pub chat_id: ChatId,
1245}
1246
1247impl ExportChatInviteLink {
1248    /// Create a new exportChatInviteLink request
1249    pub fn new(chat_id: impl Into<ChatId>) -> Self {
1250        Self {
1251            chat_id: chat_id.into(),
1252        }
1253    }
1254}
1255
1256impl TelegramMethod for ExportChatInviteLink {
1257    type Response = String;
1258
1259    fn name() -> &'static str {
1260        "exportChatInviteLink"
1261    }
1262}
1263
1264impl JsonMethod for ExportChatInviteLink {}
1265
1266/// Use this method to create an additional invite link for a chat.
1267/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
1268/// The link can be revoked using the method [revokeChatInviteLink](https://core.telegram.org/bots/api#revokechatinvitelink).
1269/// Returns the new invite link as [ChatInviteLink](https://core.telegram.org/bots/api#chatinvitelink) object.
1270#[derive(Clone, Serialize)]
1271pub struct CreateChatInviteLink {
1272    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
1273    pub chat_id: ChatId,
1274    /// Invite link name; 0-32 characters
1275    #[serde(skip_serializing_if = "Option::is_none")]
1276    pub name: Option<String>,
1277    /// Point in time (Unix timestamp) when the link will expire
1278    #[serde(skip_serializing_if = "Option::is_none")]
1279    pub expire_date: Option<u64>,
1280    /// Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
1281    #[serde(skip_serializing_if = "Option::is_none")]
1282    pub member_limit: Option<u32>,
1283    /// _True_, if users joining the chat via the link need to be approved by chat administrators. If _True_, *member_limit* can't be specified
1284    #[serde(skip_serializing_if = "Option::is_none")]
1285    pub creates_join_request: Option<bool>,
1286}
1287
1288impl CreateChatInviteLink {
1289    /// Create a new createChatInviteLink request
1290    pub fn new(chat_id: impl Into<ChatId>) -> Self {
1291        Self {
1292            chat_id: chat_id.into(),
1293            name: None,
1294            expire_date: None,
1295            member_limit: None,
1296            creates_join_request: None,
1297        }
1298    }
1299    /// Set invite link name
1300    pub fn with_name(self, name: impl Into<String>) -> Self {
1301        Self {
1302            name: Some(name.into()),
1303            ..self
1304        }
1305    }
1306    /// Set link expire date
1307    pub fn with_expire_date(self, expire_date: u64) -> Self {
1308        Self {
1309            expire_date: Some(expire_date),
1310            ..self
1311        }
1312    }
1313    /// Set link member limit
1314    pub fn with_member_limit(self, member_limit: u32) -> Self {
1315        Self {
1316            member_limit: Some(member_limit),
1317            ..self
1318        }
1319    }
1320    /// Set `creates_join_request` to `true`
1321    pub fn create_join_reqeuest(self) -> Self {
1322        Self {
1323            creates_join_request: Some(true),
1324            ..self
1325        }
1326    }
1327}
1328
1329impl TelegramMethod for CreateChatInviteLink {
1330    type Response = ChatInviteLink;
1331
1332    fn name() -> &'static str {
1333        "createChatInviteLink"
1334    }
1335}
1336
1337impl JsonMethod for CreateChatInviteLink {}
1338
1339/// Use this method to edit a non-primary invite link created by the bot.
1340/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
1341/// Returns the edited invite link as a [ChatInviteLink](https://core.telegram.org/bots/api#chatinvitelink) object.
1342#[derive(Clone, Serialize)]
1343pub struct EditChatInviteLink {
1344    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
1345    pub chat_id: ChatId,
1346    /// The invite link to edit
1347    pub invite_link: String,
1348    /// Invite link name; 0-32 characters
1349    #[serde(skip_serializing_if = "Option::is_none")]
1350    pub name: Option<String>,
1351    /// Point in time (Unix timestamp) when the link will expire
1352    #[serde(skip_serializing_if = "Option::is_none")]
1353    pub expire_date: Option<u64>,
1354    /// Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
1355    #[serde(skip_serializing_if = "Option::is_none")]
1356    pub member_limit: Option<u32>,
1357    /// _True_, if users joining the chat via the link need to be approved by chat administrators. If _True_, *member_limit* can't be specified
1358    #[serde(skip_serializing_if = "Option::is_none")]
1359    pub creates_join_request: Option<bool>,
1360}
1361
1362impl EditChatInviteLink {
1363    /// Create a new editChatInviteLink request
1364    pub fn new(chat_id: impl Into<ChatId>, invite_link: impl Into<String>) -> Self {
1365        Self {
1366            chat_id: chat_id.into(),
1367            invite_link: invite_link.into(),
1368            name: None,
1369            expire_date: None,
1370            member_limit: None,
1371            creates_join_request: None,
1372        }
1373    }
1374    /// Set invite link name
1375    pub fn with_name(self, name: impl Into<String>) -> Self {
1376        Self {
1377            name: Some(name.into()),
1378            ..self
1379        }
1380    }
1381    /// Set link expire date
1382    pub fn with_expire_date(self, expire_date: u64) -> Self {
1383        Self {
1384            expire_date: Some(expire_date),
1385            ..self
1386        }
1387    }
1388    /// Set link member limit
1389    pub fn with_member_limit(self, member_limit: u32) -> Self {
1390        Self {
1391            member_limit: Some(member_limit),
1392            ..self
1393        }
1394    }
1395    /// Set `creates_join_request` to `true`
1396    pub fn create_join_reqeuest(self) -> Self {
1397        Self {
1398            creates_join_request: Some(true),
1399            ..self
1400        }
1401    }
1402}
1403
1404/// Use this method to revoke an invite link created by the bot.
1405/// If the primary link is revoked, a new link is automatically generated.
1406/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
1407/// Returns the revoked invite link as [ChatInviteLink](https://core.telegram.org/bots/api#chatinvitelink) object.
1408#[derive(Clone, Serialize)]
1409pub struct RevokeChatInviteLink {
1410    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
1411    pub chat_id: ChatId,
1412    /// The invite link to revoke
1413    pub invite_link: String,
1414}
1415
1416impl RevokeChatInviteLink {
1417    /// Create a new revokeChatInviteLink object
1418    pub fn new(chat_id: impl Into<ChatId>, invite_link: impl Into<String>) -> Self {
1419        Self {
1420            chat_id: chat_id.into(),
1421            invite_link: invite_link.into(),
1422        }
1423    }
1424}
1425
1426impl TelegramMethod for RevokeChatInviteLink {
1427    type Response = ChatInviteLink;
1428
1429    fn name() -> &'static str {
1430        "revokeChatInviteLink"
1431    }
1432}
1433
1434impl JsonMethod for RevokeChatInviteLink {}
1435
1436/// Use this method to approve a chat join request.
1437/// The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator right.
1438/// Returns _True_ on success.
1439#[derive(Clone, Serialize)]
1440pub struct ApproveChatJoinRequest {
1441    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
1442    pub chat_id: ChatId,
1443    /// Unique identifier of the target user
1444    pub user_id: i64,
1445}
1446
1447impl ApproveChatJoinRequest {
1448    /// Create a new approveChatJoinRequest request
1449    pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
1450        Self {
1451            chat_id: chat_id.into(),
1452            user_id,
1453        }
1454    }
1455}
1456
1457impl TelegramMethod for ApproveChatJoinRequest {
1458    type Response = bool;
1459
1460    fn name() -> &'static str {
1461        "approveChatJoinRequest"
1462    }
1463}
1464
1465impl JsonMethod for ApproveChatJoinRequest {}
1466
1467/// Use this method to decline a chat join request.
1468/// The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator right.
1469/// Returns _True_ on success.
1470#[derive(Clone, Serialize)]
1471pub struct DeclineChatJoinRequest {
1472    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
1473    pub chat_id: ChatId,
1474    /// Unique identifier of the target user
1475    pub user_id: i64,
1476}
1477
1478impl DeclineChatJoinRequest {
1479    /// Create a new declineChatJoinRequest request
1480    pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
1481        Self {
1482            chat_id: chat_id.into(),
1483            user_id,
1484        }
1485    }
1486}
1487
1488impl TelegramMethod for DeclineChatJoinRequest {
1489    type Response = bool;
1490
1491    fn name() -> &'static str {
1492        "declineChatJoinRequest"
1493    }
1494}
1495
1496impl JsonMethod for DeclineChatJoinRequest {}
1497
1498/// Use this method to set a new profile photo for the chat.
1499/// Photos can't be changed for private chats.
1500/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
1501/// Returns _True_ on success.
1502#[derive(Clone, Serialize)]
1503pub struct SetChatPhoto {
1504    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
1505    pub chat_id: ChatId,
1506    /// New chat photo, uploaded using multipart/form-data
1507    pub photo: InputFile,
1508}
1509
1510impl SetChatPhoto {
1511    /// Create a new setChatPhoto request
1512    pub fn new(chat_id: impl Into<ChatId>, photo: InputFile) -> Self {
1513        Self {
1514            chat_id: chat_id.into(),
1515            photo,
1516        }
1517    }
1518}
1519
1520impl TelegramMethod for SetChatPhoto {
1521    type Response = bool;
1522
1523    fn name() -> &'static str {
1524        "setChatPhoto"
1525    }
1526}
1527
1528impl JsonMethod for SetChatPhoto {}
1529
1530/// Use this method to delete a chat photo.
1531/// Photos can't be changed for private chats.
1532/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
1533/// Returns _True_ on success.
1534#[derive(Clone, Serialize)]
1535pub struct DeleteChatPhoto {
1536    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
1537    pub chat_id: ChatId,
1538}
1539
1540impl DeleteChatPhoto {
1541    /// Create a new deleteChatPhoto request
1542    pub fn new(chat_id: impl Into<ChatId>) -> Self {
1543        Self {
1544            chat_id: chat_id.into(),
1545        }
1546    }
1547}
1548
1549impl TelegramMethod for DeleteChatPhoto {
1550    type Response = bool;
1551
1552    fn name() -> &'static str {
1553        "deleteChatPhoto"
1554    }
1555}
1556
1557impl JsonMethod for DeleteChatPhoto {}
1558
1559/// Use this method to change the title of a chat.
1560/// Titles can't be changed for private chats.
1561/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
1562/// Returns _True_ on success.
1563#[derive(Clone, Serialize)]
1564pub struct SetChatTitle {
1565    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
1566    pub chat_id: ChatId,
1567    /// New chat title, 1-255 characters
1568    pub title: String,
1569}
1570
1571impl SetChatTitle {
1572    /// Create a new setChatTitle request
1573    pub fn new(chat_id: impl Into<ChatId>, title: impl Into<String>) -> Self {
1574        Self {
1575            chat_id: chat_id.into(),
1576            title: title.into(),
1577        }
1578    }
1579}
1580
1581impl TelegramMethod for SetChatTitle {
1582    type Response = bool;
1583
1584    fn name() -> &'static str {
1585        "setChatTitle"
1586    }
1587}
1588
1589impl JsonMethod for SetChatTitle {}
1590
1591/// Use this method to change the description of a group, a supergroup or a channel.
1592/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
1593/// Returns _True_ on success.
1594#[derive(Clone, Serialize)]
1595pub struct SetChatDescription {
1596    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
1597    pub chat_id: ChatId,
1598    /// New chat description, 0-255 characters
1599    #[serde(skip_serializing_if = "Option::is_none")]
1600    pub description: Option<String>,
1601}
1602
1603impl SetChatDescription {
1604    /// Create a new setChatDescription request which empties the description
1605    pub fn new_empty(chat_id: impl Into<ChatId>) -> Self {
1606        Self {
1607            chat_id: chat_id.into(),
1608            description: None,
1609        }
1610    }
1611
1612    /// Create a new setChatDescription request with description
1613    pub fn new(chat_id: impl Into<ChatId>, description: impl Into<String>) -> Self {
1614        Self {
1615            chat_id: chat_id.into(),
1616            description: Some(description.into()),
1617        }
1618    }
1619}
1620
1621impl TelegramMethod for SetChatDescription {
1622    type Response = bool;
1623
1624    fn name() -> &'static str {
1625        "setChatDescription"
1626    }
1627}
1628
1629/// Use this method to add a message to the list of pinned messages in a chat.
1630/// If the chat is not a private chat, the bot must be an administrator in the chat for this to work
1631/// and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel.
1632/// Returns _True_ on success.
1633#[derive(Clone, Serialize)]
1634pub struct PinChatMessage {
1635    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
1636    pub chat_id: ChatId,
1637    /// Identifier of a message to pin
1638    pub message_id: i64,
1639    /// Pass True, if it is not necessary to send a notification to all chat members about the new pinned message.
1640    /// Notifications are always disabled in channels and private chats.
1641    #[serde(skip_serializing_if = "Option::is_none")]
1642    pub disable_notification: Option<bool>,
1643}
1644
1645impl PinChatMessage {
1646    /// Create a new pinChatMessage request
1647    pub fn new(chat_id: impl Into<ChatId>, message_id: i64) -> Self {
1648        Self {
1649            chat_id: chat_id.into(),
1650            message_id,
1651            disable_notification: None,
1652        }
1653    }
1654
1655    /// Disable notification about the new pinned message
1656    pub fn disable_notification(self) -> Self {
1657        Self {
1658            disable_notification: Some(true),
1659            ..self
1660        }
1661    }
1662}
1663
1664impl TelegramMethod for PinChatMessage {
1665    type Response = bool;
1666
1667    fn name() -> &'static str {
1668        "pinChatMessage"
1669    }
1670}
1671
1672impl JsonMethod for PinChatMessage {}
1673
1674/// Use this method to remove a message from the list of pinned messages in a chat.
1675/// If the chat is not a private chat, the bot must be an administrator in the chat for this to work
1676/// and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel.
1677/// Returns _True_ on success.
1678#[derive(Clone, Serialize)]
1679pub struct UnpinChatMessage {
1680    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
1681    pub chat_id: ChatId,
1682    /// Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned.
1683    #[serde(skip_serializing_if = "Option::is_none")]
1684    pub message_id: Option<i64>,
1685}
1686
1687impl UnpinChatMessage {
1688    /// Create a new unpinChatMessage request that unpins the most recent pinned message
1689    pub fn new_recent(chat_id: impl Into<ChatId>) -> Self {
1690        Self {
1691            chat_id: chat_id.into(),
1692            message_id: None,
1693        }
1694    }
1695
1696    /// Create a new unpinChatMessage request
1697    pub fn new(chat_id: impl Into<ChatId>, message_id: i64) -> Self {
1698        Self {
1699            chat_id: chat_id.into(),
1700            message_id: Some(message_id),
1701        }
1702    }
1703}
1704
1705impl TelegramMethod for UnpinChatMessage {
1706    type Response = bool;
1707
1708    fn name() -> &'static str {
1709        "unpinChatMessage"
1710    }
1711}
1712
1713impl JsonMethod for UnpinChatMessage {}
1714
1715/// Use this method to clear the list of pinned messages in a chat.
1716/// If the chat is not a private chat, the bot must be an administrator in the chat for this to work
1717/// and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel.
1718/// Returns _True_ on success.
1719#[derive(Clone, Serialize)]
1720pub struct UnpinAllChatMessages {
1721    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
1722    pub chat_id: ChatId,
1723}
1724
1725impl UnpinAllChatMessages {
1726    /// Create a new unpinAllChatMessages request
1727    pub fn new(chat_id: impl Into<ChatId>) -> Self {
1728        Self {
1729            chat_id: chat_id.into(),
1730        }
1731    }
1732}
1733
1734impl TelegramMethod for UnpinAllChatMessages {
1735    type Response = bool;
1736
1737    fn name() -> &'static str {
1738        "unpinAllChatMessages"
1739    }
1740}
1741
1742impl JsonMethod for UnpinAllChatMessages {}
1743
1744/// Use this method for your bot to leave a group, supergroup or channel. Returns _True_ on success.
1745#[derive(Clone, Serialize)]
1746pub struct LeaveChat {
1747    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
1748    pub chat_id: ChatId,
1749}
1750
1751impl LeaveChat {
1752    /// Create a new leaveChat request
1753    pub fn new(chat_id: impl Into<ChatId>) -> Self {
1754        Self {
1755            chat_id: chat_id.into(),
1756        }
1757    }
1758}
1759
1760impl TelegramMethod for LeaveChat {
1761    type Response = bool;
1762
1763    fn name() -> &'static str {
1764        "leaveChat"
1765    }
1766}
1767
1768impl JsonMethod for LeaveChat {}
1769
1770/// Use this method to get up to date information about the chat
1771/// (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).
1772/// Returns a Chat object on success.
1773#[derive(Clone, Serialize)]
1774pub struct GetChat {
1775    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
1776    pub chat_id: ChatId,
1777}
1778
1779impl GetChat {
1780    /// Create a new getChat request
1781    pub fn new(chat_id: impl Into<ChatId>) -> Self {
1782        Self {
1783            chat_id: chat_id.into(),
1784        }
1785    }
1786}
1787
1788impl TelegramMethod for GetChat {
1789    type Response = Chat;
1790
1791    fn name() -> &'static str {
1792        "getChat"
1793    }
1794}
1795
1796impl JsonMethod for GetChat {}
1797
1798/// Use this method to get a list of administrators in a chat.
1799/// On success, returns an Array of [ChatMember](https://core.telegram.org/bots/api#chatmember) objects
1800/// that contains information about all chat administrators except other bots.
1801/// If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.
1802#[derive(Clone, Serialize)]
1803pub struct GetChatAdministrators {
1804    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
1805    pub chat_id: ChatId,
1806}
1807
1808impl GetChatAdministrators {
1809    /// Create a new getChatAdministrators request
1810    pub fn new(chat_id: impl Into<ChatId>) -> Self {
1811        Self {
1812            chat_id: chat_id.into(),
1813        }
1814    }
1815}
1816
1817impl TelegramMethod for GetChatAdministrators {
1818    type Response = Vec<ChatMember>;
1819
1820    fn name() -> &'static str {
1821        "getChatAdministrators"
1822    }
1823}
1824
1825impl JsonMethod for GetChatAdministrators {}
1826
1827/// Use this method to get the number of members in a chat. Returns _Int_ on success.
1828#[derive(Clone, Serialize)]
1829pub struct GetChatMemberCount {
1830    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
1831    pub chat_id: ChatId,
1832}
1833
1834impl GetChatMemberCount {
1835    /// Create a new getChatMemberCount request
1836    pub fn new(chat_id: impl Into<ChatId>) -> Self {
1837        Self {
1838            chat_id: chat_id.into(),
1839        }
1840    }
1841}
1842
1843impl TelegramMethod for GetChatMemberCount {
1844    type Response = u32;
1845
1846    fn name() -> &'static str {
1847        "getChatMemberCount"
1848    }
1849}
1850
1851impl JsonMethod for GetChatMemberCount {}
1852
1853/// Use this method to get information about a member of a chat.
1854/// Returns a [ChatMember](https://core.telegram.org/bots/api#chatmember) object on success.
1855#[derive(Clone, Serialize)]
1856pub struct GetChatMember {
1857    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
1858    pub chat_id: ChatId,
1859    /// Unique identifier of the target user
1860    pub user_id: i64,
1861}
1862
1863impl GetChatMember {
1864    /// Create a new getChatMember request
1865    pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
1866        Self {
1867            chat_id: chat_id.into(),
1868            user_id,
1869        }
1870    }
1871}
1872
1873impl TelegramMethod for GetChatMember {
1874    type Response = ChatMember;
1875
1876    fn name() -> &'static str {
1877        "getChatMember"
1878    }
1879}
1880
1881/// Use this method to set a new group sticker set for a supergroup.
1882/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
1883/// Use the field *can_set_sticker_set* optionally returned in [getChat](https://core.telegram.org/bots/api#getchat) requests to check if the bot can use this method.
1884/// Returns _True_ on success.
1885#[derive(Clone, Serialize)]
1886pub struct SetChatStickerSet {
1887    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
1888    pub chat_id: ChatId,
1889    /// Name of the sticker set to be set as the group sticker set
1890    pub sticker_set_name: String,
1891}
1892
1893impl SetChatStickerSet {
1894    /// Create a new setChatStickerSet request
1895    pub fn new(chat_id: impl Into<ChatId>, sticker_set_name: impl Into<String>) -> Self {
1896        Self {
1897            chat_id: chat_id.into(),
1898            sticker_set_name: sticker_set_name.into(),
1899        }
1900    }
1901}
1902
1903impl TelegramMethod for SetChatStickerSet {
1904    type Response = bool;
1905
1906    fn name() -> &'static str {
1907        "setChatStickerSet"
1908    }
1909}
1910
1911impl JsonMethod for SetChatStickerSet {}
1912
1913/// Use this method to delete a group sticker set from a supergroup.
1914/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
1915/// Use the field *can_set_sticker_set* optionally returned in [getChat](https://core.telegram.org/bots/api#getchat) requests to check if the bot can use this method.
1916/// Returns _True_ on success.
1917#[derive(Clone, Serialize)]
1918pub struct DeleteChatStickerSet {
1919    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
1920    pub chat_id: ChatId,
1921}
1922
1923impl DeleteChatStickerSet {
1924    /// Create a new deleteChatStickerSet request
1925    pub fn new(chat_id: impl Into<ChatId>) -> Self {
1926        Self {
1927            chat_id: chat_id.into(),
1928        }
1929    }
1930}
1931
1932impl TelegramMethod for DeleteChatStickerSet {
1933    type Response = bool;
1934
1935    fn name() -> &'static str {
1936        "deleteChatStickerSet"
1937    }
1938}
1939
1940impl JsonMethod for DeleteChatStickerSet {}