telbot-types 0.3.0

Telegram API types for telbot
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
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
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
use serde::{Deserialize, Serialize};

use crate::file::{InputFile, InputFileVariant, InputMedia};
use crate::markup::InlineKeyboardMarkup;
use crate::message::{
    ChatActionKind, DeleteMessage, EditMessageCaption, EditMessageMedia, EditMessageReplyMarkup,
    EditMessageText, Location, Message, SendAnimation, SendAudio, SendChatAction, SendContact,
    SendDice, SendDocument, SendLocation, SendMediaGroup, SendMessage, SendPhoto, SendPoll,
    SendVenue, SendVideo, SendVideoNote, SendVoice, StopPoll,
};
use crate::user::User;
use crate::{JsonMethod, TelegramMethod};

/// This object represents a chat.
#[derive(Debug, Deserialize)]
pub struct Chat {
    /// Unique identifier for this chat.
    pub id: i64,
    /// Type of chat.
    #[serde(flatten)]
    pub kind: ChatKind,
    /// Title, for supergroups, channels and group chats
    pub title: Option<String>,
    /// Username, for private chats, supergroups and channels if available
    pub username: Option<String>,
    /// First name of the other party in a private chat
    pub first_name: Option<String>,
    /// Last name of the other party in a private chat
    pub last_name: Option<String>,
    /// Chat photo.
    /// Returned only in getChat.
    pub photo: Option<ChatPhoto>,
    /// Bio of the other party in a private chat.
    /// Returned only in getChat.
    pub bio: Option<String>,
    /// Description, for groups, supergroups and channel chats.
    /// Returned only in getChat.
    pub description: Option<String>,
    /// Primary invite link, for groups, supergroups and channel chats.
    /// Returned only in getChat.
    pub invite_link: Option<String>,
    /// The most recent pinned message (by sending date).
    /// Returned only in getChat.
    pub pinned_message: Option<Box<Message>>,
    /// Default chat member permissions, for groups and supergroups.
    /// Returned only in getChat.
    pub permissions: Option<ChatPermissions>,
    /// Default chat member permissions, for groups and supergroups.
    /// Returned only in getChat.
    pub slow_mode_delay: Option<i32>,
    /// The time after which all messages sent to the chat will be automatically deleted; in seconds.
    /// Returned only in getChat.
    pub message_auto_delete_time: Option<i32>,
    /// For supergroups, name of group sticker set.
    /// Returned only in getChat.
    pub sticker_set_name: Option<String>,
    /// True, if the bot can change the group sticker set.
    /// Returned only in getChat.
    pub can_get_sticker_set: Option<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 getChat.
    pub linked_chat_id: Option<i32>,
    /// For supergroups, the location to which the supergroup is connected.
    /// Returned only in getChat.
    pub location: Option<ChatLocation>,
}

impl Chat {
    pub fn send_animation(&self, animation: impl Into<InputFileVariant>) -> SendAnimation {
        SendAnimation::new(self.id, animation)
    }

    pub fn send_audio(&self, audio: impl Into<InputFileVariant>) -> SendAudio {
        SendAudio::new(self.id, audio)
    }

    pub fn send_chat_action(&self, action: ChatActionKind) -> SendChatAction {
        SendChatAction::new(self.id, action)
    }

    pub fn send_contact(
        &self,
        phone_number: impl Into<String>,
        first_name: impl Into<String>,
    ) -> SendContact {
        SendContact::new(self.id, phone_number, first_name)
    }

    pub fn send_dice(&self) -> SendDice {
        SendDice::new(self.id)
    }

    pub fn send_document(&self, document: impl Into<InputFileVariant>) -> SendDocument {
        SendDocument::new(self.id, document)
    }

    pub fn send_location(
        &self,
        latitude: f32,
        longitude: f32,
        horizontal_accuracy: f32,
    ) -> SendLocation {
        SendLocation::new(self.id, latitude, longitude, horizontal_accuracy)
    }

    pub fn send_media_group(&self) -> SendMediaGroup {
        SendMediaGroup::new(self.id)
    }

    pub fn send_message(&self, text: impl Into<String>) -> SendMessage {
        SendMessage::new(self.id, text)
    }

    pub fn send_photo(&self, photo: impl Into<InputFileVariant>) -> SendPhoto {
        SendPhoto::new(self.id, photo)
    }

    pub fn send_poll(&self, question: impl Into<String>, options: Vec<String>) -> SendPoll {
        SendPoll::new_regular(self.id, question, options)
    }

    pub fn send_quiz(
        &self,
        question: impl Into<String>,
        options: Vec<String>,
        correct_option_id: u32,
    ) -> SendPoll {
        SendPoll::new_quiz(self.id, question, options, correct_option_id)
    }

    pub fn send_venue(
        &self,
        latitude: f32,
        longitude: f32,
        title: impl Into<String>,
        address: impl Into<String>,
    ) -> SendVenue {
        SendVenue::new(self.id, latitude, longitude, title, address)
    }

    pub fn send_video(&self, video: impl Into<InputFileVariant>) -> SendVideo {
        SendVideo::new(self.id, video)
    }

    pub fn send_video_note(&self, video_note: impl Into<InputFileVariant>) -> SendVideoNote {
        SendVideoNote::new(self.id, video_note)
    }

    pub fn send_voice(&self, voice: impl Into<InputFileVariant>) -> SendVoice {
        SendVoice::new(self.id, voice)
    }

    pub fn ban(&self, user_id: i64) -> BanChatMember {
        BanChatMember::new(self.id, user_id)
    }

    pub fn unban(&self, user_id: i64) -> UnbanChatMember {
        UnbanChatMember::new(self.id, user_id)
    }

    pub fn restrict(&self, user_id: i64, permissions: ChatPermissions) -> RestrictChatMember {
        RestrictChatMember::new(self.id, user_id, permissions)
    }

    pub fn promote(&self, user_id: i64) -> PromoteChatMember {
        PromoteChatMember::new(self.id, user_id)
    }

    pub fn set_administrator_title(
        &self,
        user_id: i64,
        custom_title: impl Into<String>,
    ) -> SetChatAdministratorCustomTitle {
        SetChatAdministratorCustomTitle::new(self.id, user_id, custom_title)
    }

    pub fn set_permissions(&self, permissions: ChatPermissions) -> SetChatPermissions {
        SetChatPermissions::new(self.id, permissions)
    }

