telegram-bot-api-nodejs 1.0.1 โ†’ 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.ts DELETED
@@ -1,1616 +0,0 @@
1
- /**
2
- * Common headers for API calls
3
- */
4
- const headers = {
5
- "Accept": "application/json",
6
- "Content-Type": "application/json",
7
- }
8
-
9
- export type ChatType = "private"
10
- | "group"
11
- | "supergroup"
12
- | "channel";
13
-
14
- export type ChatAction = "typing"
15
- | "upload_photo"
16
- | "record_video"
17
- | "upload_video"
18
- | "record_audio"
19
- | "upload_audio"
20
- | "upload_document"
21
- | "find_location"
22
- | "record_video_note"
23
- | "upload_video_note";
24
-
25
- export type ChatMemberStatus = "creator"
26
- | "administrator"
27
- | "member"
28
- | "restricted"
29
- | "left"
30
- | "kicked";
31
-
32
- export type DocumentMimeType = "application/pdf" | "application/zip";
33
-
34
- export type MessageType =
35
- | "text"
36
- | "animation"
37
- | "audio"
38
- | "channel_chat_created"
39
- | "contact"
40
- | "delete_chat_photo"
41
- | "document"
42
- | "game"
43
- | "group_chat_created"
44
- | "invoice"
45
- | "left_chat_member"
46
- | "location"
47
- | "migrate_from_chat_id"
48
- | "migrate_to_chat_id"
49
- | "new_chat_members"
50
- | "new_chat_photo"
51
- | "new_chat_title"
52
- | "passport_data"
53
- | "photo"
54
- | "pinned_message"
55
- | "sticker"
56
- | "successful_payment"
57
- | "supergroup_chat_created"
58
- | "video"
59
- | "video_note"
60
- | "voice";
61
-
62
- type MessageEntityType = "mention"
63
- | "hashtag"
64
- | "bot_command"
65
- | "url"
66
- | "email"
67
- | "bold"
68
- | "italic"
69
- | "code"
70
- | "pre"
71
- | "text_link"
72
- | "text_mention"
73
-
74
- type ParseMode = "Markdown"
75
- | "MarkdownV2"
76
- | "HTML";
77
-
78
- export type AllowedUpdates = keyof (Omit<Update, "update_id">)
79
-
80
- export interface SetWebHookOptions {
81
- url: string;
82
- max_connections?: number;
83
- allowed_updates?: AllowedUpdates[]
84
- }
85
-
86
- interface SendBasicOptions {
87
- chat_id: number | string
88
- disable_notification?: boolean;
89
- reply_to_message_id?: number | string;
90
- reply_markup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
91
- }
92
-
93
- export interface SendMessageOptions extends SendBasicOptions {
94
- text: string
95
- parse_mode?: ParseMode;
96
- disable_web_page_preview?: boolean;
97
- entities?: MessageEntity[]
98
- }
99
-
100
- interface AnswerInlineQueryOptions {
101
- cache_time?: number;
102
- is_personal?: boolean;
103
- next_offset?: string;
104
- switch_pm_text?: string;
105
- switch_pm_parameter?: string;
106
- }
107
-
108
- interface ForwardMessageOptions {
109
- disable_notification?: boolean;
110
- }
111
-
112
- export interface SendPhotoOptions extends SendBasicOptions {
113
- photo: string
114
- parse_mode?: ParseMode;
115
- caption?: string;
116
- }
117
-
118
- export interface SendAnimationOptions extends SendBasicOptions {
119
- animation: string
120
- parse_mode?: ParseMode;
121
- caption?: string;
122
- }
123
-
124
- interface SendAudioOptions extends SendBasicOptions {
125
- parse_mode?: ParseMode;
126
- caption?: string;
127
- duration?: number;
128
- performer?: string;
129
- title?: string;
130
- }
131
-
132
- interface SendDocumentOptions extends SendBasicOptions {
133
- document: string
134
- parse_mode?: ParseMode;
135
- caption?: string;
136
- }
137
-
138
- interface SendMediaGroupOptions {
139
- disable_notification?: boolean;
140
- reply_to_message_id?: number;
141
- }
142
-
143
- type SendStickerOptions = SendBasicOptions;
144
-
145
- interface SendVideoOptions extends SendBasicOptions {
146
- parse_mode?: ParseMode;
147
- duration?: number;
148
- width?: number;
149
- height?: number;
150
- caption?: string;
151
- }
152
-
153
- interface SendVoiceOptions extends SendBasicOptions {
154
- parse_mode?: ParseMode;
155
- caption?: string;
156
- duration?: number;
157
- }
158
-
159
- interface SendVideoNoteOptions extends SendBasicOptions {
160
- duration?: number;
161
- length?: number;
162
- }
163
-
164
- type SendLocationOptions = SendBasicOptions;
165
-
166
- type EditMessageLiveLocationOptions = EditMessageCaptionOptions;
167
-
168
- type StopMessageLiveLocationOptions = EditMessageCaptionOptions;
169
-
170
- interface SendVenueOptions extends SendBasicOptions {
171
- foursquare_id?: string;
172
- }
173
-
174
- interface SendContactOptions extends SendBasicOptions {
175
- last_name?: string;
176
- }
177
-
178
- type SendGameOptions = SendBasicOptions;
179
-
180
- interface SendInvoiceOptions extends SendBasicOptions {
181
- provider_data?: string;
182
- photo_url?: string;
183
- photo_size?: number;
184
- photo_width?: number;
185
- photo_height?: number;
186
- need_name?: boolean;
187
- need_phone_number?: boolean;
188
- need_email?: boolean;
189
- need_shipping_address?: boolean;
190
- is_flexible?: boolean;
191
- }
192
-
193
- interface RestrictChatMemberOptions {
194
- until_date?: number;
195
- can_send_messages?: boolean;
196
- can_send_media_messages?: boolean;
197
- can_send_other_messages?: boolean;
198
- can_add_web_page_previews?: boolean;
199
- }
200
-
201
- interface PromoteChatMemberOptions {
202
- can_change_info?: boolean
203
- can_post_messages?: boolean
204
- can_edit_messages?: boolean
205
- can_delete_messages?: boolean
206
- can_invite_users?: boolean
207
- can_restrict_members?: boolean
208
- can_pin_messages?: boolean
209
- can_promote_members?: boolean
210
- }
211
-
212
- export interface AnswerCallbackQueryOptions {
213
- callback_query_id: string
214
- text?: string
215
- show_alert?: boolean
216
- url?: string
217
- cache_time?: number
218
- }
219
-
220
- export interface GetChatOptions {
221
- chat_id: string
222
- }
223
-
224
- interface SetMyCommandsOptions {
225
- commands: BotCommand[]
226
- }
227
-
228
- interface DeleteMyCommandsOptions { }
229
-
230
- interface EditMessageTextOptions extends EditMessageReplyMarkupOptions {
231
- parse_mode?: ParseMode;
232
- disable_web_page_preview?: boolean;
233
- text: string
234
- }
235
-
236
- interface EditMessageCaptionOptions extends EditMessageReplyMarkupOptions {
237
- reply_markup?: InlineKeyboardMarkup;
238
- }
239
-
240
- interface EditMessageReplyMarkupOptions {
241
- chat_id?: number | string;
242
- message_id?: number | string;
243
- inline_message_id?: string;
244
- }
245
-
246
- export interface GetUserProfilePhotosOptions {
247
- user_id: number | string
248
- offset?: number;
249
- limit?: number;
250
- }
251
-
252
- interface SetGameScoreOptions {
253
- force?: boolean;
254
- disable_edit_message?: boolean;
255
- chat_id?: number;
256
- message_id?: number;
257
- inline_message_id?: string;
258
- }
259
-
260
- interface GetGameHighScoresOptions {
261
- chat_id?: number;
262
- message_id?: number;
263
- inline_message_id?: string;
264
- }
265
-
266
- interface AnswerShippingQueryOptions {
267
- shipping_options?: ShippingOption[];
268
- error_message?: string;
269
- }
270
-
271
- interface AnswerPreCheckoutQueryOptions {
272
- error_message?: string;
273
- }
274
-
275
- /// TELEGRAM TYPES ///
276
- interface PassportFile {
277
- file_id: string;
278
- file_size: number;
279
- file_date: number;
280
- }
281
-
282
- interface EncryptedPassportElement {
283
- type: string;
284
- data?: string;
285
- phone_number?: string;
286
- email?: string;
287
- files?: PassportFile[];
288
- front_side?: PassportFile;
289
- reverse_side?: PassportFile;
290
- selfie?: PassportFile;
291
- translation?: PassportFile[];
292
- hash: string;
293
- }
294
-
295
- interface EncryptedCredentials {
296
- data: string;
297
- hash: string;
298
- secret: string;
299
- }
300
-
301
- interface PassportData {
302
- data: EncryptedPassportElement[];
303
- credentials: EncryptedCredentials;
304
- }
305
-
306
- export interface Update {
307
- update_id: number;
308
- message?: Message;
309
- edited_message?: Message;
310
- channel_post?: Message;
311
- edited_channel_post?: Message
312
- message_reaction?: MessageReactionUpdated
313
- message_reaction_count?: MessageReactionCountUpdated
314
- inline_query?: InlineQuery;
315
- chosen_inline_result?: ChosenInlineResult;
316
- callback_query?: CallbackQuery;
317
- shipping_query?: ShippingQuery;
318
- pre_checkout_query?: PreCheckoutQuery;
319
- }
320
-
321
- export interface WebhookInfo {
322
- url: string;
323
- has_custom_certificate: boolean;
324
- pending_update_count: number;
325
- last_error_date?: number;
326
- last_error_message?: string;
327
- max_connections?: number;
328
- allowed_updates?: AllowedUpdates[]
329
- }
330
-
331
- export interface User {
332
- id: string;
333
- is_bot: boolean;
334
- first_name: string;
335
- last_name?: string;
336
- username?: string;
337
- language_code?: string;
338
- can_join_groups?: boolean
339
- supports_inline_queries?: boolean
340
- can_read_all_group_messages?: boolean
341
- }
342
-
343
- export interface Chat {
344
- id: number;
345
- type: ChatType;
346
- title?: string;
347
- username?: string;
348
- first_name?: string;
349
- last_name?: string;
350
- photo?: ChatPhoto;
351
- description?: string;
352
- invite_link?: string;
353
- pinned_message?: Message;
354
- permissions?: ChatPermissions;
355
- can_set_sticker_set?: boolean;
356
- sticker_set_name?: string;
357
- }
358
-
359
- export interface Message {
360
- message_id: number;
361
- from?: User;
362
- date: number;
363
- chat: Chat;
364
- forward_from?: User;
365
- forward_from_chat?: Chat;
366
- forward_from_message_id?: number;
367
- forward_signature?: string;
368
- forward_sender_name?: string;
369
- forward_date?: number;
370
- reply_to_message?: Message;
371
- edit_date?: number;
372
- media_group_id?: string;
373
- author_signature?: string;
374
- text?: string;
375
- entities?: MessageEntity[];
376
- caption_entities?: MessageEntity[];
377
- audio?: Audio;
378
- document?: Document;
379
- animation?: Animation;
380
- game?: Game;
381
- photo?: PhotoSize[];
382
- sticker?: Sticker;
383
- video?: Video;
384
- voice?: Voice;
385
- video_note?: VideoNote;
386
- caption?: string;
387
- contact?: Contact;
388
- location?: Location;
389
- venue?: Venue;
390
- poll?: Poll;
391
- new_chat_members?: User[];
392
- left_chat_member?: User;
393
- new_chat_title?: string;
394
- new_chat_photo?: PhotoSize[];
395
- delete_chat_photo?: boolean;
396
- group_chat_created?: boolean;
397
- supergroup_chat_created?: boolean;
398
- channel_chat_created?: boolean;
399
- migrate_to_chat_id?: number;
400
- migrate_from_chat_id?: number;
401
- pinned_message?: Message;
402
- invoice?: Invoice;
403
- successful_payment?: SuccessfulPayment;
404
- connected_website?: string;
405
- passport_data?: PassportData;
406
- reply_markup?: InlineKeyboardMarkup;
407
- sender_chat?: Chat
408
- }
409
-
410
- export interface MessageReactionUpdated {
411
- chat: Chat
412
- message_id: number
413
- user?: User
414
- actor_chat?: Chat
415
- date: number
416
- old_reaction: ReactionType[]
417
- new_reaction: ReactionType[]
418
- }
419
-
420
- /**
421
- * @see https://core.telegram.org/bots/api#reactiontype
422
- */
423
- export type ReactionType = ReactionTypeEmoji
424
- | ReactionTypeCustomEmoji
425
-
426
- /**
427
- * @see https://core.telegram.org/bots/api#reactiontypeemoji
428
- */
429
- export interface ReactionTypeEmoji {
430
- type: "emoji"
431
- emoji: string
432
- }
433
-
434
- /**
435
- * @see https://core.telegram.org/bots/api#reactiontypecustomemoji
436
- */
437
- export interface ReactionTypeCustomEmoji {
438
- type: "custom_emoji"
439
- custom_emoji_id: string
440
- }
441
-
442
- /**
443
- * @see https://core.telegram.org/bots/api#messagereactioncountupdated
444
- */
445
- export interface MessageReactionCountUpdated {
446
- chat: Chat
447
- message_id: number
448
- date: number
449
- reactions: ReactionCount[]
450
- }
451
-
452
- /**
453
- * @see https://core.telegram.org/bots/api#reactioncount
454
- */
455
- export interface ReactionCount {
456
- type: ReactionType
457
- total_count: number
458
- }
459
-
460
- export interface MessageEntity {
461
- type: MessageEntityType;
462
- offset: number;
463
- length: number;
464
- url?: string;
465
- user?: User;
466
- }
467
-
468
- interface FileBase {
469
- file_id: string;
470
- file_size?: number;
471
- }
472
-
473
- export interface PhotoSize extends FileBase {
474
- width: number;
475
- height: number;
476
- }
477
-
478
- export interface Audio extends FileBase {
479
- duration: number;
480
- performer?: string;
481
- title?: string;
482
- file_name?: string;
483
- mime_type?: string;
484
- thumb?: PhotoSize;
485
- }
486
-
487
- export interface Document extends FileBase {
488
- thumb?: PhotoSize;
489
- file_name?: string;
490
- mime_type?: string;
491
- file_size?: number;
492
- }
493
-
494
- export interface Video extends FileBase {
495
- width: number;
496
- height: number;
497
- duration: number;
498
- thumb?: PhotoSize;
499
- mime_type?: string;
500
- file_name?: string;
501
- }
502
-
503
- export interface Voice extends FileBase {
504
- duration: number;
505
- mime_type?: string;
506
- }
507
-
508
- interface InputMediaBase {
509
- media: string;
510
- caption?: string;
511
- parse_mode?: ParseMode;
512
- }
513
-
514
- interface InputMediaPhoto extends InputMediaBase {
515
- type: "photo";
516
- }
517
-
518
- interface InputMediaVideo extends InputMediaBase {
519
- type: "video";
520
- width?: number;
521
- height?: number;
522
- duration?: number;
523
- supports_streaming?: boolean;
524
- }
525
-
526
- type InputMedia = InputMediaPhoto | InputMediaVideo;
527
-
528
- export interface VideoNote extends FileBase {
529
- length: number;
530
- duration: number;
531
- thumb?: PhotoSize;
532
- }
533
-
534
- export interface Contact {
535
- phone_number: string;
536
- first_name: string;
537
- last_name?: string;
538
- user_id?: number;
539
- vcard?: string;
540
- }
541
-
542
- export interface Location {
543
- longitude: number;
544
- latitude: number;
545
- }
546
-
547
- export interface Venue {
548
- location: Location;
549
- title: string;
550
- address: string;
551
- foursquare_id?: string;
552
- foursquare_type?: string;
553
- google_place_id?: string;
554
- google_place_type?: string;
555
- }
556
-
557
- export interface PollOption {
558
- text: string;
559
- voter_count: number;
560
- }
561
-
562
- export interface Poll {
563
- id: string;
564
- question: string;
565
- options: PollOption[];
566
- is_closed: boolean;
567
- }
568
-
569
- export interface UserProfilePhotos {
570
- total_count: number;
571
- photos: PhotoSize[][];
572
- }
573
-
574
- export interface File extends FileBase {
575
- file_path?: string;
576
- }
577
-
578
- interface ReplyKeyboardMarkup {
579
- keyboard: KeyboardButton[][];
580
- resize_keyboard?: boolean;
581
- one_time_keyboard?: boolean;
582
- selective?: boolean;
583
- }
584
-
585
- interface KeyboardButton {
586
- text: string;
587
- request_contact?: boolean;
588
- request_location?: boolean;
589
- }
590
-
591
- interface ReplyKeyboardRemove {
592
- remove_keyboard: boolean;
593
- selective?: boolean;
594
- }
595
-
596
- export interface InlineKeyboardMarkup {
597
- inline_keyboard: InlineKeyboardButton[][];
598
- }
599
-
600
- export interface InlineKeyboardButton {
601
- text: string;
602
- url?: string;
603
- login_url?: LoginUrl;
604
- callback_data?: string;
605
- switch_inline_query?: string;
606
- switch_inline_query_current_chat?: string;
607
- callback_game?: CallbackGame;
608
- pay?: boolean;
609
- }
610
-
611
- interface LoginUrl {
612
- url: string;
613
- forward_text?: string;
614
- bot_username?: string;
615
- request_write_acces?: boolean;
616
- }
617
-
618
- export interface CallbackQuery {
619
- id: string;
620
- from: User;
621
- message?: Message;
622
- inline_message_id?: string;
623
- chat_instance: string;
624
- data?: string;
625
- game_short_name?: string;
626
- }
627
-
628
- interface ForceReply {
629
- force_reply: boolean;
630
- selective?: boolean;
631
- }
632
-
633
- interface ChatPhoto {
634
- small_file_id: string
635
- small_file_unique_id: string
636
- big_file_id: string
637
- big_file_unique_id: string
638
- }
639
-
640
- interface ChatMember {
641
- user: User;
642
- status: ChatMemberStatus;
643
- until_date?: number;
644
- can_be_edited?: boolean;
645
- can_post_messages?: boolean;
646
- can_edit_messages?: boolean;
647
- can_delete_messages?: boolean;
648
- can_restrict_members?: boolean;
649
- can_promote_members?: boolean;
650
- can_change_info?: boolean;
651
- can_invite_users?: boolean;
652
- can_pin_messages?: boolean;
653
- is_member?: boolean;
654
- can_send_messages?: boolean;
655
- can_send_media_messages?: boolean;
656
- can_send_polls: boolean;
657
- can_send_other_messages?: boolean;
658
- can_add_web_page_previews?: boolean;
659
- }
660
-
661
- interface ChatPermissions {
662
- can_send_messages?: boolean;
663
- can_send_media_messages?: boolean;
664
- can_send_polls?: boolean;
665
- can_send_other_messages?: boolean;
666
- can_add_web_page_previews?: boolean;
667
- can_change_info?: boolean;
668
- can_invite_users?: boolean;
669
- can_pin_messages?: boolean;
670
- }
671
-
672
- export interface Sticker {
673
- file_id: string;
674
- width: number;
675
- height: number;
676
- thumb?: PhotoSize;
677
- emoji?: string;
678
- set_name?: string;
679
- mask_position?: MaskPosition;
680
- file_size?: number;
681
- }
682
-
683
- interface StickerSet {
684
- name: string;
685
- title: string;
686
- contains_masks: boolean;
687
- stickers: Sticker[];
688
- }
689
-
690
- interface MaskPosition {
691
- point: string;
692
- x_shift: number;
693
- y_shift: number;
694
- scale: number;
695
- }
696
-
697
- interface InlineQuery {
698
- id: string;
699
- from: User;
700
- location?: Location;
701
- query: string;
702
- offset: string;
703
- }
704
-
705
- interface InlineQueryResultBase {
706
- id: string;
707
- reply_markup?: InlineKeyboardMarkup;
708
- }
709
-
710
- interface InlineQueryResultArticle extends InlineQueryResultBase {
711
- type: "article";
712
- title: string;
713
- input_message_content: InputMessageContent;
714
- url?: string;
715
- hide_url?: boolean;
716
- description?: string;
717
- thumb_url?: string;
718
- thumb_width?: number;
719
- thumb_height?: number;
720
- }
721
-
722
- interface InlineQueryResultPhoto extends InlineQueryResultBase {
723
- type: "photo";
724
- photo_url: string;
725
- thumb_url: string;
726
- photo_width?: number;
727
- photo_height?: number;
728
- title?: string;
729
- description?: string;
730
- caption?: string;
731
- input_message_content?: InputMessageContent;
732
- }
733
-
734
- interface InlineQueryResultGif extends InlineQueryResultBase {
735
- type: "gif";
736
- gif_url: string;
737
- gif_width?: number;
738
- gif_height?: number;
739
- gif_duration?: number;
740
- thumb_url?: string;
741
- title?: string;
742
- caption?: string;
743
- input_message_content?: InputMessageContent;
744
- }
745
-
746
- interface InlineQueryResultMpeg4Gif extends InlineQueryResultBase {
747
- type: "mpeg4_gif";
748
- mpeg4_url: string;
749
- mpeg4_width?: number;
750
- mpeg4_height?: number;
751
- mpeg4_duration?: number;
752
- thumb_url?: string;
753
- title?: string;
754
- caption?: string;
755
- input_message_content?: InputMessageContent;
756
- }
757
-
758
- interface InlineQueryResultVideo extends InlineQueryResultBase {
759
- type: "video";
760
- video_url: string;
761
- mime_type: string;
762
- thumb_url: string;
763
- title: string;
764
- caption?: string;
765
- video_width?: number;
766
- video_height?: number;
767
- video_duration?: number;
768
- description?: string;
769
- input_message_content?: InputMessageContent;
770
- }
771
-
772
- interface InlineQueryResultAudio extends InlineQueryResultBase {
773
- type: "audio";
774
- audio_url: string;
775
- title: string;
776
- caption?: string;
777
- performer?: string;
778
- audio_duration?: number;
779
- input_message_content?: InputMessageContent;
780
- }
781
-
782
- interface InlineQueryResultVoice extends InlineQueryResultBase {
783
- type: "voice";
784
- voice_url: string;
785
- title: string;
786
- caption?: string;
787
- voice_duration?: number;
788
- input_message_content?: InputMessageContent;
789
- }
790
-
791
- interface InlineQueryResultDocument extends InlineQueryResultBase {
792
- type: "document";
793
- title: string;
794
- caption?: string;
795
- document_url: string;
796
- mime_type: string;
797
- description?: string;
798
- input_message_content?: InputMessageContent;
799
- thumb_url?: string;
800
- thumb_width?: number;
801
- thumb_height?: number;
802
- }
803
-
804
- interface InlineQueryResultLocationBase extends InlineQueryResultBase {
805
- latitude: number;
806
- longitude: number;
807
- title: string;
808
- input_message_content?: InputMessageContent;
809
- thumb_url?: string;
810
- thumb_width?: number;
811
- thumb_height?: number;
812
- }
813
-
814
- interface InlineQueryResultLocation extends InlineQueryResultLocationBase {
815
- type: "location";
816
- }
817
-
818
- interface InlineQueryResultVenue extends InlineQueryResultLocationBase {
819
- type: "venue";
820
- address: string;
821
- foursquare_id?: string;
822
- }
823
-
824
- interface InlineQueryResultContact extends InlineQueryResultBase {
825
- type: "contact";
826
- phone_number: string;
827
- first_name: string;
828
- last_name?: string;
829
- input_message_content?: InputMessageContent;
830
- thumb_url?: string;
831
- thumb_width?: number;
832
- thumb_height?: number;
833
- }
834
-
835
- interface InlineQueryResultGame extends InlineQueryResultBase {
836
- type: "game";
837
- game_short_name: string;
838
- }
839
-
840
- interface InlineQueryResultCachedPhoto extends InlineQueryResultBase {
841
- type: "photo";
842
- photo_file_id: string;
843
- title?: string;
844
- description?: string;
845
- caption?: string;
846
- input_message_content?: InputMessageContent;
847
- }
848
-
849
- interface InlineQueryResultCachedGif extends InlineQueryResultBase {
850
- type: "gif";
851
- gif_file_id: string;
852
- title?: string;
853
- caption?: string;
854
- input_message_content?: InputMessageContent;
855
- }
856
-
857
- interface InlineQueryResultCachedMpeg4Gif extends InlineQueryResultBase {
858
- type: "mpeg4_gif";
859
- mpeg4_file_id: string;
860
- title?: string;
861
- caption?: string;
862
- input_message_content?: InputMessageContent;
863
- }
864
-
865
- interface InlineQueryResultCachedSticker extends InlineQueryResultBase {
866
- type: "sticker";
867
- sticker_file_id: string;
868
- input_message_content?: InputMessageContent;
869
- }
870
-
871
- interface InlineQueryResultCachedDocument extends InlineQueryResultBase {
872
- type: "document";
873
- title: string;
874
- document_file_id: string;
875
- description?: string;
876
- caption?: string;
877
- input_message_content?: InputMessageContent;
878
- }
879
-
880
- interface InlineQueryResultCachedVideo extends InlineQueryResultBase {
881
- type: "video";
882
- video_file_id: string;
883
- title: string;
884
- description?: string;
885
- caption?: string;
886
- input_message_content?: InputMessageContent;
887
- }
888
-
889
- interface InlineQueryResultCachedVoice extends InlineQueryResultBase {
890
- type: "voice";
891
- voice_file_id: string;
892
- title: string;
893
- caption?: string;
894
- input_message_content?: InputMessageContent;
895
- }
896
-
897
- interface InlineQueryResultCachedAudio extends InlineQueryResultBase {
898
- type: "audio";
899
- audio_file_id: string;
900
- caption?: string;
901
- input_message_content?: InputMessageContent;
902
- }
903
-
904
- type InlineQueryResult =
905
- InlineQueryResultCachedAudio |
906
- InlineQueryResultCachedDocument |
907
- InlineQueryResultCachedGif |
908
- InlineQueryResultCachedMpeg4Gif |
909
- InlineQueryResultCachedPhoto |
910
- InlineQueryResultCachedSticker |
911
- InlineQueryResultCachedVideo |
912
- InlineQueryResultCachedVoice |
913
- InlineQueryResultArticle |
914
- InlineQueryResultAudio |
915
- InlineQueryResultContact |
916
- InlineQueryResultGame |
917
- InlineQueryResultDocument |
918
- InlineQueryResultGif |
919
- InlineQueryResultLocation |
920
- InlineQueryResultMpeg4Gif |
921
- InlineQueryResultPhoto |
922
- InlineQueryResultVenue |
923
- InlineQueryResultVideo |
924
- InlineQueryResultVoice;
925
-
926
- type InputMessageContent = object;
927
-
928
- interface InputTextMessageContent extends InputMessageContent {
929
- message_text: string;
930
- parse_mode?: ParseMode;
931
- disable_web_page_preview?: boolean;
932
- }
933
-
934
- interface InputLocationMessageContent extends InputMessageContent {
935
- latitude: number;
936
- longitude: number;
937
- }
938
-
939
- interface InputVenueMessageContent extends InputLocationMessageContent {
940
- title: string;
941
- address: string;
942
- foursquare_id?: string;
943
- }
944
-
945
- interface InputContactMessageContent extends InputMessageContent {
946
- phone_number: string;
947
- first_name: string;
948
- last_name?: string;
949
- }
950
-
951
- interface ChosenInlineResult {
952
- result_id: string;
953
- from: User;
954
- location?: Location;
955
- inline_message_id?: string;
956
- query: string;
957
- }
958
-
959
- interface ResponseParameters {
960
- migrate_to_chat_id?: number;
961
- retry_after?: number;
962
- }
963
-
964
- interface LabeledPrice {
965
- label: string;
966
- amount: number;
967
- }
968
-
969
- interface Invoice {
970
- title: string;
971
- description: string;
972
- start_parameter: string;
973
- currency: string;
974
- total_amount: number;
975
- }
976
-
977
- interface ShippingAddress {
978
- country_code: string;
979
- state: string;
980
- city: string;
981
- street_line1: string;
982
- street_line2: string;
983
- post_code: string;
984
- }
985
-
986
- interface OrderInfo {
987
- name?: string;
988
- phone_number?: string;
989
- email?: string;
990
- shipping_address?: ShippingAddress;
991
- }
992
-
993
- interface ShippingOption {
994
- id: string;
995
- title: string;
996
- prices: LabeledPrice[];
997
- }
998
-
999
- interface SuccessfulPayment {
1000
- currency: string;
1001
- total_amount: number;
1002
- invoice_payload: string;
1003
- shipping_option_id?: string;
1004
- order_info?: OrderInfo;
1005
- telegram_payment_charge_id: string;
1006
- provider_payment_charge_id: string;
1007
- }
1008
-
1009
- interface ShippingQuery {
1010
- id: string;
1011
- from: User;
1012
- invoice_payload: string;
1013
- shipping_address: ShippingAddress;
1014
- }
1015
-
1016
- interface PreCheckoutQuery {
1017
- id: string;
1018
- from: User;
1019
- currency: string;
1020
- total_amount: number;
1021
- invoice_payload: string;
1022
- shipping_option_id?: string;
1023
- order_info?: OrderInfo;
1024
- }
1025
-
1026
- interface Game {
1027
- title: string;
1028
- description: string;
1029
- photo: PhotoSize[];
1030
- text?: string;
1031
- text_entities?: MessageEntity[];
1032
- animation?: Animation;
1033
- }
1034
-
1035
- export interface Animation extends FileBase {
1036
- width: number;
1037
- height: number;
1038
- duration: number;
1039
- thumb?: PhotoSize;
1040
- file_name?: string;
1041
- mime_type?: string;
1042
- }
1043
-
1044
- type CallbackGame = object;
1045
-
1046
- interface GameHighScore {
1047
- position: number;
1048
- user: User;
1049
- score: number;
1050
- }
1051
-
1052
- interface Metadata {
1053
- type?: MessageType;
1054
- }
1055
-
1056
- interface BotCommand {
1057
- command: string
1058
- description: string
1059
- }
1060
-
1061
- /**
1062
- * Methods
1063
- */
1064
-
1065
- export function setWebhook(token: string, body: SetWebHookOptions, signal: AbortSignal) {
1066
- return fetch(`https://api.telegram.org/bot${token}/setWebhook`, {
1067
- method: "POST",
1068
- body: JSON.stringify(body),
1069
- headers,
1070
- signal
1071
- }).then(parseResponse<Boolean>)
1072
- }
1073
-
1074
- export function deleteWebhook(token: string, signal: AbortSignal) {
1075
- return fetch(`https://api.telegram.org/bot${token}/deleteWebhook`, {
1076
- method: "POST",
1077
- body: JSON.stringify({}),
1078
- headers,
1079
- signal
1080
- }).then(parseResponse<Boolean>)
1081
- }
1082
-
1083
- /** @todo cehck if response is the same as in typings */
1084
- export function getWebhookInfo(token: string, signal: AbortSignal) {
1085
- return fetch(`https://api.telegram.org/bot${token}/getWebhookInfo`, {
1086
- method: "POST",
1087
- body: JSON.stringify({}),
1088
- headers,
1089
- signal
1090
- }).then(parseResponse<WebhookInfo>)
1091
- }
1092
-
1093
- export function getMe(token: string, signal: AbortSignal) {
1094
- return fetch(`https://api.telegram.org/bot${token}/getMe`, {
1095
- method: "POST",
1096
- body: JSON.stringify({}),
1097
- headers,
1098
- signal
1099
- }).then(parseResponse<User>)
1100
- }
1101
-
1102
- export function sendMessage(token: string, payload: SendMessageOptions, signal: AbortSignal) {
1103
- return fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
1104
- method: "POST",
1105
- body: JSON.stringify(payload),
1106
- headers,
1107
- signal
1108
- }).then(parseResponse<Message>)
1109
- }
1110
-
1111
- export function editMessageText(token: string, payload: EditMessageTextOptions, signal: AbortSignal) {
1112
- return fetch(`https://api.telegram.org/bot${token}/editMessageText`, {
1113
- method: "POST",
1114
- body: JSON.stringify(payload),
1115
- headers,
1116
- signal
1117
- }).then(parseResponse<Message>)
1118
- }
1119
-
1120
- export function sendPhoto(token: string, payload: SendPhotoOptions, signal: AbortSignal) {
1121
- return fetch(`https://api.telegram.org/bot${token}/sendPhoto`, {
1122
- method: "POST",
1123
- body: JSON.stringify(payload),
1124
- headers,
1125
- signal
1126
- }).then(parseResponse<Message>)
1127
- }
1128
-
1129
- export function sendAnimation(token: string, payload: SendAnimationOptions, signal: AbortSignal) {
1130
- return fetch(`https://api.telegram.org/bot${token}/sendAnimation`, {
1131
- method: "POST",
1132
- body: JSON.stringify(payload),
1133
- headers,
1134
- signal
1135
- }).then(parseResponse<Message>)
1136
- }
1137
-
1138
- export function sendDocument(token: string, payload: SendDocumentOptions, signal: AbortSignal) {
1139
- return fetch(`https://api.telegram.org/bot${token}/sendDocument`, {
1140
- method: "POST",
1141
- body: JSON.stringify(payload),
1142
- headers,
1143
- signal
1144
- }).then(parseResponse<Message>)
1145
- }
1146
-
1147
- export function setMessageReaction(token: string, payload: {
1148
- chat_id: string | number
1149
- message_id: number
1150
- reaction?: ReactionType[]
1151
- is_big?: boolean
1152
- }, signal: AbortSignal) {
1153
- return fetch(`https://api.telegram.org/bot${token}/setMessageReaction`, {
1154
- method: "POST",
1155
- body: JSON.stringify(payload),
1156
- headers,
1157
- signal
1158
- }).then(parseResponse<Boolean>)
1159
- }
1160
-
1161
- export function getUserProfilePhotos(token: string, payload: GetUserProfilePhotosOptions, signal: AbortSignal) {
1162
- return fetch(`https://api.telegram.org/bot${token}/getUserProfilePhotos`, {
1163
- method: "POST",
1164
- body: JSON.stringify(payload),
1165
- headers,
1166
- signal
1167
- }).then(parseResponse<UserProfilePhotos>)
1168
- }
1169
-
1170
- export function getFile(token: string, file_id: string, signal: AbortSignal) {
1171
- return fetch(`https://api.telegram.org/bot${token}/getFile`, {
1172
- method: "POST",
1173
- body: JSON.stringify({ file_id }),
1174
- headers,
1175
- signal
1176
- }).then(parseResponse<File>)
1177
- }
1178
-
1179
- export function answerCallbackQuery(token: string, payload: AnswerCallbackQueryOptions, signal: AbortSignal) {
1180
- return fetch(`https://api.telegram.org/bot${token}/answerCallbackQuery`, {
1181
- method: "POST",
1182
- body: JSON.stringify(payload),
1183
- headers,
1184
- signal
1185
- }).then(parseResponse<File>)
1186
- }
1187
-
1188
- export function getChat(token: string, payload: GetChatOptions, signal: AbortSignal) {
1189
- return fetch(`https://api.telegram.org/bot${token}/getChat`, {
1190
- method: "POST",
1191
- body: JSON.stringify(payload),
1192
- headers,
1193
- signal
1194
- }).then(parseResponse<Chat>)
1195
- }
1196
-
1197
- export function getChatMember(token: string, payload: { chat_id: string, user_id: string }, signal?: AbortSignal) {
1198
- return fetch(`https://api.telegram.org/bot${token}/getChatMember`, {
1199
- method: "POST",
1200
- body: JSON.stringify(payload),
1201
- headers,
1202
- signal: signal
1203
- }).then(parseResponse<ChatMember>)
1204
- }
1205
-
1206
- export function setMyCommands(token: string, payload: SetMyCommandsOptions, signal?: AbortSignal) {
1207
- return fetch(`https://api.telegram.org/bot${token}/setMyCommands`, {
1208
- method: "POST",
1209
- body: JSON.stringify(payload),
1210
- headers,
1211
- signal
1212
- }).then(parseResponse<Chat>)
1213
- }
1214
-
1215
- export function deleteMyCommands(token: string, payload: DeleteMyCommandsOptions, signal: AbortSignal): Promise<Chat> {
1216
- return fetch(`https://api.telegram.org/bot${token}/deleteMyCommands`, {
1217
- method: "POST",
1218
- body: JSON.stringify(payload),
1219
- headers,
1220
- signal
1221
- }).then(parseResponse<Chat>)
1222
- }
1223
-
1224
- /**
1225
- * Parsers
1226
- */
1227
-
1228
- export function parseUpdate(update: any): Update {
1229
- const u: Update = {
1230
- update_id: Number(update.update_id)
1231
- }
1232
-
1233
- if (update.message) {
1234
- u.message = parseMessage(update.message)
1235
- }
1236
-
1237
- if (update.edited_message) {
1238
- u.edited_message = parseMessage(update.edited_message)
1239
- }
1240
-
1241
- if (update.callback_query) {
1242
- u.callback_query = parseCallbackQuery(update.callback_query)
1243
- }
1244
-
1245
- if (update.message_reaction) {
1246
- u.message_reaction = parseMessageReaction(update.message_reaction)
1247
- }
1248
-
1249
- if (update.message_reaction_count) {
1250
- u.message_reaction_count = parseMessageReactionCount(update.message_reaction_count)
1251
- }
1252
-
1253
- return u
1254
- }
1255
-
1256
- export function parseMessage(m: any): Message {
1257
- return {
1258
- message_id: Number(m.message_id),
1259
- from: m.from ? parseUser(m.from) : void 0,
1260
- date: Number(m.date),
1261
- chat: parseChat(m.chat),
1262
- text: String(m.text ?? ""),
1263
- forward_from: m.forward_from ? parseUser(m.forward_from) : void 0, // User;
1264
- forward_from_chat: m.forward_from_chat ? parseChat(m.forward_from_chat) : void 0, // Chat;
1265
- forward_from_message_id: m.forward_from_message_id ? Number(m.forward_from_message_id) : void 0, // number;
1266
- forward_signature: m.forward_signature ? String(m.forward_signature) : void 0, // string;
1267
- forward_sender_name: m.forward_sender_name ? String(m.forward_sender_name) : void 0, // string;
1268
- forward_date: m.forward_date ? Number(m.forward_date) : void 0, // number;
1269
- // reply_to_message: m.reply_to_message ? parseMessage(m.reply_to_message) : void 0, // Message;
1270
- edit_date: m.edit_date ? Number(m.edit_date) : void 0, // number;
1271
- media_group_id: m.media_group_id ? String(m.media_group_id) : void 0, // string;
1272
- author_signature: m.author_signature ? String(m.author_signature) : void 0, // string;
1273
- entities: m.entities ? parseEntities(m.entities) : void 0, // MessageEntity[];
1274
- // caption_entities: m.caption_entities ? parseSometh(m.caption_entities) : void 0, // MessageEntity[];
1275
- audio: m.audio ? parseAudio(m.audio) : void 0,
1276
- document: m.document ? parseDocument(m.document) : void 0,
1277
- animation: m.animation ? parseAnimation(m.animation) : void 0,
1278
- // game?: Game;
1279
- photo: m.photo ? parsePhotoSizes(m.photo) : void 0,
1280
- sticker: m.sticker ? parseSticker(m.sticker) : void 0,
1281
- video: m.video ? parseVideo(m.video) : void 0,
1282
- voice: m.voice ? parseVoice(m.voice) : void 0,
1283
- video_note: m.video_note ? parseVideoNote(m.video_note) : void 0,
1284
- caption: m.caption ? String(m.caption) : void 0,
1285
- contact: m.contact ? parseContact(m.contact) : void 0,
1286
- location: m.location ? parseLocation(m.location) : void 0,
1287
- venue: m.venue ? parseVenue(m.venue) : void 0,
1288
- poll: m.poll ? parsePoll(m.poll) : void 0,
1289
- // new_chat_members?: User[];
1290
- // left_chat_member?: User;
1291
- // new_chat_title?: string;
1292
- // new_chat_photo?: PhotoSize[];
1293
- // delete_chat_photo?: boolean;
1294
- // group_chat_created?: boolean;
1295
- // supergroup_chat_created?: boolean;
1296
- // channel_chat_created?: boolean;
1297
- // migrate_to_chat_id?: number;
1298
- // migrate_from_chat_id?: number;
1299
- // pinned_message?: Message;
1300
- // invoice?: Invoice;
1301
- // successful_payment?: SuccessfulPayment;
1302
- // connected_website?: string;
1303
- // passport_data?: PassportData;
1304
- // reply_markup?: InlineKeyboardMarkup;
1305
- sender_chat: m.sender_chat ? parseChat(m.sender_chat) : void 0,
1306
- }
1307
- }
1308
-
1309
- export function parseUser(u: User) {
1310
- return {
1311
- id: String(u.id),
1312
- is_bot: Boolean(u.is_bot),
1313
- first_name: String(u.first_name),
1314
- last_name: String(u.last_name ?? ""),
1315
- username: String(u.username ?? ""),
1316
- language_code: String(u.language_code ?? ""),
1317
- }
1318
- }
1319
-
1320
- export function parseChat(c: Chat) {
1321
- return {
1322
- id: Number(c.id),
1323
- type: c.type,
1324
- title: String(c.title ?? ""),
1325
- username: String(c.username ?? ""),
1326
- first_name: String(c.first_name ?? ""),
1327
- last_name: String(c.last_name ?? ""),
1328
- }
1329
- }
1330
-
1331
- export function parsePhotoSizes(p: PhotoSize[]) {
1332
- if (!Array.isArray(p)) {
1333
- return void 0
1334
- }
1335
-
1336
- return p.map(parsePhotoSize)
1337
- }
1338
-
1339
- export function parsePhotoSize(p: PhotoSize) {
1340
- return {
1341
- file_id: String(p.file_id),
1342
- file_size: Number(p.file_size),
1343
- width: Number(p.width),
1344
- height: Number(p.height),
1345
- }
1346
- }
1347
-
1348
- export function parseSticker(v: Sticker): Sticker {
1349
- return {
1350
- file_id: String(v.file_id),
1351
- width: Number(v.width),
1352
- height: Number(v.height),
1353
- thumb: v.thumb ? parsePhotoSize(v.thumb) : void 0,
1354
- emoji: String(v.emoji),
1355
- }
1356
- }
1357
-
1358
- export function parseVideo(v: Video): Video {
1359
- return {
1360
- file_id: String(v.file_id),
1361
- width: Number(v.width),
1362
- height: Number(v.height),
1363
- duration: Number(v.duration),
1364
- thumb: v.thumb ? parsePhotoSize(v.thumb) : void 0,
1365
- mime_type: String(v.mime_type ?? ""),
1366
- file_name: String(v.file_name ?? ""),
1367
- file_size: Number(v.file_size ?? ""),
1368
- }
1369
- }
1370
-
1371
- export function parseVoice(v: Voice): Voice {
1372
- return {
1373
- file_id: String(v.file_id),
1374
- file_size: Number(v.file_size),
1375
- duration: Number(v.duration),
1376
- mime_type: String(v.mime_type)
1377
- }
1378
- }
1379
-
1380
- export function parseVideoNote(v: VideoNote): VideoNote {
1381
- return {
1382
- file_id: String(v.file_id),
1383
- length: Number(v.length),
1384
- duration: Number(v.duration),
1385
- thumb: v.thumb ? parsePhotoSize(v.thumb) : void 0,
1386
- }
1387
- }
1388
-
1389
- export function parseEntities(v: MessageEntity[]): MessageEntity[] {
1390
- if (!Array.isArray(v)) {
1391
- return []
1392
- }
1393
-
1394
- return v.map(function (entity) {
1395
- return {
1396
- type: entity.type,
1397
- offset: entity.offset,
1398
- length: entity.length,
1399
- url: String(entity.url ?? ""),
1400
- user: entity.user ? parseUser(entity.user) : void 0,
1401
- }
1402
- })
1403
- }
1404
-
1405
- export function parseAudio(v: Audio): Audio {
1406
- return {
1407
- file_id: String(v.file_id),
1408
- duration: Number(v.duration),
1409
- title: String(v.title ?? ""),
1410
- performer: String(v.performer ?? ""),
1411
- file_name: String(v.file_name ?? ""),
1412
- mime_type: String(v.mime_type ?? ""),
1413
- }
1414
- }
1415
-
1416
- export function parseDocument(v: Document): Document {
1417
- return {
1418
- file_id: String(v.file_id),
1419
- file_name: String(v.file_name || ""),
1420
- mime_type: String(v.mime_type || ""),
1421
- file_size: Number(v.file_size || 0),
1422
- }
1423
- }
1424
-
1425
- export function parseAnimation(v: Animation) {
1426
- return {
1427
- file_id: String(v.file_id),
1428
- width: Number(v.width),
1429
- height: Number(v.height),
1430
- duration: Number(v.duration),
1431
- file_name: String(v.file_name),
1432
- mime_type: String(v.mime_type || ""),
1433
- }
1434
- }
1435
-
1436
- export function parseContact(v: Contact) {
1437
- return {
1438
- phone_number: String(v.phone_number),
1439
- first_name: String(v.first_name),
1440
- last_name: String(v.last_name ?? ""),
1441
- user_id: Number(v.user_id ?? ""),
1442
- vcard: String(v.vcard ?? ""),
1443
- }
1444
- }
1445
-
1446
- export function parseLocation(v: Location) {
1447
- return {
1448
- longitude: Number(v.longitude),
1449
- latitude: Number(v.latitude),
1450
- }
1451
- }
1452
-
1453
- export function parseVenue(v: Venue) {
1454
- return {
1455
- location: parseLocation(v.location),
1456
- title: String(v.title),
1457
- address: String(v.address),
1458
- foursquare_id: String(v.foursquare_id ?? ""),
1459
- foursquare_type: String(v.foursquare_type ?? ""),
1460
- google_place_id: String(v.google_place_id ?? ""),
1461
- google_place_type: String(v.google_place_type ?? ""),
1462
- }
1463
- }
1464
-
1465
- export function parsePoll(v: Poll) {
1466
- return {
1467
- id: String(v.id),
1468
- question: String(v.question),
1469
- options: parsePollOptions(v.options),
1470
- is_closed: Boolean(v.is_closed),
1471
- }
1472
- }
1473
-
1474
- export function parsePollOptions(v: PollOption[]) {
1475
- return Array.isArray(v) ? v.map(parsePollOption) : []
1476
- }
1477
-
1478
- export function parsePollOption(v: PollOption) {
1479
- return {
1480
- text: String(v.text),
1481
- voter_count: Number(v.voter_count),
1482
- }
1483
- }
1484
-
1485
- /**
1486
- * @see https://core.telegram.org/bots/api#callbackquery
1487
- */
1488
- export function parseCallbackQuery(v?: CallbackQuery): CallbackQuery | undefined {
1489
- if (!v) {
1490
- return
1491
- }
1492
-
1493
- return {
1494
- id: String(v.id),
1495
- from: parseUser(v.from),
1496
- data: String(v.data ?? ""),
1497
- message: parseMessage(v.message),
1498
- chat_instance: String(v.chat_instance ?? ""),
1499
- }
1500
- }
1501
-
1502
- function parseMessageReaction(d?: MessageReactionUpdated): MessageReactionUpdated | undefined {
1503
- if (!d) {
1504
- return
1505
- }
1506
-
1507
- return {
1508
- chat: parseChat(d.chat),
1509
- message_id: Number(d.message_id),
1510
- user: d.user ? parseUser(d.user) : void 0,
1511
- actor_chat: d.actor_chat ? parseChat(d.actor_chat) : void 0,
1512
- date: Number(d.date),
1513
- old_reaction: parseReactions(d.old_reaction),
1514
- new_reaction: parseReactions(d.new_reaction),
1515
- }
1516
- }
1517
-
1518
- function parseReactions(reactions: ReactionType[]): ReactionType[] {
1519
- if (!Array.isArray(reactions)) {
1520
- return []
1521
- }
1522
-
1523
- return reactions.map(parseReaction)
1524
- }
1525
-
1526
- function parseReaction(reaction: ReactionType): ReactionType {
1527
- if (reaction.type === "emoji") {
1528
- return {
1529
- type: "emoji",
1530
- emoji: String(reaction.emoji),
1531
- }
1532
- }
1533
-
1534
- if (reaction.type === "custom_emoji") {
1535
- return {
1536
- type: "custom_emoji",
1537
- custom_emoji_id: String(reaction.custom_emoji_id),
1538
- }
1539
- }
1540
-
1541
- throw new RangeError(`Unknown type of reaction: ${JSON.stringify(reaction)}`)
1542
- }
1543
-
1544
- function parseMessageReactionCount(d?: MessageReactionCountUpdated): MessageReactionCountUpdated | undefined {
1545
- if (!d) {
1546
- return d
1547
- }
1548
-
1549
- return {
1550
- chat: parseChat(d.chat),
1551
- message_id: Number(d.message_id),
1552
- date: Number(d.date),
1553
- reactions: parseReactionsCount(d.reactions)
1554
- }
1555
- }
1556
-
1557
- function parseReactionsCount(reactions?: ReactionCount[]): ReactionCount[] {
1558
- if (!Array.isArray(reactions)) {
1559
- return []
1560
- }
1561
-
1562
- return reactions.map(parseReactionCount)
1563
- }
1564
-
1565
- function parseReactionCount(reaction: ReactionCount): ReactionCount {
1566
- return {
1567
- type: parseReaction(reaction.type),
1568
- total_count: Number(reaction.total_count),
1569
- }
1570
- }
1571
-
1572
- function parseResponse<T>(response: Response) {
1573
- return response.text().then(function (text) {
1574
- let data: any
1575
-
1576
- try {
1577
- data = JSON.parse(text)
1578
- }
1579
- catch (err) {
1580
- throw new TelegramError(`Invalid response: ${text}`, response.status)
1581
- }
1582
-
1583
- const ok = Boolean(data.ok)
1584
-
1585
- if (ok) {
1586
- return data.result as T
1587
- }
1588
-
1589
- const error_code = Number(data.error_code ?? 0)
1590
- const description = String(data.description ?? "")
1591
-
1592
- throw new TelegramError(description, response.status)
1593
- })
1594
- }
1595
-
1596
- export class TelegramError extends Error {
1597
- status: number
1598
-
1599
- constructor(message: string, status: number) {
1600
- super(message)
1601
-
1602
- this.status = status
1603
- }
1604
- }
1605
-
1606
- /**
1607
- * Helpers
1608
- */
1609
- export const SUPPORTED_REACTION_EMOJI = ["๐Ÿ‘", "๐Ÿ‘Ž", "\u2764\ufe0f" // red heart
1610
- , "๐Ÿ”ฅ", "๐Ÿฅฐ", "๐Ÿ‘", "๐Ÿ˜", "๐Ÿค”", "๐Ÿคฏ", "๐Ÿ˜ฑ", "๐Ÿคฌ", "๐Ÿ˜ข"
1611
- , "๐ŸŽ‰", "๐Ÿคฉ", "๐Ÿคฎ", "๐Ÿ’ฉ", "๐Ÿ™", "๐Ÿ‘Œ", "๐Ÿ•Š", "๐Ÿคก", "๐Ÿฅฑ", "๐Ÿฅด", "๐Ÿ˜", "๐Ÿณ", "โคโ€๐Ÿ”ฅ"
1612
- , "๐ŸŒš", "๐ŸŒญ", "๐Ÿ’ฏ", "๐Ÿคฃ", "โšก", "๐ŸŒ", "๐Ÿ†", "๐Ÿ’”", "๐Ÿคจ", "๐Ÿ˜", "๐Ÿ“", "๐Ÿพ", "๐Ÿ’‹"
1613
- , "๐Ÿ–•", "๐Ÿ˜ˆ", "๐Ÿ˜ด", "๐Ÿ˜ญ", "๐Ÿค“", "๐Ÿ‘ป", "๐Ÿ‘จโ€๐Ÿ’ป", "๐Ÿ‘€", "๐ŸŽƒ", "๐Ÿ™ˆ", "๐Ÿ˜‡", "๐Ÿ˜จ", "๐Ÿค"
1614
- , "โœ", "๐Ÿค—", "๐Ÿซก", "๐ŸŽ…", "๐ŸŽ„", "โ˜ƒ", "๐Ÿ’…", "๐Ÿคช", "๐Ÿ—ฟ", "๐Ÿ†’", "๐Ÿ’˜", "๐Ÿ™‰", "๐Ÿฆ„"
1615
- , "๐Ÿ˜˜", "๐Ÿ’Š", "๐Ÿ™Š", "๐Ÿ˜Ž", "๐Ÿ‘พ", "๐Ÿคทโ€โ™‚", "๐Ÿคท", "๐Ÿคทโ€โ™€", "๐Ÿ˜ก"
1616
- ]