tgbot 0.47.0

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

use crate::{
    api::{Method, Payload, PayloadError},
    types::ChatId,
};

/// Represents the rights of an administrator in a chat.
#[serde_with::skip_serializing_none]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct ChatAdministratorRights {
    /// Indicates whether the user is allowed to change the chat title, photo and other settings.
    pub can_change_info: bool,
    /// Indicates whether the administrator can delete messages of other users.
    pub can_delete_messages: bool,
    /// Indicates whether the administrator can delete stories posted by other users.
    pub can_delete_stories: Option<bool>,
    /// Indicates whether the administrator can edit messages of other users
    /// and can pin messages; channels only.
    pub can_edit_messages: Option<bool>,
    /// Indicates whether the administrator can edit stories posted by other users.
    pub can_edit_stories: Option<bool>,
    /// Indicates whether the user is allowed to invite new users to the chat.
    pub can_invite_users: bool,
    /// Indicates whether the administrator can
    /// access the chat event log, boost list in channels,
    /// see channel members, report spam messages,
    /// see anonymous administrators in supergroups and ignore slow mode.
    ///
    /// Implied by any other administrator privilege.
    pub can_manage_chat: bool,
    /// Whether the administrator can manage direct messages
    /// of the channel and decline suggested posts; for channels only.
    pub can_manage_direct_messages: Option<bool>,
    /// Whether the administrator can edit tags of regular members;
    /// for groups and supergroups only.
    ///
    /// If omitted defaults to value of `can_pin_messages`.
    pub can_manage_tags: Option<bool>,
    /// Indicates whether the user is allowed to create, rename,
    /// close, and reopen forum topics; supergroups only.
    pub can_manage_topics: Option<bool>,
    /// Indicates whether the administrator can manage video chats.
    pub can_manage_video_chats: bool,
    /// Indicates whether the user is allowed to pin messages; groups and supergroups only.
    pub can_pin_messages: Option<bool>,
    /// Indicates whether the administrator can post messages in the channel,
    /// or access channel statistics; channels only.
    pub can_post_messages: Option<bool>,
    /// Indicates whether the administrator can post stories in the chat.
    pub can_post_stories: Option<bool>,
    /// Indicates whether the administrator can
    /// add new administrators with a subset of their own privileges
    /// or demote administrators that they have promoted,
    /// directly or indirectly (promoted by administrators that were appointed by the user).
    pub can_promote_members: bool,
    /// Indicates whether the administrator can restrict, ban or unban chat members,
    /// or access supergroup statistics.
    pub can_restrict_members: bool,
    /// Indicates whether the user's presence in the chat is hidden.
    pub is_anonymous: bool,
}

impl ChatAdministratorRights {
    /// Creates a new `ChatAdministratorRights` with all flags set to `true`.
    ///
    /// To create an object with all flags set to `false` use [`Self::default`] method.
    pub fn all() -> Self {
        Self {
            can_change_info: true,
            can_delete_messages: true,
            can_delete_stories: Some(true),
            can_edit_messages: Some(true),
            can_edit_stories: Some(true),
            can_invite_users: true,
            can_manage_chat: true,
            can_manage_direct_messages: Some(true),
            can_manage_tags: Some(true),
            can_manage_topics: Some(true),
            can_manage_video_chats: true,
            can_pin_messages: Some(true),
            can_post_messages: Some(true),
            can_post_stories: Some(true),
            can_promote_members: true,
            can_restrict_members: true,
            is_anonymous: true,
        }
    }

    /// Sets a new value for the `can_change_info` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the user is allowed
    ///   to change the chat title,
    ///   photo and other settings.
    pub fn with_can_change_info(mut self, value: bool) -> Self {
        self.can_change_info = value;
        self
    }

    /// Sets a new value for the `can_delete_messages` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the administrator can
    ///   delete messages of other users.
    pub fn with_can_delete_messages(mut self, value: bool) -> Self {
        self.can_delete_messages = value;
        self
    }

    /// Sets a new value for the `can_delete_stories` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the administrator can
    ///   delete stories posted by other users;
    ///   channels only.
    pub fn with_can_delete_stories(mut self, value: bool) -> Self {
        self.can_delete_stories = Some(value);
        self
    }