    pub fn export_invite_link(&self) -> ExportChatInviteLink {
        ExportChatInviteLink::new(self.id)
    }

    pub fn create_invite_link(&self) -> CreateChatInviteLink {
        CreateChatInviteLink::new(self.id)
    }

    pub fn edit_invite_link(&self, invite_link: impl Into<String>) -> EditChatInviteLink {
        EditChatInviteLink::new(self.id, invite_link)
    }

    pub fn revoke_invite_link(&self, invite_link: impl Into<String>) -> RevokeChatInviteLink {
        RevokeChatInviteLink::new(self.id, invite_link)
    }

    pub fn approve_join(&self, user_id: i64) -> ApproveChatJoinRequest {
        ApproveChatJoinRequest::new(self.id, user_id)
    }

    pub fn decline_join(&self, user_id: i64) -> DeclineChatJoinRequest {
        DeclineChatJoinRequest::new(self.id, user_id)
    }

    pub fn set_photo(&self, photo: InputFile) -> SetChatPhoto {
        SetChatPhoto::new(self.id, photo)
    }

    pub fn delete_photo(&self) -> DeleteChatPhoto {
        DeleteChatPhoto::new(self.id)
    }

    pub fn set_title(&self, title: impl Into<String>) -> SetChatTitle {
        SetChatTitle::new(self.id, title)
    }

    pub fn set_description(&self, description: impl Into<String>) -> SetChatDescription {
        SetChatDescription::new(self.id, description)
    }

    pub fn remove_description(&self) -> SetChatDescription {
        SetChatDescription::new_empty(self.id)
    }

    pub fn pin_message(&self, message_id: i64) -> PinChatMessage {
        PinChatMessage::new(self.id, message_id)
    }

    pub fn unpin_message(&self, message_id: i64) -> UnpinChatMessage {
        UnpinChatMessage::new(self.id, message_id)
    }

    pub fn unpin_latest_message(&self) -> UnpinChatMessage {
        UnpinChatMessage::new_recent(self.id)
    }

    pub fn unpin_all_messages(&self) -> UnpinAllChatMessages {
        UnpinAllChatMessages::new(self.id)
    }

    pub fn leave(&self) -> LeaveChat {
        LeaveChat::new(self.id)
    }

    pub fn get_details(&self) -> GetChat {
        GetChat::new(self.id)
    }

    pub fn get_administrators(&self) -> GetChatAdministrators {
        GetChatAdministrators::new(self.id)
    }

    pub fn get_member_count(&self) -> GetChatMemberCount {
        GetChatMemberCount::new(self.id)
    }

    pub fn get_member(&self, user_id: i64) -> GetChatMember {
        GetChatMember::new(self.id, user_id)
    }

    pub fn set_sticker_set(&self, sticker_set_name: impl Into<String>) -> SetChatStickerSet {
        SetChatStickerSet::new(self.id, sticker_set_name)
    }

    pub fn delete_sticker_set(&self) -> DeleteChatStickerSet {
        DeleteChatStickerSet::new(self.id)
    }

    pub fn edit_text_of(&self, message_id: i64, text: impl Into<String>) -> EditMessageText {
        EditMessageText::new(self.id, message_id, text)
    }

    pub fn remove_caption_of(&self, message_id: i64) -> EditMessageCaption {
        EditMessageCaption::new_empty(self.id, message_id)
    }

    pub fn edit_caption_of(
        &self,
        message_id: i64,
        caption: impl Into<String>,
    ) -> EditMessageCaption {
        EditMessageCaption::new(self.id, message_id, caption)
    }

    pub fn edit_media_of(&self, message_id: i64, media: impl Into<InputMedia>) -> EditMessageMedia {
        EditMessageMedia::new(self.id, message_id, media)
    }

    pub fn remove_reply_markup_of(&self, message_id: i64) -> EditMessageReplyMarkup {
        EditMessageReplyMarkup::new_empty(self.id, message_id)
    }

    pub fn edit_reply_markup_of(
        &self,
        message_id: i64,
        reply_markup: impl Into<InlineKeyboardMarkup>,
    ) -> EditMessageReplyMarkup {
        EditMessageReplyMarkup::new(self.id, message_id, reply_markup)
    }

    pub fn stop_poll(&self, message_id: i64) -> StopPoll {
        StopPoll::new(self.id, message_id)
    }

    pub fn delete_message(&self, message_id: i64) -> DeleteMessage {
        DeleteMessage::new(self.id, message_id)
    }
}

#[derive(Debug, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum ChatKind {
    Private,
    Group,
    Supergroup,
    Channel,
}

/// This object represents a chat photo.
#[derive(Debug, Deserialize)]
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,
}

