@core-ease/telegram-kit 3.0.1

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.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +299 -0
  3. package/dist/animation/index.d.mts +4 -0
  4. package/dist/animation/index.d.ts +4 -0
  5. package/dist/animation/index.js +2413 -0
  6. package/dist/animation/index.mjs +5 -0
  7. package/dist/animation/lottie/index.d.mts +10 -0
  8. package/dist/animation/lottie/index.d.ts +10 -0
  9. package/dist/animation/lottie/index.js +2313 -0
  10. package/dist/animation/lottie/index.mjs +4 -0
  11. package/dist/animation/tgs/index.d.mts +18 -0
  12. package/dist/animation/tgs/index.d.ts +18 -0
  13. package/dist/animation/tgs/index.js +2402 -0
  14. package/dist/animation/tgs/index.mjs +4 -0
  15. package/dist/bot/index.d.mts +477 -0
  16. package/dist/bot/index.d.ts +477 -0
  17. package/dist/bot/index.js +870 -0
  18. package/dist/bot/index.mjs +847 -0
  19. package/dist/bot-D8BnLWIi.d.mts +2041 -0
  20. package/dist/bot-D8BnLWIi.d.ts +2041 -0
  21. package/dist/browser.global.js +23 -0
  22. package/dist/chunk-7AARTHNW.mjs +40 -0
  23. package/dist/chunk-7CVYPKAL.mjs +15 -0
  24. package/dist/chunk-B3PWALX5.mjs +4418 -0
  25. package/dist/chunk-BQEUEAVK.mjs +2262 -0
  26. package/dist/chunk-FPWYSKK2.mjs +3089 -0
  27. package/dist/chunk-JXK5HCDV.mjs +254 -0
  28. package/dist/chunk-OMH2JGOH.mjs +88 -0
  29. package/dist/chunk-PXO36YTU.mjs +38 -0
  30. package/dist/core/index.d.mts +151 -0
  31. package/dist/core/index.d.ts +151 -0
  32. package/dist/core/index.js +3837 -0
  33. package/dist/core/index.mjs +495 -0
  34. package/dist/dev/index.d.mts +77 -0
  35. package/dist/dev/index.d.ts +77 -0
  36. package/dist/dev/index.js +3214 -0
  37. package/dist/dev/index.mjs +151 -0
  38. package/dist/engine-BDm1_hzn.d.mts +382 -0
  39. package/dist/engine-BDm1_hzn.d.ts +382 -0
  40. package/dist/format/index.d.mts +61 -0
  41. package/dist/format/index.d.ts +61 -0
  42. package/dist/format/index.js +121 -0
  43. package/dist/format/index.mjs +112 -0
  44. package/dist/hooks/index.d.mts +1 -0
  45. package/dist/hooks/index.d.ts +1 -0
  46. package/dist/hooks/index.js +4234 -0
  47. package/dist/hooks/index.mjs +3 -0
  48. package/dist/hooks-C5Per70R.d.mts +1066 -0
  49. package/dist/hooks-C5Per70R.d.ts +1066 -0
  50. package/dist/index.d.mts +849 -0
  51. package/dist/index.d.ts +849 -0
  52. package/dist/index.js +5026 -0
  53. package/dist/index.mjs +478 -0
  54. package/dist/keyboards/index.d.mts +50 -0
  55. package/dist/keyboards/index.d.ts +50 -0
  56. package/dist/keyboards/index.js +127 -0
  57. package/dist/keyboards/index.mjs +124 -0
  58. package/dist/links/index.d.mts +53 -0
  59. package/dist/links/index.d.ts +53 -0
  60. package/dist/links/index.js +139 -0
  61. package/dist/links/index.mjs +133 -0
  62. package/dist/lottie/index.d.mts +3 -0
  63. package/dist/lottie/index.d.ts +3 -0
  64. package/dist/lottie/index.js +2313 -0
  65. package/dist/lottie/index.mjs +4 -0
  66. package/dist/qr/index.d.mts +75 -0
  67. package/dist/qr/index.d.ts +75 -0
  68. package/dist/qr/index.js +983 -0
  69. package/dist/qr/index.mjs +946 -0
  70. package/dist/sdk/index.d.mts +322 -0
  71. package/dist/sdk/index.d.ts +322 -0
  72. package/dist/sdk/index.js +3138 -0
  73. package/dist/sdk/index.mjs +2 -0
  74. package/dist/server/index.d.mts +28 -0
  75. package/dist/server/index.d.ts +28 -0
  76. package/dist/server/index.js +254 -0
  77. package/dist/server/index.mjs +246 -0
  78. package/dist/tgs/index.d.mts +3 -0
  79. package/dist/tgs/index.d.ts +3 -0
  80. package/dist/tgs/index.js +2402 -0
  81. package/dist/tgs/index.mjs +4 -0
  82. package/dist/webapp-B-3_74nK.d.mts +842 -0
  83. package/dist/webapp-B-3_74nK.d.ts +842 -0
  84. package/dist/webapp-BDi9q3-a.d.mts +42 -0
  85. package/dist/webapp-YvmwFYUQ.d.ts +42 -0
  86. package/package.json +165 -0
