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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
use chrono::{DateTime, Utc};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use super::{raw::RawChat, utils::unix_date_formatting, User};
/// A private chat object, also known as a DM, between the bot and an user
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PrivateChat {
/// Unique identifier for this chat
pub id: i64,
/// Username if available
pub username: Option<String>,
/// First name of the other party
pub first_name: Option<String>,
/// Bio of the other party in a private chat. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub bio: Option<String>,
/// True, if privacy settings of the other party in the private chat allows
/// to use `tg://user?id=<user_id>` links only in chats with the user.
/// Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub has_private_forwards: bool,
/// True, if the privacy settings of the other party restrict sending voice
/// and video note messages in the private chat. Returned only in
/// [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub has_restricted_voice_and_video_messages: Option<bool>,
/// Last name of the other party
pub last_name: Option<String>,
/// Chat photo. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub photo: Option<ChatPhoto>,
/// If non-empty, the list of all active chat usernames. Returned only in
/// [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub active_usernames: Vec<String>,
/// Custom emoji identifier of emoji status of the other party in a private
/// chat. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub emoji_status_custom_emoji_id: Option<String>,
/// Expiration date of the emoji status of the other party in a private
/// chat, if any. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub emoji_status_expiration_date: Option<DateTime<Utc>>,
/// The time after which all messages sent to the chat will be automatically
/// deleted; in seconds. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub message_auto_delete_time: Option<usize>,
}
/// A Group chat object
#[derive(Debug, Clone, PartialEq)]
pub struct GroupChat {
pub id: i64,
/// Title
pub title: String,
/// Chat photo. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub photo: Option<ChatPhoto>,
/// Description. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub description: Option<String>,
/// Chat invite link
pub invite_link: Option<String>,
/// Pinned message. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub pinned_message: Option<Box<super::Message>>,
/// Default chat member permissions. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub permissions: Option<super::ChatPermissions>,
/// True, if non-administrators can only get the list of bots and
/// administrators in the chat. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub has_hidden_members: bool,
/// True, if messages from the chat can't be forwarded to other chats.
/// Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub has_protected_content: bool,
}
/// A supergroup object (a group with more than 200 members)
#[derive(Debug, Clone, PartialEq)]
pub struct SuperGroupChat {
pub id: i64,
/// Title
pub title: String,
/// Username if available
pub username: Option<String>,
/// True, if the supergroup chat is a forum (has [topics] enabled)
///
/// [topics]: https://telegram.org/blog/topics-in-groups-collectible-usernames#topics-in-groups
pub is_forum: bool,
/// Chat photo. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub photo: Option<ChatPhoto>,
/// If non-empty, the list of all active chat usernames. Returned only in
/// [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub active_usernames: Vec<String>,
/// True, if users need to join the supergroup before they can send
/// messages.Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub join_to_send_messages: bool,
/// True, if all users directly joining the supergroup need to be approved
/// by supergroup administrators.Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub join_by_request: bool,
/// Description. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub description: Option<String>,
/// Chat invite link
pub invite_link: Option<String>,
/// Pinned message. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub pinned_message: Option<Box<super::Message>>,
/// Default chat member permissions. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub permissions: Option<super::ChatPermissions>,
/// The minimum allowed delay between consecutive messages sent by each
/// unprivileged user. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub slow_mode_delay: Option<usize>,
/// True, if aggressive anti-spam checks are enabled in the supergroup. The
/// field is only available to chat administrators. Returned only in
/// [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub has_aggressive_anti_spam_enabled: bool,
/// True, if non-administrators can only get the list of bots and
/// administrators in the chat. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub has_hidden_members: bool,
/// True, if messages from the chat can't be forwarded to other chats.
/// Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub has_protected_content: bool,
/// Name of group sticker set. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub sticker_set_name: Option<String>,
/// True, if the bot can change the group sticker set. Returned only in
/// [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub can_set_sticker_set: bool,
/// Unique identifier for the linked chat, i.e. the discussion group
/// identifier for a channel and vice versa; for supergroups and channel
/// chats. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub linked_chat_id: Option<i64>,
/// For supergroups, the location to which the supergroup is connected.
/// Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub location: Option<ChatLocation>,
}
/// A Channel object
#[derive(Debug, Clone, PartialEq)]
pub struct ChannelChat {
pub id: i64,
/// Title
pub title: String,
/// Username if available
pub username: Option<String>,
/// Chat photo. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub photo: Option<ChatPhoto>,
/// If non-empty, the list of all active chat usernames. Returned only in
/// [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub active_usernames: Vec<String>,
/// Description. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub description: Option<String>,
/// Chat invite link
pub invite_link: Option<String>,
/// Pinned message. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub pinned_message: Option<Box<super::Message>>,
/// True, if non-administrators can only get the list of bots and
/// administrators in the chat. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub has_hidden_members: bool,
/// True, if messages from the chat can't be forwarded to other chats.
/// Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub has_protected_content: bool,
/// Unique identifier for the linked chat, i.e. the discussion group
/// identifier for a channel and vice versa; for supergroups and channel
/// chats. Returned only in [`get_chat`].
///
/// [`get_chat`]: ../../api/trait.API.html#method.get_chat
pub linked_chat_id: Option<i64>,
}
/// This object represents a chat. It can be a private, group, supergroup or
/// channel chat
#[allow(clippy::large_enum_variant)] // Using a box makes it more user-unfriendly
#[derive(Debug, Clone, PartialEq)]
pub enum Chat {
Private(PrivateChat),
Group(GroupChat),
SuperGroup(SuperGroupChat),
Channel(ChannelChat),
}
/// Represents a location to which a chat is connected.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct ChatLocation {
/// The location to which the supergroup is connected. Can't be a live
/// location.
pub location: super::Location,
/// Location address; 1-64 characters, as defined by the chat owner
pub address: String,
}
/// Describes actions that a non-administrator user is allowed to take in a
/// chat.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct ChatPermissions {
/// True, if the user is allowed to send text messages, contacts, locations
/// and venues.
#[serde(default)]
pub can_send_messages: bool,
/// True, if the user is allowed to send audios
#[serde(default)]
pub can_send_audios: bool,
/// True, if the user is allowed to send documents
#[serde(default)]
pub can_send_documents: bool,
/// True, if the user is allowed to send photos
#[serde(default)]
pub can_send_photos: bool,
/// True, if the user is allowed to send videos
#[serde(default)]
pub can_send_videos: bool,
/// True, if the user is allowed to send video notes
#[serde(default)]
pub can_send_video_notes: bool,
/// True, if the user is allowed to send voice notes
#[serde(default)]
pub can_send_voice_notes: bool,
/// True, if the user is allowed to send polls, implies can_send_messages to
/// be true.
#[serde(default)]
pub can_send_polls: bool,
/// True, if the user is allowed to send animations, games, stickers and use
/// inline bots, implies can_send_media_messages to be true.
#[serde(default)]
pub can_send_other_messages: bool,
/// True, if the user is allowed to add web page previews to their messages,
/// implies can_send_media_messages to be true.
#[serde(default)]
pub can_add_web_page_previews: bool,
/// True, if the user is allowed to change the chat title, photo and other
/// settings. Ignored in public supergroups.
#[serde(default)]
pub can_change_info: bool,
/// True, if the user is allowed to invite new users to the chat.
#[serde(default)]
pub can_invite_users: bool,
/// True, if the user is allowed to pin messages. Ignored in public
/// supergroups.
#[serde(default)]
pub can_pin_messages: bool,
/// True, if the user is allowed to create forum topics. If omitted defaults
/// to the value of can_pin_messages
#[serde(default)]
pub can_manage_topics: bool,
}
/// This object represents a chat photo.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct ChatPhoto {
/// File identifier of small (160x160) chat photo.
/// This file_id can be used only for photo download and only for as long as
/// the photo is not changed.
pub small_file_id: String,
/// Unique file identifier of small (160x160) chat photo, which is supposed
/// to be the same over time and for different bots. Can't be used to
/// download or reuse the file.
pub small_file_unique_id: String,
/// File identifier of big (640x640) chat photo.
/// This file_id can be used only for photo download and only for as long as
/// the photo is not changed.
pub big_file_id: String,
/// Unique file identifier of big (640x640) chat photo, which is supposed to
/// be the same over time and for different bots. Can't be used to
/// download or reuse the file.
pub big_file_unique_id: String,
}
impl Chat {
/// Gets the id of the chat
pub fn get_id(&self) -> i64 {
match self {
Chat::Private(c) => c.id,
Chat::Channel(c) => c.id,
Chat::Group(c) => c.id,
Chat::SuperGroup(c) => c.id,
}
}
/// Gets the title of the chat, or username if it's a private chat
/// In the possible case the user's username is unavailable, it is set to
/// "unknown user"
pub fn get_title(&self) -> &str {
match self {
Chat::Private(c) => c.username.as_ref().map_or("unknown user", String::as_str),
Chat::Channel(c) => &c.title,
Chat::Group(c) => &c.title,
Chat::SuperGroup(c) => &c.title,
}
}
}
impl From<RawChat> for Chat {
fn from(raw: RawChat) -> Chat {
match raw.chat_type {
ChatType::Channel => Chat::Channel(ChannelChat {
id: raw.id,
title: raw.title.unwrap_or_default(),
username: raw.username,
photo: raw.photo,
active_usernames: raw.active_usernames,
description: raw.description,
pinned_message: raw.pinned_message.map(|m| Box::new((*m).into())),
invite_link: raw.invite_link,
has_hidden_members: raw.has_hidden_members,
has_protected_content: raw.has_protected_content,
linked_chat_id: raw.linked_chat_id,
}),
ChatType::Private => Chat::Private(PrivateChat {
id: raw.id,
first_name: raw.first_name,
last_name: raw.last_name,
username: raw.username,
photo: raw.photo,
active_usernames: raw.active_usernames,
emoji_status_custom_emoji_id: raw.emoji_status_custom_emoji_id,
emoji_status_expiration_date: raw.emoji_status_expiration_date,
bio: raw.bio,
has_restricted_voice_and_video_messages: raw
.has_restricted_voice_and_video_messages,
has_private_forwards: raw.has_private_forwards,
message_auto_delete_time: raw.message_auto_delete_time,
}),
ChatType::Group => Chat::Group(GroupChat {
id: raw.id,
title: raw.title.unwrap_or_default(),
photo: raw.photo,
description: raw.description,
pinned_message: raw.pinned_message.map(|m| Box::new((*m).into())),
invite_link: raw.invite_link,
permissions: raw.permissions,
has_hidden_members: raw.has_hidden_members,
has_protected_content: raw.has_protected_content,
}),
ChatType::SuperGroup => Chat::SuperGroup(SuperGroupChat {
id: raw.id,
title: raw.title.unwrap_or_default(),
username: raw.username,
is_forum: raw.is_forum,
photo: raw.photo,
active_usernames: raw.active_usernames,
join_by_request: raw.join_by_request,
join_to_send_messages: raw.join_to_send_messages,
description: raw.description,
pinned_message: raw.pinned_message.map(|m| Box::new((*m).into())),
invite_link: raw.invite_link,
permissions: raw.permissions,
has_aggressive_anti_spam_enabled: raw.has_aggressive_anti_spam_enabled,
has_hidden_members: raw.has_hidden_members,
has_protected_content: raw.has_protected_content,
sticker_set_name: raw.sticker_set_name,
can_set_sticker_set: raw.can_set_sticker_set,
slow_mode_delay: raw.slow_mode_delay,
linked_chat_id: raw.linked_chat_id,
location: raw.location,
}),
ChatType::Sender => unreachable!(),
}
}
}
impl From<Chat> for RawChat {
fn from(chat: Chat) -> RawChat {
match chat {
Chat::Private(c) => RawChat {
chat_type: ChatType::Private,
first_name: c.first_name,
last_name: c.last_name,
id: c.id,
username: c.username,
photo: c.photo,
active_usernames: c.active_usernames,
emoji_status_custom_emoji_id: c.emoji_status_custom_emoji_id,
emoji_status_expiration_date: c.emoji_status_expiration_date,
bio: c.bio,
has_private_forwards: c.has_private_forwards,
message_auto_delete_time: c.message_auto_delete_time,
has_restricted_voice_and_video_messages: c.has_restricted_voice_and_video_messages,
join_to_send_messages: false,
join_by_request: false,
title: None,
description: None,
pinned_message: None,
invite_link: None,
permissions: None,
has_aggressive_anti_spam_enabled: false,
has_hidden_members: false,
has_protected_content: false,
sticker_set_name: None,
can_set_sticker_set: false,
slow_mode_delay: None,
linked_chat_id: None,
location: None,
is_forum: false,
},
Chat::Group(c) => RawChat {
chat_type: ChatType::Group,
id: c.id,
title: Some(c.title),
photo: c.photo,
description: c.description,
pinned_message: c.pinned_message.map(|m| Box::new((*m).into())),
invite_link: c.invite_link,
permissions: c.permissions,
has_hidden_members: c.has_hidden_members,
has_protected_content: c.has_protected_content,
username: None,
message_auto_delete_time: None,
sticker_set_name: None,
can_set_sticker_set: false,
slow_mode_delay: None,
first_name: None,
last_name: None,
bio: None,
has_private_forwards: false,
linked_chat_id: None,
location: None,
has_restricted_voice_and_video_messages: None,
has_aggressive_anti_spam_enabled: false,
join_to_send_messages: false,
join_by_request: false,
is_forum: false,
active_usernames: Vec::new(),
emoji_status_custom_emoji_id: None,
emoji_status_expiration_date: None,
},
Chat::SuperGroup(c) => RawChat {
chat_type: ChatType::SuperGroup,
id: c.id,
title: Some(c.title),
username: c.username,
photo: c.photo,
active_usernames: c.active_usernames,
description: c.description,
pinned_message: c.pinned_message.map(|m| Box::new((*m).into())),
invite_link: c.invite_link,
permissions: c.permissions,
has_aggressive_anti_spam_enabled: c.has_aggressive_anti_spam_enabled,
has_hidden_members: c.has_hidden_members,
has_protected_content: c.has_protected_content,
sticker_set_name: c.sticker_set_name,
can_set_sticker_set: c.can_set_sticker_set,
slow_mode_delay: c.slow_mode_delay,
linked_chat_id: c.linked_chat_id,
location: c.location,
join_to_send_messages: c.join_to_send_messages,
join_by_request: c.join_by_request,
is_forum: c.is_forum,
has_restricted_voice_and_video_messages: None,
bio: None,
has_private_forwards: false,
first_name: None,
last_name: None,
message_auto_delete_time: None,
emoji_status_custom_emoji_id: None,
emoji_status_expiration_date: None,
},
Chat::Channel(c) => RawChat {
chat_type: ChatType::Channel,
id: c.id,
title: Some(c.title),
username: c.username,
photo: c.photo,
active_usernames: c.active_usernames,
description: c.description,
pinned_message: c.pinned_message.map(|m| Box::new((*m).into())),
invite_link: c.invite_link,
has_hidden_members: c.has_hidden_members,
has_protected_content: c.has_protected_content,
linked_chat_id: c.linked_chat_id,
permissions: None,
message_auto_delete_time: None,
sticker_set_name: None,
can_set_sticker_set: false,
slow_mode_delay: None,
first_name: None,
last_name: None,
bio: None,
has_private_forwards: false,
location: None,
has_aggressive_anti_spam_enabled: false,
has_restricted_voice_and_video_messages: None,
join_to_send_messages: false,
join_by_request: false,
is_forum: false,
emoji_status_custom_emoji_id: None,
emoji_status_expiration_date: None,
},
}
}
}
impl<'de> Deserialize<'de> for Chat {
fn deserialize<D>(deserializer: D) -> Result<Chat, D::Error>
where
D: Deserializer<'de>,
{
let raw: RawChat = Deserialize::deserialize(deserializer)?;
Ok(raw.into())
}
}
impl Serialize for Chat {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
RawChat::from(self.clone()).serialize(serializer)
}
}
/// This object contains information about one member of a chat.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
#[serde(tag = "status")]
pub enum ChatMember {
#[serde(rename = "creator")]
Creator(CreatorMemberStatus),
#[serde(rename = "administrator")]
Administrator(AdministratorMemberStatus),
#[serde(rename = "member")]
Member(MemberMemberStatus),
#[serde(rename = "restricted")]
Restricted(RestrictedMemberStatus),
#[serde(rename = "left")]
Left(LeftMemberStatus),
#[serde(rename = "kicked")]
Kicked(KickedMemberStatus),
}
/// Represents a [`ChatMember`] who is the creator or owner of the [`Chat`].
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct CreatorMemberStatus {
/// Information about the user
pub user: User,
/// Custom title for this user
pub custom_title: Option<String>,
/// Owner and administrators only. True, if the user's presence in the chat
/// is hidden
#[serde(default)]
pub is_anonymous: bool,
}
/// Represents a [`ChatMember`] who is an Admin of the [`Chat`].
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct AdministratorMemberStatus {
/// Information about the user
pub user: User,
/// True, if the bot is allowed to edit administrator privileges of that
/// user
#[serde(default)]
pub can_be_edited: bool,
/// Owner and administrators only. True, if the user's presence in the chat
/// is hidden
#[serde(default)]
pub is_anonymous: bool,
/// True, if the administrator can access the chat event log, chat
/// statistics, message statistics in channels, see channel members, see
/// anonymous administrators in supergroups and ignore slow mode.
/// Implied by any other administrator privilege
#[serde(default)]
pub can_manage_chat: bool,
/// True, if the administrator can delete messages of other users
#[serde(default)]
pub can_delete_messages: bool,
/// True, if the administrator can manage video chats
#[serde(default)]
pub can_manage_video_chats: bool,
/// True, if the administrator can restrict, ban or unban chat members, or
/// access supergroup statistics
#[serde(default)]
pub can_restrict_members: bool,
/// True, if 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)
#[serde(default)]
pub can_promote_members: bool,
/// True, if the user is allowed to change the chat title, photo and other
/// settings
#[serde(default)]
pub can_change_info: bool,
/// True, if the user is allowed to invite new users to the chat
#[serde(default)]
pub can_invite_users: bool,
/// True, if the administrator can post messages in the channel, or access
/// channel statistics; channels only
#[serde(default)]
pub can_post_messages: bool,
/// True, if the administrator can edit messages of other users and can pin
/// messages; channels only
#[serde(default)]
pub can_edit_messages: bool,
/// True, if the user is allowed to pin messages; groups and supergroups
/// only
#[serde(default)]
pub can_pin_messages: bool,
/// True, if the administrator can post stories in the channel; channels
/// only
#[serde(default)]
pub can_post_stories: bool,
/// True, if the administrator can edit stories posted by other users;
/// channels only
#[serde(default)]
pub can_edit_stories: bool,
/// True, if the administrator can delete stories posted by other users;
/// channels only
#[serde(default)]
pub can_delete_stories: bool,
/// True, if the user is allowed to create, rename, close, and reopen forum
/// topics; supergroups only
#[serde(default)]
pub can_manage_topics: bool,
/// Custom title for this user
pub custom_title: Option<String>,
}
/// Represents a [`ChatMember`] who is a normal member of the [`Chat`] without
/// any special powers.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct MemberMemberStatus {
/// Information about the user
pub user: User,
}
/// Represents a restricted [`ChatMember`] of a [`Chat`].
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct RestrictedMemberStatus {
/// Information about the user
pub user: User,
/// True, if the user is a member of the chat at the moment of the request
#[serde(default)]
pub is_member: bool,
/// True, if the user is allowed to send text messages, contacts, locations
/// and venues
#[serde(default)]
pub can_send_messages: bool,
/// True, if the user is allowed to send audios
#[serde(default)]
pub can_send_audios: bool,
/// True, if the user is allowed to send documents
#[serde(default)]
pub can_send_documents: bool,
/// True, if the user is allowed to send photos
#[serde(default)]
pub can_send_photos: bool,
/// True, if the user is allowed to send videos
#[serde(default)]
pub can_send_videos: bool,
/// True, if the user is allowed to send video notes
#[serde(default)]
pub can_send_video_notes: bool,
/// True, if the user is allowed to send voice notes
#[serde(default)]
pub can_send_voice_notes: bool,
/// True, if the user is allowed to send polls
#[serde(default)]
pub can_send_polls: bool,
/// True, if the user is allowed to send animations, games, stickers and use
/// inline bots
#[serde(default)]
pub can_send_other_messages: bool,
/// True, if the user is allowed to add web page previews to their messages
#[serde(default)]
pub can_add_web_page_previews: bool,
#[serde(default)]
/// True, if the user is allowed to change the chat title, photo and other
/// settings
pub can_change_info: bool,
/// True, if the user is allowed to invite new users to the chat
#[serde(default)]
pub can_invite_users: bool,
/// True, if the user is allowed to pin messages; groups and supergroups
/// only
#[serde(default)]
pub can_pin_messages: bool,
/// True, if the user is allowed to create forum topics
#[serde(default)]
pub can_manage_topics: bool,
/// Date when restrictions will be lifted for this user; unix time
#[serde(with = "unix_date_formatting::optional")]
pub until_date: Option<DateTime<Utc>>,
}
/// Represents a [`ChatMember`] who left the [`Chat`].
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct LeftMemberStatus {
/// Information about the user
pub user: User,
}
/// Represents a [`ChatMember`] who has been kicked from the [`Chat`].
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct KickedMemberStatus {
/// Information about the user
pub user: User,
/// Date when restrictions will be lifted for this user; unix time
#[serde(with = "unix_date_formatting::optional")]
pub until_date: Option<DateTime<Utc>>,
}
impl ChatMember {
/// Retrieves the underlying [`User`] of the [`ChatMember`].
pub fn get_user(&self) -> &User {
match self {
ChatMember::Administrator(m) => &m.user,
ChatMember::Creator(m) => &m.user,
ChatMember::Kicked(m) => &m.user,
ChatMember::Left(m) => &m.user,
ChatMember::Member(m) => &m.user,
ChatMember::Restricted(m) => &m.user,
}
}
}
/// Represents an invite link for a chat.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct ChatInviteLink {
/// The invite link. If the link was created by another chat administrator,
/// then the second part of the link will be replaced with “…”.
pub invite_link: String,
/// Creator of the link
pub creator: User,
/// If the link is primary
pub is_primary: bool,
/// If the link is revoked
pub is_revoked: bool,
/// If users joining the chat via the link need to be approved by chat
/// administrators
pub creates_join_request: bool,
/// Invite link name
#[serde(default)]
pub name: Option<String>,
/// When the link will expire or has been expired
#[serde(with = "unix_date_formatting::optional")]
pub expire_date: Option<DateTime<Utc>>,
/// Maximum number of users that can be members of the chat simultaneously
/// after joining the chat via this invite link; 1-99999
#[serde(default)]
pub member_limit: Option<i32>,
/// Number of pending join requests created using this link
#[serde(default)]
pub pending_join_request_count: Option<i32>,
}
/// Represents changes in the status of a chat member.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct ChatMemberUpdated {
/// Chat the user belongs to
pub chat: Chat,
/// Performer of the action, which resulted in the change
pub from: User,
/// Date the change was done
#[serde(with = "unix_date_formatting")]
pub date: DateTime<Utc>,
/// Previous information about the chat member
pub old_chat_member: ChatMember,
/// New information about the chat member
pub new_chat_member: ChatMember,
/// Chat invite link, which was used by the user to join the chat; for
/// joining by invite link events only.
pub invite_link: Option<ChatInviteLink>,
/// True, if the user joined the chat via a chat folder invite link
#[serde(default)]
pub via_chat_folder_invite_link: bool,
}
/// The type of chat
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum ChatType {
#[serde(rename = "private")]
Private,
#[serde(rename = "group")]
Group,
#[serde(rename = "supergroup")]
SuperGroup,
#[serde(rename = "channel")]
Channel,
#[serde(rename = "sender")]
Sender,
}
/// Represents a join request sent to a chat.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct ChatJoinRequest {
/// Chat to which the request was sent
pub chat: Chat,
/// User that sent the join request
pub from: User,
/// Identifier of a private chat with the user who sent the join request.
/// The bot can use this identifier for 24 hours to send messages until the
/// join request is processed, assuming no other administrator contacted the
/// user.
pub user_chat_id: i64,
/// Date the request was sent in Unix time.
#[serde(with = "unix_date_formatting")]
pub date: DateTime<Utc>,
/// Bio of the user.
#[serde(default)]
pub bio: Option<String>,
/// Chat invite link that was used by the user to send the join request
#[serde(default)]
pub invite_link: Option<ChatInviteLink>,
}
/// Represents the rights of an administrator in a chat.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct ChatAdministratorRights {
/// True, if the user's presence in the chat is hidden
pub is_anonymous: bool,
/// True, if the administrator can access the chat event log, chat
/// statistics, message statistics in channels, see channel members, see
/// anonymous administrators in supergroups and ignore slow mode. Implied by
/// any other administrator privilege
pub can_manage_chat: bool,
/// True, if the administrator can delete messages of other users
pub can_delete_messages: bool,
/// True, if the administrator can manage video chats
pub can_manage_video_chats: bool,
/// True, if the administrator can restrict, ban or unban chat members
pub can_restrict_members: bool,
/// True, if the administrator can add new administrators with a subset of
/// their own privileges or demote administrators that he has promoted,
/// directly or indirectly (promoted by administrators that were appointed
/// by the user)
pub can_promote_members: bool,
/// True, if the user is allowed to change the chat title, photo and other
/// settings
pub can_change_info: bool,
/// True, if the user is allowed to invite new users to the chat
pub can_invite_users: bool,
/// True, if the administrator can post in the channel; channels only
#[serde(skip_serializing_if = "Option::is_none")]
pub can_post_messages: Option<bool>,
/// True, if the administrator can edit messages of other users and can pin
/// messages; channels only
#[serde(skip_serializing_if = "Option::is_none")]
pub can_edit_messages: Option<bool>,
/// True, if the user is allowed to pin messages; groups and supergroups
/// only
#[serde(skip_serializing_if = "Option::is_none")]
pub can_pin_messages: Option<bool>,
/// True, if the administrator can post stories in the channel; channels
/// only
#[serde(skip_serializing_if = "Option::is_none")]
pub can_post_stories: Option<bool>,
/// True, if the administrator can edit stories posted by other users;
/// channels only
#[serde(skip_serializing_if = "Option::is_none")]
pub can_edit_stories: Option<bool>,
/// True, if the administrator can delete stories posted by other users;
/// channels only
#[serde(skip_serializing_if = "Option::is_none")]
pub can_delete_stories: Option<bool>,
/// True, if the user is allowed to create, rename, close, and reopen forum
/// topics; supergroups only
#[serde(skip_serializing_if = "Option::is_none")]
pub can_manage_topics: Option<bool>,
}
/// This object represents a forum topic.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct ForumTopic {
/// Unique identifier of the forum topic
pub message_thread_id: i64,
/// Name of the topic
pub name: String,
/// Color of the topic icon in RGB format
pub icon_color: i64,
/// Unique identifier of the custom emoji shown as the topic icon
pub icon_custom_emoji_id: Option<String>,
}