#[derive(Debug, Deserialize)]
pub struct ChatLocation {
    /// The location to which the supergroup is connected.
    /// Can't be a live location.
    pub location: 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(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ChatPermissions {
    /// True, if the user is allowed to send text messages, contacts, locations and venues
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_send_messages: Option<bool>,
    /// True, if the user is allowed to send audios, documents,
    /// photos, videos, video notes and voice notes, implies can_send_messages
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_send_media_messages: Option<bool>,
    /// True, if the user is allowed to send polls, implies can_send_messages
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_send_polls: Option<bool>,
    /// True, if the user is allowed to send animations, games, stickers
    /// and use inline bots, implies can_send_media_messages
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_send_other_messages: Option<bool>,
    /// True, if the user is allowed to add web page previews to their messages,
    /// implies can_send_media_messages
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_add_web_page_previews: Option<bool>,
    /// True, if the user is allowed to change the chat title, photo and other settings.
    /// Ignored in public supergroups
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_change_info: Option<bool>,
    /// True, if the user is allowed to invite new users to the chat
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_invite_users: Option<bool>,
    /// True, if the user is allowed to pin messages.
    /// Ignored in public supergroups
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_pin_messages: Option<bool>,
}

impl ChatPermissions {
    /// Create a new ChatPermissions object
    pub fn new() -> Self {
        Default::default()
    }
    /// Set can_send_messages to `true`
    pub fn allow_send_messages(self) -> Self {
        Self {
            can_send_messages: Some(true),
            ..self
        }
    }
    /// Set can_send_media_messages to `true`
    pub fn allow_send_media_messages(self) -> Self {
        Self {
            can_send_media_messages: Some(true),
            ..self
        }
    }
    /// Set can_send_polls to `true`
    pub fn allow_send_polls(self) -> Self {
        Self {
            can_send_polls: Some(true),
            ..self
        }
    }
    /// Set can_send_other_messages to `true`
    pub fn allow_send_other_messages(self) -> Self {
        Self {
            can_send_other_messages: Some(true),
            ..self
        }
    }
    /// Set can_add_web_page_previews to `true`
    pub fn allow_add_web_page_previews(self) -> Self {
        Self {
            can_add_web_page_previews: Some(true),
            ..self
        }
    }
    /// Set can_change_info to `true`
    pub fn allow_change_info(self) -> Self {
        Self {
            can_change_info: Some(true),
            ..self
        }
    }
    /// Set can_invite_users to `true`
    pub fn allow_invite_users(self) -> Self {
        Self {
            can_invite_users: Some(true),
            ..self
        }
    }
    /// Set can_pin_messages to `true`
    pub fn allow_pin_messages(self) -> Self {
        Self {
            can_pin_messages: Some(true),
            ..self
        }
    }
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "snake_case", tag = "status")]
pub enum ChatMember {
    /// Represents a [chat member](https://core.telegram.org/bots/api#chatmember)
    /// that owns the chat and has all administrator privileges.
    #[serde(rename = "creator")]
    Owner {
        /// Information about the user
        user: User,
        /// True, if the user's presence in the chat is hidden
        is_anonymous: bool,
        /// Custom title for this user
        custom_title: Option<String>,
    },
    /// Represents a [chat member](https://core.telegram.org/bots/api#chatmember)
    /// that has some additional privileges.
    Administrator {
        /// Information about the user
        user: User,
        /// True, if the bot is allowed to edit administrator privileges of that user
        can_be_edited: bool,
        /// True, if the user's presence in the chat is hidden
        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
        can_manage_chat: bool,
        /// True, if the administrator can delete messages of other users
        can_delete_messages: bool,
        /// True, if the administrator can manage voice chats
        can_manage_voice_chats: bool,
        /// True, if the administrator can restrict, ban or unban chat members
        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)
        can_promote_members: bool,
        /// True, if the user is allowed to change the chat title, photo and other settings
        can_change_info: bool,
        /// True, if the user is allowed to invite new users to the chat
        can_invite_users: bool,
        /// True, if the administrator can post in the channel; channels only
        can_post_messages: Option<bool>,
        /// True, if the administrator can edit messages of other users and can pin messages; channels only
        can_edit_messages: Option<bool>,
        /// True, if the user is allowed to pin messages; groups and supergroups only
        can_pin_messages: Option<bool>,
        /// Custom title for this user
        custom_title: Option<String>,
    },
    /// Represents a [chat member](https://core.telegram.org/bots/api#chatmember)
    /// that has no additional privileges or restrictions.
    Member {
        /// Information about the user
        user: User,
    },
    /// Represents a [chat member](https://core.telegram.org/bots/api#chatmember)
    /// that is under certain restrictions in the chat. Supergroups only.
    Restricted {
        /// Information about the user
        user: User,
        /// True, if the user is a member of the chat at the moment of the request
        is_member: bool,
        /// True, if the user is allowed to change the chat title, photo and other settings
        can_change_info: bool,
        /// True, if the user is allowed to invite new users to the chat
        can_invite_users: bool,
        /// True, if the user is allowed to pin messages
        can_pin_messages: bool,
        /// True, if the user is allowed to send text messages, contacts, locations and venues
        can_send_messages: bool,
        /// True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes
        can_send_media_messages: bool,
        /// True, if the user is allowed to send polls
        can_send_polls: bool,
        /// True, if the user is allowed to send animations, games, stickers and use inline bots
        can_send_other_messages: bool,
        /// True, if the user is allowed to add web page previews to their messages
        can_add_web_page_previews: bool,
        /// Date when restrictions will be lifted for this user; unix time.
        /// If 0, then the user is restricted forever
        until_date: u64,
    },
    /// Represents a [chat member](https://core.telegram.org/bots/api#chatmember)
    /// that isn't currently a member of the chat, but may join it themselves.
    Left {
        /// Information about the user
        user: User,
    },
    /// Represents a [chat member](https://core.telegram.org/bots/api#chatmember)
    /// that was banned in the chat and can't return to the chat or view chat messages.
    #[serde(rename = "kicked")]
    Banned {
        /// Information about the user
        user: User,
        /// Date when restrictions will be lifted for this user; unix time.
        /// If 0, then the user is banned forever
        until_date: u64,
    },
}

impl ChatMember {
    pub fn user(&self) -> &User {
        match self {
            ChatMember::Owner { user, .. }
            | ChatMember::Administrator { user, .. }
            | ChatMember::Member { user }
            | ChatMember::Restricted { user, .. }
            | ChatMember::Left { user }
            | ChatMember::Banned { user, .. } => user,
        }
    }

    pub fn is_anonymous(&self) -> Option<bool> {
        match self {
            ChatMember::Owner { is_anonymous, .. }
            | ChatMember::Administrator { is_anonymous, .. } => Some(*is_anonymous),
            _ => None,
        }
    }

    pub fn custom_title(&self) -> Option<&str> {
        match self {
            Self::Owner { custom_title, .. } | Self::Administrator { custom_title, .. } => {
                custom_title.as_deref()
            }
            _ => None,
        }
    }

    pub fn can_be_edited(&self) -> Option<bool> {
        match self {
            Self::Administrator { can_be_edited, .. } => Some(*can_be_edited),
            _ => None,
        }
    }

    pub fn can_manage_chat(&self) -> Option<bool> {
        match self {
            Self::Administrator {
                can_manage_chat, ..
            } => Some(*can_manage_chat),
            _ => None,
        }
    }

    pub fn can_delete_messages(&self) -> Option<bool> {
        match self {
            Self::Administrator {
                can_delete_messages,
                ..
            } => Some(*can_delete_messages),
            _ => None,
        }
    }

    pub fn can_manage_voice_chats(&self) -> Option<bool> {
        match self {
            Self::Administrator {
                can_manage_voice_chats,
                ..
            } => Some(*can_manage_voice_chats),
            _ => None,
        }
    }

    pub fn can_restrict_members(&self) -> Option<bool> {
        match self {
            Self::Administrator {
                can_restrict_members,
                ..
            } => Some(*can_restrict_members),
            _ => None,
        }
    }

