Skip to main content

tgbot/types/definitions/chat/
member.rs

1use serde::{Deserialize, Deserializer, Serialize, Serializer};
2
3use crate::{
4    api::{Method, Payload},
5    types::{Chat, ChatId, ChatInviteLink, ChatPermissions, Integer, User},
6};
7
8/// Represents a member of a chat.
9#[serde_with::skip_serializing_none]
10#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
11#[serde(rename_all = "snake_case")]
12#[serde(tag = "status")]
13pub enum ChatMember {
14    /// Represents a chat administrator.
15    Administrator(ChatMemberAdministrator),
16    /// Represents a chat creator.
17    Creator(ChatMemberCreator),
18    /// Represents a kicked user.
19    Kicked(ChatMemberKicked),
20    /// Represents a user who left the chat.
21    #[serde(deserialize_with = "ChatMemberUser::deserialize_value")]
22    #[serde(serialize_with = "ChatMemberUser::serialize_value")]
23    Left(User),
24    /// Represents a regular chat member.
25    Member {
26        /// Information about the user.
27        user: User,
28        /// Tag of the member.
29        tag: Option<String>,
30        /// Date when the user's subscription will expire; unix time.
31        until_date: Option<Integer>,
32    },
33    /// Represents a restricted user.
34    Restricted(ChatMemberRestricted),
35}
36
37impl ChatMember {
38    /// Returns the user object associated with the chat member.
39    pub fn get_user(&self) -> &User {
40        use self::ChatMember::*;
41        match self {
42            Administrator(admin) => &admin.user,
43            Creator(creator) => &creator.user,
44            Kicked(kicked) => &kicked.user,
45            Left(user) => user,
46            Member { user, .. } => user,
47            Restricted(restricted) => &restricted.user,
48        }
49    }
50
51    /// Checks if a user is a member of the chat.
52    pub fn is_member(&self) -> bool {
53        use self::ChatMember::*;
54        match self {
55            Administrator(_) | Creator(_) | Member { .. } => true,
56            Kicked(_) | Left(_) => false,
57            Restricted(restricted) => restricted.is_member,
58        }
59    }
60}
61
62#[derive(Deserialize, Serialize)]
63struct ChatMemberUser {
64    user: User,
65}
66
67impl ChatMemberUser {
68    fn deserialize_value<'de, T>(deserializer: T) -> Result<User, T::Error>
69    where
70        T: Deserializer<'de>,
71    {
72        ChatMemberUser::deserialize(deserializer).map(|x| x.user)
73    }
74
75    fn serialize_value<T>(value: &User, serializer: T) -> Result<T::Ok, T::Error>
76    where
77        T: Serializer,
78    {
79        let value = ChatMemberUser { user: value.clone() };
80        value.serialize(serializer)
81    }
82}
83
84/// Represents a chat administrator.
85#[serde_with::skip_serializing_none]
86#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
87pub struct ChatMemberAdministrator {
88    /// Information about the user.
89    pub user: User,
90    /// Indicates whether a bot is allowed to edit administrator privileges of that user.
91    pub can_be_edited: bool,
92    /// Indicates whether the administrator can change the chat title, photo and other settings.
93    pub can_change_info: bool,
94    /// Indicates whether the administrator can delete messages of other users.
95    pub can_delete_messages: bool,
96    /// Indicates whether the administrator can delete stories posted by other users;
97    /// channels only.
98    pub can_delete_stories: Option<bool>,
99    /// Indicates whether the administrator can edit messages
100    /// of other users and can pin messages; channels only.
101    pub can_edit_messages: Option<bool>,
102    /// Indicates whether the administrator can edit stories posted by other users; channels only.
103    pub can_edit_stories: Option<bool>,
104    /// Indicates whether the administrator can invite new users to the chat.
105    pub can_invite_users: bool,
106    /// Indicates whether the administrator can access the chat event log,
107    /// chat statistics, message statistics in channels, see channel members,
108    /// see anonymous administrators in supergroups and ignore slow mode;
109    /// implied by any other administrator privilege.
110    pub can_manage_chat: bool,
111    /// Whether the administrator can manage direct messages
112    /// of the channel and decline suggested posts; for channels only.
113    pub can_manage_direct_messages: Option<bool>,
114    /// Whether the administrator can edit tags of regular members;
115    /// for groups and supergroups only.
116    ///
117    /// If omitted defaults to the value of `can_pin_messages`.
118    pub can_manage_tags: Option<bool>,
119    /// Indicates whether the administrator is allowed to
120    /// create, rename, close, and reopen forum topics; supergroups only.
121    pub can_manage_topics: Option<bool>,
122    /// Indicates whether the administrator can manage video chats.
123    pub can_manage_video_chats: bool,
124    /// Indicates whether the administrator can pin messages; groups and supergroups only.
125    pub can_pin_messages: Option<bool>,
126    /// Indicates whether the administrator can post in the channel; channels only.
127    pub can_post_messages: Option<bool>,
128    /// Indicates whether the administrator can post stories in the channel; channels only.
129    pub can_post_stories: Option<bool>,
130    /// Indicates whether the administrator can add new administrators with a subset
131    /// of his own privileges or demote administrators that he has promoted,
132    /// directly or indirectly (promoted by administrators that were appointed by the user).
133    pub can_promote_members: bool,
134    /// Indicates whether the administrator can restrict, ban or unban chat members.
135    pub can_restrict_members: bool,
136    /// Custom title for the administrator.
137    pub custom_title: Option<String>,
138    /// Indicates whether the administrator's presence in the chat is hidden.
139    pub is_anonymous: bool,
140}
141
142impl ChatMemberAdministrator {
143    /// Creates a new `ChatMemberAdministrator`
144    ///
145    /// # Arguments
146    ///
147    /// * `user` - Information about the user.
148    pub fn new(user: User) -> Self {
149        Self {
150            user,
151            can_be_edited: false,
152            can_change_info: false,
153            can_delete_messages: false,
154            can_delete_stories: None,
155            can_edit_messages: None,
156            can_edit_stories: None,
157            can_invite_users: false,
158            can_manage_chat: false,
159            can_manage_direct_messages: None,
160            can_manage_tags: None,
161            can_manage_topics: None,
162            can_manage_video_chats: false,
163            can_pin_messages: None,
164            can_post_messages: None,
165            can_post_stories: None,
166            can_promote_members: false,
167            can_restrict_members: false,
168            is_anonymous: false,
169            custom_title: None,
170        }
171    }
172
173    /// Sets a new value for the `can_be_edited` flag.
174    ///
175    /// # Arguments
176    ///
177    /// * `value` - Indicates whether a bot is allowed to edit privileges of that administrator.
178    pub fn with_can_be_edited(mut self, value: bool) -> Self {
179        self.can_be_edited = value;
180        self
181    }
182
183    /// Sets a new value for the `can_change_info` flag.
184    ///
185    /// # Arguments
186    ///
187    /// * `value` - Indicates whether the administrator can change the chat title,
188    ///   photo and other settings.
189    pub fn with_can_change_info(mut self, value: bool) -> Self {
190        self.can_change_info = value;
191        self
192    }
193
194    /// Sets a new value for the `can_delete_messages` flag.
195    ///
196    /// # Arguments
197    ///
198    /// * `value` - Indicates whether the administrator can delete messages of other users.
199    pub fn with_can_delete_messages(mut self, value: bool) -> Self {
200        self.can_delete_messages = value;
201        self
202    }
203
204    /// Sets a new value for the `can_delete_stories` flag.
205    ///
206    /// # Arguments
207    ///
208    /// * `value` - Indicates whether the administrator
209    ///   can delete stories posted by other users; channels only.
210    pub fn with_can_delete_stories(mut self, value: bool) -> Self {
211        self.can_delete_stories = Some(value);
212        self
213    }
214
215    /// Sets a new value for the `can_edit_messages` flag.
216    ///
217    /// # Arguments
218    ///
219    /// * `value` - Indicates whether the administrator can edit messages
220    ///   of other users and can pin messages; channels only.
221    pub fn with_can_edit_messages(mut self, value: bool) -> Self {
222        self.can_edit_messages = Some(value);
223        self
224    }
225
226    /// Sets a new value for the `can_edit_stories` flag.
227    ///
228    /// # Arguments
229    ///
230    /// * `value` - Indicates whether the administrator can
231    ///   edit stories posted by other users; channels only.
232    pub fn with_can_edit_stories(mut self, value: bool) -> Self {
233        self.can_edit_stories = Some(value);
234        self
235    }
236
237    /// Sets a new value for the `can_invite_users` flag.
238    ///
239    /// # Arguments
240    ///
241    /// * `value` - Indicates whether the administrator can invite new users to the chat.
242    pub fn with_can_invite_users(mut self, value: bool) -> Self {
243        self.can_invite_users = value;
244        self
245    }
246
247    /// Sets a new value for the `can_manage_chat` flag.
248    ///
249    /// # Arguments
250    ///
251    /// * `value` - Indicates whether the administrator can access the chat event log,
252    ///   chat statistics, message statistics in channels, see channel members,
253    ///   see anonymous administrators in supergroups and ignore slow mode;
254    ///   implied by any other administrator privilege.
255    pub fn with_can_manage_chat(mut self, value: bool) -> Self {
256        self.can_manage_chat = value;
257        self
258    }
259
260    /// Sets a new value for the `can_manage_direct_messages` flag.
261    ///
262    /// # Arguments
263    ///
264    /// * `value` - Whether the administrator can manage direct messages
265    ///   of the channel and decline suggested posts; for channels only
266    pub fn with_can_manage_direct_messages(mut self, value: bool) -> Self {
267        self.can_manage_direct_messages = Some(value);
268        self
269    }
270
271    /// Sets a new value for the `can_manage_tags` flag.
272    ///
273    /// # Arguments
274    ///
275    /// * `value` -> Whether the administrator can manage tags of regular members.
276    pub fn with_can_manage_tags(mut self, value: bool) -> Self {
277        self.can_manage_tags = Some(value);
278        self
279    }
280
281    /// Sets a new value for the `can_manage_topics` flag.
282    ///
283    /// # Arguments
284    ///
285    /// * `value` -  Indicates whether the administrator is allowed to
286    ///   create, rename, close, and reopen forum topics; supergroups only.
287    pub fn with_can_manage_topics(mut self, value: bool) -> Self {
288        self.can_manage_topics = Some(value);
289        self
290    }
291
292    /// Sets a new value for the `can_manage_video_chats` flag.
293    ///
294    /// # Arguments
295    ///
296    /// * `value` - Indicates whether the administrator can manage video chats.
297    pub fn with_can_manage_video_chats(mut self, value: bool) -> Self {
298        self.can_manage_video_chats = value;
299        self
300    }
301
302    /// Sets a new value for the `can_pin_messages` flag.
303    ///
304    /// # Arguments
305    ///
306    /// * `value` - Indicates whether the administrator can pin messages;
307    ///   groups and supergroups only.
308    pub fn with_can_pin_messages(mut self, value: bool) -> Self {
309        self.can_pin_messages = Some(value);
310        self
311    }
312
313    /// Sets a new value for the `can_post_messages` flag.
314    ///
315    /// # Arguments
316    ///
317    /// * `value` - Indicates whether the administrator can post in the channel; channels only.
318    pub fn with_can_post_messages(mut self, value: bool) -> Self {
319        self.can_post_messages = Some(value);
320        self
321    }
322
323    /// Sets a new value for the `can_post_stories` flag.
324    ///
325    /// # Arguments
326    ///
327    /// * `value` - Indicates whether the administrator can
328    ///   post stories in the channel; channels only.
329    pub fn with_can_post_stories(mut self, value: bool) -> Self {
330        self.can_post_stories = Some(value);
331        self
332    }
333
334    /// Sets a new value for the `can_promote_members` flag.
335    ///
336    /// # Arguments
337    ///
338    /// * `value` - Indicates whether the administrator can add new administrators with a subset
339    ///   of his own privileges or demote administrators that he has promoted,
340    ///   directly or indirectly (promoted by administrators
341    ///   that were appointed by the user).
342    pub fn with_can_promote_members(mut self, value: bool) -> Self {
343        self.can_promote_members = value;
344        self
345    }
346
347    /// Sets a new value for the `can_restrict_members` flag.
348    ///
349    /// # Arguments
350    ///
351    /// * `value` - Indicates whether the administrator can restrict, ban or unban chat members.
352    pub fn with_can_restrict_members(mut self, value: bool) -> Self {
353        self.can_restrict_members = value;
354        self
355    }
356
357    /// Sets a new custom title.
358    ///
359    /// # Arguments
360    ///
361    /// * `value` - Custom title for the administrator.
362    pub fn with_custom_title<T>(mut self, value: T) -> Self
363    where
364        T: Into<String>,
365    {
366        self.custom_title = Some(value.into());
367        self
368    }
369
370    /// Sets a new value for the `is_anonymous` flag.
371    ///
372    /// # Arguments
373    ///
374    /// * `value` - Indicates whether the administrator's presence in the chat is hidden.
375    pub fn with_is_anonymous(mut self, value: bool) -> Self {
376        self.is_anonymous = value;
377        self
378    }
379}
380
381/// Represents a chat member that owns the chat and has all administrator privileges.
382#[serde_with::skip_serializing_none]
383#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
384pub struct ChatMemberCreator {
385    /// Indicates whether the creator's presence in the chat is hidden.
386    pub is_anonymous: bool,
387    /// Information about the user.
388    pub user: User,
389    /// Custom title for the creator.
390    pub custom_title: Option<String>,
391}
392
393impl ChatMemberCreator {
394    /// Creates a new `ChatMemberCreator`.
395    ///
396    /// # Arguments
397    ///
398    /// * `user` - Information about the user.
399    pub fn new(user: User) -> Self {
400        Self {
401            is_anonymous: false,
402            user,
403            custom_title: None,
404        }
405    }
406
407    /// Sets a new custom title.
408    ///
409    /// # Arguments
410    ///
411    /// * `value` - Custom title for the creator.
412    pub fn with_custom_title<T>(mut self, value: T) -> Self
413    where
414        T: Into<String>,
415    {
416        self.custom_title = Some(value.into());
417        self
418    }
419
420    /// Sets a new value of an `is_anonymous` flag.
421    ///
422    /// # Arguments
423    ///
424    /// * `value` - Indicates whether the creator's presence in the chat is hidden.
425    pub fn with_is_anonymous(mut self, value: bool) -> Self {
426        self.is_anonymous = value;
427        self
428    }
429}
430
431/// Represents a kicked chat member.
432#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
433pub struct ChatMemberKicked {
434    /// Date when restrictions will be lifted for this user; unix time.
435    pub until_date: Integer,
436    /// Information about the user.
437    pub user: User,
438}
439
440impl ChatMemberKicked {
441    /// Creates a new `ChatMemberKicked`.
442    ///
443    /// # Arguments
444    ///
445    /// * `until_date` - Date when restrictions will be lifted for this user; unix time.
446    /// * `user` - Information about the user.
447    pub fn new(until_date: Integer, user: User) -> Self {
448        Self { user, until_date }
449    }
450}
451
452/// Represents a restricted user.
453#[serde_with::skip_serializing_none]
454#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
455pub struct ChatMemberRestricted {
456    /// Information about the user.
457    pub user: User,
458    /// Whether the user may add web page previews to his messages.
459    pub can_add_web_page_previews: bool,
460    /// Whether the user is allowed to change the chat title, photo and other settings.
461    pub can_change_info: bool,
462    /// Whether the user is allowed to edit their own tag.
463    pub can_edit_tag: bool,
464    /// Whether the user is allowed to invite new users to the chat.
465    pub can_invite_users: bool,
466    /// Whether the user is allowed to create forum topics.
467    pub can_manage_topics: bool,
468    /// Whether the user is allowed to pin messages; groups and supergroups only.
469    pub can_pin_messages: bool,
470    /// Whether the user is allowed to react to messages.
471    pub can_react_to_messages: bool,
472    /// Whether the user is allowed to send audios.
473    pub can_send_audios: bool,
474    /// Whether the user is allowed to send documents.
475    pub can_send_documents: bool,
476    /// Whether the user can send text messages, contacts, locations and venues.
477    pub can_send_messages: bool,
478    /// Whether the user can send animations, games, stickers and use inline bots.
479    pub can_send_other_messages: bool,
480    /// Whether the user is allowed to send photos.
481    pub can_send_photos: bool,
482    /// Whether the user is allowed to send polls.
483    pub can_send_polls: bool,
484    /// Whether the user is allowed to send video notes.
485    pub can_send_video_notes: bool,
486    /// Whether the user is allowed to send videos.
487    pub can_send_videos: bool,
488    /// Whether the user is allowed to send voice notes.
489    pub can_send_voice_notes: bool,
490    /// Whether the user is a member of the chat at the moment of the request.
491    pub is_member: bool,
492    /// Date when restrictions will be lifted for this user; unix time.
493    pub until_date: Integer,
494    /// Tag of the member.
495    pub tag: Option<String>,
496}
497
498impl ChatMemberRestricted {
499    /// Creates a new `ChatMemberRestricted`
500    ///
501    /// # Arguments
502    ///
503    /// * `user` - Information about the user.
504    /// * `until_date` - Date when restrictions will be lifted for this user; unix time.
505    pub fn new(user: User, until_date: Integer) -> Self {
506        Self {
507            user,
508            can_add_web_page_previews: false,
509            can_change_info: false,
510            can_edit_tag: false,
511            can_invite_users: false,
512            can_manage_topics: false,
513            can_pin_messages: false,
514            can_react_to_messages: false,
515            can_send_audios: false,
516            can_send_documents: false,
517            can_send_messages: false,
518            can_send_other_messages: false,
519            can_send_photos: false,
520            can_send_polls: false,
521            can_send_video_notes: false,
522            can_send_videos: false,
523            can_send_voice_notes: false,
524            is_member: false,
525            tag: None,
526            until_date,
527        }
528    }
529
530    /// Sets a new value for the `can_add_web_page_previews` flag.
531    ///
532    /// # Arguments
533    ///
534    /// * `value` - Whether the user may add web page previews to his messages.
535    pub fn with_can_add_web_page_previews(mut self, value: bool) -> Self {
536        self.can_add_web_page_previews = value;
537        self
538    }
539
540    /// Sets a new value for the `can_change_info` flag.
541    ///
542    /// # Arguments
543    ///
544    /// * `value` - Whether the user is allowed to change the chat title,
545    ///   photo and other settings.
546    pub fn with_can_change_info(mut self, value: bool) -> Self {
547        self.can_change_info = value;
548        self
549    }
550
551    /// Sets a new value for the `can_edit_tag` flag.
552    ///
553    /// # Arguments
554    ///
555    /// * `value` - Whether the user is allowed to edit their own tag.
556    pub fn with_can_edit_tag(mut self, value: bool) -> Self {
557        self.can_edit_tag = value;
558        self
559    }
560
561    /// Sets a new value for the `can_invite_users` flag.
562    ///
563    /// # Arguments
564    ///
565    /// * `value` - Whether the user is allowed to invite new users to the chat.
566    pub fn with_can_invite_users(mut self, value: bool) -> Self {
567        self.can_invite_users = value;
568        self
569    }
570
571    /// Sets a new value for the `can_manage_topics` flag.
572    ///
573    /// # Arguments
574    ///
575    /// * `value` - Whether the user is allowed to create forum topics.
576    pub fn with_can_manage_topics(mut self, value: bool) -> Self {
577        self.can_manage_topics = value;
578        self
579    }
580
581    /// Sets a new value for the `can_pin_messages` flag.
582    ///
583    /// # Arguments
584    ///
585    /// * `value` - Whether the user is allowed to pin messages;
586    ///   groups and supergroups only.
587    pub fn with_can_pin_messages(mut self, value: bool) -> Self {
588        self.can_pin_messages = value;
589        self
590    }
591
592    /// Sets a new value for the `can_react_to_messages` flag.
593    ///
594    /// # Arguments
595    ///
596    /// * `value` - Whether the user is allowed to react to messages.
597    pub fn with_can_react_to_messages(mut self, value: bool) -> Self {
598        self.can_react_to_messages = value;
599        self
600    }
601
602    /// Sets a new value for the `can_send_audios` flag.
603    ///
604    /// # Arguments
605    ///
606    /// * `value` - Whether the user is allowed to send audios.
607    pub fn with_can_send_audios(mut self, value: bool) -> Self {
608        self.can_send_audios = value;
609        self
610    }
611
612    /// Sets a new value for the `can_send_documents` flag.
613    ///
614    /// # Arguments
615    ///
616    /// * `value` - Whether the user is allowed to send documents.
617    pub fn with_can_send_documents(mut self, value: bool) -> Self {
618        self.can_send_documents = value;
619        self
620    }
621
622    /// Sets a new value for the `can_send_messages` flag.
623    ///
624    /// # Arguments
625    ///
626    /// * `value` - Whether the user can send text messages,
627    ///   contacts, locations and venues.
628    pub fn with_can_send_messages(mut self, value: bool) -> Self {
629        self.can_send_messages = value;
630        self
631    }
632
633    /// Sets a new value for the `can_send_other_messages` flag.
634    ///
635    /// # Arguments
636    ///
637    /// * `value` - Whether the user can send animations,
638    ///   games, stickers and use inline bots.
639    pub fn with_can_send_other_messages(mut self, value: bool) -> Self {
640        self.can_send_other_messages = value;
641        self
642    }
643
644    /// Sets a new value for the `can_send_photos` flag.
645    ///
646    /// # Arguments
647    ///
648    /// * `value` - Whether the user is allowed to send photos.
649    pub fn with_can_send_photos(mut self, value: bool) -> Self {
650        self.can_send_photos = value;
651        self
652    }
653
654    /// Sets a new value for the `can_send_polls` flag.
655    ///
656    /// # Arguments
657    ///
658    /// * `value` - Whether the user is allowed to send polls.
659    pub fn with_can_send_polls(mut self, value: bool) -> Self {
660        self.can_send_polls = value;
661        self
662    }
663
664    /// Sets a new value for the `can_send_video_notes` flag.
665    ///
666    /// # Arguments
667    ///
668    /// * `value` - Whether the user is allowed to send video notes.
669    pub fn with_can_send_video_notes(mut self, value: bool) -> Self {
670        self.can_send_video_notes = value;
671        self
672    }
673
674    /// Sets a new value for the `can_send_videos` flag.
675    ///
676    /// # Arguments
677    ///
678    /// * `value` - Whether the user is allowed to send videos.
679    pub fn with_can_send_videos(mut self, value: bool) -> Self {
680        self.can_send_videos = value;
681        self
682    }
683
684    /// Sets a new value for the `can_send_voice_notes` flag.
685    ///
686    /// # Arguments
687    ///
688    /// * `value` - Whether the user is allowed to send voice notes.
689    pub fn with_can_send_voice_notes(mut self, value: bool) -> Self {
690        self.can_send_voice_notes = value;
691        self
692    }
693
694    /// Sets a new value for the `is_member` flag.
695    ///
696    /// # Arguments
697    ///
698    /// * `value` - Whether the user is a member of the chat at the moment of the request.
699    pub fn with_is_member(mut self, value: bool) -> Self {
700        self.is_member = value;
701        self
702    }
703
704    /// Sets a new tag.
705    ///
706    /// # Arguments
707    ///
708    /// * `value` - Tag of the member.
709    pub fn with_tag<T>(mut self, value: T) -> Self
710    where
711        T: Into<String>,
712    {
713        self.tag = Some(value.into());
714        self
715    }
716}
717
718/// Represents changes in a status of a chat member.
719#[serde_with::skip_serializing_none]
720#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
721pub struct ChatMemberUpdated {
722    /// Chat the user belongs to.
723    pub chat: Chat,
724    /// Date the change was done in Unix time.
725    pub date: Integer,
726    /// Performer of the action, which resulted in the change.
727    pub from: User,
728    /// New information about the chat member.
729    pub new_chat_member: ChatMember,
730    /// Previous information about the chat member.
731    pub old_chat_member: ChatMember,
732    /// Chat invite link, which was used by the user to join the chat;
733    /// for joining by invite link events only.
734    pub invite_link: Option<ChatInviteLink>,
735    /// Indicates whether the user joined the chat via a chat folder invite link.
736    pub via_chat_folder_invite_link: Option<bool>,
737    /// Indicates whether the user joined the chat after sending a direct join request
738    /// and being approved by an administrator.
739    pub via_join_request: Option<bool>,
740}
741
742impl ChatMemberUpdated {
743    /// Creates a new `ChatMemberUpdated`.
744    ///
745    /// # Arguments
746    ///
747    /// * `chat` - Chat the user belongs to.
748    /// * `date` - Date the change was done in Unix time.
749    /// * `from` - Performer of the action, which resulted in the change.
750    /// * `new_chat_member` - New information about the chat member.
751    /// * `old_chat_member` - Previous information about the chat member.
752    pub fn new(
753        chat: Chat,
754        date: Integer,
755        from: User,
756        new_chat_member: ChatMember,
757        old_chat_member: ChatMember,
758    ) -> Self {
759        Self {
760            chat,
761            date,
762            from,
763            new_chat_member,
764            old_chat_member,
765            invite_link: None,
766            via_chat_folder_invite_link: None,
767            via_join_request: None,
768        }
769    }
770
771    /// Sets a new invite link
772    ///
773    /// # Arguments
774    ///
775    /// * `value` - The invite link, which was used by the user to join the chat.
776    pub fn with_invite_link(mut self, value: ChatInviteLink) -> Self {
777        self.invite_link = Some(value);
778        self
779    }
780
781    /// Sets a new value for the `via_chat_folder_invite_link` flag.
782    ///
783    /// # Arguments
784    ///
785    /// * `value` - Indicates whether the user joined the chat via a chat folder invite link.
786    pub fn with_via_chat_folder_invite_link(mut self, value: bool) -> Self {
787        self.via_chat_folder_invite_link = Some(value);
788        self
789    }
790
791    /// Sets a new value for the `via_join_request` flag.
792    ///
793    /// # Arguments
794    ///
795    /// * `value` - Indicates whether the user joined the chat after sending a direct join request
796    ///   and being approved by an administrator.
797    pub fn with_via_join_request(mut self, value: bool) -> Self {
798        self.via_join_request = Some(value);
799        self
800    }
801}
802
803/// Bans a user in a chat.
804///
805/// In the case of supergroups and channels,
806/// the user will not be able to return to the chat on their own using invite links,
807/// etc., unless unbanned first.
808///
809/// The bot must be an administrator in the chat
810/// for this to work and must have the appropriate admin rights.
811#[serde_with::skip_serializing_none]
812#[derive(Clone, Debug, Serialize)]
813pub struct BanChatMember {
814    chat_id: ChatId,
815    user_id: Integer,
816    revoke_messages: Option<bool>,
817    until_date: Option<Integer>,
818}
819
820impl BanChatMember {
821    /// Creates a new `BanChatMember`.
822    ///
823    /// # Arguments
824    ///
825    /// * `chat_id` - Unique identifier of the target chat.
826    /// * `user_id` - Unique identifier of the target user.
827    pub fn new<T>(chat_id: T, user_id: Integer) -> Self
828    where
829        T: Into<ChatId>,
830    {
831        Self {
832            chat_id: chat_id.into(),
833            user_id,
834            until_date: None,
835            revoke_messages: None,
836        }
837    }
838
839    /// Sets a new value for the `revoke_messages` flag.
840    ///
841    /// # Arguments
842    ///
843    /// * `value` - Delete all messages from the chat for the user that is being removed;
844    ///   if `false`, the user will be able to see messages in the group that were
845    ///   sent before the user was removed;
846    ///   always `true` for supergroups and channels.
847    pub fn with_revoke_messages(mut self, value: bool) -> Self {
848        self.revoke_messages = Some(value);
849        self
850    }
851
852    /// Sets a new until date.
853    ///
854    /// # Arguments
855    ///
856    /// * `value` - The date when the user will be unbanned, unix time.
857    ///
858    /// If user is banned for more than 366 days or less than 30 seconds
859    /// from the current time they are considered to be banned forever.
860    pub fn with_until_date(mut self, value: Integer) -> Self {
861        self.until_date = Some(value);
862        self
863    }
864}
865
866impl Method for BanChatMember {
867    type Response = bool;
868
869    fn into_payload(self) -> Payload {
870        Payload::json("banChatMember", self)
871    }
872}
873
874/// Returns a list of administrators in a chat.
875///
876/// On success, returns an array of [`ChatMember`] objects that contains
877/// information about all chat administrators except other bots.
878///
879/// If the chat is a group or a supergroup and no administrators
880/// were appointed, only the creator will be returned.
881#[serde_with::skip_serializing_none]
882#[derive(Clone, Debug, Serialize)]
883pub struct GetChatAdministrators {
884    chat_id: ChatId,
885    return_bots: Option<bool>,
886}
887
888impl GetChatAdministrators {
889    /// Creates a new `GetChatAdministrators`.
890    ///
891    /// # Arguments
892    ///
893    /// * `chat_id` - Unique identifier of the target chat.
894    pub fn new<T>(chat_id: T) -> Self
895    where
896        T: Into<ChatId>,
897    {
898        Self {
899            chat_id: chat_id.into(),
900            return_bots: None,
901        }
902    }
903
904    /// Sets a new value for the `return_bots` flag.
905    ///
906    /// # Arguments
907    ///
908    /// * `value` - Whether to receive all bots that are administrators of the chat;
909    ///   by default, bots other tthan current bot are omitted.
910    pub fn with_return_bots(mut self, value: bool) -> Self {
911        self.return_bots = Some(value);
912        self
913    }
914}
915
916impl Method for GetChatAdministrators {
917    type Response = Vec<ChatMember>;
918
919    fn into_payload(self) -> Payload {
920        Payload::json("getChatAdministrators", self)
921    }
922}
923
924/// Returns a member of a chat.
925#[derive(Clone, Debug, Serialize)]
926pub struct GetChatMember {
927    chat_id: ChatId,
928    user_id: Integer,
929}
930
931impl GetChatMember {
932    /// Creates a new `GetChatMember`
933    ///
934    /// # Arguments
935    ///
936    /// * `chat_id` - Unique identifier of the target chat.
937    /// * `user_id` - Unique identifier of the target user.
938    pub fn new<T>(chat_id: T, user_id: Integer) -> Self
939    where
940        T: Into<ChatId>,
941    {
942        Self {
943            chat_id: chat_id.into(),
944            user_id,
945        }
946    }
947}
948
949impl Method for GetChatMember {
950    type Response = ChatMember;
951
952    fn into_payload(self) -> Payload {
953        Payload::json("getChatMember", self)
954    }
955}
956
957/// Returns a number of members in a chat.
958#[derive(Clone, Debug, Serialize)]
959pub struct GetChatMemberCount {
960    chat_id: ChatId,
961}
962
963impl GetChatMemberCount {
964    /// Creates a new `GetChatMemberCount`.
965    ///
966    /// # Arguments
967    ///
968    /// * `chat_id` - Unique identifier of the target chat.
969    pub fn new<T>(chat_id: T) -> Self
970    where
971        T: Into<ChatId>,
972    {
973        Self {
974            chat_id: chat_id.into(),
975        }
976    }
977}
978
979impl Method for GetChatMemberCount {
980    type Response = Integer;
981
982    fn into_payload(self) -> Payload {
983        Payload::json("getChatMemberCount", self)
984    }
985}
986
987/// Promotes or demotes a user in a chat.
988///
989/// The bot must be an administrator in the chat
990/// for this to work and must have the appropriate admin rights.
991#[serde_with::skip_serializing_none]
992#[derive(Clone, Debug, Serialize)]
993pub struct PromoteChatMember {
994    chat_id: ChatId,
995    user_id: Integer,
996    can_change_info: Option<bool>,
997    can_delete_messages: Option<bool>,
998    can_delete_stories: Option<bool>,
999    can_edit_messages: Option<bool>,
1000    can_edit_stories: Option<bool>,
1001    can_invite_users: Option<bool>,
1002    can_manage_chat: Option<bool>,
1003    can_manage_direct_messages: Option<bool>,
1004    can_manage_tags: Option<bool>,
1005    can_manage_topics: Option<bool>,
1006    can_manage_video_chats: Option<bool>,
1007    can_pin_messages: Option<bool>,
1008    can_post_messages: Option<bool>,
1009    can_post_stories: Option<bool>,
1010    can_promote_members: Option<bool>,
1011    can_restrict_members: Option<bool>,
1012    is_anonymous: Option<bool>,
1013}
1014
1015impl PromoteChatMember {
1016    /// Creates a new `PromoteChatMember`
1017    ///
1018    /// # Arguments
1019    ///
1020    /// * `chat_id` - Unique identifier of the target chat.
1021    /// * `user_id` - Unique identifier of the target user.
1022    pub fn new<T>(chat_id: T, user_id: Integer) -> Self
1023    where
1024        T: Into<ChatId>,
1025    {
1026        Self {
1027            chat_id: chat_id.into(),
1028            user_id,
1029            can_change_info: None,
1030            can_delete_messages: None,
1031            can_delete_stories: None,
1032            can_edit_messages: None,
1033            can_edit_stories: None,
1034            can_invite_users: None,
1035            can_manage_chat: None,
1036            can_manage_direct_messages: None,
1037            can_manage_tags: None,
1038            can_manage_topics: None,
1039            can_manage_video_chats: None,
1040            can_pin_messages: None,
1041            can_post_messages: None,
1042            can_post_stories: None,
1043            can_promote_members: None,
1044            can_restrict_members: None,
1045            is_anonymous: None,
1046        }
1047    }
1048
1049    /// Promotes all privileges.
1050    pub fn promote_all(mut self) -> Self {
1051        self.is_anonymous = Some(true);
1052        self.can_change_info = Some(true);
1053        self.can_delete_messages = Some(true);
1054        self.can_delete_stories = Some(true);
1055        self.can_edit_messages = Some(true);
1056        self.can_edit_stories = Some(true);
1057        self.can_invite_users = Some(true);
1058        self.can_manage_chat = Some(true);
1059        self.can_manage_direct_messages = Some(true);
1060        self.can_manage_tags = Some(true);
1061        self.can_manage_topics = Some(true);
1062        self.can_manage_video_chats = Some(true);
1063        self.can_pin_messages = Some(true);
1064        self.can_post_messages = Some(true);
1065        self.can_post_stories = Some(true);
1066        self.can_promote_members = Some(true);
1067        self.can_restrict_members = Some(true);
1068        self
1069    }
1070
1071    /// Demotes all privileges.
1072    pub fn demote_all(mut self) -> Self {
1073        self.is_anonymous = Some(false);
1074        self.can_change_info = Some(false);
1075        self.can_delete_messages = Some(false);
1076        self.can_delete_stories = Some(false);
1077        self.can_edit_messages = Some(false);
1078        self.can_edit_stories = Some(false);
1079        self.can_invite_users = Some(false);
1080        self.can_manage_chat = Some(false);
1081        self.can_manage_direct_messages = Some(false);
1082        self.can_manage_tags = Some(false);
1083        self.can_manage_topics = Some(false);
1084        self.can_manage_video_chats = Some(false);
1085        self.can_pin_messages = Some(false);
1086        self.can_post_messages = Some(false);
1087        self.can_post_stories = Some(false);
1088        self.can_promote_members = Some(false);
1089        self.can_restrict_members = Some(false);
1090        self
1091    }
1092
1093    /// Sets a new value for the `can_change_info` flag.
1094    ///
1095    /// # Arguments
1096    ///
1097    /// * `value` - Indicates whether the administrator can change chat title,
1098    ///   photo and other settings.
1099    pub fn with_can_change_info(mut self, value: bool) -> Self {
1100        self.can_change_info = Some(value);
1101        self
1102    }
1103
1104    /// Sets a new value for the `can_delete_messages` flag.
1105    ///
1106    /// # Arguments
1107    ///
1108    /// * `value` - Indicates whether the administrator can delete messages of other users.
1109    pub fn with_can_delete_messages(mut self, value: bool) -> Self {
1110        self.can_delete_messages = Some(value);
1111        self
1112    }
1113
1114    /// Sets a new value for the `can_delete_stories` flag.
1115    ///
1116    /// # Arguments
1117    ///
1118    /// * `value` - Indicates whether the administrator can delete stories posted by other users; channels only.
1119    pub fn with_can_delete_stories(mut self, value: bool) -> Self {
1120        self.can_delete_stories = Some(value);
1121        self
1122    }
1123
1124    /// Sets a new value for the `can_edit_messages` flag.
1125    ///
1126    /// # Arguments
1127    ///
1128    /// * `value` - Indicates whether the administrator can edit messages
1129    ///   of other users and can pin messages; channels only.
1130    pub fn with_can_edit_messages(mut self, value: bool) -> Self {
1131        self.can_edit_messages = Some(value);
1132        self
1133    }
1134
1135    /// Sets a new value for the `can_edit_stories` flag.
1136    ///
1137    /// # Arguments
1138    ///
1139    /// * `value` - Indicates whether the administrator can
1140    ///   edit stories posted by other users; channels only.
1141    pub fn with_can_edit_stories(mut self, value: bool) -> Self {
1142        self.can_edit_stories = Some(value);
1143        self
1144    }
1145
1146    /// Sets a new value for the `can_invite_users` flag.
1147    ///
1148    /// # Arguments
1149    ///
1150    /// * `value` - Indicates whether the administrator can invite new users to the chat.
1151    pub fn with_can_invite_users(mut self, value: bool) -> Self {
1152        self.can_invite_users = Some(value);
1153        self
1154    }
1155
1156    /// Sets a new value for the `can_manage_chat` flag.
1157    ///
1158    /// # Arguments
1159    ///
1160    /// * `value` - Indicates whether the administrator can access the chat event log,
1161    ///   chat statistics, message statistics in channels, see channel members,
1162    ///   see anonymous administrators in supergroups and ignore slow mode;
1163    ///   implied by any other administrator privilege.
1164    pub fn with_can_manage_chat(mut self, value: bool) -> Self {
1165        self.can_manage_chat = Some(value);
1166        self
1167    }
1168
1169    /// Sets a new value for the `can_manage_direct_messages` flag.
1170    ///
1171    /// # Arguments
1172    ///
1173    /// * `value` - Whether the administrator can manage direct messages
1174    ///   within the channel and decline suggested posts; for channels only.
1175    pub fn with_can_manage_direct_messages(mut self, value: bool) -> Self {
1176        self.can_manage_direct_messages = Some(value);
1177        self
1178    }
1179
1180    /// Sets a new value for the `can_manage_tags` flag.
1181    ///
1182    /// # Arguments
1183    ///
1184    /// * `value` - Whether the administrator can edit the tags of regular members;
1185    ///   for groups and supergroups only.
1186    pub fn with_can_manage_tags(mut self, value: bool) -> Self {
1187        self.can_manage_tags = Some(value);
1188        self
1189    }
1190
1191    /// Sets a new value for the `can_manage_topics` flag.
1192    ///
1193    /// # Arguments
1194    ///
1195    /// * `value` - User is allowed to create, rename, close, and reopen forum topics; supergroups only.
1196    pub fn with_can_manage_topics(mut self, value: bool) -> Self {
1197        self.can_manage_topics = Some(value);
1198        self
1199    }
1200
1201    /// Sets a new value for the `can_manage_video_chats` flag.
1202    ///
1203    /// # Arguments
1204    ///
1205    /// * `value` - Indicates whether the administrator can manage video chats; supergroups only.
1206    pub fn with_can_manage_video_chats(mut self, value: bool) -> Self {
1207        self.can_manage_video_chats = Some(value);
1208        self
1209    }
1210
1211    /// Sets a new value for the `can_pin_messages` flag.
1212    ///
1213    /// # Arguments
1214    ///
1215    /// * `value` - Indicates whether the administrator can pin messages; supergroups only.
1216    pub fn with_can_pin_messages(mut self, value: bool) -> Self {
1217        self.can_pin_messages = Some(value);
1218        self
1219    }
1220
1221    /// Sets a new value for the `can_post_messages` flag.
1222    ///
1223    /// # Arguments
1224    ///
1225    /// * `value` - Indicates whether the administrator can create channel posts; channels only.
1226    pub fn with_can_post_messages(mut self, value: bool) -> Self {
1227        self.can_post_messages = Some(value);
1228        self
1229    }
1230
1231    /// Sets a new value for the `can_post_stories` flag.
1232    ///
1233    /// # Arguments
1234    ///
1235    /// * `value` - Indicates whether the administrator can post stories in the channel; channels only.
1236    pub fn with_can_post_stories(mut self, value: bool) -> Self {
1237        self.can_post_stories = Some(value);
1238        self
1239    }
1240
1241    /// Sets a new value for the `can_promote_members` flag.
1242    ///
1243    /// # Arguments
1244    ///
1245    /// * `value` - Indicates whether the administrator can add new administrators with a subset
1246    ///   of his own privileges or demote administrators that he has promoted,
1247    ///   directly or indirectly (promoted by administrators that were appointed by him).
1248    pub fn with_can_promote_members(mut self, value: bool) -> Self {
1249        self.can_promote_members = Some(value);
1250        self
1251    }
1252
1253    /// Sets a new value for the `can_restrict_members` flag.
1254    ///
1255    /// # Arguments
1256    ///
1257    /// * `value` - Indicates whether the administrator can restrict, ban or unban chat members.
1258    pub fn with_can_restrict_members(mut self, value: bool) -> Self {
1259        self.can_restrict_members = Some(value);
1260        self
1261    }
1262
1263    /// Sets a new value for the `is_anonymous` flag.
1264    ///
1265    /// # Arguments
1266    ///
1267    /// * `value` - Indicates whether the administrator's presence in the chat is hidden.
1268    pub fn with_is_anonymous(mut self, value: bool) -> Self {
1269        self.is_anonymous = Some(value);
1270        self
1271    }
1272}
1273
1274impl Method for PromoteChatMember {
1275    type Response = bool;
1276
1277    fn into_payload(self) -> Payload {
1278        Payload::json("promoteChatMember", self)
1279    }
1280}
1281
1282/// Restricts a user in a supergroup.
1283///
1284/// The bot must be an administrator in the supergroup
1285/// for this to work and must have the appropriate admin rights.
1286#[serde_with::skip_serializing_none]
1287#[derive(Clone, Debug, Serialize)]
1288pub struct RestrictChatMember {
1289    chat_id: ChatId,
1290    permissions: ChatPermissions,
1291    user_id: Integer,
1292    until_date: Option<Integer>,
1293    use_independent_chat_permissions: Option<bool>,
1294}
1295
1296impl RestrictChatMember {
1297    /// Creates a new `RestrictChatMember`.
1298    ///
1299    /// # Arguments
1300    ///
1301    /// * `chat_id` - Unique identifier for the target chat.
1302    /// * `user_id` - Unique identifier of the target user.
1303    pub fn new<T>(chat_id: T, user_id: Integer) -> Self
1304    where
1305        T: Into<ChatId>,
1306    {
1307        RestrictChatMember {
1308            chat_id: chat_id.into(),
1309            permissions: ChatPermissions::default(),
1310            user_id,
1311            until_date: None,
1312            use_independent_chat_permissions: None,
1313        }
1314    }
1315
1316    /// Allows everything.
1317    pub fn allow_all(mut self) -> Self {
1318        self.permissions = ChatPermissions::allowed();
1319        self
1320    }
1321
1322    /// Restricts everything.
1323    pub fn restrict_all(mut self) -> Self {
1324        self.permissions = ChatPermissions::restricted();
1325        self
1326    }
1327
1328    /// Replaces current permissions with the new one.
1329    ///
1330    /// # Arguments
1331    ///
1332    /// * `value` - The new permissions.
1333    pub fn with_permissions(mut self, value: ChatPermissions) -> Self {
1334        self.permissions = value;
1335        self
1336    }
1337
1338    /// Sets a new until date.
1339    ///
1340    /// # Arguments
1341    ///
1342    /// * `value` - The date when restrictions will be lifted for the user, unix time.
1343    ///
1344    /// If user is restricted for more than 366 days or less than 30 seconds
1345    /// from the current time, they are considered to be restricted forever.
1346    pub fn with_until_date(mut self, value: Integer) -> Self {
1347        self.until_date = Some(value);
1348        self
1349    }
1350
1351    /// Sets a new value for the `use_independent_chat_permissions` flag.
1352    ///
1353    /// # Arguments
1354    ///
1355    /// * `value` - Indicates whether the chat permissions are set independently.
1356    ///
1357    /// If `false`, the `can_send_other_messages` and `can_add_web_page_previews` permissions
1358    /// will imply the `can_send_messages`, `can_send_audios`, `can_send_documents`,
1359    /// `can_send_photos`, `can_send_videos`, `can_send_video_notes`,
1360    /// and `can_send_voice_notes` permissions; the `can_send_polls` permission
1361    /// will imply the `can_send_messages` permission.
1362    pub fn with_use_independent_chat_permissions(mut self, value: bool) -> Self {
1363        self.use_independent_chat_permissions = Some(value);
1364        self
1365    }
1366}
1367
1368impl Method for RestrictChatMember {
1369    type Response = bool;
1370
1371    fn into_payload(self) -> Payload {
1372        Payload::json("restrictChatMember", self)
1373    }
1374}
1375
1376/// Sets a custom title for an administrator in a supergroup promoted by the bot.
1377#[derive(Clone, Debug, Serialize)]
1378pub struct SetChatAdministratorCustomTitle {
1379    chat_id: ChatId,
1380    user_id: Integer,
1381    custom_title: String,
1382}
1383
1384impl SetChatAdministratorCustomTitle {
1385    /// Creates a new `SetChatAdministratorCustomTitle`.
1386    ///
1387    /// # Arguments
1388    ///
1389    /// * `chat_id` - Unique identifier of the target chat.
1390    /// * `custom_title` - New custom title for the administrator; 0-16 characters; emoji are not allowed.
1391    /// * `user_id` - Unique identifier of the target user.
1392    pub fn new<A, B>(chat_id: A, custom_title: B, user_id: Integer) -> Self
1393    where
1394        A: Into<ChatId>,
1395        B: Into<String>,
1396    {
1397        Self {
1398            chat_id: chat_id.into(),
1399            custom_title: custom_title.into(),
1400            user_id,
1401        }
1402    }
1403}
1404
1405impl Method for SetChatAdministratorCustomTitle {
1406    type Response = bool;
1407
1408    fn into_payload(self) -> Payload {
1409        Payload::json("setChatAdministratorCustomTitle", self)
1410    }
1411}
1412
1413/// Sets a tag for a regular member in a group or a supergroup.
1414///
1415/// The bot must be an administrator in the chat for this to work
1416/// and must have the `can_manage_tags` administrator right.
1417#[serde_with::skip_serializing_none]
1418#[derive(Clone, Debug, Serialize)]
1419pub struct SetChatMemberTag {
1420    chat_id: ChatId,
1421    user_id: Integer,
1422    tag: Option<String>,
1423}
1424
1425impl SetChatMemberTag {
1426    /// Creates a new `SetChatMemberTag`.
1427    ///
1428    /// # Arguments
1429    ///
1430    /// * `chat_id` - Unique identifier of the target chat.
1431    /// * `user_id` - Unique identifier of the target user.
1432    pub fn new<T>(chat_id: T, user_id: Integer) -> Self
1433    where
1434        T: Into<ChatId>,
1435    {
1436        Self {
1437            chat_id: chat_id.into(),
1438            user_id,
1439            tag: None,
1440        }
1441    }
1442
1443    /// Sets a new tag.
1444    ///
1445    /// # Arguments
1446    ///
1447    /// * `value` - New tag for the member; 0-16 characters, emoji are not allowed.
1448    pub fn with_tag<T>(mut self, value: T) -> Self
1449    where
1450        T: Into<String>,
1451    {
1452        self.tag = Some(value.into());
1453        self
1454    }
1455}
1456
1457impl Method for SetChatMemberTag {
1458    type Response = bool;
1459
1460    fn into_payload(self) -> Payload {
1461        Payload::json("setChatMemberTag", self)
1462    }
1463}
1464
1465/// Unbans a previously kicked user in a supergroup or channel.
1466///
1467/// The user will not return to the group or channel
1468/// automatically, but will be able to join via link, etc.
1469///
1470/// The bot must be an administrator for this to work
1471#[serde_with::skip_serializing_none]
1472#[derive(Clone, Debug, Serialize)]
1473pub struct UnbanChatMember {
1474    chat_id: ChatId,
1475    user_id: Integer,
1476    only_if_banned: Option<bool>,
1477}
1478
1479impl UnbanChatMember {
1480    /// Creates a new `UnbanChatMember`.
1481    ///
1482    /// # Arguments
1483    ///
1484    /// * `chat_id` - Unique identifier of the target chat.
1485    /// * `user_id` - Unique identifier of the target user.
1486    pub fn new<T>(chat_id: T, user_id: Integer) -> Self
1487    where
1488        T: Into<ChatId>,
1489    {
1490        UnbanChatMember {
1491            chat_id: chat_id.into(),
1492            user_id,
1493            only_if_banned: None,
1494        }
1495    }
1496
1497    /// Sets a new value for the `only_if_banned` flag.
1498    ///
1499    /// # Arguments
1500    ///
1501    /// * `value` - If `true` - do nothing if the user is not banned.
1502    pub fn with_only_if_banned(mut self, only_if_banned: bool) -> Self {
1503        self.only_if_banned = Some(only_if_banned);
1504        self
1505    }
1506}
1507
1508impl Method for UnbanChatMember {
1509    type Response = bool;
1510
1511    fn into_payload(self) -> Payload {
1512        Payload::json("unbanChatMember", self)
1513    }
1514}