-
Notifications
You must be signed in to change notification settings - Fork 7
/
client.ts
6262 lines (6001 loc) · 204 KB
/
client.ts
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
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging, @typescript-eslint/unified-signatures */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* THIS FILE WAS AUTO-GENERATED */
import EventEmitter from 'events'
import Long from 'long'
import { tdFileId } from '@mtcute/file-id'
import { tl } from '@mtcute/tl'
import { RpcCallOptions } from '../network/index.js'
import { MaybeArray, MaybePromise, MtUnsupportedError, PartialExcept, PartialOnly } from '../types/index.js'
import { BaseTelegramClient, BaseTelegramClientOptions } from './base.js'
import { ITelegramClient } from './client.types.js'
import { checkPassword } from './methods/auth/check-password.js'
import { getPasswordHint } from './methods/auth/get-password-hint.js'
import { logOut } from './methods/auth/log-out.js'
import { recoverPassword } from './methods/auth/recover-password.js'
import { resendCode } from './methods/auth/resend-code.js'
import { run } from './methods/auth/run.js'
import { sendCode } from './methods/auth/send-code.js'
import { sendRecoveryCode } from './methods/auth/send-recovery-code.js'
import { signIn } from './methods/auth/sign-in.js'
import { signInBot } from './methods/auth/sign-in-bot.js'
import { start } from './methods/auth/start.js'
import { startTest } from './methods/auth/start-test.js'
import { isSelfPeer } from './methods/auth/utils.js'
import { answerCallbackQuery } from './methods/bots/answer-callback-query.js'
import { answerInlineQuery } from './methods/bots/answer-inline-query.js'
import { answerPreCheckoutQuery } from './methods/bots/answer-pre-checkout-query.js'
import { deleteMyCommands } from './methods/bots/delete-my-commands.js'
import { getBotInfo } from './methods/bots/get-bot-info.js'
import { getBotMenuButton } from './methods/bots/get-bot-menu-button.js'
import { getCallbackAnswer } from './methods/bots/get-callback-answer.js'
import { getGameHighScores, getInlineGameHighScores } from './methods/bots/get-game-high-scores.js'
import { getMyCommands } from './methods/bots/get-my-commands.js'
import { setBotInfo } from './methods/bots/set-bot-info.js'
import { setBotMenuButton } from './methods/bots/set-bot-menu-button.js'
import { setGameScore, setInlineGameScore } from './methods/bots/set-game-score.js'
import { setMyCommands } from './methods/bots/set-my-commands.js'
import { setMyDefaultRights } from './methods/bots/set-my-default-rights.js'
import { addChatMembers } from './methods/chats/add-chat-members.js'
import { archiveChats } from './methods/chats/archive-chats.js'
import { banChatMember } from './methods/chats/ban-chat-member.js'
import { createChannel } from './methods/chats/create-channel.js'
import { createGroup, CreateGroupResult } from './methods/chats/create-group.js'
import { createSupergroup } from './methods/chats/create-supergroup.js'
import { deleteChannel } from './methods/chats/delete-channel.js'
import { deleteChatPhoto } from './methods/chats/delete-chat-photo.js'
import { deleteGroup } from './methods/chats/delete-group.js'
import { deleteHistory } from './methods/chats/delete-history.js'
import { deleteUserHistory } from './methods/chats/delete-user-history.js'
import { editAdminRights } from './methods/chats/edit-admin-rights.js'
import { getChat } from './methods/chats/get-chat.js'
import { getChatEventLog } from './methods/chats/get-chat-event-log.js'
import { getChatMember } from './methods/chats/get-chat-member.js'
import { getChatMembers } from './methods/chats/get-chat-members.js'
import { getChatPreview } from './methods/chats/get-chat-preview.js'
import { getFullChat } from './methods/chats/get-full-chat.js'
import { getNearbyChats } from './methods/chats/get-nearby-chats.js'
import { getSimilarChannels } from './methods/chats/get-similar-channels.js'
import { iterChatEventLog } from './methods/chats/iter-chat-event-log.js'
import { iterChatMembers } from './methods/chats/iter-chat-members.js'
import { joinChat } from './methods/chats/join-chat.js'
import { kickChatMember } from './methods/chats/kick-chat-member.js'
import { leaveChat } from './methods/chats/leave-chat.js'
import { markChatUnread } from './methods/chats/mark-chat-unread.js'
import { closeChat, openChat } from './methods/chats/open-chat.js'
import { reorderUsernames } from './methods/chats/reorder-usernames.js'
import { restrictChatMember } from './methods/chats/restrict-chat-member.js'
import { saveDraft } from './methods/chats/save-draft.js'
import { setChatColor } from './methods/chats/set-chat-color.js'
import { setChatDefaultPermissions } from './methods/chats/set-chat-default-permissions.js'
import { setChatDescription } from './methods/chats/set-chat-description.js'
import { setChatPhoto } from './methods/chats/set-chat-photo.js'
import { setChatTitle } from './methods/chats/set-chat-title.js'
import { setChatTtl } from './methods/chats/set-chat-ttl.js'
import { setChatUsername } from './methods/chats/set-chat-username.js'
import { setSlowMode } from './methods/chats/set-slow-mode.js'
import { toggleContentProtection } from './methods/chats/toggle-content-protection.js'
import { toggleFragmentUsername } from './methods/chats/toggle-fragment-username.js'
import { toggleJoinRequests } from './methods/chats/toggle-join-requests.js'
import { toggleJoinToSend } from './methods/chats/toggle-join-to-send.js'
import { unarchiveChats } from './methods/chats/unarchive-chats.js'
import { unbanChatMember } from './methods/chats/unban-chat-member.js'
import { addContact } from './methods/contacts/add-contact.js'
import { deleteContacts } from './methods/contacts/delete-contacts.js'
import { getContacts } from './methods/contacts/get-contacts.js'
import { importContacts } from './methods/contacts/import-contacts.js'
import { createFolder } from './methods/dialogs/create-folder.js'
import { deleteFolder } from './methods/dialogs/delete-folder.js'
import { editFolder } from './methods/dialogs/edit-folder.js'
import { findFolder } from './methods/dialogs/find-folder.js'
import { getFolders } from './methods/dialogs/get-folders.js'
import { getPeerDialogs } from './methods/dialogs/get-peer-dialogs.js'
import { iterDialogs } from './methods/dialogs/iter-dialogs.js'
import { setFoldersOrder } from './methods/dialogs/set-folders-order.js'
import { downloadAsBuffer } from './methods/files/download-buffer.js'
import { downloadAsIterable } from './methods/files/download-iterable.js'
import { downloadAsStream } from './methods/files/download-stream.js'
import { _normalizeInputFile } from './methods/files/normalize-input-file.js'
import { _normalizeInputMedia } from './methods/files/normalize-input-media.js'
import { uploadFile } from './methods/files/upload-file.js'
import { uploadMedia } from './methods/files/upload-media.js'
import { createForumTopic } from './methods/forums/create-forum-topic.js'
import { deleteForumTopicHistory } from './methods/forums/delete-forum-topic-history.js'
import { editForumTopic } from './methods/forums/edit-forum-topic.js'
import { getForumTopics, GetForumTopicsOffset } from './methods/forums/get-forum-topics.js'
import { getForumTopicsById } from './methods/forums/get-forum-topics-by-id.js'
import { iterForumTopics } from './methods/forums/iter-forum-topics.js'
import { reorderPinnedForumTopics } from './methods/forums/reorder-pinned-forum-topics.js'
import { toggleForum } from './methods/forums/toggle-forum.js'
import { toggleForumTopicClosed } from './methods/forums/toggle-forum-topic-closed.js'
import { toggleForumTopicPinned } from './methods/forums/toggle-forum-topic-pinned.js'
import { toggleGeneralTopicHidden } from './methods/forums/toggle-general-topic-hidden.js'
import { createInviteLink } from './methods/invite-links/create-invite-link.js'
import { editInviteLink } from './methods/invite-links/edit-invite-link.js'
import { exportInviteLink } from './methods/invite-links/export-invite-link.js'
import { getInviteLink } from './methods/invite-links/get-invite-link.js'
import { getInviteLinkMembers } from './methods/invite-links/get-invite-link-members.js'
import { getInviteLinks, GetInviteLinksOffset } from './methods/invite-links/get-invite-links.js'
import { getPrimaryInviteLink } from './methods/invite-links/get-primary-invite-link.js'
import { hideAllJoinRequests } from './methods/invite-links/hide-all-join-requests.js'
import { hideJoinRequest } from './methods/invite-links/hide-join-request.js'
import { iterInviteLinkMembers } from './methods/invite-links/iter-invite-link-members.js'
import { iterInviteLinks } from './methods/invite-links/iter-invite-links.js'
import { revokeInviteLink } from './methods/invite-links/revoke-invite-link.js'
import { closePoll } from './methods/messages/close-poll.js'
import { deleteMessages, deleteMessagesById, DeleteMessagesParams } from './methods/messages/delete-messages.js'
import { deleteScheduledMessages } from './methods/messages/delete-scheduled-messages.js'
import { editInlineMessage } from './methods/messages/edit-inline-message.js'
import { editMessage } from './methods/messages/edit-message.js'
import { ForwardMessageOptions, forwardMessages, forwardMessagesById } from './methods/messages/forward-messages.js'
import { getAllScheduledMessages } from './methods/messages/get-all-scheduled-messages.js'
import { getCallbackQueryMessage } from './methods/messages/get-callback-query-message.js'
import { getDiscussionMessage } from './methods/messages/get-discussion-message.js'
import { getHistory, GetHistoryOffset } from './methods/messages/get-history.js'
import { getMessageByLink } from './methods/messages/get-message-by-link.js'
import { getMessageGroup } from './methods/messages/get-message-group.js'
import { getMessageReactions, getMessageReactionsById } from './methods/messages/get-message-reactions.js'
import { getMessages } from './methods/messages/get-messages.js'
import { getMessagesUnsafe } from './methods/messages/get-messages-unsafe.js'
import { getReactionUsers, GetReactionUsersOffset } from './methods/messages/get-reaction-users.js'
import { getReplyTo } from './methods/messages/get-reply-to.js'
import { getScheduledMessages } from './methods/messages/get-scheduled-messages.js'
import { iterHistory } from './methods/messages/iter-history.js'
import { iterReactionUsers } from './methods/messages/iter-reaction-users.js'
import { iterSearchGlobal } from './methods/messages/iter-search-global.js'
import { iterSearchMessages } from './methods/messages/iter-search-messages.js'
import { pinMessage } from './methods/messages/pin-message.js'
import { readHistory } from './methods/messages/read-history.js'
import { readReactions } from './methods/messages/read-reactions.js'
import { searchGlobal, SearchGlobalOffset } from './methods/messages/search-global.js'
import { searchMessages, SearchMessagesOffset } from './methods/messages/search-messages.js'
import { answerMedia, answerMediaGroup, answerText } from './methods/messages/send-answer.js'
import { commentMedia, commentMediaGroup, commentText } from './methods/messages/send-comment.js'
import { CommonSendParams } from './methods/messages/send-common.js'
import { sendCopy, SendCopyParams } from './methods/messages/send-copy.js'
import { sendCopyGroup, SendCopyGroupParams } from './methods/messages/send-copy-group.js'
import { sendMedia } from './methods/messages/send-media.js'
import { sendMediaGroup } from './methods/messages/send-media-group.js'
import { QuoteParamsFrom, quoteWithMedia, quoteWithMediaGroup, quoteWithText } from './methods/messages/send-quote.js'
import { sendReaction } from './methods/messages/send-reaction.js'
import { replyMedia, replyMediaGroup, replyText } from './methods/messages/send-reply.js'
import { sendScheduled } from './methods/messages/send-scheduled.js'
import { sendText } from './methods/messages/send-text.js'
import { sendTyping } from './methods/messages/send-typing.js'
import { sendVote } from './methods/messages/send-vote.js'
import { translateMessage } from './methods/messages/translate-message.js'
import { translateText } from './methods/messages/translate-text.js'
import { unpinAllMessages } from './methods/messages/unpin-all-messages.js'
import { unpinMessage } from './methods/messages/unpin-message.js'
import { getCollectibleInfo } from './methods/misc/get-collectible-info.js'
import { initTakeoutSession } from './methods/misc/init-takeout-session.js'
import { _normalizePrivacyRules } from './methods/misc/normalize-privacy-rules.js'
import { withParams } from './methods/misc/with-params.js'
import { changeCloudPassword } from './methods/password/change-cloud-password.js'
import { enableCloudPassword } from './methods/password/enable-cloud-password.js'
import { cancelPasswordEmail, resendPasswordEmail, verifyPasswordEmail } from './methods/password/password-email.js'
import { removeCloudPassword } from './methods/password/remove-cloud-password.js'
import { applyBoost } from './methods/premium/apply-boost.js'
import { canApplyBoost, CanApplyBoostResult } from './methods/premium/can-apply-boost.js'
import { createBusinessChatLink } from './methods/premium/create-business-chat-link.js'
import { deleteBusinessChatLink, editBusinessChatLink } from './methods/premium/edit-business-chat-link.js'
import { getBoostStats } from './methods/premium/get-boost-stats.js'
import { getBoosts } from './methods/premium/get-boosts.js'
import { getBusinessChatLinks } from './methods/premium/get-business-chat-links.js'
import { getBusinessConnection } from './methods/premium/get-business-connection.js'
import { getMyBoostSlots } from './methods/premium/get-my-boost-slots.js'
import { iterBoosters } from './methods/premium/iter-boosters.js'
import { setBusinessIntro } from './methods/premium/set-business-intro.js'
import { setBusinessWorkHours } from './methods/premium/set-business-work-hours.js'
import { addStickerToSet } from './methods/stickers/add-sticker-to-set.js'
import { createStickerSet } from './methods/stickers/create-sticker-set.js'
import { deleteStickerFromSet } from './methods/stickers/delete-sticker-from-set.js'
import { getCustomEmojis, getCustomEmojisFromMessages } from './methods/stickers/get-custom-emojis.js'
import { getInstalledStickers } from './methods/stickers/get-installed-stickers.js'
import { getMyStickerSets } from './methods/stickers/get-my-sticker-sets.js'
import { getStickerSet } from './methods/stickers/get-sticker-set.js'
import { moveStickerInSet } from './methods/stickers/move-sticker-in-set.js'
import { replaceStickerInSet } from './methods/stickers/replace-sticker-in-set.js'
import { setChatStickerSet } from './methods/stickers/set-chat-sticker-set.js'
import { setStickerSetThumb } from './methods/stickers/set-sticker-set-thumb.js'
import { canSendStory, CanSendStoryResult } from './methods/stories/can-send-story.js'
import { deleteStories } from './methods/stories/delete-stories.js'
import { editStory } from './methods/stories/edit-story.js'
import { getAllStories } from './methods/stories/get-all-stories.js'
import { getPeerStories } from './methods/stories/get-peer-stories.js'
import { getProfileStories } from './methods/stories/get-profile-stories.js'
import { getStoriesById } from './methods/stories/get-stories-by-id.js'
import { getStoriesInteractions } from './methods/stories/get-stories-interactions.js'
import { getStoryLink } from './methods/stories/get-story-link.js'
import { getStoryViewers } from './methods/stories/get-story-viewers.js'
import { hideMyStoriesViews } from './methods/stories/hide-my-stories-views.js'
import { incrementStoriesViews } from './methods/stories/increment-stories-views.js'
import { iterAllStories } from './methods/stories/iter-all-stories.js'
import { iterProfileStories } from './methods/stories/iter-profile-stories.js'
import { iterStoryViewers } from './methods/stories/iter-story-viewers.js'
import { readStories } from './methods/stories/read-stories.js'
import { reportStory } from './methods/stories/report-story.js'
import { sendStory } from './methods/stories/send-story.js'
import { sendStoryReaction } from './methods/stories/send-story-reaction.js'
import { togglePeerStoriesArchived } from './methods/stories/toggle-peer-stories-archived.js'
import { toggleStoriesPinned } from './methods/stories/toggle-stories-pinned.js'
import { blockUser } from './methods/users/block-user.js'
import { deleteProfilePhotos } from './methods/users/delete-profile-photos.js'
import { editCloseFriends, editCloseFriendsRaw } from './methods/users/edit-close-friends.js'
import { getCommonChats } from './methods/users/get-common-chats.js'
import { getGlobalTtl } from './methods/users/get-global-ttl.js'
import { getMe } from './methods/users/get-me.js'
import { getMyUsername } from './methods/users/get-my-username.js'
import { getProfilePhoto } from './methods/users/get-profile-photo.js'
import { getProfilePhotos } from './methods/users/get-profile-photos.js'
import { getUsers } from './methods/users/get-users.js'
import { iterProfilePhotos } from './methods/users/iter-profile-photos.js'
import { resolveChannel, resolvePeer, resolveUser } from './methods/users/resolve-peer.js'
import { resolvePeerMany } from './methods/users/resolve-peer-many.js'
import { setGlobalTtl } from './methods/users/set-global-ttl.js'
import { setMyBirthday } from './methods/users/set-my-birthday.js'
import { setMyEmojiStatus } from './methods/users/set-my-emoji-status.js'
import { setMyProfilePhoto } from './methods/users/set-my-profile-photo.js'
import { setMyUsername } from './methods/users/set-my-username.js'
import { setOffline } from './methods/users/set-offline.js'
import { unblockUser } from './methods/users/unblock-user.js'
import { updateProfile } from './methods/users/update-profile.js'
import { ITelegramStorageProvider } from './storage/provider.js'
import { Conversation } from './types/conversation.js'
import {
AllStories,
ArrayPaginated,
ArrayWithTotal,
Boost,
BoostSlot,
BoostStats,
BotChatJoinRequestUpdate,
BotCommands,
BotReactionCountUpdate,
BotReactionUpdate,
BotStoppedUpdate,
BusinessChatLink,
BusinessConnection,
BusinessMessage,
BusinessWorkHoursDay,
CallbackQuery,
Chat,
ChatEvent,
ChatInviteLink,
ChatInviteLinkMember,
ChatJoinRequestUpdate,
ChatMember,
ChatMemberUpdate,
ChatPreview,
ChosenInlineResult,
CollectibleInfo,
DeleteBusinessMessageUpdate,
DeleteMessageUpdate,
DeleteStoryUpdate,
Dialog,
FileDownloadLocation,
FileDownloadParameters,
ForumTopic,
FullChat,
GameHighScore,
HistoryReadUpdate,
InlineCallbackQuery,
InlineQuery,
InputChatEventFilters,
InputDialogFolder,
InputFileLike,
InputInlineResult,
InputMediaLike,
InputMediaSticker,
InputMessageId,
InputPeerLike,
InputPrivacyRule,
InputReaction,
InputStickerSet,
InputStickerSetItem,
InputText,
MaybeDynamic,
Message,
MessageMedia,
MessageReactions,
ParametersSkip2,
ParsedUpdate,
PeerReaction,
PeersIndex,
PeerStories,
Photo,
Poll,
PollUpdate,
PollVoteUpdate,
PreCheckoutQuery,
RawDocument,
ReplyMarkup,
SentCode,
Sticker,
StickerSet,
StickerSourceType,
StickerType,
StoriesStealthMode,
Story,
StoryInteractions,
StoryUpdate,
StoryViewer,
StoryViewersList,
TakeoutSession,
TextWithEntities,
TypingStatus,
UploadedFile,
UploadFileLike,
User,
UserStatusUpdate,
UserTypingUpdate,
} from './types/index.js'
import { makeParsedUpdateHandler, ParsedUpdateHandlerParams } from './updates/parsed.js'
import { StringSessionData } from './utils/string-session.js'
// from methods/_init.ts
// @copy
type TelegramClientOptions = (
| (PartialOnly<Omit<BaseTelegramClientOptions, 'storage'>, 'transport' | 'crypto'> & {
/**
* Storage to use for this client.
*
* If a string is passed, it will be used as
* a name for the default platform-specific storage provider to use.
*
* @default `"client.session"`
*/
storage?: string | ITelegramStorageProvider
})
| { client: ITelegramClient }
) & {
updates?: Omit<ParsedUpdateHandlerParams, 'onUpdate'>
/**
* If `true`, the updates that were handled by some {@link Conversation}
* will not be dispatched any further.
*
* @default true
*/
skipConversationUpdates?: boolean
}
export interface TelegramClient extends ITelegramClient {
/**
* Register a raw update handler
*
* @param name Event name
* @param handler Raw update handler
*/
on(name: 'raw_update', handler: (upd: tl.TypeUpdate | tl.TypeMessage, peers: PeersIndex) => void): this
/**
* Register a parsed update handler
*
* @param name Event name
* @param handler Raw update handler
*/
on(name: 'update', handler: (upd: ParsedUpdate) => void): this
/**
* Register a new message handler
*
* @param name Event name
* @param handler New message handler
*/
on(name: 'new_message', handler: (upd: Message) => void): this
/**
* Register an edit message handler
*
* @param name Event name
* @param handler Edit message handler
*/
on(name: 'edit_message', handler: (upd: Message) => void): this
/**
* Register a message group handler
*
* @param name Event name
* @param handler Message group handler
*/
on(name: 'message_group', handler: (upd: Message[]) => void): this
/**
* Register a delete message handler
*
* @param name Event name
* @param handler Delete message handler
*/
on(name: 'delete_message', handler: (upd: DeleteMessageUpdate) => void): this
/**
* Register a chat member update handler
*
* @param name Event name
* @param handler Chat member update handler
*/
on(name: 'chat_member', handler: (upd: ChatMemberUpdate) => void): this
/**
* Register an inline query handler
*
* @param name Event name
* @param handler Inline query handler
*/
on(name: 'inline_query', handler: (upd: InlineQuery) => void): this
/**
* Register a chosen inline result handler
*
* @param name Event name
* @param handler Chosen inline result handler
*/
on(name: 'chosen_inline_result', handler: (upd: ChosenInlineResult) => void): this
/**
* Register a callback query handler
*
* @param name Event name
* @param handler Callback query handler
*/
on(name: 'callback_query', handler: (upd: CallbackQuery) => void): this
/**
* Register an inline callback query handler
*
* @param name Event name
* @param handler Inline callback query handler
*/
on(name: 'inline_callback_query', handler: (upd: InlineCallbackQuery) => void): this
/**
* Register a poll update handler
*
* @param name Event name
* @param handler Poll update handler
*/
on(name: 'poll', handler: (upd: PollUpdate) => void): this
/**
* Register a poll vote handler
*
* @param name Event name
* @param handler Poll vote handler
*/
on(name: 'poll_vote', handler: (upd: PollVoteUpdate) => void): this
/**
* Register an user status update handler
*
* @param name Event name
* @param handler User status update handler
*/
on(name: 'user_status', handler: (upd: UserStatusUpdate) => void): this
/**
* Register an user typing handler
*
* @param name Event name
* @param handler User typing handler
*/
on(name: 'user_typing', handler: (upd: UserTypingUpdate) => void): this
/**
* Register a history read handler
*
* @param name Event name
* @param handler History read handler
*/
on(name: 'history_read', handler: (upd: HistoryReadUpdate) => void): this
/**
* Register a bot stopped handler
*
* @param name Event name
* @param handler Bot stopped handler
*/
on(name: 'bot_stopped', handler: (upd: BotStoppedUpdate) => void): this
/**
* Register a bot chat join request handler
*
* @param name Event name
* @param handler Bot chat join request handler
*/
on(name: 'bot_chat_join_request', handler: (upd: BotChatJoinRequestUpdate) => void): this
/**
* Register a chat join request handler
*
* @param name Event name
* @param handler Chat join request handler
*/
on(name: 'chat_join_request', handler: (upd: ChatJoinRequestUpdate) => void): this
/**
* Register a pre checkout query handler
*
* @param name Event name
* @param handler Pre checkout query handler
*/
on(name: 'pre_checkout_query', handler: (upd: PreCheckoutQuery) => void): this
/**
* Register a story update handler
*
* @param name Event name
* @param handler Story update handler
*/
on(name: 'story', handler: (upd: StoryUpdate) => void): this
/**
* Register a delete story handler
*
* @param name Event name
* @param handler Delete story handler
*/
on(name: 'delete_story', handler: (upd: DeleteStoryUpdate) => void): this
/**
* Register a bot reaction update handler
*
* @param name Event name
* @param handler Bot reaction update handler
*/
on(name: 'bot_reaction', handler: (upd: BotReactionUpdate) => void): this
/**
* Register a bot reaction count update handler
*
* @param name Event name
* @param handler Bot reaction count update handler
*/
on(name: 'bot_reaction_count', handler: (upd: BotReactionCountUpdate) => void): this
/**
* Register a business connection update handler
*
* @param name Event name
* @param handler Business connection update handler
*/
on(name: 'business_connection', handler: (upd: BusinessConnection) => void): this
/**
* Register a new business message handler
*
* @param name Event name
* @param handler New business message handler
*/
on(name: 'new_business_message', handler: (upd: BusinessMessage) => void): this
/**
* Register an edit business message handler
*
* @param name Event name
* @param handler Edit business message handler
*/
on(name: 'edit_business_message', handler: (upd: BusinessMessage) => void): this
/**
* Register a business message group handler
*
* @param name Event name
* @param handler Business message group handler
*/
on(name: 'business_message_group', handler: (upd: BusinessMessage[]) => void): this
/**
* Register a delete business message handler
*
* @param name Event name
* @param handler Delete business message handler
*/
on(name: 'delete_business_message', handler: (upd: DeleteBusinessMessageUpdate) => void): this
// eslint-disable-next-line @typescript-eslint/no-explicit-any
on(name: string, handler: (...args: any[]) => void): this
/**
* Wrap this client so that all RPC calls will use the specified parameters.
*
* @param params Parameters to use
* @returns Wrapped client
*/
withParams(params: RpcCallOptions): this
/**
* Check your Two-Step verification password and log in
*
* **Available**: 👤 users only
*
* @param password Your Two-Step verification password
* @returns The authorized user
* @throws BadRequestError In case the password is invalid
*/
checkPassword(password: string): Promise<User>
/**
* Get your Two-Step Verification password hint.
*
* **Available**: 👤 users only
*
* @returns The password hint as a string, if any
*/
getPasswordHint(): Promise<string | null>
/**
* Log out from Telegram account and optionally reset the session storage.
*
* When you log out, you can immediately log back in using
* the same {@link TelegramClient} instance.
*
* **Available**: ✅ both users and bots
*
* @returns On success, `true` is returned
*/
logOut(): Promise<true>
/**
* Recover your password with a recovery code and log in.
*
* **Available**: 👤 users only
*
* @returns The authorized user
* @throws BadRequestError In case the code is invalid
*/
recoverPassword(params: {
/** The recovery code sent via email */
recoveryCode: string
}): Promise<User>
/**
* Re-send the confirmation code using a different type.
*
* The type of the code to be re-sent is specified in the `nextType` attribute of
* {@link SentCode} object returned by {@link sendCode}
* **Available**: 👤 users only
*
*/
resendCode(params: {
/** Phone number in international format */
phone: string
/** Confirmation code identifier from {@link SentCode} */
phoneCodeHash: string
}): Promise<SentCode>
/**
* Simple wrapper that calls {@link start} and then
* provided callback function (if any) without the
* need to introduce a `main()` function manually.
*
* Errors that were encountered while calling {@link start}
* and `then` will be emitted as usual, and can be caught with {@link onError}
*
* **Available**: ✅ both users and bots
*
* @param params Parameters to be passed to {@link start}
* @param then Function to be called after {@link start} returns
*/
run(params: Parameters<typeof start>[1], then?: (user: User) => void | Promise<void>): void
/**
* Send the confirmation code to the given phone number
*
* **Available**: 👤 users only
*
* @returns An object containing information about the sent confirmation code
*/
sendCode(params: {
/** Phone number in international format */
phone: string
}): Promise<SentCode>
/**
* Send a code to email needed to recover your password
*
* **Available**: 👤 users only
*
* @returns String containing email pattern to which the recovery code was sent
*/
sendRecoveryCode(): Promise<string>
/**
* Authorize a bot using its token issued by [@BotFather](//t.me/BotFather)
*
* **Available**: ✅ both users and bots
*
* @param token Bot token issued by BotFather
* @returns Bot's {@link User} object
* @throws BadRequestError In case the bot token is invalid
*/
signInBot(token: string): Promise<User>
/**
* Authorize a user in Telegram with a valid confirmation code.
*
* **Available**: 👤 users only
*
* @returns If the code was valid and authorization succeeded, the {@link User} is returned.
* @throws BadRequestError In case the arguments are invalid
* @throws SessionPasswordNeededError In case a password is needed to sign in
*/
signIn(params: {
/** Phone number in international format */
phone: string
/** Code identifier from {@link sendCode} */
phoneCodeHash: string
/** The confirmation code that was received */
phoneCode: string
}): Promise<User>
/**
* Utility function to quickly authorize on test DC
* using a [Test phone number](https://core.telegram.org/api/auth#test-phone-numbers),
* which is randomly generated by default.
*
* > **Note**: Using this method assumes that you
* > are using a test DC in `primaryDc` parameter.
*
* **Available**: ✅ both users and bots
*
* @param params Additional parameters
*/
startTest(params?: {
/**
* Whether to log out if current session is logged in.
*
* @default false.
*/
logout?: boolean
/**
* Override phone number. Must be a valid Test phone number.
*
* By default is randomly generated.
*/
phone?: string
/**
* Override user's DC. Must be a valid test DC.
*/
dcId?: number
}): Promise<User>
/**
* Start the client in an interactive and declarative manner,
* by providing callbacks for authorization details.
*
* This method handles both login and sign up, and also handles 2FV
*
* All parameters are `MaybeDynamic<T>`, meaning you
* can either supply `T`, or a function that returns `MaybePromise<T>`
*
* This method is intended for simple and fast use in automated
* scripts and bots. If you are developing a custom client,
* you'll probably need to use other auth methods.
* **Available**: ✅ both users and bots
*
*/
start(params: {
/**
* String session exported using {@link TelegramClient.exportSession}.
*
* This simply calls {@link TelegramClient.importSession} before anything else.
*
* Note that passed session will be ignored in case storage already
* contains authorization.
*/
session?: string | StringSessionData
/**
* Whether to overwrite existing session.
*/
sessionForce?: boolean
/**
* Phone number of the account.
* If account does not exist, it will be created
*/
phone?: MaybeDynamic<string>
/**
* Bot token to use. Ignored if `phone` is supplied.
*/
botToken?: MaybeDynamic<string>
/**
* 2FA password. Ignored if `botToken` is supplied
*/
password?: MaybeDynamic<string>
/**
* Code sent to the phone (either sms, call, flash call or other).
* Ignored if `botToken` is supplied, must be present if `phone` is supplied.
*/
code?: MaybeDynamic<string>
/**
* If passed, this function will be called if provided code or 2FA password
* was invalid. New code/password will be requested later.
*
* If provided `code`/`password` is a constant string, providing an
* invalid one will interrupt authorization flow.
*/
invalidCodeCallback?: (type: 'code' | 'password') => MaybePromise<void>
/**
* Whether to force code delivery through SMS
*/
forceSms?: boolean
/**
* Custom method that is called when a code is sent. Can be used
* to show a GUI alert of some kind.
*
* This method is called *before* {@link start.params.code}.
*
* @param code
* @default `console.log`.
*/
codeSentCallback?: (code: SentCode) => MaybePromise<void>
}): Promise<User>
/**
* Check if the given peer/input peer is referring to the current user
* **Available**: ✅ both users and bots
*
*/
isSelfPeer(peer: tl.TypeInputPeer | tl.TypePeer | tl.TypeInputUser): boolean
/**
* Send an answer to a callback query.
*
* **Available**: 🤖 bots only
*
* @param queryId ID of the callback query, or the query itself
* @param params Parameters of the answer
*/
answerCallbackQuery(
queryId: Long | CallbackQuery,
params?: {
/**
* Maximum amount of time in seconds for which
* this result can be cached by the client (not server!).
*
* @default 0
*/
cacheTime?: number
/**
* Text of the notification (0-200 chars).
*
* If not set, nothing will be displayed
*/
text?: string
/**
* Whether to show an alert in the middle of the screen
* instead of a notification at the top of the screen.
*
* @default false
*/
alert?: boolean
/**
* URL that the client should open.
*
* If this was a button containing a game,
* you can provide arbitrary link to your game.
* Otherwise, you can only use links in the format
* `t.me/your_bot?start=...` that open your bot
* with a deep-link parameter.
*/
url?: string
},
): Promise<void>
/**
* Answer an inline query.
*
* **Available**: 🤖 bots only
*
* @param queryId Inline query ID
* @param results Results of the query
* @param params Additional parameters
*/
answerInlineQuery(
queryId: tl.Long | InlineQuery,
results: InputInlineResult[],
params?: {
/**
* Maximum number of time in seconds that the results of the
* query may be cached on the server for.
*
* @default 300
*/
cacheTime?: number
/**
* Whether the results should be displayed as a gallery instead
* of a vertical list. Only applicable to some media types.
*
* In some cases changing this may lead to the results not being
* displayed by the client.
*
* Default is derived automatically based on result types
*/
gallery?: boolean
/**
* Whether the results should only be cached on the server
* for the user who sent the query.
*
* @default false
*/
private?: boolean
/**
* Next pagination offset (up to 64 bytes).
*
* When user has reached the end of the current results,
* the client will re-send the inline query with the same text, but
* with `offset` set to this value.
*
* If omitted or empty string is provided, it is assumed that
* there are no more results.
*/
nextOffset?: string
/**
* If passed, clients will display a button before any other results,
* that when clicked switches the user to a private chat with the bot
* and sends the bot `/start ${parameter}`.
*
* An example from the Bot API docs:
*
* An inline bot that sends YouTube videos can ask the user to connect
* the bot to their YouTube account to adapt search results accordingly.
* To do this, it displays a "Connect your YouTube account" button above
* the results, or even before showing any. The user presses the button,
* switches to a private chat with the bot and, in doing so, passes a start
* parameter that instructs the bot to return an oauth link. Once done, the
* bot can offer a switch_inline button so that the user can easily return to
* the chat where they wanted to use the bot's inline capabilities
*/
switchPm?: {
/**
* Text of the button
*/
text: string
/**
* Parameter for `/start` command
*/
parameter: string
}
/**
* If passed, clients will display a button on top of the remaining inline result
* list with the specified text, that switches the user to the specified bot web app.
*/
switchWebview?: {
/**
* Text of the button
*/
text: string
/**
* URL to open
*/
url: string
}
},
): Promise<void>
/**
* Answer a pre-checkout query.
*
* **Available**: ✅ both users and bots
*
* @param queryId Pre-checkout query ID
*/
answerPreCheckoutQuery(
queryId: tl.Long | PreCheckoutQuery,
params?: {
/** If pre-checkout is rejected, error message to show to the user */
error?: string
},
): Promise<void>
/**
* Delete commands for the current bot and the given scope.
*
* Does the same as passing `null` to {@link setMyCommands}
*
* Learn more about scopes in the [Bot API docs](https://core.telegram.org/bots/api#botcommandscope)
* **Available**: ✅ both users and bots
*
*/
deleteMyCommands(params?: {
/**
* Scope of the commands.
*
* @default `BotScope.default_` (i.e. `botCommandScopeDefault`)
*/
scope?: tl.TypeBotCommandScope | BotCommands.IntermediateScope
/**
* User language applied to the scope.
*/
langCode?: string
}): Promise<void>
/**
* Gets information about a bot the current uzer owns (or the current bot)
* **Available**: ✅ both users and bots
*
*/
getBotInfo(params: {
/**
* When called by a user, a bot the user owns must be specified.
* When called by a bot, must be empty
*/
bot?: InputPeerLike