    pub fn can_promote_members(&self) -> Option<bool> {
        match self {
            Self::Administrator {
                can_promote_members,
                ..
            } => Some(*can_promote_members),
            _ => None,
        }
    }

    pub fn can_change_info(&self) -> Option<bool> {
        match self {
            Self::Administrator {
                can_change_info, ..
            }
            | Self::Restricted {
                can_change_info, ..
            } => Some(*can_change_info),
            _ => None,
        }
    }

    pub fn can_invite_users(&self) -> Option<bool> {
        match self {
            Self::Administrator {
                can_invite_users, ..
            }
            | Self::Restricted {
                can_invite_users, ..
            } => Some(*can_invite_users),
            _ => None,
        }
    }

    pub fn can_edit_messages(&self) -> Option<bool> {
        match self {
            Self::Administrator {
                can_edit_messages, ..
            } => *can_edit_messages,
            _ => None,
        }
    }

    pub fn can_pin_messages(&self) -> Option<bool> {
        match self {
            Self::Administrator {
                can_pin_messages, ..
            } => *can_pin_messages,
            Self::Restricted {
                can_pin_messages, ..
            } => Some(*can_pin_messages),
            _ => None,
        }
    }

    pub fn can_post_messages(&self) -> Option<bool> {
        match self {
            Self::Administrator {
                can_post_messages, ..
            } => *can_post_messages,
            _ => None,
        }
    }

    pub fn can_send_messages(&self) -> Option<bool> {
        match self {
            Self::Restricted {
                can_send_messages, ..
            } => Some(*can_send_messages),
            _ => None,
        }
    }

    pub fn can_send_media_messages(&self) -> Option<bool> {
        match self {
            Self::Restricted {
                can_send_media_messages,
                ..
            } => Some(*can_send_media_messages),
            _ => None,
        }
    }

    pub fn can_send_polls(&self) -> Option<bool> {
        match self {
            Self::Restricted { can_send_polls, .. } => Some(*can_send_polls),
            _ => None,
        }
    }

    pub fn can_send_other_messages(&self) -> Option<bool> {
        match self {
            Self::Restricted {
                can_send_other_messages,
                ..
            } => Some(*can_send_other_messages),
            _ => None,
        }
    }

    pub fn can_add_web_page_previews(&self) -> Option<bool> {
        match self {
            Self::Restricted {
                can_add_web_page_previews,
                ..
            } => Some(*can_add_web_page_previews),
            _ => None,
        }
    }

    pub fn is_member(&self) -> bool {
        match self {
            Self::Owner { .. } | Self::Administrator { .. } | Self::Member { .. } => true,
            Self::Restricted { is_member, .. } => *is_member,
            ChatMember::Left { .. } | ChatMember::Banned { .. } => false,
        }
    }

    pub fn banned_until(&self) -> Option<u64> {
        match self {
            Self::Banned { until_date, .. } => Some(*until_date),
            _ => None,
        }
    }

    pub fn restricted_until(&self) -> Option<u64> {
        match self {
            Self::Restricted { until_date, .. } => Some(*until_date),
            _ => None,
        }
    }
}

/// Represents an invite link for a chat.
#[derive(Debug, Deserialize)]
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,
    /// True, if the link is primary
    pub is_primary: bool,
    /// True, if the link is revoked
    pub is_revoked: bool,
    /// Point in time (Unix timestamp) when the link will expire or has been expired
    pub expire_date: Option<u64>,
    /// Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
    pub member_limit: Option<u32>,
}

/// This object represents changes in the status of a chat member.
#[derive(Debug, Deserialize)]
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 in Unix time
    pub date: u64,
    /// 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>,
}

/// Chat identifier
#[derive(Clone, Serialize)]
#[serde(untagged)]
pub enum ChatId {
    Id(i64),
    Username(String),
}

impl From<i64> for ChatId {
    fn from(id: i64) -> Self {
        Self::Id(id)
    }
}

impl From<String> for ChatId {
    fn from(username: String) -> Self {
        Self::Username(username)
    }
}

impl From<&str> for ChatId {
    fn from(username: &str) -> Self {
        Self::Username(username.to_string())
    }
}

/// Use this method to ban a user in a group, a supergroup or a channel.
/// In the case of supergroups and channels, the user will not be able to return to the chat
/// on their own using invite links, etc., unless unbanned first.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// Returns True on success.
#[derive(Clone, Serialize)]
pub struct BanChatMember {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
    pub chat_id: ChatId,
    /// Unique identifier of the target user
    pub user_id: i64,
    /// Date when the user will be unbanned, unix time.
    /// If user is banned for more than 366 days or less than 30 seconds from the current time
    /// they are considered to be banned forever.
    /// Applied for supergroups and channels only.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub until_date: Option<u64>,
    /// Pass _True_ to delete all messages from the chat for the user that is being removed.
    /// If _False_, the user will be able to see messages in the group that were sent before the user was removed.
    /// Always _True_ for supergroups and channels.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub revoke_messages: Option<bool>,
}

impl BanChatMember {
    /// Create a new banChatMember request
    pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
        Self {
            chat_id: chat_id.into(),
            user_id,
            until_date: None,
            revoke_messages: None,
        }
    }

    /// Set the date at which the user will be unbanned
    pub fn until_date(self, date: u64) -> Self {
        Self {
            until_date: Some(date),
            ..self
        }
    }

    /// Set revoke_messages to `true`
    pub fn revoke_messages(self) -> Self {
        Self {
            revoke_messages: Some(true),
            ..self
        }
    }
}

impl TelegramMethod for BanChatMember {
    type Response = bool;

    fn name() -> &'static str {
        "banChatMember"
    }
}

impl JsonMethod for BanChatMember {}

/// Use this method to unban a previously banned user in a supergroup or channel.
/// The user will **not** return to the group or channel automatically, but will be able to join via link, etc.
/// The bot must be an administrator for this to work.
/// By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it.
/// So if the user is a member of the chat they will also be **removed** from the chat.
/// If you don't want this, use the parameter *only_if_banned*.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct UnbanChatMember {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
    /// Unique identifier of the target user
    pub user_id: i64,
    /// Do nothing if the user is not banned
    #[serde(skip_serializing_if = "Option::is_none")]
    pub only_if_banned: Option<bool>,
}

impl UnbanChatMember {
    /// Create a new unbanChatMember request
    pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
        Self {
            chat_id: chat_id.into(),
            user_id,
            only_if_banned: None,
        }
    }

    /// Set only_if_banned to `true`
    pub fn only_if_banned(self) -> Self {
        Self {
            only_if_banned: Some(true),
            ..self
        }
    }
}