    /// Sets a new value for the `can_edit_messages` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the administrator can
    ///   edit messages of other users and can pin messages;
    ///   channels only.
    pub fn with_can_edit_messages(mut self, value: bool) -> Self {
        self.can_edit_messages = Some(value);
        self
    }

    /// Sets a new value for the `can_edit_stories` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the administrator can
    ///   edit stories posted by other users;
    ///   channels only.
    pub fn with_can_edit_stories(mut self, value: bool) -> Self {
        self.can_edit_stories = Some(value);
        self
    }

    /// Sets a new value for the `can_invite_users` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the user is allowed to
    ///   invite new users to the chat.
    pub fn with_can_invite_users(mut self, value: bool) -> Self {
        self.can_invite_users = value;
        self
    }

    /// Sets a new value for the `can_manage_chat` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the administrator can
    ///   access the chat event log, boost list in channels,
    ///   see channel members, report spam messages,
    ///   see anonymous administrators in supergroups and ignore slow mode.
    pub fn with_can_manage_chat(mut self, value: bool) -> Self {
        self.can_manage_chat = value;
        self
    }

    /// Sets a new value for the `can_manage_direct_messages` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Whether the administrator can manage direct messages
    ///   of the channel and decline suggested posts; for channels only.
    pub fn with_can_manage_direct_messages(mut self, value: bool) -> Self {
        self.can_manage_direct_messages = Some(value);
        self
    }

    /// Sets a new value for the `can_manage_tags` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Whether the administrator can manage tags of regular members.
    pub fn with_can_manage_tags(mut self, value: bool) -> Self {
        self.can_manage_tags = Some(value);
        self
    }

    /// Sets a new value for the `can_manage_topics` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the user is allowed to
    ///   create, rename, close, and reopen forum topics;
    ///   supergroups only.
    pub fn with_can_manage_topics(mut self, value: bool) -> Self {
        self.can_manage_topics = Some(value);
        self
    }

    /// Sets a new value for the `can_manage_video_chats` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the administrator can
    ///   manage video chats.
    pub fn with_can_manage_video_chats(mut self, value: bool) -> Self {
        self.can_manage_video_chats = value;
        self
    }

    /// Sets a new value for the `can_pin_messages` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the user is allowed to
    ///   pin messages;
    ///   groups and supergroups only.
    pub fn with_can_pin_messages(mut self, value: bool) -> Self {
        self.can_pin_messages = Some(value);
        self
    }

    /// Sets a new value for the `can_post_messages` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the administrator can
    ///   post messages in the channel,
    ///   or access channel statistics;
    ///   channels only.
    pub fn with_can_post_messages(mut self, value: bool) -> Self {
        self.can_post_messages = Some(value);
        self
    }

    /// Sets a new value for the `can_post_stories` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the administrator can
    ///   post stories in the channel;
    ///   channels only.
    pub fn with_can_post_stories(mut self, value: bool) -> Self {
        self.can_post_stories = Some(value);
        self
    }

    /// Sets a new value for the `can_promote_members` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the administrator can
    ///   add new administrators with a subset of their own privileges
    ///   or demote administrators that they have promoted,
    ///   directly or indirectly (promoted by administrators that
    ///   were appointed by the user).
    pub fn with_can_promote_members(mut self, value: bool) -> Self {
        self.can_promote_members = value;
        self
    }

    /// Sets a new value for the `can_restrict_members` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the administrator can
    ///   restrict, ban or unban chat members,
    ///   or access supergroup statistics.
    pub fn with_can_restrict_members(mut self, value: bool) -> Self {
        self.can_restrict_members = value;
        self
    }

    /// Sets a new value for the `is_anonymous` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the user's presence in the chat is hidden.
    pub fn with_is_anonymous(mut self, value: bool) -> Self {
        self.is_anonymous = value;
        self
    }
}