@@ -0,0 +1,847 @@
1
+ import { __spreadProps, __spreadValues } from '../chunk-7AARTHNW.mjs';
2
+
3
+ // src/types/bot.ts
4
+ var TelegramApiError = class extends Error {
5
+ constructor(errorCode, description, parameters) {
6
+ super(`Telegram API error ${errorCode}: ${description}`);
7
+ this.errorCode = errorCode;
8
+ this.description = description;
9
+ this.parameters = parameters;
10
+ this.name = "TelegramApiError";
11
+ }
12
+ };
13
+
14
+ // src/_internal/bot/client.ts
15
+ var TelegramBot = class {
16
+ constructor(options) {
17
+ const { token, apiBase = "https://api.telegram.org", timeout = 3e4 } = options;
18
+ this.apiBase = `${apiBase}/bot${token}`;
19
+ this.timeout = timeout;
20
+ }
21
+ async request(method, params) {
22
+ var _a, _b;
23
+ const url = `${this.apiBase}/${method}`;
24
+ const controller = new AbortController();
25
+ const timer = setTimeout(() => controller.abort(), this.timeout);
26
+ try {
27
+ const res = await fetch(url, {
28
+ method: "POST",
29
+ headers: { "Content-Type": "application/json" },
30
+ body: params != null ? JSON.stringify(params) : void 0,
31
+ signal: controller.signal
32
+ });
33
+ const data = await res.json();
34
+ if (!data.ok) {
35
+ throw new TelegramApiError(
36
+ (_a = data.error_code) != null ? _a : res.status,
37
+ (_b = data.description) != null ? _b : "Unknown error",
38
+ data.parameters
39
+ );
40
+ }
41
+ return data.result;
42
+ } finally {
43
+ clearTimeout(timer);
44
+ }
45
+ }
46
+ getUpdates(params) {
47
+ return this.request("getUpdates", params);
48
+ }
49
+ setWebhook(params) {
50
+ return this.request("setWebhook", params);
51
+ }
52
+ deleteWebhook(params) {
53
+ return this.request("deleteWebhook", params);
54
+ }
55
+ getWebhookInfo() {
56
+ return this.request("getWebhookInfo");
57
+ }
58
+ getMe() {
59
+ return this.request("getMe");
60
+ }
61
+ logOut() {
62
+ return this.request("logOut");
63
+ }
64
+ close() {
65
+ return this.request("close");
66
+ }
67
+ setMyDescription(params) {
68
+ return this.request("setMyDescription", params);
69
+ }
70
+ getMyDescription(params) {
71
+ return this.request("getMyDescription", params);
72
+ }
73
+ setMyShortDescription(params) {
74
+ return this.request("setMyShortDescription", params);
75
+ }
76
+ getMyShortDescription(params) {
77
+ return this.request("getMyShortDescription", params);
78
+ }
79
+ setMyName(params) {
80
+ return this.request("setMyName", params);
81
+ }
82
+ getMyName(params) {
83
+ return this.request("getMyName", params);
84
+ }
85
+ sendMessage(params) {
86
+ return this.request("sendMessage", params);
87
+ }
88
+ forwardMessage(params) {
89
+ return this.request("forwardMessage", params);
90
+ }
91
+ forwardMessages(params) {
92
+ return this.request("forwardMessages", params);
93
+ }
94
+ copyMessage(params) {
95
+ return this.request("copyMessage", params);
96
+ }
97
+ copyMessages(params) {
98
+ return this.request("copyMessages", params);
99
+ }
100
+ sendPhoto(params) {
101
+ return this.request("sendPhoto", params);
102
+ }
103
+ sendAudio(params) {
104
+ return this.request("sendAudio", params);
105
+ }
106
+ sendDocument(params) {
107
+ return this.request("sendDocument", params);
108
+ }
109
+ sendVideo(params) {
110
+ return this.request("sendVideo", params);
111
+ }
112
+ sendAnimation(params) {
113
+ return this.request("sendAnimation", params);
114
+ }
115
+ sendVoice(params) {
116
+ return this.request("sendVoice", params);
117
+ }
118
+ sendVideoNote(params) {
119
+ return this.request("sendVideoNote", params);
120
+ }
121
+ sendSticker(params) {
122
+ return this.request("sendSticker", params);
123
+ }
124
+ sendMediaGroup(params) {
125
+ return this.request("sendMediaGroup", params);
126
+ }
127
+ sendLocation(params) {
128
+ return this.request("sendLocation", params);
129
+ }
130
+ sendVenue(params) {
131
+ return this.request("sendVenue", params);
132
+ }
133
+ sendContact(params) {
134
+ return this.request("sendContact", params);
135
+ }
136
+ sendPoll(params) {
137
+ return this.request("sendPoll", params);
138
+ }
139
+ sendDice(params) {
140
+ return this.request("sendDice", params);
141
+ }
142
+ sendChatAction(params) {
143
+ return this.request("sendChatAction", params);
144
+ }
145
+ setMessageReaction(params) {
146
+ return this.request("setMessageReaction", params);
147
+ }
148
+ editMessageText(params) {
149
+ return this.request("editMessageText", params);
150
+ }
151
+ editMessageCaption(params) {
152
+ return this.request("editMessageCaption", params);
153
+ }
154
+ editMessageMedia(params) {
155
+ return this.request("editMessageMedia", params);
156
+ }
157
+ editMessageReplyMarkup(params) {
158
+ return this.request("editMessageReplyMarkup", params);
159
+ }
160
+ stopPoll(params) {
161
+ return this.request("stopPoll", params);
162
+ }
163
+ deleteMessage(params) {
164
+ return this.request("deleteMessage", params);
165
+ }
166
+ deleteMessages(params) {
167
+ return this.request("deleteMessages", params);
168
+ }
169
+ pinChatMessage(params) {
170
+ return this.request("pinChatMessage", params);
171
+ }
172
+ unpinChatMessage(params) {
173
+ return this.request("unpinChatMessage", params);
174
+ }
175
+ unpinAllChatMessages(params) {
176
+ return this.request("unpinAllChatMessages", params);
177
+ }
178
+ getFile(params) {
179
+ return this.request("getFile", params);
180
+ }
181
+ getUserProfilePhotos(params) {
182
+ return this.request("getUserProfilePhotos", params);
183
+ }
184
+ getChat(params) {
185
+ return this.request("getChat", params);
186
+ }
187
+ getChatAdministrators(params) {
188
+ return this.request("getChatAdministrators", params);
189
+ }
190
+ getChatMemberCount(params) {
191
+ return this.request("getChatMemberCount", params);
192
+ }
193
+ getChatMember(params) {
194
+ return this.request("getChatMember", params);
195
+ }
196
+ banChatMember(params) {
197
+ return this.request("banChatMember", params);
198
+ }
199
+ unbanChatMember(params) {
200
+ return this.request("unbanChatMember", params);
201
+ }
202
+ restrictChatMember(params) {
203
+ return this.request("restrictChatMember", params);
204
+ }
205
+ promoteChatMember(params) {
206
+ return this.request("promoteChatMember", params);
207
+ }
208
+ setChatAdministratorCustomTitle(params) {
209
+ return this.request("setChatAdministratorCustomTitle", params);
210
+ }
211
+ banChatSenderChat(params) {
212
+ return this.request("banChatSenderChat", params);
213
+ }
214
+ unbanChatSenderChat(params) {
215
+ return this.request("unbanChatSenderChat", params);
216
+ }
217
+ setChatPermissions(params) {
218
+ return this.request("setChatPermissions", params);
219
+ }
220
+ exportChatInviteLink(params) {
221
+ return this.request("exportChatInviteLink", params);
222
+ }
223
+ createChatInviteLink(params) {
224
+ return this.request("createChatInviteLink", params);
225
+ }
226
+ editChatInviteLink(params) {
227
+ return this.request("editChatInviteLink", params);
228
+ }
229
+ revokeChatInviteLink(params) {
230
+ return this.request("revokeChatInviteLink", params);
231
+ }
232
+ approveChatJoinRequest(params) {
233
+ return this.request("approveChatJoinRequest", params);
234
+ }
235
+ declineChatJoinRequest(params) {
236
+ return this.request("declineChatJoinRequest", params);
237
+ }
238
+ setChatPhoto(params) {
239
+ return this.request("setChatPhoto", params);
240
+ }
241
+ deleteChatPhoto(params) {
242
+ return this.request("deleteChatPhoto", params);
243
+ }
244
+ setChatTitle(params) {
245
+ return this.request("setChatTitle", params);
246
+ }
247
+ setChatDescription(params) {
248
+ return this.request("setChatDescription", params);
249
+ }
250
+ leaveChat(params) {
251
+ return this.request("leaveChat", params);
252
+ }
253
+ setMyCommands(params) {
254
+ return this.request("setMyCommands", params);
255
+ }
256
+ getMyCommands(params) {
257
+ return this.request("getMyCommands", params);
258
+ }
259
+ deleteMyCommands(params) {
260
+ return this.request("deleteMyCommands", params);
261
+ }
262
+ getChatMenuButton(params) {
263
+ return this.request("getChatMenuButton", params);
264
+ }
265
+ setChatMenuButton(params) {
266
+ return this.request("setChatMenuButton", params);
267
+ }
268
+ setMyDefaultAdministratorRights(params) {
269
+ return this.request("setMyDefaultAdministratorRights", params);
270
+ }
271
+ getMyDefaultAdministratorRights(params) {
272
+ return this.request("getMyDefaultAdministratorRights", params);
273
+ }
274
+ answerCallbackQuery(params) {
275
+ return this.request("answerCallbackQuery", params);
276
+ }
277
+ answerInlineQuery(params) {
278
+ return this.request("answerInlineQuery", params);
279
+ }
280
+ answerWebAppQuery(params) {
281
+ return this.request("answerWebAppQuery", params);
282
+ }
283
+ answerShippingQuery(params) {
284
+ return this.request("answerShippingQuery", params);
285
+ }
286
+ answerPreCheckoutQuery(params) {
287
+ return this.request("answerPreCheckoutQuery", params);
288
+ }
289
+ sendInvoice(params) {
290
+ return this.request("sendInvoice", params);
291
+ }
292
+ createInvoiceLink(params) {
293
+ return this.request("createInvoiceLink", params);
294
+ }
295
+ getStickerSet(params) {
296
+ return this.request("getStickerSet", params);
297
+ }
298
+ getCustomEmojiStickers(params) {
299
+ return this.request("getCustomEmojiStickers", params);
300
+ }
301
+ createNewStickerSet(params) {
302
+ return this.request("createNewStickerSet", params);
303
+ }
304
+ addStickerToSet(params) {
305
+ return this.request("addStickerToSet", params);
306
+ }
307
+ setStickerPositionInSet(params) {
308
+ return this.request("setStickerPositionInSet", params);
309
+ }
310
+ deleteStickerFromSet(params) {
311
+ return this.request("deleteStickerFromSet", params);
312
+ }
313
+ replaceStickerInSet(params) {
314
+ return this.request("replaceStickerInSet", params);
315
+ }
316
+ setStickerEmojiList(params) {
317
+ return this.request("setStickerEmojiList", params);
318
+ }
319
+ setStickerKeywords(params) {
320
+ return this.request("setStickerKeywords", params);
321
+ }
322
+ setStickerMaskPosition(params) {
323
+ return this.request("setStickerMaskPosition", params);
324
+ }
325
+ setStickerSetTitle(params) {
326
+ return this.request("setStickerSetTitle", params);
327
+ }
328
+ setStickerSetThumbnail(params) {
329
+ return this.request("setStickerSetThumbnail", params);
330
+ }
331
+ setCustomEmojiStickerSetThumbnail(params) {
332
+ return this.request("setCustomEmojiStickerSetThumbnail", params);
333
+ }
334
+ deleteStickerSet(params) {
335
+ return this.request("deleteStickerSet", params);
336
+ }
337
+ sendGame(params) {
338
+ return this.request("sendGame", params);
339
+ }
340
+ setGameScore(params) {
341
+ return this.request("setGameScore", params);
342
+ }
343
+ getGameHighScores(params) {
344
+ return this.request("getGameHighScores", params);
345
+ }
346
+ createForumTopic(params) {
347
+ return this.request("createForumTopic", params);
348
+ }
349
+ editForumTopic(params) {
350
+ return this.request("editForumTopic", params);
351
+ }
352
+ closeForumTopic(params) {
353
+ return this.request("closeForumTopic", params);
354
+ }
355
+ reopenForumTopic(params) {
356
+ return this.request("reopenForumTopic", params);
357
+ }
358
+ deleteForumTopic(params) {
359
+ return this.request("deleteForumTopic", params);
360
+ }
361
+ unpinAllForumTopicMessages(params) {
362
+ return this.request("unpinAllForumTopicMessages", params);
363
+ }
364
+ hideGeneralForumTopic(params) {
365
+ return this.request("hideGeneralForumTopic", params);
366
+ }
367
+ unhideGeneralForumTopic(params) {
368
+ return this.request("unhideGeneralForumTopic", params);
369
+ }
370
+ unpinAllGeneralForumTopicMessages(params) {
371
+ return this.request("unpinAllGeneralForumTopicMessages", params);
372
+ }
373
+ setMyStarTransactionWithdrawalLimit(params) {
374
+ return this.request("setMyStarTransactionWithdrawalLimit", params);
375
+ }
376
+ getStarTransactions(params) {
377
+ return this.request("getStarTransactions", params);
378
+ }
379
+ refundStarPayment(params) {
380
+ return this.request("refundStarPayment", params);
381
+ }
382
+ sendPaidMedia(params) {
383
+ return this.request("sendPaidMedia", params);
384
+ }
385
+ getBusinessConnection(params) {
386
+ return this.request("getBusinessConnection", params);
387
+ }
388
+ setChatStickerSet(params) {
389
+ return this.request("setChatStickerSet", params);
390
+ }
391
+ deleteChatStickerSet(params) {
392
+ return this.request("deleteChatStickerSet", params);
393
+ }
394
+ createChatSubscriptionInviteLink(params) {
395
+ return this.request("createChatSubscriptionInviteLink", params);
396
+ }
397
+ editChatSubscriptionInviteLink(params) {
398
+ return this.request("editChatSubscriptionInviteLink", params);
399
+ }
400
+ getAvailableGifts(_params) {
401
+ return this.request("getAvailableGifts");
402
+ }
403
+ sendGift(params) {
404
+ return this.request("sendGift", params);
405
+ }
406
+ setUserEmojiStatus(params) {
407
+ return this.request("setUserEmojiStatus", params);
408
+ }
409
+ verifyUser(params) {
410
+ return this.request("verifyUser", params);
411
+ }
412
+ removeUserVerification(params) {
413
+ return this.request("removeUserVerification", params);
414
+ }
415
+ verifyChat(params) {
416
+ return this.request("verifyChat", params);
417
+ }
418
+ removeChatVerification(params) {
419
+ return this.request("removeChatVerification", params);
420
+ }
421
+ readBusinessMessage(params) {
422
+ return this.request("readBusinessMessage", params);
423
+ }
424
+ deleteBusinessMessages(params) {
425
+ return this.request("deleteBusinessMessages", params);
426
+ }
427
+ allowUserMessages(params) {
428
+ return this.request("allowUserMessages", params);
429
+ }
430
+ disallowUserMessages(params) {
431
+ return this.request("disallowUserMessages", params);
432
+ }
433
+ getUserChatBoosts(params) {
434
+ return this.request("getUserChatBoosts", params);
435
+ }
436
+ savePreparedInlineMessage(params) {
437
+ return this.request("savePreparedInlineMessage", params);
438
+ }
439
+ getFileDownloadUrl(filePath) {
440
+ const [base, tokenPart] = this.apiBase.split("/bot");
441
+ return `${base}/file/bot${tokenPart}/${filePath}`;
442
+ }
443
+ async getFileWithUrl(fileId) {
444
+ const file = await this.getFile({ file_id: fileId });
445
+ const downloadUrl = file.file_path ? this.getFileDownloadUrl(file.file_path) : "";
446
+ return __spreadProps(__spreadValues({}, file), { downloadUrl });
447
+ }
448
+ editMessageLiveLocation(params) {
449
+ return this.request("editMessageLiveLocation", params);
450
+ }
451
+ stopMessageLiveLocation(params) {
452
+ return this.request("stopMessageLiveLocation", params);
453
+ }
454
+ sendChecklist(params) {
455
+ return this.request("sendChecklist", params);
456
+ }
457
+ editMessageChecklist(params) {
458
+ return this.request("editMessageChecklist", params);
459
+ }
460
+ uploadStickerFile(params) {
461
+ return this.request("uploadStickerFile", params);
462
+ }
463
+ setPassportDataErrors(params) {
464
+ return this.request("setPassportDataErrors", params);
465
+ }
466
+ getForumTopicIconStickers() {
467
+ return this.request("getForumTopicIconStickers");
468
+ }
469
+ editGeneralForumTopic(params) {
470
+ return this.request("editGeneralForumTopic", params);
471
+ }
472
+ closeGeneralForumTopic(params) {
473
+ return this.request("closeGeneralForumTopic", params);
474
+ }
475
+ reopenGeneralForumTopic(params) {
476
+ return this.request("reopenGeneralForumTopic", params);
477
+ }
478
+ editUserStarSubscription(params) {
479
+ return this.request("editUserStarSubscription", params);
480
+ }
481
+ getBusinessAccountGifts(params) {
482
+ return this.request("getBusinessAccountGifts", params);
483
+ }
484
+ getBusinessAccountStarBalance(params) {
485
+ return this.request("getBusinessAccountStarBalance", params);
486
+ }
487
+ convertGiftToStars(params) {
488
+ return this.request("convertGiftToStars", params);
489
+ }
490
+ upgradeGift(params) {
491
+ return this.request("upgradeGift", params);
492
+ }
493
+ transferGift(params) {
494
+ return this.request("transferGift", params);
495
+ }
496
+ transferBusinessAccountStars(params) {
497
+ return this.request("transferBusinessAccountStars", params);
498
+ }
499
+ setBusinessAccountName(params) {
500
+ return this.request("setBusinessAccountName", params);
501
+ }
502
+ setBusinessAccountUsername(params) {
503
+ return this.request("setBusinessAccountUsername", params);
504
+ }
505
+ setBusinessAccountBio(params) {
506
+ return this.request("setBusinessAccountBio", params);
507
+ }
508
+ setBusinessAccountProfilePhoto(params) {
509
+ return this.request("setBusinessAccountProfilePhoto", params);
510
+ }
511
+ removeBusinessAccountProfilePhoto(params) {
512
+ return this.request("removeBusinessAccountProfilePhoto", params);
513
+ }
514
+ setBusinessAccountGiftSettings(params) {
515
+ return this.request("setBusinessAccountGiftSettings", params);
516
+ }
517
+ postStory(params) {
518
+ return this.request("postStory", params);
519
+ }
520
+ editStory(params) {
521
+ return this.request("editStory", params);
522
+ }
523
+ deleteStory(params) {
524
+ return this.request("deleteStory", params);
525
+ }
526
+ callMethod(method, params) {
527
+ return this.request(method, params);
528
+ }
529
+ };
530
+
531
+ // src/_internal/bot/dispatcher.ts
532
+ var Dispatcher = class {
533
+ constructor(options = {}) {
534
+ this.options = options;
535
+ this.messageHandlers = [];
536
+ this.editedMessageHandlers = [];
537
+ this.channelPostHandlers = [];
538
+ this.editedChannelPostHandlers = [];
539
+ this.businessMessageHandlers = [];
540
+ this.editedBusinessMessageHandlers = [];
541
+ this.deletedBusinessMessagesHandlers = [];
542
+ this.pollHandlers = [];
543
+ this.callbackQueryHandlers = [];
544
+ this.inlineQueryHandlers = [];
545
+ this.chosenInlineResultHandlers = [];
546
+ this.shippingQueryHandlers = [];
547
+ this.preCheckoutQueryHandlers = [];
548
+ this.pollAnswerHandlers = [];
549
+ this.myChatMemberHandlers = [];
550
+ this.chatMemberHandlers = [];
551
+ this.chatJoinRequestHandlers = [];
552
+ this.chatBoostHandlers = [];
553
+ this.removedChatBoostHandlers = [];
554
+ this.messageReactionHandlers = [];
555
+ this.businessConnectionHandlers = [];
556
+ this.purchasedPaidMediaHandlers = [];
557
+ this.messageReactionCountHandlers = [];
558
+ var _a;
559
+ this.botUsername = (_a = options.botUsername) == null ? void 0 : _a.replace(/^@/, "");
560
+ }
561
+ setBotUsername(username) {
562
+ this.botUsername = username.replace(/^@/, "");
563
+ return this;
564
+ }
565
+ onMessage(handler, filter) {
566
+ this.messageHandlers.push({ handler, filter });
567
+ return this;
568
+ }
569
+ onCommand(command, handler) {
570
+ const commandFilter = (msg) => {
571
+ var _a, _b;
572
+ const text = (_b = (_a = msg.text) == null ? void 0 : _a.trim()) != null ? _b : "";
573
+ const cmd = text.split(" ")[0];
574
+ if (cmd === `/${command}`) return true;
575
+ if (this.botUsername && cmd === `/${command}@${this.botUsername}`) return true;
576
+ return false;
577
+ };
578
+ this.messageHandlers.push({ handler, filter: commandFilter });
579
+ return this;
580
+ }
581
+ onEditedMessage(handler, filter) {
582
+ this.editedMessageHandlers.push({ handler, filter });
583
+ return this;
584
+ }
585
+ onChannelPost(handler, filter) {
586
+ this.channelPostHandlers.push({ handler, filter });
587
+ return this;
588
+ }
589
+ onEditedChannelPost(handler, filter) {
590
+ this.editedChannelPostHandlers.push({ handler, filter });
591
+ return this;
592
+ }
593
+ onBusinessMessage(handler, filter) {
594
+ this.businessMessageHandlers.push({ handler, filter });
595
+ return this;
596
+ }
597
+ onEditedBusinessMessage(handler, filter) {
598
+ this.editedBusinessMessageHandlers.push({ handler, filter });
599
+ return this;
600
+ }
601
+ onDeletedBusinessMessages(handler) {
602
+ this.deletedBusinessMessagesHandlers.push({ handler });
603
+ return this;
604
+ }
605
+ onPoll(handler) {
606
+ this.pollHandlers.push({ handler });
607
+ return this;
608
+ }
609
+ onCallbackQuery(handler, pattern) {
610
+ this.callbackQueryHandlers.push({ handler, pattern });
611
+ return this;
612
+ }
613
+ onInlineQuery(handler) {
614
+ this.inlineQueryHandlers.push({ handler });
615
+ return this;
616
+ }
617
+ onChosenInlineResult(handler) {
618
+ this.chosenInlineResultHandlers.push({ handler });
619
+ return this;
620
+ }
621
+ onShippingQuery(handler) {
622
+ this.shippingQueryHandlers.push({ handler });
623
+ return this;
624
+ }
625
+ onPreCheckoutQuery(handler) {
626
+ this.preCheckoutQueryHandlers.push({ handler });
627
+ return this;
628
+ }
629
+ onPollAnswer(handler) {
630
+ this.pollAnswerHandlers.push({ handler });
631
+ return this;
632
+ }
633
+ onMyChatMember(handler) {
634
+ this.myChatMemberHandlers.push({ handler });
635
+ return this;
636
+ }
637
+ onChatMember(handler) {
638
+ this.chatMemberHandlers.push({ handler });
639
+ return this;
640
+ }
641
+ onChatJoinRequest(handler) {
642
+ this.chatJoinRequestHandlers.push({ handler });
643
+ return this;
644
+ }
645
+ onChatBoost(handler) {
646
+ this.chatBoostHandlers.push({ handler });
647
+ return this;
648
+ }
649
+ onRemovedChatBoost(handler) {
650
+ this.removedChatBoostHandlers.push({ handler });
651
+ return this;
652
+ }
653
+ onMessageReaction(handler) {
654
+ this.messageReactionHandlers.push({ handler });
655
+ return this;
656
+ }
657
+ onBusinessConnection(handler) {
658
+ this.businessConnectionHandlers.push({ handler });
659
+ return this;
660
+ }
661
+ onPurchasedPaidMedia(handler) {
662
+ this.purchasedPaidMediaHandlers.push({ handler });
663
+ return this;
664
+ }
665
+ onMessageReactionCount(handler) {
666
+ this.messageReactionCountHandlers.push({ handler });
667
+ return this;
668
+ }
669
+ async dispatch(update) {
670
+ var _a, _b;
671
+ try {
672
+ if (update.message) {
673
+ await this._runMessageHandlers(update.message, this.messageHandlers);
674
+ } else if (update.edited_message) {
675
+ await this._runMessageHandlers(update.edited_message, this.editedMessageHandlers);
676
+ } else if (update.channel_post) {
677
+ await this._runMessageHandlers(update.channel_post, this.channelPostHandlers);
678
+ } else if (update.edited_channel_post) {
679
+ await this._runMessageHandlers(update.edited_channel_post, this.editedChannelPostHandlers);
680
+ } else if (update.business_message) {
681
+ await this._runMessageHandlers(update.business_message, this.businessMessageHandlers);
682
+ } else if (update.edited_business_message) {
683
+ await this._runMessageHandlers(
684
+ update.edited_business_message,
685
+ this.editedBusinessMessageHandlers
686
+ );
687
+ } else if (update.deleted_business_messages) {
688
+ for (const { handler } of this.deletedBusinessMessagesHandlers) {
689
+ await handler(update.deleted_business_messages);
690
+ }
691
+ } else if (update.poll) {
692
+ for (const { handler } of this.pollHandlers) {
693
+ await handler(update.poll);
694
+ }
695
+ } else if (update.callback_query) {
696
+ await this._runCallbackQueryHandlers(update.callback_query);
697
+ } else if (update.inline_query) {
698
+ for (const { handler } of this.inlineQueryHandlers) {
699
+ await handler(update.inline_query);
700
+ }
701
+ } else if (update.chosen_inline_result) {
702
+ for (const { handler } of this.chosenInlineResultHandlers) {
703
+ await handler(update.chosen_inline_result);
704
+ }
705
+ } else if (update.shipping_query) {
706
+ for (const { handler } of this.shippingQueryHandlers) {
707
+ await handler(update.shipping_query);
708
+ }
709
+ } else if (update.pre_checkout_query) {
710
+ for (const { handler } of this.preCheckoutQueryHandlers) {
711
+ await handler(update.pre_checkout_query);
712
+ }
713
+ } else if (update.poll_answer) {
714
+ for (const { handler } of this.pollAnswerHandlers) {
715
+ await handler(update.poll_answer);
716
+ }
717
+ } else if (update.my_chat_member) {
718
+ for (const { handler } of this.myChatMemberHandlers) {
719
+ await handler(update.my_chat_member);
720
+ }
721
+ } else if (update.chat_member) {
722
+ for (const { handler } of this.chatMemberHandlers) {
723
+ await handler(update.chat_member);
724
+ }
725
+ } else if (update.chat_join_request) {
726
+ for (const { handler } of this.chatJoinRequestHandlers) {
727
+ await handler(update.chat_join_request);
728
+ }
729
+ } else if (update.chat_boost) {
730
+ for (const { handler } of this.chatBoostHandlers) {
731
+ await handler(update.chat_boost);
732
+ }
733
+ } else if (update.removed_chat_boost) {
734
+ for (const { handler } of this.removedChatBoostHandlers) {
735
+ await handler(update.removed_chat_boost);
736
+ }
737
+ } else if (update.message_reaction) {
738
+ for (const { handler } of this.messageReactionHandlers) {
739
+ await handler(update.message_reaction);
740
+ }
741
+ } else if (update.message_reaction_count) {
742
+ for (const { handler } of this.messageReactionCountHandlers) {
743
+ await handler(update.message_reaction_count);
744
+ }
745
+ } else if (update.business_connection) {
746
+ for (const { handler } of this.businessConnectionHandlers) {
747
+ await handler(update.business_connection);
748
+ }
749
+ } else if (update.purchased_paid_media) {
750
+ for (const { handler } of this.purchasedPaidMediaHandlers) {
751
+ await handler(update.purchased_paid_media);
752
+ }
753
+ }
754
+ } catch (err) {
755
+ const error = err instanceof Error ? err : new Error(String(err));
756
+ (_b = (_a = this.options).onError) == null ? void 0 : _b.call(_a, error, update);
757
+ }
758
+ }
759
+ async _runMessageHandlers(message, handlers) {
760
+ for (const { handler, filter } of handlers) {
761
+ if (filter) {
762
+ const passes = await Promise.resolve(filter(message));
763
+ if (!passes) continue;
764
+ }
765
+ await handler(message);
766
+ }
767
+ }
768
+ async _runCallbackQueryHandlers(query) {
769
+ var _a;
770
+ for (const { handler, pattern } of this.callbackQueryHandlers) {
771
+ if (pattern !== void 0) {
772
+ const data = (_a = query.data) != null ? _a : "";
773
+ const matches = typeof pattern === "string" ? data === pattern : pattern.test(data);
774
+ if (!matches) continue;
775
+ }
776
+ await handler(query);
777
+ }
778
+ }
779
+ toHandler() {
780
+ return (update) => this.dispatch(update);
781
+ }
782
+ };
783
+
784
+ // src/_internal/bot/polling.ts
785
+ var TelegramPoller = class {
786
+ constructor(getUpdates, handler, options = {}) {
787
+ this.getUpdates = getUpdates;
788
+ this.handler = handler;
789
+ this.options = options;
790
+ this.running = false;
791
+ this.offset = 0;
792
+ this.abortController = null;
793
+ }
794
+ start() {
795
+ if (this.running) return;
796
+ this.running = true;
797
+ void this._loop();
798
+ }
799
+ stop() {
800
+ var _a;
801
+ this.running = false;
802
+ (_a = this.abortController) == null ? void 0 : _a.abort();
803
+ this.abortController = null;
804
+ }
805
+ get isRunning() {
806
+ return this.running;
807
+ }
808
+ async _loop() {
809
+ const {
810
+ timeout = 30,
811
+ limit = 100,
812
+ allowedUpdates,
813
+ onError,
814
+ retryAfterMs = 5e3
815
+ } = this.options;
816
+ while (this.running) {
817
+ this.abortController = new AbortController();
818
+ try {
819
+ const updates = await this.getUpdates({
820
+ offset: this.offset,
821
+ timeout,
822
+ limit,
823
+ allowed_updates: allowedUpdates
824
+ });
825
+ for (const update of updates) {
826
+ if (!this.running) break;
827
+ this.offset = update.update_id + 1;
828
+ try {
829
+ await this.handler(update);
830
+ } catch (err) {
831
+ onError == null ? void 0 : onError(err instanceof Error ? err : new Error(String(err)));
832
+ }
833
+ }
834
+ } catch (err) {
835
+ if (!this.running) break;
836
+ const error = err instanceof Error ? err : new Error(String(err));
837
+ onError == null ? void 0 : onError(error);
838
+ await _sleep(retryAfterMs);
839
+ }
840
+ }
841
+ }
842
+ };
843
+ function _sleep(ms) {
844
+ return new Promise((resolve) => setTimeout(resolve, ms));
845
+ }
846
+
847
+ export { Dispatcher, TelegramApiError, TelegramBot, TelegramPoller };