impl TelegramMethod for UnbanChatMember {
    type Response = bool;

    fn name() -> &'static str {
        "unbanChatMember"
    }
}

impl JsonMethod for UnbanChatMember {}

/// Use this method to restrict a user in a supergroup.
/// The bot must be an administrator in the supergroup for this to work and must have the appropriate administrator rights.
/// Pass *True* for all permissions to lift restrictions from a user.
/// Returns *True* on success.
#[derive(Clone, Serialize)]
pub struct RestrictChatMember {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
    pub chat_id: ChatId,
    /// Unique identifier of the target user
    pub user_id: i64,
    /// A JSON-serialized object for new user permissions
    pub permissions: ChatPermissions,
    /// Date when restrictions will be lifted for the user, unix time.
    /// If user is restricted for more than 366 days or less than 30 seconds from the current time,
    /// they are considered to be restricted forever
    #[serde(skip_serializing_if = "Option::is_none")]
    pub until_date: Option<u64>,
}

impl RestrictChatMember {
    /// Create a new restrictChatMember request
    pub fn new(chat_id: impl Into<ChatId>, user_id: i64, permissions: ChatPermissions) -> Self {
        Self {
            chat_id: chat_id.into(),
            user_id,
            permissions,
            until_date: None,
        }
    }

    /// Set the date at which the restriction wil be lifted
    pub fn until_date(self, date: u64) -> Self {
        Self {
            until_date: Some(date),
            ..self
        }
    }
}

impl TelegramMethod for RestrictChatMember {
    type Response = bool;

    fn name() -> &'static str {
        "restrictChatMember"
    }
}

impl JsonMethod for RestrictChatMember {}

/// Use this method to promote or demote a user in a supergroup or a channel.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// Pass _False_ for all boolean parameters to demote a user.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct PromoteChatMember {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
    /// Unique identifier of the target user
    pub user_id: i64,
    /// Pass _True_, if the administrator's presence in the chat is hidden
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_anonymous: Option<bool>,
    /// Pass _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(skip_serializing_if = "Option::is_none")]
    pub can_manage_chat: Option<bool>,
    /// Pass _True_, if the administrator can delete messages of other users
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_delete_messages: Option<bool>,
    /// Pass _True_, if the administrator can manage voice chats
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_manage_voice_chats: Option<bool>,
    /// Pass _True_, if the administrator can restrict, ban or unban chat members
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_restrict_members: Option<bool>,
    /// Pass _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 him)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_promote_members: Option<bool>,
    /// Pass _True_, if the administrator can change chat title, photo and other settings
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_change_info: Option<bool>,
    /// Pass _True_, if the administrator can invite new users to the chat
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_invite_users: Option<bool>,
    /// Pass _True_, if the administrator can create channel posts, channels only
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_post_messages: Option<bool>,
    /// Pass _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>,
    /// Pass _True_, if the administrator can pin messages, supergroups only
    #[serde(skip_serializing_if = "Option::is_none")]
    pub can_pin_messages: Option<bool>,
}

impl PromoteChatMember {
    /// Create a new promoteChatMember request
    pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
        Self {
            chat_id: chat_id.into(),
            user_id,
            is_anonymous: None,
            can_manage_chat: None,
            can_delete_messages: None,
            can_manage_voice_chats: None,
            can_restrict_members: None,
            can_promote_members: None,
            can_change_info: None,
            can_invite_users: None,
            can_post_messages: None,
            can_edit_messages: None,
            can_pin_messages: None,
        }
    }

    /// Create a new promoteChatMember request that demotes the user
    ///
    /// It creates a new promoteChatMember request with all options disabled.
    pub fn demote(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
        Self {
            chat_id: chat_id.into(),
            user_id,
            is_anonymous: Some(false),
            can_manage_chat: Some(false),
            can_delete_messages: Some(false),
            can_manage_voice_chats: Some(false),
            can_restrict_members: Some(false),
            can_promote_members: Some(false),
            can_change_info: Some(false),
            can_invite_users: Some(false),
            can_post_messages: Some(false),
            can_edit_messages: Some(false),
            can_pin_messages: Some(false),
        }
    }

    /// Set `is_anonymous` to `true`
    pub fn anonymous(self) -> Self {
        Self {
            is_anonymous: Some(true),
            ..self
        }
    }

    /// Set `can_manage_chat` to `true`
    pub fn allow_manage_chat(self) -> Self {
        Self {
            can_manage_chat: Some(true),
            ..self
        }
    }

    /// Set `can_delete_messages` to `true`
    pub fn allow_delete_messages(self) -> Self {
        Self {
            can_delete_messages: Some(true),
            ..self
        }
    }

    /// Set `can_manage_voice_chats` to `true`
    pub fn allow_manage_voice_chats(self) -> Self {
        Self {
            can_manage_voice_chats: Some(true),
            ..self
        }
    }

    /// Set `can_restrict_members` to `true`
    pub fn allow_restrict_members(self) -> Self {
        Self {
            can_restrict_members: Some(true),
            ..self
        }
    }

    /// Set `can_promote_members` to `true`
    pub fn allow_promote_members(self) -> Self {
        Self {
            can_promote_members: Some(true),
            ..self
        }
    }

    /// Set `can_change_info` to `true`
    pub fn allow_change_info(self) -> Self {
        Self {
            can_change_info: Some(true),
            ..self
        }
    }

    /// Set `can_invite_users` to `true`
    pub fn allow_invite_users(self) -> Self {
        Self {
            can_invite_users: Some(true),
            ..self
        }
    }

    /// Set `can_post_messages` to `true`
    pub fn allow_post_messages(self) -> Self {
        Self {
            can_post_messages: Some(true),
            ..self
        }
    }

    /// Set `can_edit_messages` to `true`
    pub fn allow_edit_messages(self) -> Self {
        Self {
            can_edit_messages: Some(true),
            ..self
        }
    }

    /// Set `can_pin_messages` to `true`
    pub fn allow_pin_messages(self) -> Self {
        Self {
            can_pin_messages: Some(true),
            ..self
        }
    }
}

impl TelegramMethod for PromoteChatMember {
    type Response = bool;

    fn name() -> &'static str {
        "promoteChatMember"
    }
}