/// Represents actions that a non-administrator user is allowed to take in a chat.
#[serde_with::skip_serializing_none]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
pub struct ChatPermissions {
    /// Indicates whether the user is allowed to add web page previews to their messages.
    pub can_add_web_page_previews: Option<bool>,
    /// Indicates whether the user is allowed to change the chat title, photo and other settings.
    ///
    /// Ignored in public supergroups.
    pub can_change_info: Option<bool>,
    /// Indicates whether the user is allowed to edit their own tag.
    pub can_edit_tag: Option<bool>,
    /// Indicates whether the user is allowed to invite new users to the chat.
    pub can_invite_users: Option<bool>,
    /// Indicates whether the user is allowed to create forum topics.
    ///
    /// If omitted defaults to the value of `can_pin_messages`.
    pub can_manage_topics: Option<bool>,
    /// Indicates whether the user is allowed to pin messages.
    ///
    /// Ignored in public supergroups.
    pub can_pin_messages: Option<bool>,
    /// Indicates whether the user is allowed to react to messages.
    ///
    /// If omitted, defaults to the value of `can_send_messages`.
    pub can_react_to_messages: Option<bool>,
    /// Indicates whether the user is allowed to send audios.
    pub can_send_audios: Option<bool>,
    /// Indicates whether the user is allowed to send documents.
    pub can_send_documents: Option<bool>,
    /// Indicates whether the user is allowed to send text messages, contacts, locations and venues.
    pub can_send_messages: Option<bool>,
    /// Indicates whether the user is allowed to send animations,
    /// games, stickers and use inline bots.
    pub can_send_other_messages: Option<bool>,
    /// Indicates whether the user is allowed to send photos.
    pub can_send_photos: Option<bool>,
    /// Indicates whether the user is allowed to send polls, implies `can_send_messages`.
    pub can_send_polls: Option<bool>,
    /// Indicates whether the user is allowed to send video notes.
    pub can_send_video_notes: Option<bool>,
    /// Indicates whether the user is allowed to send videos.
    pub can_send_videos: Option<bool>,
    /// Indicates whether the user is allowed to send voice notes.
    pub can_send_voice_notes: Option<bool>,
}

impl ChatPermissions {
    /// Restrict everything.
    pub fn restricted() -> Self {
        Self {
            can_change_info: Some(false),
            can_add_web_page_previews: Some(false),
            can_edit_tag: Some(false),
            can_invite_users: Some(false),
            can_manage_topics: Some(false),
            can_pin_messages: Some(false),
            can_react_to_messages: Some(false),
            can_send_audios: Some(false),
            can_send_documents: Some(false),
            can_send_messages: Some(false),
            can_send_other_messages: Some(false),
            can_send_photos: Some(false),
            can_send_polls: Some(false),
            can_send_video_notes: Some(false),
            can_send_videos: Some(false),
            can_send_voice_notes: Some(false),
        }
    }

    /// Allow everything.
    pub fn allowed() -> Self {
        Self {
            can_add_web_page_previews: Some(true),
            can_change_info: Some(true),
            can_edit_tag: Some(true),
            can_invite_users: Some(true),
            can_manage_topics: Some(true),
            can_pin_messages: Some(true),
            can_react_to_messages: Some(true),
            can_send_audios: Some(true),
            can_send_documents: Some(true),
            can_send_messages: Some(true),
            can_send_other_messages: Some(true),
            can_send_photos: Some(true),
            can_send_polls: Some(true),
            can_send_video_notes: Some(true),
            can_send_videos: Some(true),
            can_send_voice_notes: Some(true),
        }
    }

    /// Sets a new value for the `can_add_web_page_previews` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission add web page previews to messages.
    pub fn with_can_add_web_page_previews(mut self, value: bool) -> Self {
        self.can_add_web_page_previews = Some(value);
        self
    }

    /// Sets a new value for the `can_change_info` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to change the chat title, photo and other settings.
    pub fn with_can_change_info(mut self, value: bool) -> Self {
        self.can_change_info = Some(value);
        self
    }

    /// Sets a new value for the `can_edit_tag` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to change user tag.
    pub fn with_can_edit_tag(mut self, value: bool) -> Self {
        self.can_edit_tag = Some(value);
        self
    }

    /// Sets a new value for the `can_invite_users` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to invite new users to the chat.
    pub fn with_can_invite_users(mut self, value: bool) -> Self {
        self.can_invite_users = Some(value);
        self
    }

