teledzik 1.0.0

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 (198) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +1126 -0
  3. package/filters.d.ts +1 -0
  4. package/filters.js +1 -0
  5. package/format.d.ts +1 -0
  6. package/format.js +1 -0
  7. package/future.d.ts +1 -0
  8. package/future.js +1 -0
  9. package/lib/button.js +101 -0
  10. package/lib/cli.mjs +105 -0
  11. package/lib/composer.js +581 -0
  12. package/lib/context.js +1300 -0
  13. package/lib/core/helpers/ai-stream.js +69 -0
  14. package/lib/core/helpers/args.js +58 -0
  15. package/lib/core/helpers/check.js +56 -0
  16. package/lib/core/helpers/compact.js +17 -0
  17. package/lib/core/helpers/deunionize.js +13 -0
  18. package/lib/core/helpers/formatting.js +89 -0
  19. package/lib/core/helpers/input-box.js +87 -0
  20. package/lib/core/helpers/rich-sanitizer.js +31 -0
  21. package/lib/core/helpers/smart-queue.js +70 -0
  22. package/lib/core/helpers/util.js +50 -0
  23. package/lib/core/network/client.js +318 -0
  24. package/lib/core/network/error.js +21 -0
  25. package/lib/core/network/multipart-stream.js +61 -0
  26. package/lib/core/network/polling.js +86 -0
  27. package/lib/core/network/webhook.js +54 -0
  28. package/lib/core/types/rich-message.js +287 -0
  29. package/lib/core/types/typegram.js +18 -0
  30. package/lib/filters.js +69 -0
  31. package/lib/format.js +38 -0
  32. package/lib/future.js +166 -0
  33. package/lib/index.js +61 -0
  34. package/lib/input.js +61 -0
  35. package/lib/markup.js +111 -0
  36. package/lib/middleware.js +2 -0
  37. package/lib/paginated.js +76 -0
  38. package/lib/reactions.js +81 -0
  39. package/lib/router.js +45 -0
  40. package/lib/scenes/base.js +39 -0
  41. package/lib/scenes/context.js +99 -0
  42. package/lib/scenes/form-scene.js +23 -0
  43. package/lib/scenes/index.js +21 -0
  44. package/lib/scenes/stage.js +49 -0
  45. package/lib/scenes/wizard/context.js +30 -0
  46. package/lib/scenes/wizard/index.js +45 -0
  47. package/lib/scenes.js +17 -0
  48. package/lib/session.js +163 -0
  49. package/lib/telegraf.js +274 -0
  50. package/lib/telegram-types.js +6 -0
  51. package/lib/telegram.js +1286 -0
  52. package/lib/types.js +2 -0
  53. package/lib/utils.js +5 -0
  54. package/markup.d.ts +1 -0
  55. package/markup.js +1 -0
  56. package/package.json +141 -0
  57. package/scenes.d.ts +1 -0
  58. package/scenes.js +1 -0
  59. package/session.d.ts +1 -0
  60. package/session.js +1 -0
  61. package/src/button.ts +182 -0
  62. package/src/composer.ts +1008 -0
  63. package/src/context.ts +1778 -0
  64. package/src/core/helpers/ai-stream.ts +96 -0
  65. package/src/core/helpers/args.ts +63 -0
  66. package/src/core/helpers/check.ts +71 -0
  67. package/src/core/helpers/compact.ts +18 -0
  68. package/src/core/helpers/deunionize.ts +26 -0
  69. package/src/core/helpers/formatting.ts +119 -0
  70. package/src/core/helpers/input-box.ts +86 -0
  71. package/src/core/helpers/rich-sanitizer.ts +36 -0
  72. package/src/core/helpers/smart-queue.ts +89 -0
  73. package/src/core/helpers/util.ts +96 -0
  74. package/src/core/network/client.ts +396 -0
  75. package/src/core/network/error.ts +29 -0
  76. package/src/core/network/multipart-stream.ts +45 -0
  77. package/src/core/network/polling.ts +94 -0
  78. package/src/core/network/webhook.ts +58 -0
  79. package/src/core/types/rich-message.ts +375 -0
  80. package/src/core/types/typegram.ts +44 -0
  81. package/src/filters.js +69 -0
  82. package/src/filters.ts +109 -0
  83. package/src/format.js +38 -0
  84. package/src/format.ts +110 -0
  85. package/src/future.js +147 -0
  86. package/src/future.ts +231 -0
  87. package/src/index.ts +27 -0
  88. package/src/input.ts +59 -0
  89. package/src/markup.js +93 -0
  90. package/src/markup.ts +142 -0
  91. package/src/middleware.ts +24 -0
  92. package/src/paginated.ts +75 -0
  93. package/src/reactions.ts +118 -0
  94. package/src/router.ts +55 -0
  95. package/src/scenes/base.ts +52 -0
  96. package/src/scenes/context.ts +136 -0
  97. package/src/scenes/form-scene.ts +34 -0
  98. package/src/scenes/index.ts +21 -0
  99. package/src/scenes/stage.ts +71 -0
  100. package/src/scenes/wizard/context.ts +58 -0
  101. package/src/scenes/wizard/index.ts +63 -0
  102. package/src/scenes.js +17 -0
  103. package/src/scenes.ts +1 -0
  104. package/src/session.js +175 -0
  105. package/src/session.ts +204 -0
  106. package/src/telegraf.ts +385 -0
  107. package/src/telegram-types.ts +256 -0
  108. package/src/telegram.ts +1700 -0
  109. package/src/types.js +2 -0
  110. package/src/types.ts +2 -0
  111. package/src/utils.js +5 -0
  112. package/src/utils.ts +1 -0
  113. package/types.d.ts +1 -0
  114. package/types.js +1 -0
  115. package/typings/button.d.ts +35 -0
  116. package/typings/button.d.ts.map +1 -0
  117. package/typings/composer.d.ts +226 -0
  118. package/typings/composer.d.ts.map +1 -0
  119. package/typings/context.d.ts +711 -0
  120. package/typings/context.d.ts.map +1 -0
  121. package/typings/core/helpers/ai-stream.d.ts +33 -0
  122. package/typings/core/helpers/args.d.ts +10 -0
  123. package/typings/core/helpers/args.d.ts.map +1 -0
  124. package/typings/core/helpers/check.d.ts +55 -0
  125. package/typings/core/helpers/check.d.ts.map +1 -0
  126. package/typings/core/helpers/compact.d.ts +3 -0
  127. package/typings/core/helpers/compact.d.ts.map +1 -0
  128. package/typings/core/helpers/deunionize.d.ts +17 -0
  129. package/typings/core/helpers/deunionize.d.ts.map +1 -0
  130. package/typings/core/helpers/formatting.d.ts +29 -0
  131. package/typings/core/helpers/formatting.d.ts.map +1 -0
  132. package/typings/core/helpers/input-box.d.ts +32 -0
  133. package/typings/core/helpers/rich-sanitizer.d.ts +5 -0
  134. package/typings/core/helpers/smart-queue.d.ts +18 -0
  135. package/typings/core/helpers/util.d.ts +26 -0
  136. package/typings/core/helpers/util.d.ts.map +1 -0
  137. package/typings/core/network/client.d.ts +54 -0
  138. package/typings/core/network/client.d.ts.map +1 -0
  139. package/typings/core/network/error.d.ts +15 -0
  140. package/typings/core/network/error.d.ts.map +1 -0
  141. package/typings/core/network/multipart-stream.d.ts +19 -0
  142. package/typings/core/network/multipart-stream.d.ts.map +1 -0
  143. package/typings/core/network/polling.d.ts +15 -0
  144. package/typings/core/network/polling.d.ts.map +1 -0
  145. package/typings/core/network/webhook.d.ts +6 -0
  146. package/typings/core/network/webhook.d.ts.map +1 -0
  147. package/typings/core/types/rich-message.d.ts +143 -0
  148. package/typings/core/types/rich-message.d.ts.map +1 -0
  149. package/typings/core/types/typegram.d.ts +36 -0
  150. package/typings/core/types/typegram.d.ts.map +1 -0
  151. package/typings/filters.d.ts +17 -0
  152. package/typings/filters.d.ts.map +1 -0
  153. package/typings/format.d.ts +21 -0
  154. package/typings/format.d.ts.map +1 -0
  155. package/typings/future.d.ts +11 -0
  156. package/typings/future.d.ts.map +1 -0
  157. package/typings/index.d.ts +21 -0
  158. package/typings/index.d.ts.map +1 -0
  159. package/typings/input.d.ts +58 -0
  160. package/typings/input.d.ts.map +1 -0
  161. package/typings/markup.d.ts +26 -0
  162. package/typings/markup.d.ts.map +1 -0
  163. package/typings/middleware.d.ts +7 -0
  164. package/typings/middleware.d.ts.map +1 -0
  165. package/typings/paginated.d.ts +20 -0
  166. package/typings/reactions.d.ts +31 -0
  167. package/typings/reactions.d.ts.map +1 -0
  168. package/typings/router.d.ts +20 -0
  169. package/typings/router.d.ts.map +1 -0
  170. package/typings/scenes/base.d.ts +21 -0
  171. package/typings/scenes/base.d.ts.map +1 -0
  172. package/typings/scenes/context.d.ts +35 -0
  173. package/typings/scenes/context.d.ts.map +1 -0
  174. package/typings/scenes/form-scene.d.ts +17 -0
  175. package/typings/scenes/index.d.ts +10 -0
  176. package/typings/scenes/index.d.ts.map +1 -0
  177. package/typings/scenes/stage.d.ts +23 -0
  178. package/typings/scenes/stage.d.ts.map +1 -0
  179. package/typings/scenes/wizard/context.d.ts +28 -0
  180. package/typings/scenes/wizard/context.d.ts.map +1 -0
  181. package/typings/scenes/wizard/index.d.ts +15 -0
  182. package/typings/scenes/wizard/index.d.ts.map +1 -0
  183. package/typings/scenes.d.ts +1 -0
  184. package/typings/scenes.d.ts.map +1 -0
  185. package/typings/session.d.ts +54 -0
  186. package/typings/session.d.ts.map +1 -0
  187. package/typings/telegraf.d.ts +118 -0
  188. package/typings/telegraf.d.ts.map +1 -0
  189. package/typings/telegram-types.d.ts +140 -0
  190. package/typings/telegram-types.d.ts.map +1 -0
  191. package/typings/telegram.d.ts +697 -0
  192. package/typings/telegram.d.ts.map +1 -0
  193. package/typings/types.d.ts +2 -0
  194. package/typings/types.d.ts.map +1 -0
  195. package/typings/utils.d.ts +1 -0
  196. package/typings/utils.d.ts.map +1 -0
  197. package/utils.d.ts +1 -0
  198. package/utils.js +1 -0