impl JsonMethod for PromoteChatMember {}

/// Use this method to set a custom title for an administrator in a supergroup promoted by the bot.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct SetChatAdministratorCustomTitle {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
    /// Unique identifier of the target user
    pub user_id: i64,
    /// New custom title for the administrator; 0-16 characters, emoji are not allowed
    pub custom_title: String,
}

impl SetChatAdministratorCustomTitle {
    /// Create a new setChatAdministratorCustomTitle request
    pub fn new(chat_id: impl Into<ChatId>, user_id: i64, custom_title: impl Into<String>) -> Self {
        Self {
            chat_id: chat_id.into(),
            user_id,
            custom_title: custom_title.into(),
        }
    }
}

impl TelegramMethod for SetChatAdministratorCustomTitle {
    type Response = bool;

    fn name() -> &'static str {
        "setChatAdministratorCustomTitle"
    }
}

impl JsonMethod for SetChatAdministratorCustomTitle {}

/// Use this method to set 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* administrator rights.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct SetChatPermissions {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
    /// A JSON-serialized object for new user permissions
    pub permissions: ChatPermissions,
}

impl SetChatPermissions {
    /// Create a new setChatPermissions request
    pub fn new(chat_id: impl Into<ChatId>, permissions: ChatPermissions) -> Self {
        Self {
            chat_id: chat_id.into(),
            permissions,
        }
    }
}

impl TelegramMethod for SetChatPermissions {
    type Response = bool;

    fn name() -> &'static str {
        "setChatPermissions"
    }
}

impl JsonMethod for SetChatPermissions {}

/// Use this method to generate a new primary invite link for a chat;
/// any previously generated primary link is revoked.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// Returns the new invite link as _String_ on success.
///
/// Note: Each administrator in a chat generates their own invite links.
/// Bots can't use invite links generated by other administrators.
/// If you want your bot to work with invite links,
/// it will need to generate its own link using [exportChatInviteLink](https://core.telegram.org/bots/api#exportchatinvitelink)
/// or by calling the [getChat](https://core.telegram.org/bots/api#getchat) method.
/// If your bot needs to generate a new primary invite link replacing its previous one,
/// use [exportChatInviteLink](https://core.telegram.org/bots/api#exportchatinvitelink) again.
#[derive(Clone, Serialize)]
pub struct ExportChatInviteLink {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
}

impl ExportChatInviteLink {
    /// Create a new exportChatInviteLink request
    pub fn new(chat_id: impl Into<ChatId>) -> Self {
        Self {
            chat_id: chat_id.into(),
        }
    }
}

impl TelegramMethod for ExportChatInviteLink {
    type Response = String;

    fn name() -> &'static str {
        "exportChatInviteLink"
    }
}

impl JsonMethod for ExportChatInviteLink {}

/// Use this method to create an additional invite link for a chat.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// The link can be revoked using the method [revokeChatInviteLink](https://core.telegram.org/bots/api#revokechatinvitelink).
/// Returns the new invite link as [ChatInviteLink](https://core.telegram.org/bots/api#chatinvitelink) object.
#[derive(Clone, Serialize)]
pub struct CreateChatInviteLink {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
    /// Invite link name; 0-32 characters
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Point in time (Unix timestamp) when the link will expire
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expire_date: Option<u64>,
    /// Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
    #[serde(skip_serializing_if = "Option::is_none")]
    pub member_limit: Option<u32>,
    /// _True_, if users joining the chat via the link need to be approved by chat administrators. If _True_, *member_limit* can't be specified
    #[serde(skip_serializing_if = "Option::is_none")]
    pub creates_join_request: Option<bool>,
}

impl CreateChatInviteLink {
    /// Create a new createChatInviteLink request
    pub fn new(chat_id: impl Into<ChatId>) -> Self {
        Self {
            chat_id: chat_id.into(),
            name: None,
            expire_date: None,
            member_limit: None,
            creates_join_request: None,
        }
    }
    /// Set invite link name
    pub fn with_name(self, name: impl Into<String>) -> Self {
        Self {
            name: Some(name.into()),
            ..self
        }
    }
    /// Set link expire date
    pub fn with_expire_date(self, expire_date: u64) -> Self {
        Self {
            expire_date: Some(expire_date),
            ..self
        }
    }
    /// Set link member limit
    pub fn with_member_limit(self, member_limit: u32) -> Self {
        Self {
            member_limit: Some(member_limit),
            ..self
        }
    }
    /// Set `creates_join_request` to `true`
    pub fn create_join_reqeuest(self) -> Self {
        Self {
            creates_join_request: Some(true),
            ..self
        }
    }
}

impl TelegramMethod for CreateChatInviteLink {
    type Response = ChatInviteLink;

    fn name() -> &'static str {
        "createChatInviteLink"
    }
}

impl JsonMethod for CreateChatInviteLink {}

/// Use this method to edit a non-primary invite link created by the bot.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// Returns the edited invite link as a [ChatInviteLink](https://core.telegram.org/bots/api#chatinvitelink) object.
#[derive(Clone, Serialize)]
pub struct EditChatInviteLink {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
    /// The invite link to edit
    pub invite_link: String,
    /// Invite link name; 0-32 characters
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    /// Point in time (Unix timestamp) when the link will expire
    #[serde(skip_serializing_if = "Option::is_none")]
    pub expire_date: Option<u64>,
    /// Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
    #[serde(skip_serializing_if = "Option::is_none")]
    pub member_limit: Option<u32>,
    /// _True_, if users joining the chat via the link need to be approved by chat administrators. If _True_, *member_limit* can't be specified
    #[serde(skip_serializing_if = "Option::is_none")]
    pub creates_join_request: Option<bool>,
}

impl EditChatInviteLink {
    /// Create a new editChatInviteLink request
    pub fn new(chat_id: impl Into<ChatId>, invite_link: impl Into<String>) -> Self {
        Self {
            chat_id: chat_id.into(),
            invite_link: invite_link.into(),
            name: None,
            expire_date: None,
            member_limit: None,
            creates_join_request: None,
        }
    }
    /// Set invite link name
    pub fn with_name(self, name: impl Into<String>) -> Self {
        Self {
            name: Some(name.into()),
            ..self
        }
    }
    /// Set link expire date
    pub fn with_expire_date(self, expire_date: u64) -> Self {
        Self {
            expire_date: Some(expire_date),
            ..self
        }
    }
    /// Set link member limit
    pub fn with_member_limit(self, member_limit: u32) -> Self {
        Self {
            member_limit: Some(member_limit),
            ..self
        }
    }
    /// Set `creates_join_request` to `true`
    pub fn create_join_reqeuest(self) -> Self {
        Self {
            creates_join_request: Some(true),
            ..self
        }
    }
}