    /// Sets a new value for the `can_manage_topics` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to manage topics.
    pub fn with_can_manage_topics(mut self, value: bool) -> Self {
        self.can_manage_topics = Some(value);
        self
    }

    /// Sets a new value for the `can_pin_messages` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to pin messages.
    pub fn with_can_pin_messages(mut self, value: bool) -> Self {
        self.can_pin_messages = Some(value);
        self
    }

    /// Sets a new value for the `can_react_messages` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to react to messages.
    pub fn with_can_react_to_messages(mut self, value: bool) -> Self {
        self.can_react_to_messages = Some(value);
        self
    }

    /// Sets a new value for the `can_send_audios` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to send audios.
    pub fn with_can_send_audios(mut self, value: bool) -> Self {
        self.can_send_audios = Some(value);
        self
    }

    /// Sets a new value for the `can_send_documents` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to send documents.
    pub fn with_can_send_documents(mut self, value: bool) -> Self {
        self.can_send_documents = Some(value);
        self
    }

    /// Sets a new value for the `can_send_messages` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to send text messages, contacts, locations and venues.
    pub fn with_can_send_messages(mut self, value: bool) -> Self {
        self.can_send_messages = Some(value);
        self
    }

    /// Sets a new value for the `can_send_other_messages` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to send animations, games, stickers and use inline bots.
    pub fn with_can_send_other_messages(mut self, value: bool) -> Self {
        self.can_send_other_messages = Some(value);
        self
    }

    /// Sets a new value for the `can_send_photos` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to send photos.
    pub fn with_can_send_photos(mut self, value: bool) -> Self {
        self.can_send_photos = Some(value);
        self
    }

    /// Sets a new value for the `can_send_polls` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to send polls.
    pub fn with_can_send_polls(mut self, value: bool) -> Self {
        self.can_send_polls = Some(value);
        self
    }

    /// Sets a new value for the `can_send_video_notes` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to send video notes.
    pub fn with_can_send_video_notes(mut self, value: bool) -> Self {
        self.can_send_video_notes = Some(value);
        self
    }

    /// Sets a new value for the `can_send_videos` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to send videos.
    pub fn with_can_send_videos(mut self, value: bool) -> Self {
        self.can_send_videos = Some(value);
        self
    }

    /// Sets a new value for the `can_send_voice_notes` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Permission to send voice notes.
    pub fn with_can_send_voice_notes(mut self, value: bool) -> Self {
        self.can_send_voice_notes = Some(value);
        self
    }
}

/// Sets default chat permissions for all members.
///
/// The bot must be an administrator in the group or a supergroup
/// for this to work and must have the `can_restrict_members` admin rights.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize)]
pub struct SetChatPermissions {
    chat_id: ChatId,
    permissions: ChatPermissions,
    use_independent_chat_permissions: Option<bool>,
}

impl SetChatPermissions {
    /// Creates a new `SetChatPermissions`
    ///
    /// # Arguments
    ///
    /// * `chat_id` - Unique identifier of the target chat.
    /// * `permissions` - New permissions.
    pub fn new<T>(chat_id: T, permissions: ChatPermissions) -> Self
    where
        T: Into<ChatId>,
    {
        SetChatPermissions {
            chat_id: chat_id.into(),
            permissions,
            use_independent_chat_permissions: None,
        }
    }

    /// Sets a new value for the `use_independent_chat_permissions` flag.
    ///
    /// # Arguments
    ///
    /// * `value` - Indicates whether the chat permissions are set independently.
    ///
    /// If `false`, the `can_send_other_messages` and `can_add_web_page_previews` permissions
    /// will imply the `can_send_messages`, `can_send_audios`, `can_send_documents`, `can_send_photos`,
    /// `can_send_videos`, `can_send_video_notes`, and `can_send_voice_notes` permissions;
    /// the `can_send_polls` permission will imply the `can_send_messages` permission.
    pub fn with_use_independent_chat_permissions(mut self, value: bool) -> Self {
        self.use_independent_chat_permissions = Some(value);
        self
    }
}

impl Method for SetChatPermissions {
    type Response = bool;

