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 debug = (0, debug_1.default)('telegraf:context');
|
9 | class Context {
|
10 | constructor(update, telegram, botInfo) {
|
11 | this.update = update;
|
12 | this.telegram = telegram;
|
13 | this.botInfo = botInfo;
|
14 |
|
15 | this.state = {};
|
16 | }
|
17 | get updateType() {
|
18 | for (const key in this.update) {
|
19 | if (typeof this.update[key] === 'object')
|
20 | return key;
|
21 | }
|
22 | throw new Error(`Cannot determine \`updateType\` of ${JSON.stringify(this.update)}`);
|
23 | }
|
24 | get me() {
|
25 | var _a;
|
26 | return (_a = this.botInfo) === null || _a === void 0 ? void 0 : _a.username;
|
27 | }
|
28 | |
29 |
|
30 |
|
31 | get tg() {
|
32 | return this.telegram;
|
33 | }
|
34 | get message() {
|
35 | return this.update.message;
|
36 | }
|
37 | get editedMessage() {
|
38 | return this.update.edited_message;
|
39 | }
|
40 | get inlineQuery() {
|
41 | return this.update.inline_query;
|
42 | }
|
43 | get shippingQuery() {
|
44 | return this.update.shipping_query;
|
45 | }
|
46 | get preCheckoutQuery() {
|
47 | return this.update.pre_checkout_query;
|
48 | }
|
49 | get chosenInlineResult() {
|
50 | return this.update.chosen_inline_result;
|
51 | }
|
52 | get channelPost() {
|
53 | return this.update.channel_post;
|
54 | }
|
55 | get editedChannelPost() {
|
56 | return this.update.edited_channel_post;
|
57 | }
|
58 | get callbackQuery() {
|
59 | return this.update.callback_query;
|
60 | }
|
61 | get poll() {
|
62 | return this.update.poll;
|
63 | }
|
64 | get pollAnswer() {
|
65 | return this.update.poll_answer;
|
66 | }
|
67 | get myChatMember() {
|
68 | return this.update.my_chat_member;
|
69 | }
|
70 | get chatMember() {
|
71 | return this.update.chat_member;
|
72 | }
|
73 | get chatJoinRequest() {
|
74 | return this.update.chat_join_request;
|
75 | }
|
76 | get chat() {
|
77 | var _a, _b, _c, _d;
|
78 | return (_d = ((_c = (_b = (_a = this.chatMember) !== null && _a !== void 0 ? _a : this.myChatMember) !== null && _b !== void 0 ? _b : this.chatJoinRequest) !== null && _c !== void 0 ? _c : getMessageFromAnySource(this))) === null || _d === void 0 ? void 0 : _d.chat;
|
79 | }
|
80 | get senderChat() {
|
81 | var _a;
|
82 | return (_a = getMessageFromAnySource(this)) === null || _a === void 0 ? void 0 : _a.sender_chat;
|
83 | }
|
84 | get from() {
|
85 | var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
86 | return (_j = ((_h = (_g = (_f = (_e = (_d = (_c = (_b = (_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineQuery) !== null && _b !== void 0 ? _b : this.shippingQuery) !== null && _c !== void 0 ? _c : this.preCheckoutQuery) !== null && _d !== void 0 ? _d : this.chosenInlineResult) !== null && _e !== void 0 ? _e : this.chatMember) !== null && _f !== void 0 ? _f : this.myChatMember) !== null && _g !== void 0 ? _g : this.chatJoinRequest) !== null && _h !== void 0 ? _h : getMessageFromAnySource(this))) === null || _j === void 0 ? void 0 : _j.from;
|
87 | }
|
88 | get inlineMessageId() {
|
89 | var _a, _b;
|
90 | return (_b = ((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.chosenInlineResult)) === null || _b === void 0 ? void 0 : _b.inline_message_id;
|
91 | }
|
92 | get passportData() {
|
93 | var _a;
|
94 | if (this.message == null)
|
95 | return undefined;
|
96 | if (!('passport_data' in this.message))
|
97 | return undefined;
|
98 | return (_a = this.message) === null || _a === void 0 ? void 0 : _a.passport_data;
|
99 | }
|
100 | get webAppData() {
|
101 | if (!('message' in this.update &&
|
102 | this.update.message &&
|
103 | 'web_app_data' in this.update.message))
|
104 | return undefined;
|
105 | const { data, button_text } = this.update.message.web_app_data;
|
106 | return {
|
107 | data: {
|
108 | json() {
|
109 | return JSON.parse(data);
|
110 | },
|
111 | text() {
|
112 | return data;
|
113 | },
|
114 | },
|
115 | button_text,
|
116 | };
|
117 | }
|
118 | |
119 |
|
120 |
|
121 | get webhookReply() {
|
122 | return this.telegram.webhookReply;
|
123 | }
|
124 | set webhookReply(enable) {
|
125 | this.telegram.webhookReply = enable;
|
126 | }
|
127 | |
128 |
|
129 |
|
130 | assert(value, method) {
|
131 | if (value === undefined) {
|
132 | throw new TypeError(`Telegraf: "${method}" isn't available for "${this.updateType}"`);
|
133 | }
|
134 | }
|
135 | has(filters) {
|
136 | if (!Array.isArray(filters))
|
137 | filters = [filters];
|
138 | for (const filter of filters)
|
139 | if (
|
140 |
|
141 |
|
142 | typeof filter !== 'string'
|
143 | ?
|
144 | filter(this.update)
|
145 | :
|
146 | filter in this.update)
|
147 | return true;
|
148 | return false;
|
149 | }
|
150 | |
151 |
|
152 |
|
153 | answerInlineQuery(...args) {
|
154 | this.assert(this.inlineQuery, 'answerInlineQuery');
|
155 | return this.telegram.answerInlineQuery(this.inlineQuery.id, ...args);
|
156 | }
|
157 | |
158 |
|
159 |
|
160 | answerCbQuery(...args) {
|
161 | this.assert(this.callbackQuery, 'answerCbQuery');
|
162 | return this.telegram.answerCbQuery(this.callbackQuery.id, ...args);
|
163 | }
|
164 | |
165 |
|
166 |
|
167 | answerGameQuery(...args) {
|
168 | this.assert(this.callbackQuery, 'answerGameQuery');
|
169 | return this.telegram.answerGameQuery(this.callbackQuery.id, ...args);
|
170 | }
|
171 | |
172 |
|
173 |
|
174 | answerShippingQuery(...args) {
|
175 | this.assert(this.shippingQuery, 'answerShippingQuery');
|
176 | return this.telegram.answerShippingQuery(this.shippingQuery.id, ...args);
|
177 | }
|
178 | |
179 |
|
180 |
|
181 | answerPreCheckoutQuery(...args) {
|
182 | this.assert(this.preCheckoutQuery, 'answerPreCheckoutQuery');
|
183 | return this.telegram.answerPreCheckoutQuery(this.preCheckoutQuery.id, ...args);
|
184 | }
|
185 | |
186 |
|
187 |
|
188 | editMessageText(text, extra) {
|
189 | var _a, _b, _c, _d;
|
190 | this.assert((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineMessageId, 'editMessageText');
|
191 | return this.telegram.editMessageText((_b = this.chat) === null || _b === void 0 ? void 0 : _b.id, (_d = (_c = this.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.message_id, this.inlineMessageId, text, extra);
|
192 | }
|
193 | |
194 |
|
195 |
|
196 | editMessageCaption(caption, extra) {
|
197 | var _a, _b, _c, _d;
|
198 | this.assert((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineMessageId, 'editMessageCaption');
|
199 | return this.telegram.editMessageCaption((_b = this.chat) === null || _b === void 0 ? void 0 : _b.id, (_d = (_c = this.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.message_id, this.inlineMessageId, caption, extra);
|
200 | }
|
201 | |
202 |
|
203 |
|
204 | editMessageMedia(media, extra) {
|
205 | var _a, _b, _c, _d;
|
206 | this.assert((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineMessageId, 'editMessageMedia');
|
207 | return this.telegram.editMessageMedia((_b = this.chat) === null || _b === void 0 ? void 0 : _b.id, (_d = (_c = this.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.message_id, this.inlineMessageId, media, extra);
|
208 | }
|
209 | |
210 |
|
211 |
|
212 | editMessageReplyMarkup(markup) {
|
213 | var _a, _b, _c, _d;
|
214 | this.assert((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineMessageId, 'editMessageReplyMarkup');
|
215 | return this.telegram.editMessageReplyMarkup((_b = this.chat) === null || _b === void 0 ? void 0 : _b.id, (_d = (_c = this.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.message_id, this.inlineMessageId, markup);
|
216 | }
|
217 | |
218 |
|
219 |
|
220 | editMessageLiveLocation(latitude, longitude, extra) {
|
221 | var _a, _b, _c, _d;
|
222 | this.assert((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineMessageId, 'editMessageLiveLocation');
|
223 | return this.telegram.editMessageLiveLocation((_b = this.chat) === null || _b === void 0 ? void 0 : _b.id, (_d = (_c = this.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.message_id, this.inlineMessageId, latitude, longitude, extra);
|
224 | }
|
225 | |
226 |
|
227 |
|
228 | stopMessageLiveLocation(markup) {
|
229 | var _a, _b, _c, _d;
|
230 | this.assert((_a = this.callbackQuery) !== null && _a !== void 0 ? _a : this.inlineMessageId, 'stopMessageLiveLocation');
|
231 | return this.telegram.stopMessageLiveLocation((_b = this.chat) === null || _b === void 0 ? void 0 : _b.id, (_d = (_c = this.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) === null || _d === void 0 ? void 0 : _d.message_id, this.inlineMessageId, markup);
|
232 | }
|
233 | |
234 |
|
235 |
|
236 | sendMessage(text, extra) {
|
237 | this.assert(this.chat, 'sendMessage');
|
238 | return this.telegram.sendMessage(this.chat.id, text, {
|
239 | message_thread_id: getThreadId(this),
|
240 | ...extra,
|
241 | });
|
242 | }
|
243 | |
244 |
|
245 |
|
246 | reply(...args) {
|
247 | return this.sendMessage(...args);
|
248 | }
|
249 | |
250 |
|
251 |
|
252 | getChat(...args) {
|
253 | this.assert(this.chat, 'getChat');
|
254 | return this.telegram.getChat(this.chat.id, ...args);
|
255 | }
|
256 | |
257 |
|
258 |
|
259 | exportChatInviteLink(...args) {
|
260 | this.assert(this.chat, 'exportChatInviteLink');
|
261 | return this.telegram.exportChatInviteLink(this.chat.id, ...args);
|
262 | }
|
263 | |
264 |
|
265 |
|
266 | createChatInviteLink(...args) {
|
267 | this.assert(this.chat, 'createChatInviteLink');
|
268 | return this.telegram.createChatInviteLink(this.chat.id, ...args);
|
269 | }
|
270 | |
271 |
|
272 |
|
273 | editChatInviteLink(...args) {
|
274 | this.assert(this.chat, 'editChatInviteLink');
|
275 | return this.telegram.editChatInviteLink(this.chat.id, ...args);
|
276 | }
|
277 | |
278 |
|
279 |
|
280 | revokeChatInviteLink(...args) {
|
281 | this.assert(this.chat, 'revokeChatInviteLink');
|
282 | return this.telegram.revokeChatInviteLink(this.chat.id, ...args);
|
283 | }
|
284 | |
285 |
|
286 |
|
287 | banChatMember(...args) {
|
288 | this.assert(this.chat, 'banChatMember');
|
289 | return this.telegram.banChatMember(this.chat.id, ...args);
|
290 | }
|
291 | |
292 |
|
293 |
|
294 |
|
295 | get kickChatMember() {
|
296 | return this.banChatMember;
|
297 | }
|
298 | |
299 |
|
300 |
|
301 | unbanChatMember(...args) {
|
302 | this.assert(this.chat, 'unbanChatMember');
|
303 | return this.telegram.unbanChatMember(this.chat.id, ...args);
|
304 | }
|
305 | |
306 |
|
307 |
|
308 | restrictChatMember(...args) {
|
309 | this.assert(this.chat, 'restrictChatMember');
|
310 | return this.telegram.restrictChatMember(this.chat.id, ...args);
|
311 | }
|
312 | |
313 |
|
314 |
|
315 | promoteChatMember(...args) {
|
316 | this.assert(this.chat, 'promoteChatMember');
|
317 | return this.telegram.promoteChatMember(this.chat.id, ...args);
|
318 | }
|
319 | |
320 |
|
321 |
|
322 | setChatAdministratorCustomTitle(...args) {
|
323 | this.assert(this.chat, 'setChatAdministratorCustomTitle');
|
324 | return this.telegram.setChatAdministratorCustomTitle(this.chat.id, ...args);
|
325 | }
|
326 | |
327 |
|
328 |
|
329 | setChatPhoto(...args) {
|
330 | this.assert(this.chat, 'setChatPhoto');
|
331 | return this.telegram.setChatPhoto(this.chat.id, ...args);
|
332 | }
|
333 | |
334 |
|
335 |
|
336 | deleteChatPhoto(...args) {
|
337 | this.assert(this.chat, 'deleteChatPhoto');
|
338 | return this.telegram.deleteChatPhoto(this.chat.id, ...args);
|
339 | }
|
340 | |
341 |
|
342 |
|
343 | setChatTitle(...args) {
|
344 | this.assert(this.chat, 'setChatTitle');
|
345 | return this.telegram.setChatTitle(this.chat.id, ...args);
|
346 | }
|
347 | |
348 |
|
349 |
|
350 | setChatDescription(...args) {
|
351 | this.assert(this.chat, 'setChatDescription');
|
352 | return this.telegram.setChatDescription(this.chat.id, ...args);
|
353 | }
|
354 | |
355 |
|
356 |
|
357 | pinChatMessage(...args) {
|
358 | this.assert(this.chat, 'pinChatMessage');
|
359 | return this.telegram.pinChatMessage(this.chat.id, ...args);
|
360 | }
|
361 | |
362 |
|
363 |
|
364 | unpinChatMessage(...args) {
|
365 | this.assert(this.chat, 'unpinChatMessage');
|
366 | return this.telegram.unpinChatMessage(this.chat.id, ...args);
|
367 | }
|
368 | |
369 |
|
370 |
|
371 | unpinAllChatMessages(...args) {
|
372 | this.assert(this.chat, 'unpinAllChatMessages');
|
373 | return this.telegram.unpinAllChatMessages(this.chat.id, ...args);
|
374 | }
|
375 | |
376 |
|
377 |
|
378 | leaveChat(...args) {
|
379 | this.assert(this.chat, 'leaveChat');
|
380 | return this.telegram.leaveChat(this.chat.id, ...args);
|
381 | }
|
382 | |
383 |
|
384 |
|
385 | setChatPermissions(...args) {
|
386 | this.assert(this.chat, 'setChatPermissions');
|
387 | return this.telegram.setChatPermissions(this.chat.id, ...args);
|
388 | }
|
389 | |
390 |
|
391 |
|
392 | getChatAdministrators(...args) {
|
393 | this.assert(this.chat, 'getChatAdministrators');
|
394 | return this.telegram.getChatAdministrators(this.chat.id, ...args);
|
395 | }
|
396 | |
397 |
|
398 |
|
399 | getChatMember(...args) {
|
400 | this.assert(this.chat, 'getChatMember');
|
401 | return this.telegram.getChatMember(this.chat.id, ...args);
|
402 | }
|
403 | |
404 |
|
405 |
|
406 | getChatMembersCount(...args) {
|
407 | this.assert(this.chat, 'getChatMembersCount');
|
408 | return this.telegram.getChatMembersCount(this.chat.id, ...args);
|
409 | }
|
410 | |
411 |
|
412 |
|
413 | setPassportDataErrors(errors) {
|
414 | this.assert(this.from, 'setPassportDataErrors');
|
415 | return this.telegram.setPassportDataErrors(this.from.id, errors);
|
416 | }
|
417 | |
418 |
|
419 |
|
420 | sendPhoto(photo, extra) {
|
421 | this.assert(this.chat, 'sendPhoto');
|
422 | return this.telegram.sendPhoto(this.chat.id, photo, {
|
423 | message_thread_id: getThreadId(this),
|
424 | ...extra,
|
425 | });
|
426 | }
|
427 | |
428 |
|
429 |
|
430 | replyWithPhoto(...args) {
|
431 | return this.sendPhoto(...args);
|
432 | }
|
433 | |
434 |
|
435 |
|
436 | sendMediaGroup(media, extra) {
|
437 | this.assert(this.chat, 'sendMediaGroup');
|
438 | return this.telegram.sendMediaGroup(this.chat.id, media, {
|
439 | message_thread_id: getThreadId(this),
|
440 | ...extra,
|
441 | });
|
442 | }
|
443 | |
444 |
|
445 |
|
446 | replyWithMediaGroup(...args) {
|
447 | return this.sendMediaGroup(...args);
|
448 | }
|
449 | |
450 |
|
451 |
|
452 | sendAudio(audio, extra) {
|
453 | this.assert(this.chat, 'sendAudio');
|
454 | return this.telegram.sendAudio(this.chat.id, audio, {
|
455 | message_thread_id: getThreadId(this),
|
456 | ...extra,
|
457 | });
|
458 | }
|
459 | |
460 |
|
461 |
|
462 | replyWithAudio(...args) {
|
463 | return this.sendAudio(...args);
|
464 | }
|
465 | |
466 |
|
467 |
|
468 | sendDice(extra) {
|
469 | this.assert(this.chat, 'sendDice');
|
470 | return this.telegram.sendDice(this.chat.id, {
|
471 | message_thread_id: getThreadId(this),
|
472 | ...extra,
|
473 | });
|
474 | }
|
475 | |
476 |
|
477 |
|
478 | replyWithDice(...args) {
|
479 | return this.sendDice(...args);
|
480 | }
|
481 | |
482 |
|
483 |
|
484 | sendDocument(document, extra) {
|
485 | this.assert(this.chat, 'sendDocument');
|
486 | return this.telegram.sendDocument(this.chat.id, document, {
|
487 | message_thread_id: getThreadId(this),
|
488 | ...extra,
|
489 | });
|
490 | }
|
491 | |
492 |
|
493 |
|
494 | replyWithDocument(...args) {
|
495 | return this.sendDocument(...args);
|
496 | }
|
497 | |
498 |
|
499 |
|
500 | sendSticker(sticker, extra) {
|
501 | this.assert(this.chat, 'sendSticker');
|
502 | return this.telegram.sendSticker(this.chat.id, sticker, {
|
503 | message_thread_id: getThreadId(this),
|
504 | ...extra,
|
505 | });
|
506 | }
|
507 | |
508 |
|
509 |
|
510 | replyWithSticker(...args) {
|
511 | return this.sendSticker(...args);
|
512 | }
|
513 | |
514 |
|
515 |
|
516 | sendVideo(video, extra) {
|
517 | this.assert(this.chat, 'sendVideo');
|
518 | return this.telegram.sendVideo(this.chat.id, video, {
|
519 | message_thread_id: getThreadId(this),
|
520 | ...extra,
|
521 | });
|
522 | }
|
523 | |
524 |
|
525 |
|
526 | replyWithVideo(...args) {
|
527 | return this.sendVideo(...args);
|
528 | }
|
529 | |
530 |
|
531 |
|
532 | sendAnimation(animation, extra) {
|
533 | this.assert(this.chat, 'sendAnimation');
|
534 | return this.telegram.sendAnimation(this.chat.id, animation, {
|
535 | message_thread_id: getThreadId(this),
|
536 | ...extra,
|
537 | });
|
538 | }
|
539 | |
540 |
|
541 |
|
542 | replyWithAnimation(...args) {
|
543 | return this.sendAnimation(...args);
|
544 | }
|
545 | |
546 |
|
547 |
|
548 | sendVideoNote(videoNote, extra) {
|
549 | this.assert(this.chat, 'sendVideoNote');
|
550 | return this.telegram.sendVideoNote(this.chat.id, videoNote, {
|
551 | message_thread_id: getThreadId(this),
|
552 | ...extra,
|
553 | });
|
554 | }
|
555 | |
556 |
|
557 |
|
558 | replyWithVideoNote(...args) {
|
559 | return this.sendVideoNote(...args);
|
560 | }
|
561 | |
562 |
|
563 |
|
564 | sendInvoice(invoice, extra) {
|
565 | this.assert(this.chat, 'sendInvoice');
|
566 | return this.telegram.sendInvoice(this.chat.id, invoice, {
|
567 | message_thread_id: getThreadId(this),
|
568 | ...extra,
|
569 | });
|
570 | }
|
571 | |
572 |
|
573 |
|
574 | replyWithInvoice(...args) {
|
575 | return this.sendInvoice(...args);
|
576 | }
|
577 | |
578 |
|
579 |
|
580 | sendGame(game, extra) {
|
581 | this.assert(this.chat, 'sendGame');
|
582 | return this.telegram.sendGame(this.chat.id, game, {
|
583 | message_thread_id: getThreadId(this),
|
584 | ...extra,
|
585 | });
|
586 | }
|
587 | |
588 |
|
589 |
|
590 | replyWithGame(...args) {
|
591 | return this.sendGame(...args);
|
592 | }
|
593 | |
594 |
|
595 |
|
596 | sendVoice(voice, extra) {
|
597 | this.assert(this.chat, 'sendVoice');
|
598 | return this.telegram.sendVoice(this.chat.id, voice, {
|
599 | message_thread_id: getThreadId(this),
|
600 | ...extra,
|
601 | });
|
602 | }
|
603 | |
604 |
|
605 |
|
606 | replyWithVoice(...args) {
|
607 | return this.sendVoice(...args);
|
608 | }
|
609 | |
610 |
|
611 |
|
612 | sendPoll(poll, options, extra) {
|
613 | this.assert(this.chat, 'sendPoll');
|
614 | return this.telegram.sendPoll(this.chat.id, poll, options, {
|
615 | message_thread_id: getThreadId(this),
|
616 | ...extra,
|
617 | });
|
618 | }
|
619 | |
620 |
|
621 |
|
622 | replyWithPoll(...args) {
|
623 | return this.sendPoll(...args);
|
624 | }
|
625 | |
626 |
|
627 |
|
628 | sendQuiz(quiz, options, extra) {
|
629 | this.assert(this.chat, 'sendQuiz');
|
630 | return this.telegram.sendQuiz(this.chat.id, quiz, options, {
|
631 | message_thread_id: getThreadId(this),
|
632 | ...extra,
|
633 | });
|
634 | }
|
635 | |
636 |
|
637 |
|
638 | replyWithQuiz(...args) {
|
639 | return this.sendQuiz(...args);
|
640 | }
|
641 | |
642 |
|
643 |
|
644 | stopPoll(...args) {
|
645 | this.assert(this.chat, 'stopPoll');
|
646 | return this.telegram.stopPoll(this.chat.id, ...args);
|
647 | }
|
648 | |
649 |
|
650 |
|
651 | sendChatAction(action, extra) {
|
652 | this.assert(this.chat, 'sendChatAction');
|
653 | return this.telegram.sendChatAction(this.chat.id, action, {
|
654 | message_thread_id: getThreadId(this),
|
655 | ...extra,
|
656 | });
|
657 | }
|
658 | |
659 |
|
660 |
|
661 |
|
662 |
|
663 |
|
664 |
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 | async persistentChatAction(action, callback, { intervalDuration, ...extra } = {}) {
|
672 | await this.sendChatAction(action, { ...extra });
|
673 | const timer = setInterval(() => this.sendChatAction(action, { ...extra }).catch((err) => {
|
674 | debug('Ignored error while persisting sendChatAction:', err);
|
675 | }), intervalDuration !== null && intervalDuration !== void 0 ? intervalDuration : 4000);
|
676 | try {
|
677 | await callback();
|
678 | }
|
679 | finally {
|
680 | clearInterval(timer);
|
681 | }
|
682 | }
|
683 | |
684 |
|
685 |
|
686 |
|
687 | replyWithChatAction(...args) {
|
688 | return this.sendChatAction(...args);
|
689 | }
|
690 | |
691 |
|
692 |
|
693 | sendLocation(latitude, longitude, extra) {
|
694 | this.assert(this.chat, 'sendLocation');
|
695 | return this.telegram.sendLocation(this.chat.id, latitude, longitude, {
|
696 | message_thread_id: getThreadId(this),
|
697 | ...extra,
|
698 | });
|
699 | }
|
700 | |
701 |
|
702 |
|
703 | replyWithLocation(...args) {
|
704 | return this.sendLocation(...args);
|
705 | }
|
706 | |
707 |
|
708 |
|
709 | sendVenue(latitude, longitude, title, address, extra) {
|
710 | this.assert(this.chat, 'sendVenue');
|
711 | return this.telegram.sendVenue(this.chat.id, latitude, longitude, title, address, { message_thread_id: getThreadId(this), ...extra });
|
712 | }
|
713 | |
714 |
|
715 |
|
716 | replyWithVenue(...args) {
|
717 | return this.sendVenue(...args);
|
718 | }
|
719 | |
720 |
|
721 |
|
722 | sendContact(phoneNumber, firstName, extra) {
|
723 | this.assert(this.chat, 'sendContact');
|
724 | return this.telegram.sendContact(this.chat.id, phoneNumber, firstName, {
|
725 | message_thread_id: getThreadId(this),
|
726 | ...extra,
|
727 | });
|
728 | }
|
729 | |
730 |
|
731 |
|
732 | replyWithContact(...args) {
|
733 | return this.sendContact(...args);
|
734 | }
|
735 | |
736 |
|
737 |
|
738 |
|
739 | getStickerSet(setName) {
|
740 | return this.telegram.getStickerSet(setName);
|
741 | }
|
742 | |
743 |
|
744 |
|
745 | setChatStickerSet(setName) {
|
746 | this.assert(this.chat, 'setChatStickerSet');
|
747 | return this.telegram.setChatStickerSet(this.chat.id, setName);
|
748 | }
|
749 | |
750 |
|
751 |
|
752 | deleteChatStickerSet() {
|
753 | this.assert(this.chat, 'deleteChatStickerSet');
|
754 | return this.telegram.deleteChatStickerSet(this.chat.id);
|
755 | }
|
756 | |
757 |
|
758 |
|
759 |
|
760 |
|
761 |
|
762 |
|
763 | createForumTopic(...args) {
|
764 | this.assert(this.chat, 'createForumTopic');
|
765 | return this.telegram.createForumTopic(this.chat.id, ...args);
|
766 | }
|
767 | |
768 |
|
769 |
|
770 |
|
771 |
|
772 |
|
773 |
|
774 | editForumTopic(extra) {
|
775 | var _a;
|
776 | this.assert(this.chat, 'editForumTopic');
|
777 | this.assert((_a = this.message) === null || _a === void 0 ? void 0 : _a.message_thread_id, 'editForumTopic');
|
778 | return this.telegram.editForumTopic(this.chat.id, this.message.message_thread_id, extra);
|
779 | }
|
780 | |
781 |
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 | closeForumTopic() {
|
788 | var _a;
|
789 | this.assert(this.chat, 'closeForumTopic');
|
790 | this.assert((_a = this.message) === null || _a === void 0 ? void 0 : _a.message_thread_id, 'closeForumTopic');
|
791 | return this.telegram.closeForumTopic(this.chat.id, this.message.message_thread_id);
|
792 | }
|
793 | |
794 |
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 | reopenForumTopic() {
|
801 | var _a;
|
802 | this.assert(this.chat, 'reopenForumTopic');
|
803 | this.assert((_a = this.message) === null || _a === void 0 ? void 0 : _a.message_thread_id, 'reopenForumTopic');
|
804 | return this.telegram.reopenForumTopic(this.chat.id, this.message.message_thread_id);
|
805 | }
|
806 | |
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 | deleteForumTopic() {
|
814 | var _a;
|
815 | this.assert(this.chat, 'deleteForumTopic');
|
816 | this.assert((_a = this.message) === null || _a === void 0 ? void 0 : _a.message_thread_id, 'deleteForumTopic');
|
817 | return this.telegram.deleteForumTopic(this.chat.id, this.message.message_thread_id);
|
818 | }
|
819 | |
820 |
|
821 |
|
822 |
|
823 |
|
824 |
|
825 | unpinAllForumTopicMessages() {
|
826 | var _a;
|
827 | this.assert(this.chat, 'unpinAllForumTopicMessages');
|
828 | this.assert((_a = this.message) === null || _a === void 0 ? void 0 : _a.message_thread_id, 'unpinAllForumTopicMessages');
|
829 | return this.telegram.unpinAllForumTopicMessages(this.chat.id, this.message.message_thread_id);
|
830 | }
|
831 | |
832 |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 | editGeneralForumTopic(name) {
|
838 | this.assert(this.chat, 'editGeneralForumTopic');
|
839 | return this.telegram.editGeneralForumTopic(this.chat.id, name);
|
840 | }
|
841 | |
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 | closeGeneralForumTopic() {
|
848 | this.assert(this.chat, 'closeGeneralForumTopic');
|
849 | return this.telegram.closeGeneralForumTopic(this.chat.id);
|
850 | }
|
851 | |
852 |
|
853 |
|
854 |
|
855 |
|
856 |
|
857 |
|
858 | reopenGeneralForumTopic() {
|
859 | this.assert(this.chat, 'reopenGeneralForumTopic');
|
860 | return this.telegram.reopenGeneralForumTopic(this.chat.id);
|
861 | }
|
862 | |
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 | hideGeneralForumTopic() {
|
870 | this.assert(this.chat, 'hideGeneralForumTopic');
|
871 | return this.telegram.hideGeneralForumTopic(this.chat.id);
|
872 | }
|
873 | |
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 | unhideGeneralForumTopic() {
|
880 | this.assert(this.chat, 'unhideGeneralForumTopic');
|
881 | return this.telegram.unhideGeneralForumTopic(this.chat.id);
|
882 | }
|
883 | |
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 | unpinAllGeneralForumTopicMessages() {
|
893 | this.assert(this.chat, 'unpinAllGeneralForumTopicMessages');
|
894 | return this.telegram.unpinAllGeneralForumTopicMessages(this.chat.id);
|
895 | }
|
896 | |
897 |
|
898 |
|
899 |
|
900 | setStickerPositionInSet(sticker, position) {
|
901 | return this.telegram.setStickerPositionInSet(sticker, position);
|
902 | }
|
903 | |
904 |
|
905 |
|
906 |
|
907 | setStickerSetThumb(...args) {
|
908 | return this.telegram.setStickerSetThumbnail(...args);
|
909 | }
|
910 | setStickerSetThumbnail(...args) {
|
911 | return this.telegram.setStickerSetThumbnail(...args);
|
912 | }
|
913 | setStickerMaskPosition(...args) {
|
914 | return this.telegram.setStickerMaskPosition(...args);
|
915 | }
|
916 | setStickerKeywords(...args) {
|
917 | return this.telegram.setStickerKeywords(...args);
|
918 | }
|
919 | setStickerEmojiList(...args) {
|
920 | return this.telegram.setStickerEmojiList(...args);
|
921 | }
|
922 | deleteStickerSet(...args) {
|
923 | return this.telegram.deleteStickerSet(...args);
|
924 | }
|
925 | setStickerSetTitle(...args) {
|
926 | return this.telegram.setStickerSetTitle(...args);
|
927 | }
|
928 | setCustomEmojiStickerSetThumbnail(...args) {
|
929 | return this.telegram.setCustomEmojiStickerSetThumbnail(...args);
|
930 | }
|
931 | |
932 |
|
933 |
|
934 |
|
935 | deleteStickerFromSet(sticker) {
|
936 | return this.telegram.deleteStickerFromSet(sticker);
|
937 | }
|
938 | |
939 |
|
940 |
|
941 | uploadStickerFile(...args) {
|
942 | this.assert(this.from, 'uploadStickerFile');
|
943 | return this.telegram.uploadStickerFile(this.from.id, ...args);
|
944 | }
|
945 | |
946 |
|
947 |
|
948 | createNewStickerSet(...args) {
|
949 | this.assert(this.from, 'createNewStickerSet');
|
950 | return this.telegram.createNewStickerSet(this.from.id, ...args);
|
951 | }
|
952 | |
953 |
|
954 |
|
955 | addStickerToSet(...args) {
|
956 | this.assert(this.from, 'addStickerToSet');
|
957 | return this.telegram.addStickerToSet(this.from.id, ...args);
|
958 | }
|
959 | |
960 |
|
961 |
|
962 |
|
963 | getMyCommands() {
|
964 | return this.telegram.getMyCommands();
|
965 | }
|
966 | |
967 |
|
968 |
|
969 |
|
970 | setMyCommands(commands) {
|
971 | return this.telegram.setMyCommands(commands);
|
972 | }
|
973 | |
974 |
|
975 |
|
976 |
|
977 | replyWithMarkdown(markdown, extra) {
|
978 | return this.reply(markdown, { parse_mode: 'Markdown', ...extra });
|
979 | }
|
980 | |
981 |
|
982 |
|
983 | replyWithMarkdownV2(markdown, extra) {
|
984 | return this.reply(markdown, { parse_mode: 'MarkdownV2', ...extra });
|
985 | }
|
986 | |
987 |
|
988 |
|
989 | replyWithHTML(html, extra) {
|
990 | return this.reply(html, { parse_mode: 'HTML', ...extra });
|
991 | }
|
992 | |
993 |
|
994 |
|
995 | deleteMessage(messageId) {
|
996 | this.assert(this.chat, 'deleteMessage');
|
997 | if (typeof messageId !== 'undefined') {
|
998 | return this.telegram.deleteMessage(this.chat.id, messageId);
|
999 | }
|
1000 | const message = getMessageFromAnySource(this);
|
1001 | this.assert(message, 'deleteMessage');
|
1002 | return this.telegram.deleteMessage(this.chat.id, message.message_id);
|
1003 | }
|
1004 | |
1005 |
|
1006 |
|
1007 | forwardMessage(chatId, extra) {
|
1008 | const message = getMessageFromAnySource(this);
|
1009 | this.assert(message, 'forwardMessage');
|
1010 | return this.telegram.forwardMessage(chatId, message.chat.id, message.message_id, extra);
|
1011 | }
|
1012 | |
1013 |
|
1014 |
|
1015 | copyMessage(chatId, extra) {
|
1016 | const message = getMessageFromAnySource(this);
|
1017 | this.assert(message, 'copyMessage');
|
1018 | return this.telegram.copyMessage(chatId, message.chat.id, message.message_id, extra);
|
1019 | }
|
1020 | |
1021 |
|
1022 |
|
1023 | approveChatJoinRequest(userId) {
|
1024 | this.assert(this.chat, 'approveChatJoinRequest');
|
1025 | return this.telegram.approveChatJoinRequest(this.chat.id, userId);
|
1026 | }
|
1027 | |
1028 |
|
1029 |
|
1030 | declineChatJoinRequest(userId) {
|
1031 | this.assert(this.chat, 'declineChatJoinRequest');
|
1032 | return this.telegram.declineChatJoinRequest(this.chat.id, userId);
|
1033 | }
|
1034 | |
1035 |
|
1036 |
|
1037 | banChatSenderChat(senderChatId) {
|
1038 | this.assert(this.chat, 'banChatSenderChat');
|
1039 | return this.telegram.banChatSenderChat(this.chat.id, senderChatId);
|
1040 | }
|
1041 | |
1042 |
|
1043 |
|
1044 | unbanChatSenderChat(senderChatId) {
|
1045 | this.assert(this.chat, 'unbanChatSenderChat');
|
1046 | return this.telegram.unbanChatSenderChat(this.chat.id, senderChatId);
|
1047 | }
|
1048 | |
1049 |
|
1050 |
|
1051 |
|
1052 | setChatMenuButton(menuButton) {
|
1053 | this.assert(this.chat, 'setChatMenuButton');
|
1054 | return this.telegram.setChatMenuButton({ chatId: this.chat.id, menuButton });
|
1055 | }
|
1056 | |
1057 |
|
1058 |
|
1059 |
|
1060 | getChatMenuButton() {
|
1061 | this.assert(this.chat, 'getChatMenuButton');
|
1062 | return this.telegram.getChatMenuButton({ chatId: this.chat.id });
|
1063 | }
|
1064 | |
1065 |
|
1066 |
|
1067 | setMyDefaultAdministratorRights(extra) {
|
1068 | return this.telegram.setMyDefaultAdministratorRights(extra);
|
1069 | }
|
1070 | |
1071 |
|
1072 |
|
1073 | getMyDefaultAdministratorRights(extra) {
|
1074 | return this.telegram.getMyDefaultAdministratorRights(extra);
|
1075 | }
|
1076 | }
|
1077 | exports.Context = Context;
|
1078 | exports.default = Context;
|
1079 | function getMessageFromAnySource(ctx) {
|
1080 | var _a, _b, _c, _d, _e;
|
1081 | return ((_e = (_d = (_b = (_a = ctx.message) !== null && _a !== void 0 ? _a : ctx.editedMessage) !== null && _b !== void 0 ? _b : (_c = ctx.callbackQuery) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : ctx.channelPost) !== null && _e !== void 0 ? _e : ctx.editedChannelPost);
|
1082 | }
|
1083 | const getThreadId = (ctx) => {
|
1084 | const msg = getMessageFromAnySource(ctx);
|
1085 | return (msg === null || msg === void 0 ? void 0 : msg.is_topic_message) ? msg.message_thread_id : undefined;
|
1086 | };
|