/// Use this method to revoke an invite link created by the bot.
/// If the primary link is revoked, a new link is automatically generated.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// Returns the revoked invite link as [ChatInviteLink](https://core.telegram.org/bots/api#chatinvitelink) object.
#[derive(Clone, Serialize)]
pub struct RevokeChatInviteLink {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
    /// The invite link to revoke
    pub invite_link: String,
}

impl RevokeChatInviteLink {
    /// Create a new revokeChatInviteLink object
    pub fn new(chat_id: impl Into<ChatId>, invite_link: impl Into<String>) -> Self {
        Self {
            chat_id: chat_id.into(),
            invite_link: invite_link.into(),
        }
    }
}

impl TelegramMethod for RevokeChatInviteLink {
    type Response = ChatInviteLink;

    fn name() -> &'static str {
        "revokeChatInviteLink"
    }
}

impl JsonMethod for RevokeChatInviteLink {}

/// Use this method to approve a chat join request.
/// The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator right.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct ApproveChatJoinRequest {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
    /// Unique identifier of the target user
    pub user_id: i64,
}

impl ApproveChatJoinRequest {
    /// Create a new approveChatJoinRequest request
    pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
        Self {
            chat_id: chat_id.into(),
            user_id,
        }
    }
}

impl TelegramMethod for ApproveChatJoinRequest {
    type Response = bool;

    fn name() -> &'static str {
        "approveChatJoinRequest"
    }
}

impl JsonMethod for ApproveChatJoinRequest {}

/// Use this method to decline a chat join request.
/// The bot must be an administrator in the chat for this to work and must have the *can_invite_users* administrator right.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct DeclineChatJoinRequest {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
    /// Unique identifier of the target user
    pub user_id: i64,
}

impl DeclineChatJoinRequest {
    /// Create a new declineChatJoinRequest request
    pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
        Self {
            chat_id: chat_id.into(),
            user_id,
        }
    }
}

impl TelegramMethod for DeclineChatJoinRequest {
    type Response = bool;

    fn name() -> &'static str {
        "declineChatJoinRequest"
    }
}

impl JsonMethod for DeclineChatJoinRequest {}

/// Use this method to set a new profile photo for the chat.
/// Photos can't be changed for private chats.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct SetChatPhoto {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
    /// New chat photo, uploaded using multipart/form-data
    pub photo: InputFile,
}

impl SetChatPhoto {
    /// Create a new setChatPhoto request
    pub fn new(chat_id: impl Into<ChatId>, photo: InputFile) -> Self {
        Self {
            chat_id: chat_id.into(),
            photo,
        }
    }
}

impl TelegramMethod for SetChatPhoto {
    type Response = bool;

    fn name() -> &'static str {
        "setChatPhoto"
    }
}

impl JsonMethod for SetChatPhoto {}

/// Use this method to delete a chat photo.
/// Photos can't be changed for private chats.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct DeleteChatPhoto {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
}

impl DeleteChatPhoto {
    /// Create a new deleteChatPhoto request
    pub fn new(chat_id: impl Into<ChatId>) -> Self {
        Self {
            chat_id: chat_id.into(),
        }
    }
}

impl TelegramMethod for DeleteChatPhoto {
    type Response = bool;

    fn name() -> &'static str {
        "deleteChatPhoto"
    }
}

impl JsonMethod for DeleteChatPhoto {}

/// Use this method to change the title of a chat.
/// Titles can't be changed for private chats.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct SetChatTitle {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
    /// New chat title, 1-255 characters
    pub title: String,
}

impl SetChatTitle {
    /// Create a new setChatTitle request
    pub fn new(chat_id: impl Into<ChatId>, title: impl Into<String>) -> Self {
        Self {
            chat_id: chat_id.into(),
            title: title.into(),
        }
    }
}

impl TelegramMethod for SetChatTitle {
    type Response = bool;

    fn name() -> &'static str {
        "setChatTitle"
    }
}

impl JsonMethod for SetChatTitle {}

/// Use this method to change the description of a group, a supergroup or a channel.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct SetChatDescription {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@username`)
    pub chat_id: ChatId,
    /// New chat description, 0-255 characters
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
}

impl SetChatDescription {
    /// Create a new setChatDescription request which empties the description
    pub fn new_empty(chat_id: impl Into<ChatId>) -> Self {
        Self {
            chat_id: chat_id.into(),
            description: None,
        }
    }

    /// Create a new setChatDescription request with description
    pub fn new(chat_id: impl Into<ChatId>, description: impl Into<String>) -> Self {
        Self {
            chat_id: chat_id.into(),
            description: Some(description.into()),
        }
    }
}

impl TelegramMethod for SetChatDescription {
    type Response = bool;

    fn name() -> &'static str {
        "setChatDescription"
    }
}

/// Use this method to add a message to the list of pinned messages in a chat.
/// If the chat is not a private chat, the bot must be an administrator in the chat for this to work
/// and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct PinChatMessage {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
    pub chat_id: ChatId,
    /// Identifier of a message to pin
    pub message_id: i64,
    /// Pass True, if it is not necessary to send a notification to all chat members about the new pinned message.
    /// Notifications are always disabled in channels and private chats.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disable_notification: Option<bool>,
}

impl PinChatMessage {
    /// Create a new pinChatMessage request
    pub fn new(chat_id: impl Into<ChatId>, message_id: i64) -> Self {
        Self {
            chat_id: chat_id.into(),
            message_id,
            disable_notification: None,
        }
    }

    /// Disable notification about the new pinned message
    pub fn disable_notification(self) -> Self {
        Self {
            disable_notification: Some(true),
            ..self
        }
    }
}

impl TelegramMethod for PinChatMessage {
    type Response = bool;

    fn name() -> &'static str {
        "pinChatMessage"
    }
}

impl JsonMethod for PinChatMessage {}

/// Use this method to remove a message from the list of pinned messages in a chat.
/// If the chat is not a private chat, the bot must be an administrator in the chat for this to work
/// and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct UnpinChatMessage {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
    pub chat_id: ChatId,
    /// Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message_id: Option<i64>,
}

