-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponents.js
More file actions
2505 lines (2352 loc) · 101 KB
/
components.js
File metadata and controls
2505 lines (2352 loc) · 101 KB
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
import {filterObject} from "./utils.js";
import { Context } from "./base.js";
class MessageId {
constructor(messageId){
this.messageId = messageId;
}
get message_id(){return this.messageId?.message_id;}
}
class Message{
constructor(message){
this.message = message;
}
/**
* Unique message identifier inside this chat. In specific instances (e.g., message containing a video sent to a big chat), the server might automatically schedule a message instead of sending it immediately. In such cases, this field will be 0 and the relevant message will be unusable until it is actually sent.
* @returns {number} Unique message identifier inside this chat.
*/
get message_id(){return this.message.message_id;}
/**
* Optional. Unique identifier of a message thread to which the message belongs; for supergroups only.
* @returns {number}
*/
get message_thread_id(){return this.message?.message_thread_id;}
/**
* Sender of the message; empty for messages sent to channels. For backward compatibility, the field contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat.
* @returns {User}
*/
get from(){return this.message.hasOwnProperty("from")? new User(this.message.from) : null;}
/**
* Date the message was sent in Unix time. It is always a positive number, representing a valid date.
* @returns {number}
*/
get date(){return this.message.date;}
/**
* Chat the message belongs to.
* @returns {Chat}
*/
get chat(){return new Chat(this.message.chat);}
/**
* For text messages, the actual UTF-8 text of the message.
* @returns {string}
*/
get text(){return this.message.hasOwnProperty("text")? this.message.text : null;}
/**
* Information about the original message for forwarded messages.
* @returns {MessageOriginUser|MessageOriginChat|MessageOriginChannel|MessageOriginHiddenUser}
*/
get forward_origin(){return this.message.hasOwnProperty("forward_origin")? new MessageOrigin(this.message.forward_origin) : null;}
/**
* Optional. True, if the message is sent to a forum topic.
* @returns {boolean}
*/
get is_topic_message(){return this.message?.is_topic_message;}
/**
* The chat the message was forwarded from.
* @returns {Chat}
*/
get forward_from_chat(){return this.message.hasOwnProperty("forward_from_chat")? new Chat(this.message.forward_from_chat) : null;}
/**
* The attached document.
* @returns {Document}
*/
get document(){return this.message.hasOwnProperty("document")? new Document(this.message.document) : null;}
/**
* A list of MessageEntity representing all the entities in the message.
* @returns {MessageEntity[]}
*/
get entities(){return this.message.hasOwnProperty('entities')? this.message.entities.map(entity => new MessageEntity(entity)) : null;}
/**
* The caption of the message.
* @returns {string}
*/
get caption(){return this.message.hasOwnProperty('caption')? this.message.caption : null;}
/**
* A list of `PhotoSize` representing the attached photos.
* @returns {Array<PhotoSize>}
*/
get photo(){return this.message.hasOwnProperty('photo') ? this.message.photo.map(pic => new PhotoSize(pic)) : null;}
/**
* The attached video.
* @returns {Video}
*/
get video(){return this.message.hasOwnProperty('video')? new Video(this.message.video) : null;}
/**
* The unique identifier of a media message group this message belongs to.
* @returns {string}
*/
get media_group_id(){return this.message.hasOwnProperty("media_group_id")?this.message.media_group_id:null;}
/**
* Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons.
* @returns {InlineKeyboardMarkup}
*/
get reply_markup(){return this.message.hasOwnProperty('reply_markup') ? new InlineKeyboardMarkup(this.message.reply_markup.map(row => row.map(col => new InlineKeyboardButton(col)))) : null;}
/**
* Unique identifier of the message effect added to the message.
* @returns {string}
*/
get effect_id(){return this.message.hasOwnProperty("effect_id")? this.message.effect_id : null;}
/**
* Options used for link preview generation for the message, if it is a text message and link preview options were changed.
* @returns {LinkPreviewOptions}
*/
get link_preview_options(){return this.message.hasOwnProperty("link_preview_options")? new LinkPreviewOptions(this.message.link_preview_options):null;}
/**
* Optional. For replies in the same chat and message thread, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
* @returns {Message}
*/
get reply_to_message(){return this.message.hasOwnProperty("reply_to_message") ? new Message(this.message.reply_to_message) : null;}
/**
* Optional. Date the message was last edited in Unix time.
* @returns {number}
*/
get edit_date(){return this.message.hasOwnProperty("edit_date") ? this.message.edit_date : null;}
/**
* Optional. True, if the message can't be forwarded.
* @returns {boolean}
*/
get has_protected_content(){return this.message.hasOwnProperty("has_protected_content")?this.message.has_protected_content:null;}
/**
* Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)
* @returns {User[]}
*/
get new_chat_members(){return this.message.hasOwnProperty("new_chat_members")?this.message.new_chat_members.map(member => new User(member)):null};
/**
* Optional. A member was removed from the group, information about them (this member may be the bot itself).
* @returns {User}
*/
get left_chat_member(){return this.message.hasOwnProperty("left_chat_member")?new User(this.message.left_chat_member):null;}
/**
* Message deep link.
*
* For example: `https://t.me/c/123456/12`.
*
* @returns {Promise<string>|Promise<null>}
*/
async message_link(){
const chat = await Context.bot.getChat(this.chat.id);
if (chat){
if (chat?.username) return `https://t.me/${chat.username}/${this.message_id}`;
return `https://t.me/c/${this.chat.id}/${this.message_id}`;
}
return null;
}
/**
* Use this method to edit text and game messages. On success, if the edited message is not an inline message, the edited `Message` is returned, otherwise `True` is returned. Note that business messages that were not sent by the bot and do not contain an inline keyboard can only be edited within 48 hours from the time they were sent.
*
* Shortcut for `bot.editMessageText(...)`.
*
* @param {{text: string, parse_mode: string, entities: Array<MessageEntity>, link_preview_options: LinkPreviewOptions, reply_markup: InlineKeyboardMarkup}} config
* @returns {Promise<Message>|Promise<boolean>}
*/
async editText(config){
return await Context.bot.editMessageText({"chat_id": this.chat.id, "message_id": this.message_id, ...config});
}
/**
* Use this method to delete a message, including service messages, with the following limitations:
- A message can only be deleted if it was sent less than 48 hours ago.
- Service messages about a supergroup, channel, or forum topic creation can't be deleted.
- A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.
- Bots can delete outgoing messages in private chats, groups, and supergroups.
- Bots can delete incoming messages in private chats.
- Bots granted `can_post_messages` permissions can delete outgoing messages in channels.
- If the bot is an administrator of a group, it can delete any message there.
- If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
Shortcut for `bot.deleteMessage(...)`.
Returns `True` on success.
* @returns {Promise<boolean>}
*/
async delete(){
return await Context.bot.deleteMessage({chat_id: this.chat.id, message_id: this.message_id});
}
/**
* Use this method to reply to a text message. On success, the sent `Message` is returned.
* @param {{text: string, parse_mode: string, link_preview_options: LinkPreviewOptions|{is_disabled: boolean, url: string, prefer_small_media: boolean, prefer_large_media: boolean, show_above_text: boolean}, disable_notification: boolean, protect_content: boolean, message_effect_id: string, reply_markup: InlineKeyboardMarkup|Object}} config
* @returns {Promise<Message>}
*/
async reply(config){
return await Context.bot.sendMessage({chat_id: this.chat.id, ...new ReplyParameters({message_id: this.message_id}), ...config});
}
/**
* 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.
*
* Shortcut of `bot.pinChatMessage()`.
*
* @param {{business_connection_id: string, disable_notification: boolean}} config
* @returns {Promise<boolean>}
*/
async pin(config){
return await Context.bot.pinChatMessage({chat_id: this.chat.id, message_id: this.message_id, ...config})
}
/**
* Use this method to forward messages of any kind. Service messages and messages with protected content can't be forwarded. On success, the sent Message is returned.
*
* Shortcut of `bot.forwardMessage()`.
*
* @param {{chat_id: number|string, message_thread_id: number, disable_notification: boolean, protect_content: boolean}} config
* @returns {Promise<Message>}
*/
async forward(config){
return await Context.bot.forwardMessage({from_chat_id: this.chat.id, message_id: this.message_id, ...config});
}
}
class User{
constructor(user){
this.user = user;
}
/**
* @returns {number} Unique identifier for this user or bot. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier.
*/
get id(){return this.user.id;}
/**
* @returns {boolean} True, if this user is a bot.
*/
get is_bot(){return this.user.is_bot;}
/**
* @returns {string} User's or bot's username.
*/
get username(){return this.user.hasOwnProperty("username")? this.user.username : null;}
/**
* @returns {string} User's or bot's first name.
*/
get first_name(){return this.user.first_name;}
/**
* @returns {string} User's or bot's last name.
*/
get last_name(){return this.user.hasOwnProperty("last_name")? this.user.last_name : null;}
/**
* @returns {string} User's or bot's full name.
*/
get full_name(){return `${this.first_name || ""}${this.first_name && this.last_name ? " " : ""}${this.last_name || ""}`;}
/**
* @returns {string} Returns an HTML `<a href>` hyperlink mentioning the user. If no name is passed, it will show their full name.
*/
mention_html(name = null){
if (name === null){
let full_name = `${this.first_name || ""}${this.first_name && this.last_name ? " " : ""}${this.last_name || ""}`;
return `<a href="tg://user?id=${this.user.id}">${full_name}</a>`;
} else {
return `<a href="tg://user?id=${this.user.id}">${name}</a>`;
}
}
/**
* @returns {string} Optional. IETF language tag of the user's language.
*/
get language_code(){return this.user?.language_code;}
/**
* @returns {string} Optional. True, if this user is a Telegram Premium user.
*/
get is_premium(){return this.user?.is_premium;}
/**
* @returns {string} Optional. True, if this user added the bot to the attachment menu.
*/
get added_to_attachment_menu(){return this.user?.added_to_attachment_menu;}
/**
* @returns {string} Optional. True, if the bot can be invited to groups. Returned only in getMe.
*/
get can_join_groups(){return this.user?.can_join_groups;}
/**
* @returns {string} Optional. True, if privacy mode is disabled for the bot. Returned only in getMe.
*/
get can_read_all_group_messages(){return this.user?.can_read_all_group_messages;}
/**
* @returns {string} Optional. True, if the bot supports inline queries. Returned only in getMe.
*/
get supports_inline_queries(){return this.user?.supports_inline_queries;}
/**
* @returns {string} Optional. True, if the bot can be connected to a Telegram Business account to receive its messages. Returned only in getMe.
*/
get can_connect_to_business(){return this.user?.can_connect_to_business;}
/**
* @returns {string} Optional. True, if the bot has a main Web App. Returned only in getMe.
*/
get has_main_web_app(){return this.user?.has_main_web_app;}
/**
* 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.
*
* 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.
*
* Shortcut of `bot.banChatMember()`.
*
* @param {{chat_id?: number, until_date: number, revoke_messages: boolean}} config
* @returns {Promise<boolean>}
*/
async ban(config){
const chat_id = Context.botData.get("effective_user_chat_id");
if (chat_id){
return await Context.bot.banChatMember({chat_id: chat_id, user_id: this.id, ...config});
} else {
try {
const ban = await Context.bot.banChatMember({chat_id: config?.chat_id, user_id: this.id, ...config});
return ban;
} catch (error) {
console.error(error);
return null;
}
}
}
/**
* 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.
*
* Shortcut of `bot.unbanChatMember()`.
*
* @param {{only_if_banned: boolean}} config
* @returns {Promise<boolean>}
*/
async unban(config){
const chat_id = Context.botData.get("effective_user_chat_id");
if (chat_id){
return await Context.bot.unbanChatMember({chat_id: chat_id, user_id: this.id, ...config});
} else {
try {
const unban = await Context.bot.unbanChatMember({chat_id: config?.chat_id, user_id: this.id, ...config});
return unban;
} catch (error) {
console.error(error);
return null;
}
}
}
}
class Chat {
constructor(chat){
this.chat = chat;
}
/**
* @returns {number} Unique identifier for this chat. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier.
*/
get id(){return this.chat.id;}
/**
* @returns {string} Type of the chat, can be either “private”, “group”, “supergroup” or “channel”.
*/
get type(){return this.chat.type;}
/**
* @returns {string} Optional. Title, for supergroups, channels and group chats.
*/
get title(){return this.chat.hasOwnProperty("title")? this.chat.title : null;}
/**
* @returns {string} Optional. Username, for private chats, supergroups and channels if available.
*/
get username(){return this.chat.hasOwnProperty("username")? this.chat.username : null;}
/**
* @returns {string} Optional. First name of the chat.
*/
get first_name(){return this.chat.hasOwnProperty("first_name")? this.chat.first_name : null;}
/**
* @returns {string} Optional. Last name of the chat.
*/
get last_name(){return this.chat.hasOwnProperty("last_name")? this.chat.last_name : null;}
/**
* @returns {string} Optional. Full name of the chat.
*/
get full_name(){return `${this.first_name || ""}${this.first_name && this.last_name ? " " : ""}${this.last_name || ""}`}
/**
* @returns {boolean} Optional. True, if the supergroup chat is a forum (has topics enabled).
*/
get is_forum(){return this.chat.hasOwnProperty("is_forum")? this.chat.is_forum : null;}
/**
*
* @param {{text: string, parse_mode: string, link_preview_options: LinkPreviewOptions|{is_disabled: boolean, url: string, prefer_small_media: boolean, prefer_large_media: boolean, show_above_text: boolean}, disable_notification: boolean, protect_content: boolean, message_effect_id: string, reply_parameters: ReplyParameters|Object, reply_markup: InlineKeyboardMarkup|Object}} config
* @returns {Promise<Message>}
*/
async sendMessage(config){
return await Context.bot.sendMessage({chat_id: this.id, ...config});
}
/**
* Use this method to send photos. On success, the sent `Message` is returned.
*
* Shortcut of `bot.sendPhoto()`.
*
* @param {{message_thread_id: number, photo: InputFile|Blob|string, caption:string, parse_mode:string, caption_entities: Array<MessageEntity>, show_caption_above_media: boolean, has_spoiler:boolean, disable_notification:boolean, protect_content: boolean, message_effect_id: string, reply_parameters: ReplyParameters, reply_markup:InlineKeyboardMarkup}} config
* @returns {Promise<Message>}
*/
async sendPhoto(config){
return await Context.bot.sendPhoto({chat_id: this.id, ...config});
}
/**
* Use this method to send video files, Telegram clients support MPEG4 videos (other formats may be sent as `Document`). On success, the sent `Message` is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
*
* Shortcut of `bot.sendVideo()`.
*
* @param {{message_thread_id: number, video: InputFile|Blob|string, duration: number, width: number, height: number, thumbnail: InputFile|string, caption: string, parse_mode: string, caption_entities: Array<MessageEntity>, show_caption_above_media: boolean, has_spoiler: boolean, supports_streaming: boolean, disable_notification: boolean, protect_content: boolean, message_effect_id: string, reply_parameters: ReplyParameters, reply_markup: InlineKeyboardMarkup}} config
* @returns {Promise<Message>}
*/
async sendVideo(config){
return await Context.bot.sendVideo({chat_id: this.id, ...config});
}
/**
* Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can be only grouped in an album with messages of the same type. On success, an array of `Messages` that were sent is returned.
*
* Shortcut of `bot.sendMediaGroup()`.
*
* @param {{message_thread_id: number, media: Array<InputMediaAudio>|Array<InputMediaDocument>|Array<InputMediaPhoto>|Array<InputMediaVideo>, disable_notification: boolean, protect_content: boolean, message_effect_id: string, reply_parameters: ReplyParameters}} config
* @returns {Promise<Message>}
*/
async sendMediaGroup(config){
return await Context.bot.sendMediaGroup({chat_id: this.id, ...config});
}
/**
* Use this method to send general files. On success, the sent `Message` is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
*
* Shortcut of `bot.sendDocument()`.
*
* @param {{document: InputFile|string, thumbnail: InputFile|string, caption:string, parse_mode: string, disable_content_type_detection:boolean, disable_notification: boolean, protect_content: boolean, message_effect_id: string, reply_parameters: ReplyParameters, reply_markup: InlineKeyboardMarkup}} config
* @returns {Promise<Message>}
*/
async sendDocument(config){
return await Context.bot.sendDocument({chat_id: this.id, ...config});
}
/**
* Use this method when you need to tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns `True` on success.
*
* Shortcut of `bot.sendChatAction()`.
*
* @param {{message_thread_id: number, action: string}} config
* @returns {Promise<boolean>}
*/
async sendChatAction(config){
return await Context.bot.sendChatAction({chat_id: this.id, ...config});
}
/**
* 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.
*
* 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.
*
* Shortcut of `bot.banChatMember()`.
*
* @param {{user_id: number, until_date: number, revoke_messages: boolean}} config
* @returns {Promise<boolean>}
*/
async banChatMember(config){
return await Context.bot.banChatMember({chat_id: this.id, ...config});
}
}
/**
* This object represents a chat photo.
*/
class ChatPhoto {
constructor(chat_photo){
this.chat_photo = chat_photo;
}
/**
* 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.
* @returns {string}
*/
get small_file_id(){return this.chat_photo?.small_file_id;}
/**
* 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.
* @returns {string}
*/
get small_file_unique_id(){return this.chat_photo?.small_file_unique_id;}
/**
* 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.
* @returns {string}
*/
get big_file_id(){return this.chat_photo?.big_file_id;}
/**
* 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.
* @returns {string}
*/
get big_file_unique_id(){return this.chat_photo?.big_file_unique_id;}
}
class Location {
constructor (location){
this.location = location;
}
/**
* Latitude as defined by the sender.
* @returns {number}
*/
get latitude(){return this.location?.latitude;}
/**
* Longitude as defined by the sender.
* @returns {number}
*/
get longitude(){return this.location?.longitude;}
/**
* Optional. The radius of uncertainty for the location, measured in meters; 0-1500.
* @returns {number}
*/
get horizontal_accuracy(){return this.location?.horizontal_accuracy;}
/**
* Optional. Time relative to the message sending date, during which the location can be updated; in seconds. For active live locations only.
* @returns {number}
*/
get live_period(){return this.location?.live_period;}
/**
* Optional. The direction in which user is moving, in degrees; 1-360. For active live locations only.
* @returns {number}
*/
get heading(){return this.location?.heading;}
/**
* Optional. The maximum distance for proximity alerts about approaching another chat member, in meters. For sent live locations only.
* @returns {number}
*/
get proximity_alert_radius(){return this.location?.proximity_alert_radius;}
}
/**
* Describes the birthdate of a user.
*/
class Birthdate {
constructor(birthdate){
this.birthdate = birthdate;
}
/**
* Day of the user's birth; 1-31.
* @returns {number}
*/
get day(){return this.birthdate?.day;}
/**
* Month of the user's birth; 1-12.
* @returns {number}
*/
get month(){return this.birthdate?.month;}
/**
* Optional. Year of the user's birth.
* @returns {number}
*/
get year(){return this.birthdate?.year;}
}
/**
* Contains information about the start page settings of a Telegram Business account.
*/
class BusinessIntro {
constructor (business_intro){
this.business_intro = business_intro;
}
/**
* Optional. Title text of the business intro.
* @returns {string}
*/
get title(){return this.business_intro?.title;}
/**
* Optional. Message text of the business intro.
* @returns {string}
*/
get message(){return this.business_intro?.message;}
/**
* Optional. Sticker of the business intro.
* @returns {string}
*/
get sticker(){return this.business_intro?.sticker;}
}
/**
* Contains information about the location of a Telegram Business account.
*/
class BusinessLocation {
constructor (business_location){
this.business_location = business_location;
}
/**
* Address of the business.
* @returns {string}
*/
get address(){return this.business_location?.address;}
/**
* Optional. Location of the business.
* @returns {Location}
*/
get location(){return new Location(this.business_location?.location);}
}
/**
* Describes an interval of time during which a business is open.
*/
class BusinessOpeningHoursInterval {
constructor (business_opening_hours_interval){
this.business_opening_hours_interval = business_opening_hours_interval;
}
/**
* The minute's sequence number in a week, starting on Monday, marking the start of the time interval during which the business is open; 0 - 7 * 24 * 60.
* @returns {number}
*/
get opening_minute(){return this.business_opening_hours_interval?.opening_minute;}
/**
* The minute's sequence number in a week, starting on Monday, marking the end of the time interval during which the business is open; 0 - 8 * 24 * 60.
* @returns {number}
*/
get closing_minute(){return this.business_opening_hours_interval?.closing_minute;}
}
/**
* Describes the opening hours of a business.
*/
class BusinessOpeningHours {
constructor (business_opening_hours) {
this.business_opening_hours = business_opening_hours;
}
/**
* Unique name of the time zone for which the opening hours are defined.
* @returns {string}
*/
get time_zone_name(){return this.business_opening_hours?.time_zone_name;}
/**
* List of time intervals describing business opening hours.
* @returns {BusinessOpeningHoursInterval[]}
*/
get opening_hours(){return this.business_opening_hours?.opening_hours.map(item => new BusinessOpeningHoursInterval(item));}
}
/**
* This object describes the type of a reaction. Currently, it can be one of.
*/
class ReactionTypeEmoji {
constructor (reaction_type_emoji){
this.reaction_type_emoji = reaction_type_emoji;
}
/**
* Type of the reaction, always “emoji”.
* @returns {string}
*/
get type(){return this.reaction_type_emoji?.type;}
/**
* Reaction emoji. Currently, it can be one of "👍", "👎", "❤", "🔥", "🥰", "👏", "😁", "🤔", "🤯", "😱", "🤬", "😢", "🎉", "🤩", "🤮", "💩", "🙏", "👌", "🕊", "🤡", "🥱", "🥴", "😍", "🐳", "❤🔥", "🌚", "🌭", "💯", "🤣", "⚡", "🍌", "🏆", "💔", "🤨", "😐", "🍓", "🍾", "💋", "🖕", "😈", "😴", "😭", "🤓", "👻", "👨💻", "👀", "🎃", "🙈", "😇", "😨", "🤝", "✍", "🤗", "🫡", "🎅", "🎄", "☃", "💅", "🤪", "🗿", "🆒", "💘", "🙉", "🦄", "😘", "💊", "🙊", "😎", "👾", "🤷♂", "🤷", "🤷♀", "😡".
* @returns {string}
*/
get emoji(){return this.reaction_type_emoji?.emoji;}
}
/**
* The reaction is based on a custom emoji.
*/
class ReactionTypeCustomEmoji {
constructor (reaction_type_custom_emoji){
this.reaction_type_custom_emoji = reaction_type_custom_emoji;
}
/**
* Type of the reaction, always “custom_emoji”.
* @returns {string}
*/
get type(){return this.reaction_type_custom_emoji?.type;}
/**
* Custom emoji identifier.
* @returns {string}
*/
get custom_emoji_id(){return this.reaction_type_custom_emoji?.custom_emoji_id;}
}
/**
* The reaction is paid.
*/
class ReactionTypePaid {
constructor (reaction_type_paid){
this.reaction_type_paid = reaction_type_paid;
}
/**
* Type of the reaction, always “paid”.
* @returns {string}
*/
get type(){return this.reaction_type_paid?.type;}
}
class ReactionType {
constructor(reaction_type) {
const typeToClassMap = {
"emoji": ReactionTypeEmoji,
"custom_emoji": ReactionTypeCustomEmoji,
"paid": ReactionTypePaid,
};
const TargetClass = typeToClassMap[reaction_type.type];
if (!TargetClass) {
throw new Error("Reaction type not recognized.");
}
const instance = new TargetClass(reaction_type);
return new Proxy(instance, {
get(target, prop) {
return prop in target ? target[prop] : undefined;
},
set(target, prop, value) {
target[prop] = value;
return true;
}
});
}
}
/**
* Describes actions that a non-administrator user is allowed to take in a chat.
*/
class ChatPermissions {
/**
*
* @param {{can_send_messages: boolean, can_send_audios: boolean, can_send_documents: boolean, can_send_photos: boolean, can_send_videos: boolean, can_send_video_notes: boolean, can_send_voice_notes: boolean, can_send_polls: boolean, can_send_other_messages: boolean, can_add_web_page_previews: boolean, can_change_info: boolean, can_invite_users: boolean, can_pin_messages: boolean, can_manage_topics: boolean}} chat_permissions
*/
constructor(chat_permissions){
this.chat_permissions = chat_permissions;
}
/**
* Optional. True, if the user is allowed to send text messages, contacts, giveaways, giveaway winners, invoices, locations and venues.
* @returns {boolean}
*/
get can_send_messages(){return this.chat_permissions?.can_send_messages;}
/**
* Optional. True, if the user is allowed to send audios.
* @returns {boolean}
*/
get can_send_audios(){return this.chat_permissions?.can_send_audios;}
/**
* Optional. True, if the user is allowed to send documents.
* @returns {boolean}
*/
get can_send_documents(){return this.chat_permissions?.can_send_documents;}
/**
* Optional. True, if the user is allowed to send photos.
* @returns {boolean}
*/
get can_send_photos(){return this.chat_permissions?.can_send_photos;}
/**
* Optional. True, if the user is allowed to send videos.
* @returns {boolean}
*/
get can_send_videos(){return this.chat_permissions?.can_send_videos;}
/**
* Optional. True, if the user is allowed to send video notes.
* @returns {boolean}
*/
get can_send_video_notes(){return this.chat_permissions?.can_send_video_notes;}
/**
* Optional. True, if the user is allowed to send voice notes.
* @returns {boolean}
*/
get can_send_voice_notes(){return this.chat_permissions?.can_send_voice_notes;}
/**
* Optional. True, if the user is allowed to send polls.
* @returns {boolean}
*/
get can_send_polls(){return this.chat_permissions?.can_send_polls;}
/**
* Optional. True, if the user is allowed to send animations, games, stickers and use inline bots.
* @returns {boolean}
*/
get can_send_other_messages(){return this.chat_permissions?.can_send_other_messages;}
/**
* Optional. True, if the user is allowed to add web page previews to their messages.
* @returns {boolean}
*/
get can_add_web_page_previews(){return this.chat_permissions?.can_add_web_page_previews;}
/**
* Optional. True, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups.
* @returns {boolean}
*/
get can_change_info(){return this.chat_permissions?.can_change_info;}
/**
* Optional. True, if the user is allowed to invite new users to the chat.
* @returns {boolean}
*/
get can_invite_users(){return this.chat_permissions?.can_invite_users;}
/**
* Optional. True, if the user is allowed to pin messages. Ignored in public supergroups.
* @returns {boolean}
*/
get can_pin_messages(){return this.chat_permissions?.can_pin_messages;}
/**
* Optional. True, if the user is allowed to create forum topics. If omitted defaults to the value of can_pin_messages.
* @returns {boolean}
*/
get can_manage_topics(){return this.chat_permissions?.can_manage_topics;}
toJSON(){
return this.chat_permissions;
}
}
class ChatLocation {
constructor (chat_location){
this.chat_location = chat_location;
}
/**
* The location to which the supergroup is connected. Can't be a live location.
* @returns {Location}
*/
get location(){return new Location(this.chat_location?.location);}
/**
* Location address; 1-64 characters, as defined by the chat owner.
* @returns {string}
*/
get address(){return this.chat_location?.address;}
}
/**
* This object contains full information about a chat.
*/
class ChatFullInfo {
constructor(chat_full_info){
this.chat_full_info = chat_full_info;
}
/**
* Unique identifier for this chat. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier.
* @returns {number}
*/
get id(){return this.chat_full_info?.id;}
/**
* Type of the chat, can be either “private”, “group”, “supergroup” or “channel”
* @returns {string}
*/
get type(){return this.chat_full_info?.type;}
/**
* Optional. Title, for supergroups, channels and group chats
* @returns {string}
*/
get title(){return this.chat_full_info?.title;}
/**
* Optional. Username, for private chats, supergroups and channels if available
* @returns {string}
*/
get username(){return this.chat_full_info?.username;}
/**
* Optional. First name of the other party in a private chat
* @returns {string}
*/
get first_name(){return this.chat_full_info?.first_name;}
/**
* Optional. Last name of the other party in a private chat
* @returns {string}
*/
get last_name(){return this.chat_full_info?.last_name;}
/**
* Optional. True, if the supergroup chat is a forum (has topics enabled)
* @returns {boolean}
*/
get is_forum(){return this.chat_full_info?.is_forum;}
/**
* Identifier of the accent color for the chat name and backgrounds of the chat photo, reply header, and link preview. See accent colors for more details.
* @returns {number}
*/
get accent_color_id(){return this.chat_full_info?.accent_color_id;}
/**
* The maximum number of reactions that can be set on a message in the chat
* @returns {number}
*/
get max_reaction_count(){return this.chat_full_info?.max_reaction_count;}
/**
* Optional. Chat photo
* @returns {ChatPhoto}
*/
get photo(){return new ChatPhoto(this.chat_full_info?.photo);}
/**
* Optional. If non-empty, the list of all active chat usernames; for private chats, supergroups and channels.
* @returns {string[]}
*/
get active_usernames(){return this.chat_full_info?.active_usernames;}
/**
* Optional. For private chats, the date of birth of the user
* @returns {Birthdate}
*/
get birthdate(){return new Birthdate(this.chat_full_info?.birthdate);}
/**
* Optional. For private chats with business accounts, the intro of the business
* @returns {BusinessIntro}
*/
get business_intro(){return new BusinessIntro(this.chat_full_info?.business_intro);}
/**
* Optional. For private chats with business accounts, the location of the business
* @returns {BusinessLocation}
*/
get business_location(){return new BusinessLocation(this.chat_full_info?.business_location);}
/**
* Optional. For private chats with business accounts, the opening hours of the business
* @returns {BusinessOpeningHours}
*/
get business_opening_hours(){return new BusinessOpeningHours(this.chat_full_info?.business_opening_hours);}
/**
* Optional. For private chats, the personal channel of the user
* @returns {Chat}
*/
get personal_chat(){return new Chat(this.chat_full_info?.personal_chat);}
/**
* Optional. List of available reactions allowed in the chat. If omitted, then all emoji reactions are allowed.
* @returns {ReactionType[]}
*/
get available_reactions(){return this.chat_full_info?.available_reactions.map(item => new ReactionType(item));}
/**
* Optional. Custom emoji identifier of the emoji chosen by the chat for the reply header and link preview background
* @returns {string}
*/
get background_custom_emoji_id(){return this.chat_full_info?.background_custom_emoji_id;}
/**
* Optional. Identifier of the accent color for the chat's profile background. See profile accent colors for more details.
* @returns {number}
*/
get profile_accent_color_id(){return this.chat_full_info?.profile_accent_color_id;}
/**
* Optional. Custom emoji identifier of the emoji chosen by the chat for its profile background
* @returns {string}
*/
get profile_background_custom_emoji_id(){return this.chat_full_info?.profile_background_custom_emoji_id;}
/**
* Optional. Custom emoji identifier of the emoji status of the chat or the other party in a private chat
* @returns {string}
*/
get emoji_status_custom_emoji_id(){return this.chat_full_info?.emoji_status_custom_emoji_id;}
/**
* Optional. Expiration date of the emoji status of the chat or the other party in a private chat, in Unix time, if any
* @returns {number}
*/
get emoji_status_expiration_date(){return this.chat_full_info?.emoji_status_expiration_date;}
/**
* Optional. Bio of the other party in a private chat
* @returns {string}
*/
get bio(){return this.chat_full_info?.bio;}
/**
* Optional. 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
* @returns {boolean}
*/
get has_private_forwards(){return this.chat_full_info?.has_private_forwards;}
/**
* Optional. True, if the privacy settings of the other party restrict sending voice and video note messages in the private chat
* @returns {boolean}
*/
get has_restricted_voice_and_video_messages(){return this.chat_full_info?.has_restricted_voice_and_video_messages;}
/**
* Optional. True, if users need to join the supergroup before they can send messages
* @returns {boolean}
*/
get join_to_send_messages(){return this.chat_full_info?.join_to_send_messages;}
/**
* Optional. True, if all users directly joining the supergroup without using an invite link need to be approved by supergroup administrators
* @returns {boolean}
*/
get join_by_request(){return this.chat_full_info?.join_by_request;}
/**
* Optional. Description, for groups, supergroups and channel chats
* @returns {string}
*/
get description(){return this.chat_full_info?.description;}
/**
* Optional. Primary invite link, for groups, supergroups and channel chats
* @returns {string}
*/
get invite_link(){return this.chat_full_info?.invite_link;}
/**
* Optional. The most recent pinned message (by sending date)
* @returns {Message}
*/
get pinned_message(){return this.chat_full_info?.pinned_message;}
/**
* Optional. Default chat member permissions, for groups and supergroups
* @returns {ChatPermissions}
*/
get permissions(){return new ChatPermissions(this.chat_full_info?.permissions);}
/**
* Optional. True, if paid media messages can be sent or forwarded to the channel chat. The field is available only for channel chats.
* @returns {boolean}
*/
get can_send_paid_media(){return this.chat_full_info?.can_send_paid_media;}
/**
* Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unprivileged user; in seconds.
* @returns {number}
*/
get slow_mode_delay(){return this.chat_full_info?.slow_mode_delay;}
/**
* Optional. For supergroups, the minimum number of boosts that a non-administrator user needs to add in order to ignore slow mode and chat permissions.
* @returns {number}
*/
get unrestrict_boost_count(){return this.chat_full_info?.unrestrict_boost_count;}
/**
* Optional. The time after which all messages sent to the chat will be automatically deleted; in seconds.
* @returns {number}
*/
get message_auto_delete_time(){return this.chat_full_info?.message_auto_delete_time;}
/**
* Optional. True, if aggressive anti-spam checks are enabled in the supergroup. The field is only available to chat administrators.
* @returns {boolean}
*/
get has_aggressive_anti_spam_enabled(){return this.chat_full_info?.has_aggressive_anti_spam_enabled;}
/**