package/lib/context.js ADDED
@@ -0,0 +1,1300 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Context = void 0;
7
+ const debug_1 = __importDefault(require("debug"));
8
+ const reactions_1 = require("./reactions");
9
+ const smart_queue_1 = require("./core/helpers/smart-queue");
10
+ const ai_stream_1 = require("./core/helpers/ai-stream");
11
+ const debug = (0, debug_1.default)('telegraf:context');
12
+ class Context {
13
+ constructor(update, telegram, botInfo) {
14
+ this.update = update;
15
+ this.telegram = telegram;
16
+ this.botInfo = botInfo;
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ this.state = {};
19
+ }
20
+ get updateType() {
21
+ for (const key in this.update) {
22
+ if (typeof this.update[key] === 'object')
23
+ return key;
24
+ }
25
+ throw new Error(`Cannot determine \`updateType\` of ${JSON.stringify(this.update)}`);
26
+ }
27
+ get me() {
28
+ return this.botInfo?.username;
29
+ }
30
+ /**
31
+ * @deprecated Use ctx.telegram instead
32
+ */
33
+ get tg() {
34
+ return this.telegram;
35
+ }
36
+ get message() {
37
+ return this.update.message;
38
+ }
39
+ get editedMessage() {
40
+ return this.update.edited_message;
41
+ }
42
+ get inlineQuery() {
43
+ return this.update.inline_query;
44
+ }
45
+ get shippingQuery() {
46
+ return this.update.shipping_query;
47
+ }
48
+ get preCheckoutQuery() {
49
+ return this.update.pre_checkout_query;
50
+ }
51
+ get chosenInlineResult() {
52
+ return this.update.chosen_inline_result;
53
+ }
54
+ get channelPost() {
55
+ return this.update.channel_post;
56
+ }
57
+ get editedChannelPost() {
58
+ return this.update.edited_channel_post;
59
+ }
60
+ get messageReaction() {
61
+ return this.update.message_reaction;
62
+ }
63
+ get messageReactionCount() {
64
+ return this.update.message_reaction_count;
65
+ }
66
+ get callbackQuery() {
67
+ return this.update.callback_query;
68
+ }
69
+ get poll() {
70
+ return this.update.poll;
71
+ }
72
+ get pollAnswer() {
73
+ return this.update.poll_answer;
74
+ }
75
+ get myChatMember() {
76
+ return this.update.my_chat_member;
77
+ }
78
+ get chatMember() {
79
+ return this.update.chat_member;
80
+ }
81
+ get chatJoinRequest() {
82
+ return this.update.chat_join_request;
83
+ }
84
+ get chatBoost() {
85
+ return this.update.chat_boost;
86
+ }
87
+ get removedChatBoost() {
88
+ return this.update.removed_chat_boost;
89
+ }
90
+ /** Shorthand for any `message` object present in the current update. One of
91
+ * `message`, `edited_message`, `channel_post`, `edited_channel_post` or
92
+ * `callback_query.message`
93
+ */
94
+ get msg() {
95
+ return getMessageFromAnySource(this);
96
+ }
97
+ /** Shorthand for any message_id present in the current update. */
98
+ get msgId() {
99
+ return getMsgIdFromAnySource(this);
100
+ }
101
+ get chat() {
102
+ return (this.msg ??
103
+ this.messageReaction ??
104
+ this.messageReactionCount ??
105
+ this.chatJoinRequest ??
106
+ this.chatMember ??
107
+ this.myChatMember ??
108
+ this.removedChatBoost)?.chat;
109
+ }
110
+ get senderChat() {
111
+ const msg = this.msg;
112
+ return (msg?.has('sender_chat') && msg.sender_chat);
113
+ }
114
+ get from() {
115
+ return getUserFromAnySource(this);
116
+ }
117
+ get inlineMessageId() {
118
+ return (this.callbackQuery ?? this.chosenInlineResult)?.inline_message_id;
119
+ }
120
+ get passportData() {
121
+ if (this.message == null)
122
+ return undefined;
123
+ if (!('passport_data' in this.message))
124
+ return undefined;
125
+ return this.message?.passport_data;
126
+ }
127
+ get webAppData() {
128
+ if (!(this.message && 'web_app_data' in this.message))
129
+ return undefined;
130
+ const { data, button_text } = this.message.web_app_data;
131
+ return {
132
+ data: {
133
+ json() {
134
+ return JSON.parse(data);
135
+ },
136
+ text() {
137
+ return data;
138
+ },
139
+ },
140
+ button_text,
141
+ };
142
+ }
143
+ /**
144
+ * @deprecated use {@link Telegram.webhookReply}
145
+ */
146
+ get webhookReply() {
147
+ return this.telegram.webhookReply;
148
+ }
149
+ set webhookReply(enable) {
150
+ this.telegram.webhookReply = enable;
151
+ }
152
+ get reactions() {
153
+ return reactions_1.MessageReactions.from(this);
154
+ }
155
+ /**
156
+ * @internal
157
+ */
158
+ assert(value, method) {
159
+ if (value === undefined) {
160
+ throw new TypeError(`Telegraf: "${method}" isn't available for "${this.updateType}"`);
161
+ }
162
+ }
163
+ has(filters) {
164
+ if (!Array.isArray(filters))
165
+ filters = [filters];
166
+ for (const filter of filters)
167
+ if (
168
+ // TODO: this should change to === 'function' once TS bug is fixed
169
+ // https://github.com/microsoft/TypeScript/pull/51502
170
+ typeof filter !== 'string'
171
+ ? // filter is a type guard
172
+ filter(this.update)
173
+ : // check if filter is the update type
174
+ filter in this.update)
175
+ return true;
176
+ return false;
177
+ }
178
+ get text() {
179
+ return getTextAndEntitiesFromAnySource(this)[0];
180
+ }
181
+ entities(...types) {
182
+ const [text = '', entities = []] = getTextAndEntitiesFromAnySource(this);
183
+ return (types.length
184
+ ? entities.filter((entity) => types.includes(entity.type))
185
+ : entities).map((entity) => ({
186
+ ...entity,
187
+ fragment: text.slice(entity.offset, entity.offset + entity.length),
188
+ }));
189
+ }
190
+ /**
191
+ * @see https://core.telegram.org/bots/api#answerinlinequery
192
+ */
193
+ answerInlineQuery(...args) {
194
+ this.assert(this.inlineQuery, 'answerInlineQuery');
195
+ return this.telegram.answerInlineQuery(this.inlineQuery.id, ...args);
196
+ }
197
+ /**
198
+ * @see https://core.telegram.org/bots/api#answercallbackquery
199
+ */
200
+ answerCbQuery(...args) {
201
+ this.assert(this.callbackQuery, 'answerCbQuery');
202
+ return this.telegram.answerCbQuery(this.callbackQuery.id, ...args);
203
+ }
204
+ /**
205
+ * @see https://core.telegram.org/bots/api#answercallbackquery
206
+ */
207
+ answerGameQuery(...args) {
208
+ this.assert(this.callbackQuery, 'answerGameQuery');
209
+ return this.telegram.answerGameQuery(this.callbackQuery.id, ...args);
210
+ }
211
+ /**
212
+ * Shorthand for {@link Telegram.getUserChatBoosts}
213
+ */
214
+ getUserChatBoosts() {
215
+ this.assert(this.chat, 'getUserChatBoosts');
216
+ this.assert(this.from, 'getUserChatBoosts');
217
+ return this.telegram.getUserChatBoosts(this.chat.id, this.from.id);
218
+ }
219
+ /**
220
+ * @see https://core.telegram.org/bots/api#answershippingquery
221
+ */
222
+ answerShippingQuery(...args) {
223
+ this.assert(this.shippingQuery, 'answerShippingQuery');
224
+ return this.telegram.answerShippingQuery(this.shippingQuery.id, ...args);
225
+ }
226
+ /**
227
+ * @see https://core.telegram.org/bots/api#answerprecheckoutquery
228
+ */
229
+ answerPreCheckoutQuery(...args) {
230
+ this.assert(this.preCheckoutQuery, 'answerPreCheckoutQuery');
231
+ return this.telegram.answerPreCheckoutQuery(this.preCheckoutQuery.id, ...args);
232
+ }
233
+ /**
234
+ * @see https://core.telegram.org/bots/api#editmessagetext
235
+ */
236
+ editMessageText(text, extra) {
237
+ this.assert(this.msgId ?? this.inlineMessageId, 'editMessageText');
238
+ return this.telegram.editMessageText(this.chat?.id, this.msgId, this.inlineMessageId, text, extra);
239
+ }
240
+ /**
241
+ * @see https://core.telegram.org/bots/api#editmessagecaption
242
+ */
243
+ editMessageCaption(caption, extra) {
244
+ this.assert(this.msgId ?? this.inlineMessageId, 'editMessageCaption');
245
+ return this.telegram.editMessageCaption(this.chat?.id, this.msgId, this.inlineMessageId, caption, extra);
246
+ }
247
+ /**
248
+ * @see https://core.telegram.org/bots/api#editmessagemedia
249
+ */
250
+ editMessageMedia(media, extra) {
251
+ this.assert(this.msgId ?? this.inlineMessageId, 'editMessageMedia');
252
+ return this.telegram.editMessageMedia(this.chat?.id, this.msgId, this.inlineMessageId, media, extra);
253
+ }
254
+ /**
255
+ * @see https://core.telegram.org/bots/api#editmessagereplymarkup
256
+ */
257
+ editMessageReplyMarkup(markup) {
258
+ this.assert(this.msgId ?? this.inlineMessageId, 'editMessageReplyMarkup');
259
+ return this.telegram.editMessageReplyMarkup(this.chat?.id, this.msgId, this.inlineMessageId, markup);
260
+ }
261
+ /**
262
+ * @see https://core.telegram.org/bots/api#editmessagelivelocation
263
+ */
264
+ editMessageLiveLocation(latitude, longitude, extra) {
265
+ this.assert(this.msgId ?? this.inlineMessageId, 'editMessageLiveLocation');
266
+ return this.telegram.editMessageLiveLocation(this.chat?.id, this.msgId, this.inlineMessageId, latitude, longitude, extra);
267
+ }
268
+ /**
269
+ * @see https://core.telegram.org/bots/api#stopmessagelivelocation
270
+ */
271
+ stopMessageLiveLocation(markup) {
272
+ this.assert(this.msgId ?? this.inlineMessageId, 'stopMessageLiveLocation');
273
+ return this.telegram.stopMessageLiveLocation(this.chat?.id, this.msgId, this.inlineMessageId, markup);
274
+ }
275
+ /**
276
+ * @see https://core.telegram.org/bots/api#sendmessage
277
+ */
278
+ sendMessage(text, extra) {
279
+ this.assert(this.chat, 'sendMessage');
280
+ return this.telegram.sendMessage(this.chat.id, text, {
281
+ message_thread_id: getThreadId(this),
282
+ ...extra,
283
+ });
284
+ }
285
+ /**
286
+ * @see https://core.telegram.org/bots/api#sendmessage
287
+ */
288
+ reply(...args) {
289
+ return this.sendMessage(...args);
290
+ }
291
+ /**
292
+ * @see https://core.telegram.org/bots/api#getchat
293
+ */
294
+ getChat(...args) {
295
+ this.assert(this.chat, 'getChat');
296
+ return this.telegram.getChat(this.chat.id, ...args);
297
+ }
298
+ /**
299
+ * @see https://core.telegram.org/bots/api#exportchatinvitelink
300
+ */
301
+ exportChatInviteLink(...args) {
302
+ this.assert(this.chat, 'exportChatInviteLink');
303
+ return this.telegram.exportChatInviteLink(this.chat.id, ...args);
304
+ }
305
+ /**
306
+ * @see https://core.telegram.org/bots/api#createchatinvitelink
307
+ */
308
+ createChatInviteLink(...args) {
309
+ this.assert(this.chat, 'createChatInviteLink');
310
+ return this.telegram.createChatInviteLink(this.chat.id, ...args);
311
+ }
312
+ /**
313
+ * @see https://core.telegram.org/bots/api#editchatinvitelink
314
+ */
315
+ editChatInviteLink(...args) {
316
+ this.assert(this.chat, 'editChatInviteLink');
317
+ return this.telegram.editChatInviteLink(this.chat.id, ...args);
318
+ }
319
+ /**
320
+ * @see https://core.telegram.org/bots/api#revokechatinvitelink
321
+ */
322
+ revokeChatInviteLink(...args) {
323
+ this.assert(this.chat, 'revokeChatInviteLink');
324
+ return this.telegram.revokeChatInviteLink(this.chat.id, ...args);
325
+ }
326
+ /**
327
+ * @see https://core.telegram.org/bots/api#banchatmember
328
+ */
329
+ banChatMember(...args) {
330
+ this.assert(this.chat, 'banChatMember');
331
+ return this.telegram.banChatMember(this.chat.id, ...args);
332
+ }
333
+ /**
334
+ * @see https://core.telegram.org/bots/api#banchatmember
335
+ * @deprecated since API 5.3. Use {@link Context.banChatMember}
336
+ */
337
+ get kickChatMember() {
338
+ return this.banChatMember;
339
+ }
340
+ /**
341
+ * @see https://core.telegram.org/bots/api#unbanchatmember
342
+ */
343
+ unbanChatMember(...args) {
344
+ this.assert(this.chat, 'unbanChatMember');
345
+ return this.telegram.unbanChatMember(this.chat.id, ...args);
346
+ }
347
+ /**
348
+ * @see https://core.telegram.org/bots/api#restrictchatmember
349
+ */
350
+ restrictChatMember(...args) {
351
+ this.assert(this.chat, 'restrictChatMember');
352
+ return this.telegram.restrictChatMember(this.chat.id, ...args);
353
+ }
354
+ /**
355
+ * @see https://core.telegram.org/bots/api#promotechatmember
356
+ */
357
+ promoteChatMember(...args) {
358
+ this.assert(this.chat, 'promoteChatMember');
359
+ return this.telegram.promoteChatMember(this.chat.id, ...args);
360
+ }
361
+ /**
362
+ * @see https://core.telegram.org/bots/api#setchatadministratorcustomtitle
363
+ */
364
+ setChatAdministratorCustomTitle(...args) {
365
+ this.assert(this.chat, 'setChatAdministratorCustomTitle');
366
+ return this.telegram.setChatAdministratorCustomTitle(this.chat.id, ...args);
367
+ }
368
+ /**
369
+ * @see https://core.telegram.org/bots/api#setchatphoto
370
+ */
371
+ setChatPhoto(...args) {
372
+ this.assert(this.chat, 'setChatPhoto');
373
+ return this.telegram.setChatPhoto(this.chat.id, ...args);
374
+ }
375
+ /**
376
+ * @see https://core.telegram.org/bots/api#deletechatphoto
377
+ */
378
+ deleteChatPhoto(...args) {
379
+ this.assert(this.chat, 'deleteChatPhoto');
380
+ return this.telegram.deleteChatPhoto(this.chat.id, ...args);
381
+ }
382
+ /**
383
+ * @see https://core.telegram.org/bots/api#setchattitle
384
+ */
385
+ setChatTitle(...args) {
386
+ this.assert(this.chat, 'setChatTitle');
387
+ return this.telegram.setChatTitle(this.chat.id, ...args);
388
+ }
389
+ /**
390
+ * @see https://core.telegram.org/bots/api#setchatdescription
391
+ */
392
+ setChatDescription(...args) {
393
+ this.assert(this.chat, 'setChatDescription');
394
+ return this.telegram.setChatDescription(this.chat.id, ...args);
395
+ }
396
+ /**
397
+ * @see https://core.telegram.org/bots/api#pinchatmessage
398
+ */
399
+ pinChatMessage(...args) {
400
+ this.assert(this.chat, 'pinChatMessage');
401
+ return this.telegram.pinChatMessage(this.chat.id, ...args);
402
+ }
403
+ /**
404
+ * @see https://core.telegram.org/bots/api#unpinchatmessage
405
+ */
406
+ unpinChatMessage(...args) {
407
+ this.assert(this.chat, 'unpinChatMessage');
408
+ return this.telegram.unpinChatMessage(this.chat.id, ...args);
409
+ }
410
+ /**
411
+ * @see https://core.telegram.org/bots/api#unpinallchatmessages
412
+ */
413
+ unpinAllChatMessages(...args) {
414
+ this.assert(this.chat, 'unpinAllChatMessages');
415
+ return this.telegram.unpinAllChatMessages(this.chat.id, ...args);
416
+ }
417
+ /**
418
+ * @see https://core.telegram.org/bots/api#leavechat
419
+ */
420
+ leaveChat(...args) {
421
+ this.assert(this.chat, 'leaveChat');
422
+ return this.telegram.leaveChat(this.chat.id, ...args);
423
+ }
424
+ /**
425
+ * @see https://core.telegram.org/bots/api#setchatpermissions
426
+ */
427
+ setChatPermissions(...args) {
428
+ this.assert(this.chat, 'setChatPermissions');
429
+ return this.telegram.setChatPermissions(this.chat.id, ...args);
430
+ }
431
+ /**
432
+ * @see https://core.telegram.org/bots/api#getchatadministrators
433
+ */
434
+ getChatAdministrators(...args) {
435
+ this.assert(this.chat, 'getChatAdministrators');
436
+ return this.telegram.getChatAdministrators(this.chat.id, ...args);
437
+ }
438
+ /**
439
+ * @see https://core.telegram.org/bots/api#getchatmember
440
+ */
441
+ getChatMember(...args) {
442
+ this.assert(this.chat, 'getChatMember');
443
+ return this.telegram.getChatMember(this.chat.id, ...args);
444
+ }
445
+ /**
446
+ * @see https://core.telegram.org/bots/api#getchatmembercount
447
+ */
448
+ getChatMembersCount(...args) {
449
+ this.assert(this.chat, 'getChatMembersCount');
450
+ return this.telegram.getChatMembersCount(this.chat.id, ...args);
451
+ }
452
+ /**
453
+ * @see https://core.telegram.org/bots/api#setpassportdataerrors
454
+ */
455
+ setPassportDataErrors(errors) {
456
+ this.assert(this.from, 'setPassportDataErrors');
457
+ return this.telegram.setPassportDataErrors(this.from.id, errors);
458
+ }
459
+ /**
460
+ * @see https://core.telegram.org/bots/api#sendphoto
461
+ */
462
+ sendPhoto(photo, extra) {
463
+ this.assert(this.chat, 'sendPhoto');
464
+ return this.telegram.sendPhoto(this.chat.id, photo, {
465
+ message_thread_id: getThreadId(this),
466
+ ...extra,
467
+ });
468
+ }
469
+ /**
470
+ * @see https://core.telegram.org/bots/api#sendphoto
471
+ */
472
+ replyWithPhoto(...args) {
473
+ return this.sendPhoto(...args);
474
+ }
475
+ /**
476
+ * @see https://core.telegram.org/bots/api#sendmediagroup
477
+ */
478
+ sendMediaGroup(media, extra) {
479
+ this.assert(this.chat, 'sendMediaGroup');
480
+ return this.telegram.sendMediaGroup(this.chat.id, media, {
481
+ message_thread_id: getThreadId(this),
482
+ ...extra,
483
+ });
484
+ }
485
+ /**
486
+ * @see https://core.telegram.org/bots/api#sendmediagroup
487
+ */
488
+ replyWithMediaGroup(...args) {
489
+ return this.sendMediaGroup(...args);
490
+ }
491
+ /**
492
+ * @see https://core.telegram.org/bots/api#sendaudio
493
+ */
494
+ sendAudio(audio, extra) {
495
+ this.assert(this.chat, 'sendAudio');
496
+ return this.telegram.sendAudio(this.chat.id, audio, {
497
+ message_thread_id: getThreadId(this),
498
+ ...extra,
499
+ });
500
+ }
501
+ /**
502
+ * @see https://core.telegram.org/bots/api#sendaudio
503
+ */
504
+ replyWithAudio(...args) {
505
+ return this.sendAudio(...args);
506
+ }
507
+ /**
508
+ * @see https://core.telegram.org/bots/api#senddice
509
+ */
510
+ sendDice(extra) {
511
+ this.assert(this.chat, 'sendDice');
512
+ return this.telegram.sendDice(this.chat.id, {
513
+ message_thread_id: getThreadId(this),
514
+ ...extra,
515
+ });
516
+ }
517
+ /**
518
+ * @see https://core.telegram.org/bots/api#senddice
519
+ */
520
+ replyWithDice(...args) {
521
+ return this.sendDice(...args);
522
+ }
523
+ /**
524
+ * @see https://core.telegram.org/bots/api#senddocument
525
+ */
526
+ sendDocument(document, extra) {
527
+ this.assert(this.chat, 'sendDocument');
528
+ return this.telegram.sendDocument(this.chat.id, document, {
529
+ message_thread_id: getThreadId(this),
530
+ ...extra,
531
+ });
532
+ }
533
+ /**
534
+ * @see https://core.telegram.org/bots/api#senddocument
535
+ */
536
+ replyWithDocument(...args) {
537
+ return this.sendDocument(...args);
538
+ }
539
+ /**
540
+ * @see https://core.telegram.org/bots/api#sendsticker
541
+ */
542
+ sendSticker(sticker, extra) {
543
+ this.assert(this.chat, 'sendSticker');
544
+ return this.telegram.sendSticker(this.chat.id, sticker, {
545
+ message_thread_id: getThreadId(this),
546
+ ...extra,
547
+ });
548
+ }
549
+ /**
550
+ * @see https://core.telegram.org/bots/api#sendsticker
551
+ */
552
+ replyWithSticker(...args) {
553
+ return this.sendSticker(...args);
554
+ }
555
+ /**
556
+ * @see https://core.telegram.org/bots/api#sendvideo
557
+ */
558
+ sendVideo(video, extra) {
559
+ this.assert(this.chat, 'sendVideo');
560
+ return this.telegram.sendVideo(this.chat.id, video, {
561
+ message_thread_id: getThreadId(this),
562
+ ...extra,
563
+ });
564
+ }
565
+ /**
566
+ * @see https://core.telegram.org/bots/api#sendvideo
567
+ */
568
+ replyWithVideo(...args) {
569
+ return this.sendVideo(...args);
570
+ }
571
+ /**
572
+ * @see https://core.telegram.org/bots/api#sendanimation
573
+ */
574
+ sendAnimation(animation, extra) {
575
+ this.assert(this.chat, 'sendAnimation');
576
+ return this.telegram.sendAnimation(this.chat.id, animation, {
577
+ message_thread_id: getThreadId(this),
578
+ ...extra,
579
+ });
580
+ }
581
+ /**
582
+ * @see https://core.telegram.org/bots/api#sendanimation
583
+ */
584
+ replyWithAnimation(...args) {
585
+ return this.sendAnimation(...args);
586
+ }
587
+ /**
588
+ * @see https://core.telegram.org/bots/api#sendvideonote
589
+ */
590
+ sendVideoNote(videoNote, extra) {
591
+ this.assert(this.chat, 'sendVideoNote');
592
+ return this.telegram.sendVideoNote(this.chat.id, videoNote, {
593
+ message_thread_id: getThreadId(this),
594
+ ...extra,
595
+ });
596
+ }
597
+ /**
598
+ * @see https://core.telegram.org/bots/api#sendvideonote
599
+ */
600
+ replyWithVideoNote(...args) {
601
+ return this.sendVideoNote(...args);
602
+ }
603
+ /**
604
+ * @see https://core.telegram.org/bots/api#sendinvoice
605
+ */
606
+ sendInvoice(invoice, extra) {
607
+ this.assert(this.chat, 'sendInvoice');
608
+ return this.telegram.sendInvoice(this.chat.id, invoice, {
609
+ message_thread_id: getThreadId(this),
610
+ ...extra,
611
+ });
612
+ }
613
+ /**
614
+ * @see https://core.telegram.org/bots/api#sendinvoice
615
+ */
616
+ replyWithInvoice(...args) {
617
+ return this.sendInvoice(...args);
618
+ }
619
+ /**
620
+ * @see https://core.telegram.org/bots/api#sendgame
621
+ */
622
+ sendGame(game, extra) {
623
+ this.assert(this.chat, 'sendGame');
624
+ return this.telegram.sendGame(this.chat.id, game, {
625
+ message_thread_id: getThreadId(this),
626
+ ...extra,
627
+ });
628
+ }
629
+ /**
630
+ * @see https://core.telegram.org/bots/api#sendgame
631
+ */
632
+ replyWithGame(...args) {
633
+ return this.sendGame(...args);
634
+ }
635
+ /**
636
+ * @see https://core.telegram.org/bots/api#sendvoice
637
+ */
638
+ sendVoice(voice, extra) {
639
+ this.assert(this.chat, 'sendVoice');
640
+ return this.telegram.sendVoice(this.chat.id, voice, {
641
+ message_thread_id: getThreadId(this),
642
+ ...extra,
643
+ });
644
+ }
645
+ /**
646
+ * @see https://core.telegram.org/bots/api#sendvoice
647
+ */
648
+ replyWithVoice(...args) {
649
+ return this.sendVoice(...args);
650
+ }
651
+ /**
652
+ * @see https://core.telegram.org/bots/api#sendpoll
653
+ */
654
+ sendPoll(poll, options, extra) {
655
+ this.assert(this.chat, 'sendPoll');
656
+ return this.telegram.sendPoll(this.chat.id, poll, options, {
657
+ message_thread_id: getThreadId(this),
658
+ ...extra,
659
+ });
660
+ }
661
+ /**
662
+ * @see https://core.telegram.org/bots/api#sendpoll
663
+ */
664
+ replyWithPoll(...args) {
665
+ return this.sendPoll(...args);
666
+ }
667
+ /**
668
+ * @see https://core.telegram.org/bots/api#sendpoll
669
+ */
670
+ sendQuiz(quiz, options, extra) {
671
+ this.assert(this.chat, 'sendQuiz');
672
+ return this.telegram.sendQuiz(this.chat.id, quiz, options, {
673
+ message_thread_id: getThreadId(this),
674
+ ...extra,
675
+ });
676
+ }
677
+ /**
678
+ * @see https://core.telegram.org/bots/api#sendpoll
679
+ */
680
+ replyWithQuiz(...args) {
681
+ return this.sendQuiz(...args);
682
+ }
683
+ /**
684
+ * @see https://core.telegram.org/bots/api#stoppoll
685
+ */
686
+ stopPoll(...args) {
687
+ this.assert(this.chat, 'stopPoll');
688
+ return this.telegram.stopPoll(this.chat.id, ...args);
689
+ }
690
+ /**
691
+ * @see https://core.telegram.org/bots/api#sendchataction
692
+ */
693
+ sendChatAction(action, extra) {
694
+ this.assert(this.chat, 'sendChatAction');
695
+ return this.telegram.sendChatAction(this.chat.id, action, {
696
+ message_thread_id: getThreadId(this),
697
+ ...extra,
698
+ });
699
+ }
700
+ /**
701
+ * @see https://core.telegram.org/bots/api#sendchataction
702
+ *
703
+ * Sends the sendChatAction request repeatedly, with a delay between requests,
704
+ * as long as the provided callback function is being processed.
705
+ *
706
+ * The sendChatAction errors should be ignored, because the goal is the actual long process completing and performing an action.
707
+ *
708
+ * @param action - chat action type.
709
+ * @param callback - a function to run along with the chat action.
710
+ * @param extra - extra parameters for sendChatAction.
711
+ * @param {number} [extra.intervalDuration=8000] - The duration (in milliseconds) between subsequent sendChatAction requests.
712
+ */
713
+ async persistentChatAction(action, callback, { intervalDuration, ...extra } = {}) {
714
+ await this.sendChatAction(action, { ...extra });
715
+ const timer = setInterval(() => this.sendChatAction(action, { ...extra }).catch((err) => {
716
+ debug('Ignored error while persisting sendChatAction:', err);
717
+ }), intervalDuration ?? 4000);
718
+ try {
719
+ await callback();
720
+ }
721
+ finally {
722
+ clearInterval(timer);
723
+ }
724
+ }
725
+ /**
726
+ * @deprecated use {@link Context.sendChatAction} instead
727
+ * @see https://core.telegram.org/bots/api#sendchataction
728
+ */
729
+ replyWithChatAction(...args) {
730
+ return this.sendChatAction(...args);
731
+ }
732
+ /**
733
+ * Shorthand for {@link Telegram.setMessageReaction}
734
+ * @param reaction An emoji or custom_emoji_id to set as reaction to current message. Leave empty to remove reactions.
735
+ * @param is_big Pass True to set the reaction with a big animation
736
+ */
737
+ react(reaction, is_big) {
738
+ this.assert(this.chat, 'setMessageReaction');
739
+ this.assert(this.msgId, 'setMessageReaction');
740
+ const emojis = reaction
741
+ ? Array.isArray(reaction)
742
+ ? reaction
743
+ : [reaction]
744
+ : undefined;
745
+ const reactions = emojis?.map((emoji) => typeof emoji === 'string'
746
+ ? reactions_1.Digit.has(emoji[0])
747
+ ? { type: 'custom_emoji', custom_emoji_id: emoji }
748
+ : { type: 'emoji', emoji: emoji }
749
+ : emoji);
750
+ return this.telegram.setMessageReaction(this.chat.id, this.msgId, reactions, is_big);
751
+ }
752
+ /**
753
+ * @see https://core.telegram.org/bots/api#sendlocation
754
+ */
755
+ sendLocation(latitude, longitude, extra) {
756
+ this.assert(this.chat, 'sendLocation');
757
+ return this.telegram.sendLocation(this.chat.id, latitude, longitude, {
758
+ message_thread_id: getThreadId(this),
759
+ ...extra,
760
+ });
761
+ }
762
+ /**
763
+ * @see https://core.telegram.org/bots/api#sendlocation
764
+ */
765
+ replyWithLocation(...args) {
766
+ return this.sendLocation(...args);
767
+ }
768
+ /**
769
+ * @see https://core.telegram.org/bots/api#sendvenue
770
+ */
771
+ sendVenue(latitude, longitude, title, address, extra) {
772
+ this.assert(this.chat, 'sendVenue');
773
+ return this.telegram.sendVenue(this.chat.id, latitude, longitude, title, address, { message_thread_id: getThreadId(this), ...extra });
774
+ }
775
+ /**
776
+ * @see https://core.telegram.org/bots/api#sendvenue
777
+ */
778
+ replyWithVenue(...args) {
779
+ return this.sendVenue(...args);
780
+ }
781
+ /**
782
+ * @see https://core.telegram.org/bots/api#sendcontact
783
+ */
784
+ sendContact(phoneNumber, firstName, extra) {
785
+ this.assert(this.chat, 'sendContact');
786
+ return this.telegram.sendContact(this.chat.id, phoneNumber, firstName, {
787
+ message_thread_id: getThreadId(this),
788
+ ...extra,
789
+ });
790
+ }
791
+ /**
792
+ * @see https://core.telegram.org/bots/api#sendcontact
793
+ */
794
+ replyWithContact(...args) {
795
+ return this.sendContact(...args);
796
+ }
797
+ /**
798
+ * @deprecated use {@link Telegram.getStickerSet}
799
+ * @see https://core.telegram.org/bots/api#getstickerset
800
+ */
801
+ getStickerSet(setName) {
802
+ return this.telegram.getStickerSet(setName);
803
+ }
804
+ /**
805
+ * @see https://core.telegram.org/bots/api#setchatstickerset
806
+ */
807
+ setChatStickerSet(setName) {
808
+ this.assert(this.chat, 'setChatStickerSet');
809
+ return this.telegram.setChatStickerSet(this.chat.id, setName);
810
+ }
811
+ /**
812
+ * @see https://core.telegram.org/bots/api#deletechatstickerset
813
+ */
814
+ deleteChatStickerSet() {
815
+ this.assert(this.chat, 'deleteChatStickerSet');
816
+ return this.telegram.deleteChatStickerSet(this.chat.id);
817
+ }
818
+ /**
819
+ * Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this
820
+ * to work and must have the can_manage_topics administrator rights. Returns information about the created topic as a
821
+ * ForumTopic object.
822
+ *
823
+ * @see https://core.telegram.org/bots/api#createforumtopic
824
+ */
825
+ createForumTopic(...args) {
826
+ this.assert(this.chat, 'createForumTopic');
827
+ return this.telegram.createForumTopic(this.chat.id, ...args);
828
+ }
829
+ /**
830
+ * Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in
831
+ * the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the
832
+ * topic. Returns True on success.
833
+ *
834
+ * @see https://core.telegram.org/bots/api#editforumtopic
835
+ */
836
+ editForumTopic(extra) {
837
+ this.assert(this.chat, 'editForumTopic');
838
+ this.assert(this.message?.message_thread_id, 'editForumTopic');
839
+ return this.telegram.editForumTopic(this.chat.id, this.message.message_thread_id, extra);
840
+ }
841
+ /**
842
+ * Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat
843
+ * for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic.
844
+ * Returns True on success.
845
+ *
846
+ * @see https://core.telegram.org/bots/api#closeforumtopic
847
+ */
848
+ closeForumTopic() {
849
+ this.assert(this.chat, 'closeForumTopic');
850
+ this.assert(this.message?.message_thread_id, 'closeForumTopic');
851
+ return this.telegram.closeForumTopic(this.chat.id, this.message.message_thread_id);
852
+ }
853
+ /**
854
+ * Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat
855
+ * for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic.
856
+ * Returns True on success.
857
+ *
858
+ * @see https://core.telegram.org/bots/api#reopenforumtopic
859
+ */
860
+ reopenForumTopic() {
861
+ this.assert(this.chat, 'reopenForumTopic');
862
+ this.assert(this.message?.message_thread_id, 'reopenForumTopic');
863
+ return this.telegram.reopenForumTopic(this.chat.id, this.message.message_thread_id);
864
+ }
865
+ /**
866
+ * Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an
867
+ * administrator in the chat for this to work and must have the can_delete_messages administrator rights.
868
+ * Returns True on success.
869
+ *
870
+ * @see https://core.telegram.org/bots/api#deleteforumtopic
871
+ */
872
+ deleteForumTopic() {
873
+ this.assert(this.chat, 'deleteForumTopic');
874
+ this.assert(this.message?.message_thread_id, 'deleteForumTopic');
875
+ return this.telegram.deleteForumTopic(this.chat.id, this.message.message_thread_id);
876
+ }
877
+ /**
878
+ * Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat
879
+ * for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.
880
+ *
881
+ * @see https://core.telegram.org/bots/api#unpinallforumtopicmessages
882
+ */
883
+ unpinAllForumTopicMessages() {
884
+ this.assert(this.chat, 'unpinAllForumTopicMessages');
885
+ this.assert(this.message?.message_thread_id, 'unpinAllForumTopicMessages');
886
+ return this.telegram.unpinAllForumTopicMessages(this.chat.id, this.message.message_thread_id);
887
+ }
888
+ /**
889
+ * Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator
890
+ * in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.
891
+ *
892
+ * @see https://core.telegram.org/bots/api#editgeneralforumtopic
893
+ */
894
+ editGeneralForumTopic(name) {
895
+ this.assert(this.chat, 'editGeneralForumTopic');
896
+ return this.telegram.editGeneralForumTopic(this.chat.id, name);
897
+ }
898
+ /**
899
+ * Use this method to close an open 'General' topic in a forum supergroup chat. The bot must be an administrator in the
900
+ * chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
901
+ *
902
+ * @see https://core.telegram.org/bots/api#closegeneralforumtopic
903
+ */
904
+ closeGeneralForumTopic() {
905
+ this.assert(this.chat, 'closeGeneralForumTopic');
906
+ return this.telegram.closeGeneralForumTopic(this.chat.id);
907
+ }
908
+ /**
909
+ * Use this method to reopen a closed 'General' topic in a forum supergroup chat. The bot must be an administrator in
910
+ * the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically
911
+ * unhidden if it was hidden. Returns True on success.
912
+ *
913
+ * @see https://core.telegram.org/bots/api#reopengeneralforumtopic
914
+ */
915
+ reopenGeneralForumTopic() {
916
+ this.assert(this.chat, 'reopenGeneralForumTopic');
917
+ return this.telegram.reopenGeneralForumTopic(this.chat.id);
918
+ }
919
+ /**
920
+ * Use this method to hide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat
921
+ * for this to work and must have the can_manage_topics administrator rights. The topic will be automatically closed
922
+ * if it was open. Returns True on success.
923
+ *
924
+ * @see https://core.telegram.org/bots/api#hidegeneralforumtopic
925
+ */
926
+ hideGeneralForumTopic() {
927
+ this.assert(this.chat, 'hideGeneralForumTopic');
928
+ return this.telegram.hideGeneralForumTopic(this.chat.id);
929
+ }
930
+ /**
931
+ * Use this method to unhide the 'General' topic in a forum supergroup chat. The bot must be an administrator in the
932
+ * chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
933
+ *
934
+ * @see https://core.telegram.org/bots/api#unhidegeneralforumtopic
935
+ */
936
+ unhideGeneralForumTopic() {
937
+ this.assert(this.chat, 'unhideGeneralForumTopic');
938
+ return this.telegram.unhideGeneralForumTopic(this.chat.id);
939
+ }
940
+ /**
941
+ * Use this method to clear the list of pinned messages in a General forum topic.
942
+ * The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator
943
+ * right in the supergroup.
944
+ *
945
+ * @param chat_id Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
946
+ *
947
+ * @see https://core.telegram.org/bots/api#unpinallgeneralforumtopicmessages
948
+ */
949
+ unpinAllGeneralForumTopicMessages() {
950
+ this.assert(this.chat, 'unpinAllGeneralForumTopicMessages');
951
+ return this.telegram.unpinAllGeneralForumTopicMessages(this.chat.id);
952
+ }
953
+ /**
954
+ * @deprecated use {@link Telegram.setStickerPositionInSet}
955
+ * @see https://core.telegram.org/bots/api#setstickerpositioninset
956
+ */
957
+ setStickerPositionInSet(sticker, position) {
958
+ return this.telegram.setStickerPositionInSet(sticker, position);
959
+ }
960
+ /**
961
+ * @deprecated use {@link Telegram.setStickerSetThumbnail}
962
+ * @see https://core.telegram.org/bots/api#setstickersetthumbnail
963
+ */
964
+ setStickerSetThumb(...args) {
965
+ return this.telegram.setStickerSetThumbnail(...args);
966
+ }
967
+ setStickerSetThumbnail(...args) {
968
+ return this.telegram.setStickerSetThumbnail(...args);
969
+ }
970
+ setStickerMaskPosition(...args) {
971
+ return this.telegram.setStickerMaskPosition(...args);
972
+ }
973
+ setStickerKeywords(...args) {
974
+ return this.telegram.setStickerKeywords(...args);
975
+ }
976
+ setStickerEmojiList(...args) {
977
+ return this.telegram.setStickerEmojiList(...args);
978
+ }
979
+ deleteStickerSet(...args) {
980
+ return this.telegram.deleteStickerSet(...args);
981
+ }
982
+ setStickerSetTitle(...args) {
983
+ return this.telegram.setStickerSetTitle(...args);
984
+ }
985
+ setCustomEmojiStickerSetThumbnail(...args) {
986
+ return this.telegram.setCustomEmojiStickerSetThumbnail(...args);
987
+ }
988
+ /**
989
+ * @deprecated use {@link Telegram.deleteStickerFromSet}
990
+ * @see https://core.telegram.org/bots/api#deletestickerfromset
991
+ */
992
+ deleteStickerFromSet(sticker) {
993
+ return this.telegram.deleteStickerFromSet(sticker);
994
+ }
995
+ /**
996
+ * @see https://core.telegram.org/bots/api#uploadstickerfile
997
+ */
998
+ uploadStickerFile(...args) {
999
+ this.assert(this.from, 'uploadStickerFile');
1000
+ return this.telegram.uploadStickerFile(this.from.id, ...args);
1001
+ }
1002
+ /**
1003
+ * @see https://core.telegram.org/bots/api#createnewstickerset
1004
+ */
1005
+ createNewStickerSet(...args) {
1006
+ this.assert(this.from, 'createNewStickerSet');
1007
+ return this.telegram.createNewStickerSet(this.from.id, ...args);
1008
+ }
1009
+ /**
1010
+ * @see https://core.telegram.org/bots/api#addstickertoset
1011
+ */
1012
+ addStickerToSet(...args) {
1013
+ this.assert(this.from, 'addStickerToSet');
1014
+ return this.telegram.addStickerToSet(this.from.id, ...args);
1015
+ }
1016
+ /**
1017
+ * @deprecated use {@link Telegram.getMyCommands}
1018
+ * @see https://core.telegram.org/bots/api#getmycommands
1019
+ */
1020
+ getMyCommands() {
1021
+ return this.telegram.getMyCommands();
1022
+ }
1023
+ /**
1024
+ * @deprecated use {@link Telegram.setMyCommands}
1025
+ * @see https://core.telegram.org/bots/api#setmycommands
1026
+ */
1027
+ setMyCommands(commands) {
1028
+ return this.telegram.setMyCommands(commands);
1029
+ }
1030
+ /**
1031
+ * @deprecated use {@link Context.replyWithMarkdownV2}
1032
+ * @see https://core.telegram.org/bots/api#sendmessage
1033
+ */
1034
+ replyWithMarkdown(markdown, extra) {
1035
+ return this.reply(markdown, { parse_mode: 'Markdown', ...extra });
1036
+ }
1037
+ /**
1038
+ * @see https://core.telegram.org/bots/api#sendmessage
1039
+ */
1040
+ replyWithMarkdownV2(markdown, extra) {
1041
+ return this.reply(markdown, { parse_mode: 'MarkdownV2', ...extra });
1042
+ }
1043
+ /**
1044
+ * @see https://core.telegram.org/bots/api#sendmessage
1045
+ */
1046
+ replyWithHTML(html, extra) {
1047
+ return this.reply(html, { parse_mode: 'HTML', ...extra });
1048
+ }
1049
+ // -------------------------------------------------------------------------
1050
+ // Bot API 10.1 — Rich Messages
1051
+ // -------------------------------------------------------------------------
1052
+ /**
1053
+ * Context-aware shorthand for {@link Telegram.sendRichMessage}.
1054
+ * Sends a structured rich message to the current chat.
1055
+ * @see https://core.telegram.org/bots/api#sendrichmessage
1056
+ */
1057
+ sendRichMessage(richMessage, extra) {
1058
+ this.assert(this.chat, 'sendRichMessage');
1059
+ return this.telegram.sendRichMessage(this.chat.id, richMessage, extra);
1060
+ }
1061
+ /**
1062
+ * Context-aware shorthand for {@link Telegram.sendRichMessageDraft}.
1063
+ * Streams a partial rich message (private chats only). Draft is ephemeral (30s).
1064
+ * Must finalize with sendRichMessage using the same draft_id.
1065
+ * @param draftId Non-zero draft ID; updates with same ID are animated
1066
+ * @see https://core.telegram.org/bots/api#sendrichmessagedraft
1067
+ */
1068
+ sendRichMessageDraft(draftId, richMessage, extra) {
1069
+ this.assert(this.chat, 'sendRichMessageDraft');
1070
+ return this.telegram.sendRichMessageDraft(this.chat.id, draftId, richMessage, extra);
1071
+ }
1072
+ /**
1073
+ * Edit current message with a rich message format.
1074
+ */
1075
+ editRichMessage(richMessage, extra) {
1076
+ this.assert(this.msgId ?? this.inlineMessageId, 'editRichMessage');
1077
+ return this.telegram.editRichMessage(this.chat?.id, this.msgId, this.inlineMessageId, richMessage, extra);
1078
+ }
1079
+ /**
1080
+ * Enqueue a Telegram API call for the current chat to prevent 429 Too Many Requests errors.
1081
+ */
1082
+ sendQueued(task) {
1083
+ const key = this.chat?.id ?? 'global';
1084
+ return smart_queue_1.SmartQueue.getInstance().enqueue(key, task);
1085
+ }
1086
+ /**
1087
+ * Create a live AI stream adapter bound to the current context.
1088
+ */
1089
+ streamAI(options = {}) {
1090
+ return new ai_stream_1.AIStreamAdapter(this, options);
1091
+ }
1092
+ /**
1093
+ * Reply to the current message with a rich message.
1094
+ * Convenience wrapper around {@link Context.sendRichMessage} that sets reply_parameters automatically.
1095
+ */
1096
+ replyWithRichMessageContent(richMessage, extra) {
1097
+ this.assert(this.chat, 'replyWithRichMessageContent');
1098
+ this.assert(this.msgId, 'replyWithRichMessageContent');
1099
+ return this.telegram.sendRichMessage(this.chat.id, richMessage, {
1100
+ reply_parameters: { message_id: this.msgId },
1101
+ ...extra,
1102
+ });
1103
+ }
1104
+ /**
1105
+ * Send a rich message with combined text, inline keyboard, parse mode, and link preview options.
1106
+ *
1107
+ * @example
1108
+ * ctx.replyWithRichMessage({
1109
+ * text: '<b>Hello!</b> Choose an option:',
1110
+ * parseMode: 'HTML',
1111
+ * buttons: [
1112
+ * [{ text: 'Visit Website', url: 'https://example.com' }],
1113
+ * [{ text: 'Callback', callback_data: 'my_action' }],
1114
+ * ],
1115
+ * disableLinkPreview: true,
1116
+ * })
1117
+ */
1118
+ replyWithRichMessage(options) {
1119
+ const { text, parseMode = 'HTML', buttons, disableLinkPreview, extra } = options;
1120
+ return this.reply(text, {
1121
+ parse_mode: parseMode,
1122
+ link_preview_options: disableLinkPreview ? { is_disabled: true } : undefined,
1123
+ reply_markup: buttons?.length
1124
+ ? { inline_keyboard: buttons }
1125
+ : undefined,
1126
+ ...extra,
1127
+ });
1128
+ }
1129
+ /**
1130
+ * @see https://core.telegram.org/bots/api#deletemessage
1131
+ */
1132
+ deleteMessage(messageId) {
1133
+ this.assert(this.chat, 'deleteMessage');
1134
+ if (typeof messageId !== 'undefined')
1135
+ return this.telegram.deleteMessage(this.chat.id, messageId);
1136
+ this.assert(this.msgId, 'deleteMessage');
1137
+ return this.telegram.deleteMessage(this.chat.id, this.msgId);
1138
+ }
1139
+ /**
1140
+ * Context-aware shorthand for {@link Telegram.deleteMessages}
1141
+ * @param messageIds Identifiers of 1-100 messages to delete. See deleteMessage for limitations on which messages can be deleted
1142
+ */
1143
+ deleteMessages(messageIds) {
1144
+ this.assert(this.chat, 'deleteMessages');
1145
+ return this.telegram.deleteMessages(this.chat.id, messageIds);
1146
+ }
1147
+ /**
1148
+ * @see https://core.telegram.org/bots/api#forwardmessage
1149
+ */
1150
+ forwardMessage(chatId, extra) {
1151
+ this.assert(this.chat, 'forwardMessage');
1152
+ this.assert(this.msgId, 'forwardMessage');
1153
+ return this.telegram.forwardMessage(chatId, this.chat.id, this.msgId, extra);
1154
+ }
1155
+ /**
1156
+ * Shorthand for {@link Telegram.forwardMessages}
1157
+ * @see https://core.telegram.org/bots/api#forwardmessages
1158
+ */
1159
+ forwardMessages(chatId, messageIds, extra) {
1160
+ this.assert(this.chat, 'forwardMessages');
1161
+ return this.telegram.forwardMessages(chatId, this.chat.id, messageIds, extra);
1162
+ }
1163
+ /**
1164
+ * @see https://core.telegram.org/bots/api#copymessage
1165
+ */
1166
+ copyMessage(chatId, extra) {
1167
+ this.assert(this.chat, 'copyMessage');
1168
+ this.assert(this.msgId, 'copyMessage');
1169
+ return this.telegram.copyMessage(chatId, this.chat.id, this.msgId, extra);
1170
+ }
1171
+ /**
1172
+ * Context-aware shorthand for {@link Telegram.copyMessages}
1173
+ * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1174
+ * @param messageIds Identifiers of 1-100 messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order.
1175
+ */
1176
+ copyMessages(chatId, messageIds, extra) {
1177
+ this.assert(this.chat, 'copyMessages');
1178
+ return this.telegram.copyMessages(chatId, this.chat?.id, messageIds, extra);
1179
+ }
1180
+ /**
1181
+ * @see https://core.telegram.org/bots/api#approvechatjoinrequest
1182
+ */
1183
+ approveChatJoinRequest(userId) {
1184
+ this.assert(this.chat, 'approveChatJoinRequest');
1185
+ return this.telegram.approveChatJoinRequest(this.chat.id, userId);
1186
+ }
1187
+ /**
1188
+ * @see https://core.telegram.org/bots/api#declinechatjoinrequest
1189
+ */
1190
+ declineChatJoinRequest(userId) {
1191
+ this.assert(this.chat, 'declineChatJoinRequest');
1192
+ return this.telegram.declineChatJoinRequest(this.chat.id, userId);
1193
+ }
1194
+ /**
1195
+ * @see https://core.telegram.org/bots/api#banchatsenderchat
1196
+ */
1197
+ banChatSenderChat(senderChatId) {
1198
+ this.assert(this.chat, 'banChatSenderChat');
1199
+ return this.telegram.banChatSenderChat(this.chat.id, senderChatId);
1200
+ }
1201
+ /**
1202
+ * @see https://core.telegram.org/bots/api#unbanchatsenderchat
1203
+ */
1204
+ unbanChatSenderChat(senderChatId) {
1205
+ this.assert(this.chat, 'unbanChatSenderChat');
1206
+ return this.telegram.unbanChatSenderChat(this.chat.id, senderChatId);
1207
+ }
1208
+ /**
1209
+ * Use this method to change the bot's menu button in the current private chat. Returns true on success.
1210
+ * @see https://core.telegram.org/bots/api#setchatmenubutton
1211
+ */
1212
+ setChatMenuButton(menuButton) {
1213
+ this.assert(this.chat, 'setChatMenuButton');
1214
+ return this.telegram.setChatMenuButton({ chatId: this.chat.id, menuButton });
1215
+ }
1216
+ /**
1217
+ * Use this method to get the current value of the bot's menu button in the current private chat. Returns MenuButton on success.
1218
+ * @see https://core.telegram.org/bots/api#getchatmenubutton
1219
+ */
1220
+ getChatMenuButton() {
1221
+ this.assert(this.chat, 'getChatMenuButton');
1222
+ return this.telegram.getChatMenuButton({ chatId: this.chat.id });
1223
+ }
1224
+ /**
1225
+ * @see https://core.telegram.org/bots/api#setmydefaultadministratorrights
1226
+ */
1227
+ setMyDefaultAdministratorRights(extra) {
1228
+ return this.telegram.setMyDefaultAdministratorRights(extra);
1229
+ }
1230
+ /**
1231
+ * @see https://core.telegram.org/bots/api#getmydefaultadministratorrights
1232
+ */
1233
+ getMyDefaultAdministratorRights(extra) {
1234
+ return this.telegram.getMyDefaultAdministratorRights(extra);
1235
+ }
1236
+ }
1237
+ exports.Context = Context;
1238
+ exports.default = Context;
1239
+ const Msg = {
1240
+ isAccessible() {
1241
+ return 'date' in this && this.date !== 0;
1242
+ },
1243
+ has(...keys) {
1244
+ return keys.some((key) =>
1245
+ // @ts-expect-error TS doesn't understand key
1246
+ this[key] != undefined);
1247
+ },
1248
+ };
1249
+ function getMessageFromAnySource(ctx) {
1250
+ const msg = ctx.message ??
1251
+ ctx.editedMessage ??
1252
+ ctx.callbackQuery?.message ??
1253
+ ctx.channelPost ??
1254
+ ctx.editedChannelPost;
1255
+ if (msg)
1256
+ return Object.assign(Object.create(Msg), msg);
1257
+ }
1258
+ function getUserFromAnySource(ctx) {
1259
+ if (ctx.callbackQuery)
1260
+ return ctx.callbackQuery.from;
1261
+ const msg = ctx.msg;
1262
+ if (msg?.has('from'))
1263
+ return msg.from;
1264
+ return ((ctx.inlineQuery ??
1265
+ ctx.shippingQuery ??
1266
+ ctx.preCheckoutQuery ??
1267
+ ctx.chosenInlineResult ??
1268
+ ctx.chatMember ??
1269
+ ctx.myChatMember ??
1270
+ ctx.chatJoinRequest)?.from ??
1271
+ (ctx.messageReaction ?? ctx.pollAnswer ?? ctx.chatBoost?.boost.source)?.user);
1272
+ }
1273
+ function getMsgIdFromAnySource(ctx) {
1274
+ const msg = getMessageFromAnySource(ctx);
1275
+ return (msg ?? ctx.messageReaction ?? ctx.messageReactionCount)
1276
+ ?.message_id;
1277
+ }
1278
+ function getTextAndEntitiesFromAnySource(ctx) {
1279
+ const msg = ctx.msg;
1280
+ let text, entities;
1281
+ if (msg) {
1282
+ if ('text' in msg)
1283
+ (text = msg.text), (entities = msg.entities);
1284
+ else if ('caption' in msg)
1285
+ (text = msg.caption), (entities = msg.caption_entities);
1286
+ else if ('game' in msg)
1287
+ (text = msg.game.text), (entities = msg.game.text_entities);
1288
+ }
1289
+ else if (ctx.poll)
1290
+ (text = ctx.poll.explanation), (entities = ctx.poll.explanation_entities);
1291
+ return [text, entities];
1292
+ }
1293
+ const getThreadId = (ctx) => {
1294
+ const msg = ctx.msg;
1295
+ return msg?.isAccessible()
1296
+ ? msg.is_topic_message
1297
+ ? msg.message_thread_id
1298
+ : undefined
1299
+ : undefined;
1300
+ };