impl UnpinChatMessage {
    /// Create a new unpinChatMessage request that unpins the most recent pinned message
    pub fn new_recent(chat_id: impl Into<ChatId>) -> Self {
        Self {
            chat_id: chat_id.into(),
            message_id: None,
        }
    }

    /// Create a new unpinChatMessage request
    pub fn new(chat_id: impl Into<ChatId>, message_id: i64) -> Self {
        Self {
            chat_id: chat_id.into(),
            message_id: Some(message_id),
        }
    }
}

impl TelegramMethod for UnpinChatMessage {
    type Response = bool;

    fn name() -> &'static str {
        "unpinChatMessage"
    }
}

impl JsonMethod for UnpinChatMessage {}

/// Use this method to clear the list of pinned messages in a chat.
/// If the chat is not a private chat, the bot must be an administrator in the chat for this to work
/// and must have the 'can_pin_messages' administrator right in a supergroup or 'can_edit_messages' administrator right in a channel.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct UnpinAllChatMessages {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
    pub chat_id: ChatId,
}

impl UnpinAllChatMessages {
    /// Create a new unpinAllChatMessages request
    pub fn new(chat_id: impl Into<ChatId>) -> Self {
        Self {
            chat_id: chat_id.into(),
        }
    }
}

impl TelegramMethod for UnpinAllChatMessages {
    type Response = bool;

    fn name() -> &'static str {
        "unpinAllChatMessages"
    }
}

impl JsonMethod for UnpinAllChatMessages {}

/// Use this method for your bot to leave a group, supergroup or channel. Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct LeaveChat {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
    pub chat_id: ChatId,
}

impl LeaveChat {
    /// Create a new leaveChat request
    pub fn new(chat_id: impl Into<ChatId>) -> Self {
        Self {
            chat_id: chat_id.into(),
        }
    }
}

impl TelegramMethod for LeaveChat {
    type Response = bool;

    fn name() -> &'static str {
        "leaveChat"
    }
}

impl JsonMethod for LeaveChat {}

/// Use this method to get up to date information about the chat
/// (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).
/// Returns a Chat object on success.
#[derive(Clone, Serialize)]
pub struct GetChat {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
    pub chat_id: ChatId,
}

impl GetChat {
    /// Create a new getChat request
    pub fn new(chat_id: impl Into<ChatId>) -> Self {
        Self {
            chat_id: chat_id.into(),
        }
    }
}

impl TelegramMethod for GetChat {
    type Response = Chat;

    fn name() -> &'static str {
        "getChat"
    }
}

impl JsonMethod for GetChat {}

/// Use this method to get a list of administrators in a chat.
/// On success, returns an Array of [ChatMember](https://core.telegram.org/bots/api#chatmember) objects
/// that contains information about all chat administrators except other bots.
/// If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.
#[derive(Clone, Serialize)]
pub struct GetChatAdministrators {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
    pub chat_id: ChatId,
}

impl GetChatAdministrators {
    /// Create a new getChatAdministrators request
    pub fn new(chat_id: impl Into<ChatId>) -> Self {
        Self {
            chat_id: chat_id.into(),
        }
    }
}

impl TelegramMethod for GetChatAdministrators {
    type Response = Vec<ChatMember>;

    fn name() -> &'static str {
        "getChatAdministrators"
    }
}

impl JsonMethod for GetChatAdministrators {}

/// Use this method to get the number of members in a chat. Returns _Int_ on success.
#[derive(Clone, Serialize)]
pub struct GetChatMemberCount {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
    pub chat_id: ChatId,
}

impl GetChatMemberCount {
    /// Create a new getChatMemberCount request
    pub fn new(chat_id: impl Into<ChatId>) -> Self {
        Self {
            chat_id: chat_id.into(),
        }
    }
}

impl TelegramMethod for GetChatMemberCount {
    type Response = u32;

    fn name() -> &'static str {
        "getChatMemberCount"
    }
}

impl JsonMethod for GetChatMemberCount {}

/// Use this method to get information about a member of a chat.
/// Returns a [ChatMember](https://core.telegram.org/bots/api#chatmember) object on success.
#[derive(Clone, Serialize)]
pub struct GetChatMember {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
    pub chat_id: ChatId,
    /// Unique identifier of the target user
    pub user_id: i64,
}

impl GetChatMember {
    /// Create a new getChatMember request
    pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
        Self {
            chat_id: chat_id.into(),
            user_id,
        }
    }
}

impl TelegramMethod for GetChatMember {
    type Response = ChatMember;

    fn name() -> &'static str {
        "getChatMember"
    }
}

/// Use this method to set a new group sticker set for a supergroup.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// Use the field *can_set_sticker_set* optionally returned in [getChat](https://core.telegram.org/bots/api#getchat) requests to check if the bot can use this method.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct SetChatStickerSet {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
    pub chat_id: ChatId,
    /// Name of the sticker set to be set as the group sticker set
    pub sticker_set_name: String,
}

impl SetChatStickerSet {
    /// Create a new setChatStickerSet request
    pub fn new(chat_id: impl Into<ChatId>, sticker_set_name: impl Into<String>) -> Self {
        Self {
            chat_id: chat_id.into(),
            sticker_set_name: sticker_set_name.into(),
        }
    }
}

impl TelegramMethod for SetChatStickerSet {
    type Response = bool;

    fn name() -> &'static str {
        "setChatStickerSet"
    }
}

impl JsonMethod for SetChatStickerSet {}

/// Use this method to delete a group sticker set from a supergroup.
/// The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights.
/// Use the field *can_set_sticker_set* optionally returned in [getChat](https://core.telegram.org/bots/api#getchat) requests to check if the bot can use this method.
/// Returns _True_ on success.
#[derive(Clone, Serialize)]
pub struct DeleteChatStickerSet {
    /// Unique identifier for the target group or username of the target supergroup or channel (in the format `@channelusername`)
    pub chat_id: ChatId,
}

impl DeleteChatStickerSet {
    /// Create a new deleteChatStickerSet request
    pub fn new(chat_id: impl Into<ChatId>) -> Self {
        Self {
            chat_id: chat_id.into(),
        }
    }
}

impl TelegramMethod for DeleteChatStickerSet {
    type Response = bool;

    fn name() -> &'static str {
        "deleteChatStickerSet"
    }
}

impl JsonMethod for DeleteChatStickerSet {}