    fn into_payload(self) -> Result<Payload, PayloadError> {
        Payload::json("setChatPermissions", self)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn chat_administrator_rights() {
        let obj = ChatAdministratorRights::default()
            .with_can_change_info(true)
            .with_can_delete_messages(false)
            .with_can_delete_stories(false)
            .with_can_edit_messages(false)
            .with_can_edit_stories(true)
            .with_can_invite_users(false)
            .with_can_manage_chat(true)
            .with_can_manage_direct_messages(false)
            .with_can_manage_tags(false)
            .with_can_manage_topics(true)
            .with_can_manage_video_chats(false)
            .with_can_pin_messages(true)
            .with_can_post_messages(true)
            .with_can_post_stories(false)
            .with_can_promote_members(true)
            .with_can_restrict_members(false)
            .with_is_anonymous(true);
        assert!(obj.can_change_info);
        assert!(!obj.can_delete_messages);
        assert!(!obj.can_delete_stories.unwrap());
        assert!(!obj.can_edit_messages.unwrap());
        assert!(obj.can_edit_stories.unwrap());
        assert!(!obj.can_invite_users);
        assert!(obj.can_manage_chat);
        assert!(!obj.can_manage_direct_messages.unwrap());
        assert!(!obj.can_manage_tags.unwrap());
        assert!(obj.can_manage_topics.unwrap());
        assert!(!obj.can_manage_video_chats);
        assert!(obj.can_pin_messages.unwrap());
        assert!(obj.can_post_messages.unwrap());
        assert!(!obj.can_post_stories.unwrap());
        assert!(obj.can_promote_members);
        assert!(!obj.can_restrict_members);
        assert!(obj.is_anonymous);

        let obj = ChatAdministratorRights::all();
        assert!(obj.can_change_info);
        assert!(obj.can_delete_messages);
        assert!(obj.can_delete_stories.unwrap());
        assert!(obj.can_edit_messages.unwrap());
        assert!(obj.can_edit_stories.unwrap());
        assert!(obj.can_invite_users);
        assert!(obj.can_manage_chat);
        assert!(obj.can_manage_direct_messages.unwrap());
        assert!(obj.can_manage_tags.unwrap());
        assert!(obj.can_manage_topics.unwrap());
        assert!(obj.can_manage_video_chats);
        assert!(obj.can_pin_messages.unwrap());
        assert!(obj.can_post_messages.unwrap());
        assert!(obj.can_post_stories.unwrap());
        assert!(obj.can_promote_members);
        assert!(obj.can_restrict_members);
        assert!(obj.is_anonymous);
    }

    #[test]
    fn chat_permissions() {
        let obj = ChatPermissions::default()
            .with_can_send_messages(true)
            .with_can_send_audios(false)
            .with_can_send_documents(true)
            .with_can_send_photos(false)
            .with_can_send_videos(true)
            .with_can_send_video_notes(false)
            .with_can_send_voice_notes(true)
            .with_can_send_polls(true)
            .with_can_send_other_messages(false)
            .with_can_add_web_page_previews(true)
            .with_can_change_info(false)
            .with_can_edit_tag(true)
            .with_can_invite_users(true)
            .with_can_pin_messages(false)
            .with_can_manage_topics(true)
            .with_can_react_to_messages(false);
        assert!(obj.can_send_messages.unwrap());
        assert!(!obj.can_send_audios.unwrap());
        assert!(obj.can_send_documents.unwrap());
        assert!(!obj.can_send_photos.unwrap());
        assert!(obj.can_send_videos.unwrap());
        assert!(!obj.can_send_video_notes.unwrap());
        assert!(obj.can_send_voice_notes.unwrap());
        assert!(obj.can_send_polls.unwrap());
        assert!(!obj.can_send_other_messages.unwrap());
        assert!(obj.can_add_web_page_previews.unwrap());
        assert!(!obj.can_change_info.unwrap());
        assert!(obj.can_edit_tag.unwrap());
        assert!(obj.can_invite_users.unwrap());
        assert!(!obj.can_pin_messages.unwrap());
        assert!(obj.can_manage_topics.unwrap());
        assert!(!obj.can_react_to_messages.unwrap());
    }
}