telegix 1.1.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.
- package/LICENSE +21 -0
- package/README.md +1534 -0
- package/index.d.ts +539 -0
- package/index.js +38 -0
- package/lib/album.js +57 -0
- package/lib/api.js +1840 -0
- package/lib/chataction.js +40 -0
- package/lib/cluster.js +68 -0
- package/lib/composer.js +419 -0
- package/lib/context.js +970 -0
- package/lib/errors.js +67 -0
- package/lib/format.js +115 -0
- package/lib/i18n.js +158 -0
- package/lib/inline-debounce.js +49 -0
- package/lib/inline.js +79 -0
- package/lib/markdownv2.js +29 -0
- package/lib/markup.js +321 -0
- package/lib/payment.js +91 -0
- package/lib/polling.js +101 -0
- package/lib/prompt.js +62 -0
- package/lib/ratelimit.js +59 -0
- package/lib/rich.js +609 -0
- package/lib/scenes.js +206 -0
- package/lib/serialize.js +141 -0
- package/lib/session.js +145 -0
- package/lib/telegix.js +176 -0
- package/lib/webapp.js +65 -0
- package/lib/webhook.js +86 -0
- package/package.json +42 -0
package/lib/context.js
ADDED
|
@@ -0,0 +1,970 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegix - Context Handler
|
|
3
|
+
* @module telegix/context
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { serializeMessage, serializeUpdate } from './serialize.js';
|
|
7
|
+
|
|
8
|
+
export class Context {
|
|
9
|
+
/**
|
|
10
|
+
* @param {object} update - Raw Telegram update object
|
|
11
|
+
* @param {import('./api.js').Telegram} telegram - Telegram API Client instance
|
|
12
|
+
* @param {object} [botInfo] - Bot info (from getMe)
|
|
13
|
+
*/
|
|
14
|
+
constructor(update, telegram, botInfo = null) {
|
|
15
|
+
this.update = update;
|
|
16
|
+
this.telegram = telegram;
|
|
17
|
+
this.api = telegram; // alias
|
|
18
|
+
this.botInfo = botInfo;
|
|
19
|
+
this.state = {};
|
|
20
|
+
this.match = null;
|
|
21
|
+
this.command = null;
|
|
22
|
+
this.payload = null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get msg() {
|
|
26
|
+
const rawMsg = this.message || this.editedMessage || this.channelPost || this.editedChannelPost || this.callbackQuery?.message;
|
|
27
|
+
return serializeMessage(rawMsg);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get quoted() {
|
|
31
|
+
return this.msg?.quoted || null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
serialize() {
|
|
35
|
+
return serializeUpdate(this.update);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Inferred type of update
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
42
|
+
get updateType() {
|
|
43
|
+
const types = [
|
|
44
|
+
'message',
|
|
45
|
+
'edited_message',
|
|
46
|
+
'channel_post',
|
|
47
|
+
'edited_channel_post',
|
|
48
|
+
'business_connection',
|
|
49
|
+
'business_message',
|
|
50
|
+
'edited_business_message',
|
|
51
|
+
'deleted_business_messages',
|
|
52
|
+
'message_reaction',
|
|
53
|
+
'message_reaction_count',
|
|
54
|
+
'inline_query',
|
|
55
|
+
'chosen_inline_result',
|
|
56
|
+
'callback_query',
|
|
57
|
+
'shipping_query',
|
|
58
|
+
'pre_checkout_query',
|
|
59
|
+
'purchased_paid_media',
|
|
60
|
+
'poll',
|
|
61
|
+
'poll_answer',
|
|
62
|
+
'my_chat_member',
|
|
63
|
+
'chat_member',
|
|
64
|
+
'chat_join_request',
|
|
65
|
+
'chat_boost',
|
|
66
|
+
'removed_chat_boost',
|
|
67
|
+
'paid_message_price_changed',
|
|
68
|
+
'stopped_message_generation',
|
|
69
|
+
'community_chat_joined',
|
|
70
|
+
];
|
|
71
|
+
for (const type of types) {
|
|
72
|
+
if (type in this.update) return type;
|
|
73
|
+
}
|
|
74
|
+
return 'unknown';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get message() {
|
|
78
|
+
return this.update.message;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get editedMessage() {
|
|
82
|
+
return this.update.edited_message;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get channelPost() {
|
|
86
|
+
return this.update.channel_post;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get editedChannelPost() {
|
|
90
|
+
return this.update.edited_channel_post;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get businessConnection() {
|
|
94
|
+
return this.update.business_connection;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get businessMessage() {
|
|
98
|
+
return this.update.business_message;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
get editedBusinessMessage() {
|
|
102
|
+
return this.update.edited_business_message;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get deletedBusinessMessages() {
|
|
106
|
+
return this.update.deleted_business_messages;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
get messageReaction() {
|
|
110
|
+
return this.update.message_reaction;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get messageReactionCount() {
|
|
114
|
+
return this.update.message_reaction_count;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
get purchasedPaidMedia() {
|
|
118
|
+
return this.update.purchased_paid_media;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
get chatBoost() {
|
|
122
|
+
return this.update.chat_boost;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
get removedChatBoost() {
|
|
126
|
+
return this.update.removed_chat_boost;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
get paidMessagePriceChanged() {
|
|
130
|
+
return this.update.paid_message_price_changed;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
get stoppedMessageGeneration() {
|
|
134
|
+
return this.update.stopped_message_generation;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
get communityChatJoined() {
|
|
138
|
+
return this.update.community_chat_joined;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
get callbackQuery() {
|
|
142
|
+
return this.update.callback_query;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
get inlineQuery() {
|
|
146
|
+
return this.update.inline_query;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
get chosenInlineResult() {
|
|
150
|
+
return this.update.chosen_inline_result;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
get shippingQuery() {
|
|
154
|
+
return this.update.shipping_query;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
get preCheckoutQuery() {
|
|
158
|
+
return this.update.pre_checkout_query;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
get poll() {
|
|
162
|
+
return this.update.poll;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
get pollAnswer() {
|
|
166
|
+
return this.update.poll_answer;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
get myChatMember() {
|
|
170
|
+
return this.update.my_chat_member;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
get chatMember() {
|
|
174
|
+
return this.update.chat_member;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
get chatJoinRequest() {
|
|
178
|
+
return this.update.chat_join_request;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
get currentMessage() {
|
|
182
|
+
return (
|
|
183
|
+
this.message ||
|
|
184
|
+
this.editedMessage ||
|
|
185
|
+
this.channelPost ||
|
|
186
|
+
this.editedChannelPost ||
|
|
187
|
+
this.businessMessage ||
|
|
188
|
+
this.editedBusinessMessage ||
|
|
189
|
+
this.callbackQuery?.message
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Sender user
|
|
195
|
+
*/
|
|
196
|
+
get from() {
|
|
197
|
+
return (
|
|
198
|
+
this.message?.from ||
|
|
199
|
+
this.editedMessage?.from ||
|
|
200
|
+
this.businessMessage?.from ||
|
|
201
|
+
this.editedBusinessMessage?.from ||
|
|
202
|
+
this.businessConnection?.user ||
|
|
203
|
+
this.messageReaction?.user ||
|
|
204
|
+
this.purchasedPaidMedia?.from ||
|
|
205
|
+
this.chatBoost?.boost?.source?.user ||
|
|
206
|
+
this.removedChatBoost?.source?.user ||
|
|
207
|
+
this.callbackQuery?.from ||
|
|
208
|
+
this.inlineQuery?.from ||
|
|
209
|
+
this.chosenInlineResult?.from ||
|
|
210
|
+
this.shippingQuery?.from ||
|
|
211
|
+
this.preCheckoutQuery?.from ||
|
|
212
|
+
this.myChatMember?.from ||
|
|
213
|
+
this.chatMember?.from ||
|
|
214
|
+
this.chatJoinRequest?.from
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Sender chat (e.g. for channel posts or anonymous group senders)
|
|
220
|
+
*/
|
|
221
|
+
get senderChat() {
|
|
222
|
+
return (
|
|
223
|
+
this.message?.sender_chat ||
|
|
224
|
+
this.editedMessage?.sender_chat ||
|
|
225
|
+
this.channelPost?.sender_chat ||
|
|
226
|
+
this.editedChannelPost?.sender_chat ||
|
|
227
|
+
this.messageReaction?.actor_chat
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Current chat object
|
|
233
|
+
*/
|
|
234
|
+
get chat() {
|
|
235
|
+
return (
|
|
236
|
+
this.message?.chat ||
|
|
237
|
+
this.editedMessage?.chat ||
|
|
238
|
+
this.channelPost?.chat ||
|
|
239
|
+
this.editedChannelPost?.chat ||
|
|
240
|
+
this.businessMessage?.chat ||
|
|
241
|
+
this.editedBusinessMessage?.chat ||
|
|
242
|
+
this.messageReaction?.chat ||
|
|
243
|
+
this.messageReactionCount?.chat ||
|
|
244
|
+
this.chatBoost?.chat ||
|
|
245
|
+
this.removedChatBoost?.chat ||
|
|
246
|
+
this.callbackQuery?.message?.chat ||
|
|
247
|
+
this.myChatMember?.chat ||
|
|
248
|
+
this.chatMember?.chat ||
|
|
249
|
+
this.chatJoinRequest?.chat
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Whether current chat is a forum supergroup
|
|
255
|
+
* @returns {boolean}
|
|
256
|
+
*/
|
|
257
|
+
get isForum() {
|
|
258
|
+
return Boolean(this.chat?.is_forum);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Forum topic thread ID (message_thread_id)
|
|
263
|
+
* @returns {number|null}
|
|
264
|
+
*/
|
|
265
|
+
get topicId() {
|
|
266
|
+
return (
|
|
267
|
+
this.currentMessage?.message_thread_id ||
|
|
268
|
+
this.message?.message_thread_id ||
|
|
269
|
+
null
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
get messageThreadId() {
|
|
274
|
+
return this.topicId;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Current chat ID
|
|
279
|
+
* @returns {number|string|null}
|
|
280
|
+
*/
|
|
281
|
+
get chatId() {
|
|
282
|
+
return this.chat?.id ?? null;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Current sender user ID
|
|
287
|
+
* @returns {number|null}
|
|
288
|
+
*/
|
|
289
|
+
get userId() {
|
|
290
|
+
return this.from?.id ?? null;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Text or caption of the message
|
|
295
|
+
* @returns {string|null}
|
|
296
|
+
*/
|
|
297
|
+
get text() {
|
|
298
|
+
return (
|
|
299
|
+
this.message?.text ||
|
|
300
|
+
this.message?.caption ||
|
|
301
|
+
this.editedMessage?.text ||
|
|
302
|
+
this.editedMessage?.caption ||
|
|
303
|
+
this.channelPost?.text ||
|
|
304
|
+
this.channelPost?.caption ||
|
|
305
|
+
this.callbackQuery?.data ||
|
|
306
|
+
this.inlineQuery?.query ||
|
|
307
|
+
null
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Entities in the message or caption
|
|
313
|
+
*/
|
|
314
|
+
get entities() {
|
|
315
|
+
return (
|
|
316
|
+
this.message?.entities ||
|
|
317
|
+
this.message?.caption_entities ||
|
|
318
|
+
this.editedMessage?.entities ||
|
|
319
|
+
this.channelPost?.entities ||
|
|
320
|
+
[]
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Assert chatId exists
|
|
326
|
+
* @private
|
|
327
|
+
*/
|
|
328
|
+
_assertChat() {
|
|
329
|
+
if (!this.chatId) {
|
|
330
|
+
throw new Error('Telegix Context: Method requires a chat context, but chatId is null.');
|
|
331
|
+
}
|
|
332
|
+
return this.chatId;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Send a text message to current chat
|
|
337
|
+
* @param {string} text
|
|
338
|
+
* @param {object} [extra]
|
|
339
|
+
*/
|
|
340
|
+
reply(text, extra = {}) {
|
|
341
|
+
return this.telegram.sendMessage(this._assertChat(), text, extra);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Send an HTML formatted message
|
|
346
|
+
* @param {string} html
|
|
347
|
+
* @param {object} [extra]
|
|
348
|
+
*/
|
|
349
|
+
replyWithHTML(html, extra = {}) {
|
|
350
|
+
return this.reply(html, { parse_mode: 'HTML', ...extra });
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Send a MarkdownV2 formatted message
|
|
355
|
+
* @param {string} markdown
|
|
356
|
+
* @param {object} [extra]
|
|
357
|
+
*/
|
|
358
|
+
replyWithMarkdown(markdown, extra = {}) {
|
|
359
|
+
return this.reply(markdown, { parse_mode: 'MarkdownV2', ...extra });
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Send a photo to current chat
|
|
364
|
+
* @param {any} photo
|
|
365
|
+
* @param {object} [extra]
|
|
366
|
+
*/
|
|
367
|
+
replyWithPhoto(photo, extra = {}) {
|
|
368
|
+
return this.telegram.sendPhoto(this._assertChat(), photo, extra);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Send an audio file
|
|
373
|
+
* @param {any} audio
|
|
374
|
+
* @param {object} [extra]
|
|
375
|
+
*/
|
|
376
|
+
replyWithAudio(audio, extra = {}) {
|
|
377
|
+
return this.telegram.sendAudio(this._assertChat(), audio, extra);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Send a document/file
|
|
382
|
+
* @param {any} document
|
|
383
|
+
* @param {object} [extra]
|
|
384
|
+
*/
|
|
385
|
+
replyWithDocument(document, extra = {}) {
|
|
386
|
+
return this.telegram.sendDocument(this._assertChat(), document, extra);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Send a video
|
|
391
|
+
* @param {any} video
|
|
392
|
+
* @param {object} [extra]
|
|
393
|
+
*/
|
|
394
|
+
replyWithVideo(video, extra = {}) {
|
|
395
|
+
return this.telegram.sendVideo(this._assertChat(), video, extra);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Send an animation / GIF
|
|
400
|
+
* @param {any} animation
|
|
401
|
+
* @param {object} [extra]
|
|
402
|
+
*/
|
|
403
|
+
replyWithAnimation(animation, extra = {}) {
|
|
404
|
+
return this.telegram.sendAnimation(this._assertChat(), animation, extra);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Send a voice note
|
|
409
|
+
* @param {any} voice
|
|
410
|
+
* @param {object} [extra]
|
|
411
|
+
*/
|
|
412
|
+
replyWithVoice(voice, extra = {}) {
|
|
413
|
+
return this.telegram.sendVoice(this._assertChat(), voice, extra);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Send a video note (round video)
|
|
418
|
+
* @param {any} videoNote
|
|
419
|
+
* @param {object} [extra]
|
|
420
|
+
*/
|
|
421
|
+
replyWithVideoNote(videoNote, extra = {}) {
|
|
422
|
+
return this.telegram.sendVideoNote(this._assertChat(), videoNote, extra);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Send media album
|
|
427
|
+
* @param {Array<object>} media
|
|
428
|
+
* @param {object} [extra]
|
|
429
|
+
*/
|
|
430
|
+
replyWithMediaGroup(media, extra = {}) {
|
|
431
|
+
return this.telegram.sendMediaGroup(this._assertChat(), media, extra);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Send location coordinates
|
|
436
|
+
* @param {number} latitude
|
|
437
|
+
* @param {number} longitude
|
|
438
|
+
* @param {object} [extra]
|
|
439
|
+
*/
|
|
440
|
+
replyWithLocation(latitude, longitude, extra = {}) {
|
|
441
|
+
return this.telegram.sendLocation(this._assertChat(), latitude, longitude, extra);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Send venue
|
|
446
|
+
*/
|
|
447
|
+
replyWithVenue(latitude, longitude, title, address, extra = {}) {
|
|
448
|
+
return this.telegram.sendVenue(this._assertChat(), latitude, longitude, title, address, extra);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Send contact
|
|
453
|
+
*/
|
|
454
|
+
replyWithContact(phoneNumber, firstName, extra = {}) {
|
|
455
|
+
return this.telegram.sendContact(this._assertChat(), phoneNumber, firstName, extra);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Send poll
|
|
460
|
+
*/
|
|
461
|
+
replyWithPoll(question, options, extra = {}) {
|
|
462
|
+
return this.telegram.sendPoll(this._assertChat(), question, options, extra);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Send animated dice
|
|
467
|
+
*/
|
|
468
|
+
replyWithDice(extra = {}) {
|
|
469
|
+
return this.telegram.sendDice(this._assertChat(), extra);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Send chat action (e.g. 'typing', 'upload_photo')
|
|
474
|
+
* @param {string} action
|
|
475
|
+
* @param {object} [extra]
|
|
476
|
+
*/
|
|
477
|
+
replyWithChatAction(action, extra = {}) {
|
|
478
|
+
return this.telegram.sendChatAction(this._assertChat(), action, extra);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Set reaction on current message
|
|
483
|
+
* @param {string|Array<string|object>} emoji
|
|
484
|
+
*/
|
|
485
|
+
react(emoji) {
|
|
486
|
+
const messageId = this.currentMessage?.message_id;
|
|
487
|
+
if (!messageId) {
|
|
488
|
+
throw new Error('Telegix Context: react() requires a message context.');
|
|
489
|
+
}
|
|
490
|
+
return this.telegram.setMessageReaction(this._assertChat(), messageId, emoji);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Answer callback query
|
|
495
|
+
* @param {string} [text]
|
|
496
|
+
* @param {object} [options]
|
|
497
|
+
*/
|
|
498
|
+
answerCallbackQuery(text = '', options = {}) {
|
|
499
|
+
if (!this.callbackQuery) {
|
|
500
|
+
throw new Error('Telegix Context: answerCallbackQuery() requires callback_query context.');
|
|
501
|
+
}
|
|
502
|
+
return this.telegram.answerCallbackQuery(this.callbackQuery.id, {
|
|
503
|
+
text,
|
|
504
|
+
...options,
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Answer inline query
|
|
510
|
+
* @param {Array<object>} results
|
|
511
|
+
* @param {object} [options]
|
|
512
|
+
*/
|
|
513
|
+
answerInlineQuery(results = [], options = {}) {
|
|
514
|
+
if (!this.inlineQuery) {
|
|
515
|
+
throw new Error('Telegix Context: answerInlineQuery() requires inline_query context.');
|
|
516
|
+
}
|
|
517
|
+
return this.telegram.answerInlineQuery(this.inlineQuery.id, results, options);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Edit current message text
|
|
522
|
+
* @param {string} text
|
|
523
|
+
* @param {object} [extra]
|
|
524
|
+
*/
|
|
525
|
+
editMessageText(text, extra = {}) {
|
|
526
|
+
const chatId = this.chatId;
|
|
527
|
+
const messageId = this.currentMessage?.message_id;
|
|
528
|
+
const inlineMessageId = this.callbackQuery?.inline_message_id;
|
|
529
|
+
return this.telegram.editMessageText(chatId, messageId, inlineMessageId, text, extra);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Edit current message caption
|
|
534
|
+
* @param {string} caption
|
|
535
|
+
* @param {object} [extra]
|
|
536
|
+
*/
|
|
537
|
+
editMessageCaption(caption, extra = {}) {
|
|
538
|
+
const chatId = this.chatId;
|
|
539
|
+
const messageId = this.currentMessage?.message_id;
|
|
540
|
+
const inlineMessageId = this.callbackQuery?.inline_message_id;
|
|
541
|
+
return this.telegram.editMessageCaption(chatId, messageId, inlineMessageId, caption, extra);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Edit current message media
|
|
546
|
+
* @param {object} media
|
|
547
|
+
* @param {object} [extra]
|
|
548
|
+
*/
|
|
549
|
+
editMessageMedia(media, extra = {}) {
|
|
550
|
+
const chatId = this.chatId;
|
|
551
|
+
const messageId = this.currentMessage?.message_id;
|
|
552
|
+
const inlineMessageId = this.callbackQuery?.inline_message_id;
|
|
553
|
+
return this.telegram.editMessageMedia(chatId, messageId, inlineMessageId, media, extra);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Edit current message reply markup
|
|
558
|
+
* @param {object} replyMarkup
|
|
559
|
+
* @param {object} [extra]
|
|
560
|
+
*/
|
|
561
|
+
editMessageReplyMarkup(replyMarkup, extra = {}) {
|
|
562
|
+
const chatId = this.chatId;
|
|
563
|
+
const messageId = this.currentMessage?.message_id;
|
|
564
|
+
const inlineMessageId = this.callbackQuery?.inline_message_id;
|
|
565
|
+
return this.telegram.editMessageReplyMarkup(chatId, messageId, inlineMessageId, replyMarkup, extra);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Delete message
|
|
570
|
+
* @param {number} [messageId] - Defaults to current message id
|
|
571
|
+
*/
|
|
572
|
+
deleteMessage(messageId = this.currentMessage?.message_id) {
|
|
573
|
+
if (!messageId) {
|
|
574
|
+
throw new Error('Telegix Context: deleteMessage() requires messageId.');
|
|
575
|
+
}
|
|
576
|
+
return this.telegram.deleteMessage(this._assertChat(), messageId);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Forward current message to another chat
|
|
581
|
+
* @param {number|string} toChatId
|
|
582
|
+
* @param {object} [extra]
|
|
583
|
+
*/
|
|
584
|
+
forwardMessage(toChatId, extra = {}) {
|
|
585
|
+
const messageId = this.currentMessage?.message_id;
|
|
586
|
+
if (!messageId) {
|
|
587
|
+
throw new Error('Telegix Context: forwardMessage() requires current message context.');
|
|
588
|
+
}
|
|
589
|
+
return this.telegram.forwardMessage(toChatId, this._assertChat(), messageId, extra);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Copy current message to another chat
|
|
594
|
+
* @param {number|string} toChatId
|
|
595
|
+
* @param {object} [extra]
|
|
596
|
+
*/
|
|
597
|
+
copyMessage(toChatId, extra = {}) {
|
|
598
|
+
const messageId = this.currentMessage?.message_id;
|
|
599
|
+
if (!messageId) {
|
|
600
|
+
throw new Error('Telegix Context: copyMessage() requires current message context.');
|
|
601
|
+
}
|
|
602
|
+
return this.telegram.copyMessage(toChatId, this._assertChat(), messageId, extra);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Pin a message
|
|
607
|
+
* @param {number} [messageId]
|
|
608
|
+
* @param {object} [extra]
|
|
609
|
+
*/
|
|
610
|
+
pinChatMessage(messageId = this.currentMessage?.message_id, extra = {}) {
|
|
611
|
+
if (!messageId) {
|
|
612
|
+
throw new Error('Telegix Context: pinChatMessage() requires messageId.');
|
|
613
|
+
}
|
|
614
|
+
return this.telegram.pinChatMessage(this._assertChat(), messageId, extra);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Unpin a message
|
|
619
|
+
* @param {number} [messageId]
|
|
620
|
+
*/
|
|
621
|
+
unpinChatMessage(messageId = this.currentMessage?.message_id) {
|
|
622
|
+
return this.telegram.unpinChatMessage(this._assertChat(), messageId);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Unpin all messages
|
|
627
|
+
*/
|
|
628
|
+
unpinAllChatMessages() {
|
|
629
|
+
return this.telegram.unpinAllChatMessages(this._assertChat());
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Leave current chat
|
|
634
|
+
*/
|
|
635
|
+
leaveChat() {
|
|
636
|
+
return this.telegram.leaveChat(this._assertChat());
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Get current chat info
|
|
641
|
+
*/
|
|
642
|
+
getChat() {
|
|
643
|
+
return this.telegram.getChat(this._assertChat());
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Get current chat administrators
|
|
648
|
+
*/
|
|
649
|
+
getChatAdministrators() {
|
|
650
|
+
return this.telegram.getChatAdministrators(this._assertChat());
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Get chat member info
|
|
655
|
+
* @param {number} [userId]
|
|
656
|
+
*/
|
|
657
|
+
getChatMember(userId = this.userId) {
|
|
658
|
+
if (!userId) {
|
|
659
|
+
throw new Error('Telegix Context: getChatMember() requires userId.');
|
|
660
|
+
}
|
|
661
|
+
return this.telegram.getChatMember(this._assertChat(), userId);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* Ban chat member
|
|
666
|
+
* @param {number} userId
|
|
667
|
+
* @param {object} [extra]
|
|
668
|
+
*/
|
|
669
|
+
banChatMember(userId, extra = {}) {
|
|
670
|
+
return this.telegram.banChatMember(this._assertChat(), userId, extra);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Unban chat member
|
|
675
|
+
* @param {number} userId
|
|
676
|
+
* @param {object} [extra]
|
|
677
|
+
*/
|
|
678
|
+
unbanChatMember(userId, extra = {}) {
|
|
679
|
+
return this.telegram.unbanChatMember(this._assertChat(), userId, extra);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Restrict chat member
|
|
684
|
+
* @param {number} userId
|
|
685
|
+
* @param {object} permissions
|
|
686
|
+
* @param {object} [extra]
|
|
687
|
+
*/
|
|
688
|
+
restrictChatMember(userId, permissions, extra = {}) {
|
|
689
|
+
return this.telegram.restrictChatMember(this._assertChat(), userId, permissions, extra);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Promote chat member
|
|
694
|
+
* @param {number} userId
|
|
695
|
+
* @param {object} rights
|
|
696
|
+
*/
|
|
697
|
+
promoteChatMember(userId, rights = {}) {
|
|
698
|
+
return this.telegram.promoteChatMember(this._assertChat(), userId, rights);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// ==========================================
|
|
702
|
+
// Context Shortcuts for Latest Telegram Features
|
|
703
|
+
// ==========================================
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Send invoice (Telegram Stars XTR or standard currencies)
|
|
707
|
+
* @param {string} title
|
|
708
|
+
* @param {string} description
|
|
709
|
+
* @param {string} payload
|
|
710
|
+
* @param {string} currency - e.g. 'XTR'
|
|
711
|
+
* @param {Array<{label: string, amount: number}>} prices
|
|
712
|
+
* @param {object} [extra]
|
|
713
|
+
*/
|
|
714
|
+
replyWithInvoice(title, description, payload, currency, prices, extra = {}) {
|
|
715
|
+
return this.telegram.sendInvoice(
|
|
716
|
+
this._assertChat(),
|
|
717
|
+
title,
|
|
718
|
+
description,
|
|
719
|
+
payload,
|
|
720
|
+
currency,
|
|
721
|
+
prices,
|
|
722
|
+
extra
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Send paid media requiring Telegram Stars
|
|
728
|
+
* @param {number} starCount
|
|
729
|
+
* @param {Array<object>} media
|
|
730
|
+
* @param {object} [extra]
|
|
731
|
+
*/
|
|
732
|
+
replyWithPaidMedia(starCount, media, extra = {}) {
|
|
733
|
+
return this.telegram.sendPaidMedia(this._assertChat(), starCount, media, extra);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/**
|
|
737
|
+
* Send sticker
|
|
738
|
+
* @param {any} sticker
|
|
739
|
+
* @param {object} [extra]
|
|
740
|
+
*/
|
|
741
|
+
replyWithSticker(sticker, extra = {}) {
|
|
742
|
+
return this.telegram.sendSticker(this._assertChat(), sticker, extra);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* Send game
|
|
747
|
+
* @param {string} gameShortName
|
|
748
|
+
* @param {object} [extra]
|
|
749
|
+
*/
|
|
750
|
+
replyWithGame(gameShortName, extra = {}) {
|
|
751
|
+
return this.telegram.sendGame(this._assertChat(), gameShortName, extra);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Create a topic in current forum chat
|
|
756
|
+
* @param {string} name
|
|
757
|
+
* @param {object} [extra]
|
|
758
|
+
*/
|
|
759
|
+
createForumTopic(name, extra = {}) {
|
|
760
|
+
return this.telegram.createForumTopic(this._assertChat(), name, extra);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* Edit forum topic in current chat
|
|
765
|
+
* @param {number} [messageThreadId=this.topicId]
|
|
766
|
+
* @param {object} [extra]
|
|
767
|
+
*/
|
|
768
|
+
editForumTopic(messageThreadId = this.topicId, extra = {}) {
|
|
769
|
+
if (!messageThreadId) {
|
|
770
|
+
throw new Error('Telegix Context: editForumTopic() requires messageThreadId.');
|
|
771
|
+
}
|
|
772
|
+
return this.telegram.editForumTopic(this._assertChat(), messageThreadId, extra);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Close forum topic in current chat
|
|
777
|
+
* @param {number} [messageThreadId=this.topicId]
|
|
778
|
+
*/
|
|
779
|
+
closeForumTopic(messageThreadId = this.topicId) {
|
|
780
|
+
if (!messageThreadId) {
|
|
781
|
+
throw new Error('Telegix Context: closeForumTopic() requires messageThreadId.');
|
|
782
|
+
}
|
|
783
|
+
return this.telegram.closeForumTopic(this._assertChat(), messageThreadId);
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* Reopen forum topic in current chat
|
|
788
|
+
* @param {number} [messageThreadId=this.topicId]
|
|
789
|
+
*/
|
|
790
|
+
reopenForumTopic(messageThreadId = this.topicId) {
|
|
791
|
+
if (!messageThreadId) {
|
|
792
|
+
throw new Error('Telegix Context: reopenForumTopic() requires messageThreadId.');
|
|
793
|
+
}
|
|
794
|
+
return this.telegram.reopenForumTopic(this._assertChat(), messageThreadId);
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Delete forum topic in current chat
|
|
799
|
+
* @param {number} [messageThreadId=this.topicId]
|
|
800
|
+
*/
|
|
801
|
+
deleteForumTopic(messageThreadId = this.topicId) {
|
|
802
|
+
if (!messageThreadId) {
|
|
803
|
+
throw new Error('Telegix Context: deleteForumTopic() requires messageThreadId.');
|
|
804
|
+
}
|
|
805
|
+
return this.telegram.deleteForumTopic(this._assertChat(), messageThreadId);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* Unpin all messages in a forum topic
|
|
810
|
+
* @param {number} [messageThreadId=this.topicId]
|
|
811
|
+
*/
|
|
812
|
+
unpinAllForumTopicMessages(messageThreadId = this.topicId) {
|
|
813
|
+
if (!messageThreadId) {
|
|
814
|
+
throw new Error('Telegix Context: unpinAllForumTopicMessages() requires messageThreadId.');
|
|
815
|
+
}
|
|
816
|
+
return this.telegram.unpinAllForumTopicMessages(this._assertChat(), messageThreadId);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Send gift to user
|
|
821
|
+
* @param {string} giftId
|
|
822
|
+
* @param {object} [extra]
|
|
823
|
+
*/
|
|
824
|
+
sendGift(giftId, extra = {}) {
|
|
825
|
+
if (!this.userId) {
|
|
826
|
+
throw new Error('Telegix Context: sendGift() requires user context.');
|
|
827
|
+
}
|
|
828
|
+
return this.telegram.sendGift(this.userId, giftId, extra);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* Verify sender user
|
|
833
|
+
* @param {string} [customDescription='']
|
|
834
|
+
*/
|
|
835
|
+
verifyUser(customDescription = '') {
|
|
836
|
+
if (!this.userId) {
|
|
837
|
+
throw new Error('Telegix Context: verifyUser() requires user context.');
|
|
838
|
+
}
|
|
839
|
+
return this.telegram.verifyUser(this.userId, customDescription);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Verify current chat
|
|
844
|
+
* @param {string} [customDescription='']
|
|
845
|
+
*/
|
|
846
|
+
verifyChat(customDescription = '') {
|
|
847
|
+
return this.telegram.verifyChat(this._assertChat(), customDescription);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* Get user chat boosts
|
|
852
|
+
* @param {number} [userId=this.userId]
|
|
853
|
+
*/
|
|
854
|
+
getUserChatBoosts(userId = this.userId) {
|
|
855
|
+
if (!userId) {
|
|
856
|
+
throw new Error('Telegix Context: getUserChatBoosts() requires userId.');
|
|
857
|
+
}
|
|
858
|
+
return this.telegram.getUserChatBoosts(this._assertChat(), userId);
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* Get business connection info
|
|
863
|
+
*/
|
|
864
|
+
getBusinessConnection() {
|
|
865
|
+
const connId = this.businessConnection?.id || this.businessMessage?.business_connection_id;
|
|
866
|
+
if (!connId) {
|
|
867
|
+
throw new Error('Telegix Context: getBusinessConnection() requires business connection context.');
|
|
868
|
+
}
|
|
869
|
+
return this.telegram.getBusinessConnection(connId);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Send a rich message
|
|
874
|
+
* @param {object|Array} richMessage
|
|
875
|
+
* @param {object} [extra]
|
|
876
|
+
*/
|
|
877
|
+
replyWithRichMessage(richMessage, extra = {}) {
|
|
878
|
+
return this.telegram.sendRichMessage(this._assertChat(), richMessage, extra);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Edit rich message text
|
|
883
|
+
* @param {object|Array} richMessage
|
|
884
|
+
* @param {object} [extra]
|
|
885
|
+
*/
|
|
886
|
+
editRichMessageText(richMessage, extra = {}) {
|
|
887
|
+
const msgId = this._assertMessage();
|
|
888
|
+
return this.telegram.editRichMessageText(this._assertChat(), msgId, richMessage, extra);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Edit rich message caption
|
|
893
|
+
* @param {string} caption
|
|
894
|
+
* @param {object} [extra]
|
|
895
|
+
*/
|
|
896
|
+
editRichMessageCaption(caption, extra = {}) {
|
|
897
|
+
const msgId = this._assertMessage();
|
|
898
|
+
return this.telegram.editRichMessageCaption(this._assertChat(), msgId, caption, extra);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* Send an ephemeral message
|
|
903
|
+
* @param {string} text
|
|
904
|
+
* @param {object} ephemeralParameters
|
|
905
|
+
* @param {object} [extra]
|
|
906
|
+
*/
|
|
907
|
+
sendEphemeralMessage(text, ephemeralParameters, extra = {}) {
|
|
908
|
+
return this.telegram.sendEphemeralMessage(this._assertChat(), text, ephemeralParameters, extra);
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* Get user personal chat messages
|
|
913
|
+
* @param {number} [userId=this.userId]
|
|
914
|
+
* @param {object} [extra]
|
|
915
|
+
*/
|
|
916
|
+
getUserPersonalChatMessages(userId = this.userId, extra = {}) {
|
|
917
|
+
if (!userId) {
|
|
918
|
+
throw new Error('Telegix Context: getUserPersonalChatMessages() requires userId.');
|
|
919
|
+
}
|
|
920
|
+
return this.telegram.getUserPersonalChatMessages(userId, extra);
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Send message draft
|
|
925
|
+
* @param {string} text
|
|
926
|
+
* @param {object} [extra]
|
|
927
|
+
*/
|
|
928
|
+
sendMessageDraft(text, extra = {}) {
|
|
929
|
+
return this.telegram.sendMessageDraft(this._assertChat(), text, extra);
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* Send rich message draft
|
|
934
|
+
* @param {object|Array} draft
|
|
935
|
+
* @param {object} [extra]
|
|
936
|
+
*/
|
|
937
|
+
sendRichMessageDraft(draft, extra = {}) {
|
|
938
|
+
return this.telegram.sendRichMessageDraft(this._assertChat(), draft, extra);
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Get bot info (getMe)
|
|
943
|
+
*/
|
|
944
|
+
getMe() {
|
|
945
|
+
return this.telegram.getMe();
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* Get managed bot access settings
|
|
950
|
+
* @param {number} [userId=this.userId]
|
|
951
|
+
*/
|
|
952
|
+
getManagedBotAccessSettings(userId = this.userId) {
|
|
953
|
+
if (!userId) {
|
|
954
|
+
throw new Error('Telegix Context: getManagedBotAccessSettings() requires userId.');
|
|
955
|
+
}
|
|
956
|
+
return this.telegram.getManagedBotAccessSettings(userId);
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* Set managed bot access settings
|
|
961
|
+
* @param {object} settings
|
|
962
|
+
* @param {number} [userId=this.userId]
|
|
963
|
+
*/
|
|
964
|
+
setManagedBotAccessSettings(settings, userId = this.userId) {
|
|
965
|
+
if (!userId) {
|
|
966
|
+
throw new Error('Telegix Context: setManagedBotAccessSettings() requires userId.');
|
|
967
|
+
}
|
|
968
|
+
return this.telegram.setManagedBotAccessSettings(userId, settings);
|
|
969
|
+
}
|
|
970
|
+
}
|