@zero-bot.net/tg-bot-api 1.2.0 → 1.5.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.
package/lib/telegram.js DELETED
@@ -1,4142 +0,0 @@
1
- // shims
2
- require('array.prototype.findindex').shim(); // for Node.js v0.x
3
-
4
- const errors = require('./errors');
5
- const TelegramBotWebHook = require('./telegramWebHook');
6
- const TelegramBotPolling = require('./telegramPolling');
7
- const debug = require('debug')('@zero-bot.net/tg-bot-api');
8
- const EventEmitter = require('eventemitter3');
9
- const fileType = require('file-type');
10
- const requestBase = require('@zero-bot.net/request');
11
- const request = options => new Promise((resolve, reject) => {
12
- requestBase(options, (err, response) => {
13
- if (err) reject(err);else resolve(response);
14
- });
15
- });
16
- const streamedRequest = requestBase;
17
- const qs = require('querystring');
18
- const stream = require('stream');
19
- const mime = require('mime');
20
- const path = require('path');
21
- const URL = require('url');
22
- const fs = require('fs');
23
- const pump = require('pump');
24
- const deprecate = require('./utils').deprecate;
25
-
26
- const _messageTypes = ['text', 'animation', 'audio', 'channel_chat_created', 'contact', 'delete_chat_photo', 'dice', 'document', 'game', 'group_chat_created', 'invoice', 'left_chat_member', 'location', 'migrate_from_chat_id', 'migrate_to_chat_id', 'new_chat_members', 'new_chat_photo', 'new_chat_title', 'passport_data', 'photo', 'pinned_message', 'poll', 'sticker', 'successful_payment', 'supergroup_chat_created', 'video', 'video_note', 'voice', 'video_chat_started', 'video_chat_ended', 'video_chat_participants_invited', 'video_chat_scheduled', 'message_auto_delete_timer_changed', 'chat_invite_link', 'chat_member_updated', 'web_app_data', 'message_reaction',
27
- // Bot API 7.7
28
- 'refunded_payment',
29
- // Bot API 9.0
30
- 'gift', 'unique_gift', 'paid_message_price_changed', 'paid_star_count',
31
- // Bot API 9.1
32
- 'checklist', 'checklist_tasks_done', 'checklist_tasks_added', 'direct_message_price_changed',
33
- // Bot API 9.2
34
- 'direct_messages_topic', 'suggested_post_info', 'suggested_post_approved', 'suggested_post_approval_failed', 'suggested_post_declined', 'suggested_post_paid', 'suggested_post_refunded',
35
- // Bot API 9.3
36
- 'gift_upgrade_sent',
37
- // Bot API 9.4
38
- 'chat_owner_left', 'chat_owner_changed',
39
- // Bot API 9.5
40
- 'sender_tag',
41
- // Bot API 9.6
42
- 'managed_bot_created', 'poll_option_added', 'poll_option_deleted',
43
- // Bot API 10.0
44
- 'guest_bot_caller_user', 'guest_bot_caller_chat', 'guest_query_id', 'live_photo',
45
- // Bot API 10.1
46
- 'rich_message',
47
- // Bot API 10.2
48
- 'ephemeral_message_id', 'receiver_user', 'community_chat_added', 'community_chat_removed',
49
- // Bot API 10.3
50
- 'stopped_message_generation', 'community_chat_joined'];
51
-
52
- const _deprecatedMessageTypes = ['new_chat_participant', 'left_chat_participant'];
53
-
54
- /**
55
- * JSON-serialize data. If the provided data is already a String,
56
- * return it as is.
57
- * @private
58
- * @param {*} data
59
- * @return {String}
60
- */
61
- function stringify(data) {
62
- if (typeof data === 'string') {
63
- return data;
64
- }
65
- return JSON.stringify(data);
66
- }
67
-
68
- class TelegramBot extends EventEmitter {
69
- /**
70
- * The different errors the library uses.
71
- * @type {Object}
72
- */
73
- static get errors() {
74
- return errors;
75
- }
76
-
77
- /**
78
- * The types of message updates the library handles.
79
- * @type {String[]}
80
- */
81
- static get messageTypes() {
82
- return _messageTypes;
83
- }
84
-
85
- /**
86
- * Add listener for the specified [event](https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#events).
87
- * This is the usual `emitter.on()` method.
88
- * @param {String} event
89
- * @param {Function} listener
90
- * @see {@link https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#events|Available events}
91
- * @see https://nodejs.org/api/events.html#events_emitter_on_eventname_listener
92
- */
93
- on(event, listener) {
94
- if (_deprecatedMessageTypes.indexOf(event) !== -1) {
95
- const url = 'https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#events';
96
- deprecate(`Events ${_deprecatedMessageTypes.join(',')} are deprecated. See the updated list of events: ${url}`);
97
- }
98
- super.on(event, listener);
99
- }
100
-
101
- /**
102
- * Both request method to obtain messages are implemented. To use standard polling, set `polling: true`
103
- * on `options`. Notice that [webHook](https://core.telegram.org/bots/api#setwebhook) will need a SSL certificate.
104
- * Emits `message` when a message arrives.
105
- *
106
- * @class TelegramBot
107
- * @constructor
108
- * @param {String} token Bot Token
109
- * @param {Object} [options]
110
- * @param {Boolean|Object} [options.polling=false] Set true to enable polling or set options.
111
- * If a WebHook has been set, it will be deleted automatically.
112
- * @param {String|Number} [options.polling.timeout=10] *Deprecated. Use `options.polling.params` instead*.
113
- * Timeout in seconds for long polling.
114
- * @param {Boolean} [options.testEnvironment=false] Set true to work with test enviroment.
115
- * When working with the test environment, you may use HTTP links without TLS to test your Web App.
116
- * @param {String|Number} [options.polling.interval=300] Interval between requests in miliseconds
117
- * @param {Boolean} [options.polling.autoStart=true] Start polling immediately
118
- * @param {Object} [options.polling.params] Parameters to be used in polling API requests.
119
- * See https://core.telegram.org/bots/api#getupdates for more information.
120
- * @param {Number} [options.polling.params.timeout=10] Timeout in seconds for long polling.
121
- * @param {Boolean|Object} [options.webHook=false] Set true to enable WebHook or set options
122
- * @param {String} [options.webHook.host="0.0.0.0"] Host to bind to
123
- * @param {Number} [options.webHook.port=8443] Port to bind to
124
- * @param {String} [options.webHook.key] Path to file with PEM private key for webHook server.
125
- * The file is read **synchronously**!
126
- * @param {String} [options.webHook.cert] Path to file with PEM certificate (public) for webHook server.
127
- * The file is read **synchronously**!
128
- * @param {String} [options.webHook.pfx] Path to file with PFX private key and certificate chain for webHook server.
129
- * The file is read **synchronously**!
130
- * @param {Boolean} [options.webHook.autoOpen=true] Open webHook immediately
131
- * @param {Object} [options.webHook.https] Options to be passed to `https.createServer()`.
132
- * Note that `options.webHook.key`, `options.webHook.cert` and `options.webHook.pfx`, if provided, will be
133
- * used to override `key`, `cert` and `pfx` in this object, respectively.
134
- * See https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener for more information.
135
- * @param {String} [options.webHook.healthEndpoint="/healthz"] An endpoint for health checks that always responds with 200 OK
136
- * @param {Boolean} [options.onlyFirstMatch=false] Set to true to stop after first match. Otherwise, all regexps are executed
137
- * @param {Object} [options.request] Options which will be added for all requests to telegram api.
138
- * See https://github.com/request/request#requestoptions-callback for more information.
139
- * @param {String} [options.baseApiUrl="https://api.telegram.org"] API Base URl; useful for proxying and testing
140
- * @param {Boolean} [options.filepath=true] Allow passing file-paths as arguments when sending files,
141
- * such as photos using `TelegramBot#sendPhoto()`. See [usage information][usage-sending-files-performance]
142
- * for more information on this option and its consequences.
143
- * @param {Boolean} [options.badRejection=false] Set to `true`
144
- * **if and only if** the Node.js version you're using terminates the
145
- * process on unhandled rejections. This option is only for
146
- * *forward-compatibility purposes*.
147
- * @see https://core.telegram.org/bots/api
148
- */
149
- constructor(token, options = {}) {
150
- super();
151
- this.token = token;
152
- this.options = options;
153
- this.options.polling = typeof options.polling === 'undefined' ? false : options.polling;
154
- this.options.webHook = typeof options.webHook === 'undefined' ? false : options.webHook;
155
- this.options.baseApiUrl = options.baseApiUrl || 'https://api.telegram.org';
156
- this.options.filepath = typeof options.filepath === 'undefined' ? true : options.filepath;
157
- this.options.badRejection = typeof options.badRejection === 'undefined' ? false : options.badRejection;
158
- this._textRegexpCallbacks = [];
159
- this._replyListenerId = 0;
160
- this._replyListeners = [];
161
- this._polling = null;
162
- this._webHook = null;
163
-
164
- if (options.polling) {
165
- const autoStart = options.polling.autoStart;
166
- if (typeof autoStart === 'undefined' || autoStart === true) {
167
- this.startPolling();
168
- }
169
- }
170
-
171
- if (options.webHook) {
172
- const autoOpen = options.webHook.autoOpen;
173
- if (typeof autoOpen === 'undefined' || autoOpen === true) {
174
- this.openWebHook();
175
- }
176
- }
177
- }
178
-
179
- /**
180
- * Generates url with bot token and provided path/method you want to be got/executed by bot
181
- * @param {String} path
182
- * @return {String} url
183
- * @private
184
- * @see https://core.telegram.org/bots/api#making-requests
185
- */
186
- _buildURL(_path) {
187
- return `${this.options.baseApiUrl}/bot${this.token}${this.options.testEnvironment ? '/test' : ''}/${_path}`;
188
- }
189
-
190
- /**
191
- * Fix 'reply_markup' parameter by making it JSON-serialized, as
192
- * required by the Telegram Bot API
193
- * @param {Object} obj Object; either 'form' or 'qs'
194
- * @private
195
- * @see https://core.telegram.org/bots/api#sendmessage
196
- */
197
- _fixReplyMarkup(obj) {
198
- const replyMarkup = obj.reply_markup;
199
- if (replyMarkup && typeof replyMarkup !== 'string') {
200
- obj.reply_markup = stringify(replyMarkup);
201
- }
202
- }
203
-
204
- /**
205
- * Fix 'entities' or 'caption_entities' or 'explanation_entities' parameter by making it JSON-serialized, as
206
- * required by the Telegram Bot API
207
- * @param {Object} obj Object;
208
- * @private
209
- * @see https://core.telegram.org/bots/api#sendmessage
210
- * @see https://core.telegram.org/bots/api#copymessage
211
- * @see https://core.telegram.org/bots/api#sendpoll
212
- */
213
- _fixEntitiesField(obj) {
214
- const entities = obj.entities;
215
- const captionEntities = obj.caption_entities;
216
- const explanationEntities = obj.explanation_entities;
217
- if (entities && typeof entities !== 'string') {
218
- obj.entities = stringify(entities);
219
- }
220
-
221
- if (captionEntities && typeof captionEntities !== 'string') {
222
- obj.caption_entities = stringify(captionEntities);
223
- }
224
-
225
- if (explanationEntities && typeof explanationEntities !== 'string') {
226
- obj.explanation_entities = stringify(explanationEntities);
227
- }
228
- }
229
-
230
- _fixAddFileThumbnail(options, opts) {
231
- if (options.thumb) {
232
- if (opts.formData === null) {
233
- opts.formData = {};
234
- }
235
-
236
- const attachName = 'photo';
237
- const [formData] = this._formatSendData(attachName, options.thumb.replace('attach://', ''));
238
-
239
- if (formData) {
240
- opts.formData[attachName] = formData[attachName];
241
- opts.qs.thumbnail = `attach://${attachName}`;
242
- }
243
- }
244
- }
245
-
246
- /**
247
- * Fix 'reply_parameters' parameter by making it JSON-serialized, as
248
- * required by the Telegram Bot API
249
- * @param {Object} obj Object; either 'form' or 'qs'
250
- * @private
251
- * @see https://core.telegram.org/bots/api#sendmessage
252
- */
253
- _fixReplyParameters(obj) {
254
- if (obj.hasOwnProperty('reply_parameters') && typeof obj.reply_parameters !== 'string') {
255
- obj.reply_parameters = stringify(obj.reply_parameters);
256
- }
257
- }
258
-
259
- /**
260
- * Fix JSON-serialized object fields by making them JSON strings if they are still objects.
261
- * Covers new Bot API 7.4-10.3 fields that accept JSON-serialized objects.
262
- * @param {Object} obj Object; either 'form' or 'qs'
263
- * @private
264
- */
265
- _fixJsonFields(obj) {
266
- const jsonFields = ['rich_message', 'content', 'result', 'button', 'web_app', 'photo', 'tasks', 'reaction_type', 'restricted_channels', 'target_business_connection_ids', 'accepted_gift_types', 'link_preview_options'];
267
- for (const field of jsonFields) {
268
- if (obj.hasOwnProperty(field) && typeof obj[field] !== 'string') {
269
- obj[field] = stringify(obj[field]);
270
- }
271
- }
272
- }
273
-
274
- /**
275
- * Make request against the API
276
- * @param {String} _path API endpoint
277
- * @param {Object} [options]
278
- * @private
279
- * @return {Promise}
280
- */
281
- _request(_path, options = {}) {
282
- if (!this.token) {
283
- return Promise.reject(new errors.FatalError('Telegram Bot Token not provided!'));
284
- }
285
-
286
- if (this.options.request) {
287
- Object.assign(options, this.options.request);
288
- }
289
-
290
- if (options.form) {
291
- this._fixReplyMarkup(options.form);
292
- this._fixEntitiesField(options.form);
293
- this._fixReplyParameters(options.form);
294
- this._fixJsonFields(options.form);
295
- }
296
- if (options.qs) {
297
- this._fixReplyMarkup(options.qs);
298
- this._fixReplyParameters(options.qs);
299
- this._fixJsonFields(options.qs);
300
- }
301
-
302
- options.method = 'POST';
303
- options.url = this._buildURL(_path);
304
- options.simple = false;
305
- options.resolveWithFullResponse = true;
306
- options.forever = true;
307
- debug('HTTP request: %j', options);
308
- return request(options).then(resp => {
309
- let data;
310
- try {
311
- data = resp.body = JSON.parse(resp.body);
312
- } catch (err) {
313
- throw new errors.ParseError(`Error parsing response: ${resp.body}`, resp);
314
- }
315
-
316
- if (data.ok) {
317
- return data.result;
318
- }
319
-
320
- throw new errors.TelegramError(`${data.error_code} ${data.description}`, resp);
321
- }).catch(error => {
322
- // TODO: why can't we do `error instanceof errors.BaseError`?
323
- if (error.response) throw error;
324
- throw new errors.FatalError(error);
325
- });
326
- }
327
-
328
- /**
329
- * Format data to be uploaded; handles file paths, streams and buffers
330
- * @param {String} type
331
- * @param {String|stream.Stream|Buffer} data
332
- * @param {Object} fileOptions File options
333
- * @param {String} [fileOptions.filename] File name
334
- * @param {String} [fileOptions.contentType] Content type (i.e. MIME)
335
- * @return {Array} formatted
336
- * @return {Object} formatted[0] formData
337
- * @return {String} formatted[1] fileId
338
- * @throws Error if Buffer file type is not supported.
339
- * @see https://npmjs.com/package/file-type
340
- * @private
341
- */
342
- _formatSendData(type, data, fileOptions = {}) {
343
- const deprecationMessage = 'See https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#sending-files' + ' for more information on how sending files has been improved and' + ' on how to disable this deprecation message altogether.';
344
- let filedata = data;
345
- let filename = fileOptions.filename;
346
- let contentType = fileOptions.contentType;
347
-
348
- if (data instanceof stream.Stream) {
349
- if (!filename && data.path) {
350
- // Will be 'null' if could not be parsed.
351
- // For example, 'data.path' === '/?id=123' from 'request("https://example.com/?id=123")'
352
- const url = URL.parse(path.basename(data.path.toString()));
353
- if (url.pathname) {
354
- filename = qs.unescape(url.pathname);
355
- }
356
- }
357
- } else if (Buffer.isBuffer(data)) {
358
- if (!filename && !process.env.NTBA_FIX_350) {
359
- deprecate(`Buffers will have their filenames default to "filename" instead of "data". ${deprecationMessage}`);
360
- filename = 'data';
361
- }
362
- if (!contentType) {
363
- const filetype = fileType(data);
364
- if (filetype) {
365
- contentType = filetype.mime;
366
- const ext = filetype.ext;
367
- if (ext && !process.env.NTBA_FIX_350) {
368
- filename = `${filename}.${ext}`;
369
- }
370
- } else if (!process.env.NTBA_FIX_350) {
371
- deprecate(`An error will no longer be thrown if file-type of buffer could not be detected. ${deprecationMessage}`);
372
- throw new errors.FatalError('Unsupported Buffer file-type');
373
- }
374
- }
375
- } else if (data) {
376
- if (this.options.filepath && fs.existsSync(data)) {
377
- filedata = fs.createReadStream(data);
378
- if (!filename) {
379
- filename = path.basename(data);
380
- }
381
- } else {
382
- return [null, data];
383
- }
384
- } else {
385
- return [null, data];
386
- }
387
-
388
- filename = filename || 'filename';
389
- contentType = contentType || mime.lookup(filename);
390
- if (process.env.NTBA_FIX_350) {
391
- contentType = contentType || 'application/octet-stream';
392
- } else {
393
- deprecate(`In the future, content-type of files you send will default to "application/octet-stream". ${deprecationMessage}`);
394
- }
395
-
396
- // TODO: Add missing file extension.
397
-
398
- return [{
399
- [type]: {
400
- value: filedata,
401
- options: {
402
- filename,
403
- contentType
404
- }
405
- }
406
- }, null];
407
- }
408
-
409
- /**
410
- * Start polling.
411
- * Rejects returned promise if a WebHook is being used by this instance.
412
- * @param {Object} [options]
413
- * @param {Boolean} [options.restart=true] Consecutive calls to this method causes polling to be restarted
414
- * @return {Promise}
415
- */
416
- startPolling(options = {}) {
417
- if (this.hasOpenWebHook()) {
418
- return Promise.reject(new errors.FatalError('Polling and WebHook are mutually exclusive'));
419
- }
420
- options.restart = typeof options.restart === 'undefined' ? true : options.restart;
421
- if (!this._polling) {
422
- this._polling = new TelegramBotPolling(this);
423
- }
424
- return this._polling.start(options);
425
- }
426
-
427
- /**
428
- * Alias of `TelegramBot#startPolling()`. This is **deprecated**.
429
- * @param {Object} [options]
430
- * @return {Promise}
431
- * @deprecated
432
- */
433
- initPolling() {
434
- deprecate('TelegramBot#initPolling() is deprecated. Use TelegramBot#startPolling() instead.');
435
- return this.startPolling();
436
- }
437
-
438
- /**
439
- * Stops polling after the last polling request resolves.
440
- * Multiple invocations do nothing if polling is already stopped.
441
- * Returning the promise of the last polling request is **deprecated**.
442
- * @param {Object} [options] Options
443
- * @param {Boolean} [options.cancel] Cancel current request
444
- * @param {String} [options.reason] Reason for stopping polling
445
- * @return {Promise}
446
- */
447
- stopPolling(options) {
448
- if (!this._polling) {
449
- return Promise.resolve();
450
- }
451
- return this._polling.stop(options);
452
- }
453
-
454
- /**
455
- * Get link for file.
456
- * Use this method to get link for file for subsequent use.
457
- * Attention: link will be valid for 1 hour.
458
- *
459
- * This method is a sugar extension of the (getFile)[#getfilefileid] method,
460
- * which returns just path to file on remote server (you will have to manually build full uri after that).
461
- *
462
- * @param {String} fileId File identifier to get info about
463
- * @param {Object} [options] Additional Telegram query options
464
- * @return {Promise} Promise which will have *fileURI* in resolve callback
465
- * @see https://core.telegram.org/bots/api#getfile
466
- */
467
- getFileLink(fileId, form = {}) {
468
- return this.getFile(fileId, form).then(resp => `${this.options.baseApiUrl}/file/bot${this.token}/${resp.file_path}`);
469
- }
470
-
471
- /**
472
- * Return a readable stream for file.
473
- *
474
- * `fileStream.path` is the specified file ID i.e. `fileId`.
475
- * `fileStream` emits event `info` passing a single argument i.e.
476
- * `info` with the interface `{ uri }` where `uri` is the URI of the
477
- * file on Telegram servers.
478
- *
479
- * This method is a sugar extension of the [getFileLink](#TelegramBot+getFileLink) method,
480
- * which returns the full URI to the file on remote server.
481
- *
482
- * @param {String} fileId File identifier to get info about
483
- * @param {Object} [options] Additional Telegram query options
484
- * @return {stream.Readable} fileStream
485
- */
486
- getFileStream(fileId, form = {}) {
487
- const fileStream = new stream.PassThrough();
488
- fileStream.path = fileId;
489
- this.getFileLink(fileId, form).then(fileURI => {
490
- fileStream.emit('info', {
491
- uri: fileURI
492
- });
493
- pump(streamedRequest(Object.assign({ uri: fileURI }, this.options.request)), fileStream);
494
- }).catch(error => {
495
- fileStream.emit('error', error);
496
- });
497
- return fileStream;
498
- }
499
-
500
- /**
501
- * Downloads file in the specified folder.
502
- *
503
- * This method is a sugar extension of the [getFileStream](#TelegramBot+getFileStream) method,
504
- * which returns a readable file stream.
505
- *
506
- * @param {String} fileId File identifier to get info about
507
- * @param {String} downloadDir Absolute path to the folder in which file will be saved
508
- * @param {Object} [options] Additional Telegram query options
509
- * @return {Promise} Promise, which will have *filePath* of downloaded file in resolve callback
510
- */
511
- downloadFile(fileId, downloadDir, form = {}) {
512
- let resolve;
513
- let reject;
514
- const promise = new Promise((a, b) => {
515
- resolve = a;
516
- reject = b;
517
- });
518
- const fileStream = this.getFileStream(fileId, form);
519
- fileStream.on('info', info => {
520
- const fileName = info.uri.slice(info.uri.lastIndexOf('/') + 1);
521
- // TODO: Ensure fileName doesn't contains slashes
522
- const filePath = path.join(downloadDir, fileName);
523
- pump(fileStream, fs.createWriteStream(filePath), error => {
524
- if (error) {
525
- return reject(error);
526
- }
527
- return resolve(filePath);
528
- });
529
- });
530
- fileStream.on('error', err => {
531
- reject(err);
532
- });
533
- return promise;
534
- }
535
-
536
- /**
537
- * Register a RegExp to test against an incomming text message.
538
- * @param {RegExp} regexpRexecuted with `exec`.
539
- * @param {Function} callback Callback will be called with 2 parameters,
540
- * the `msg` and the result of executing `regexp.exec` on message text.
541
- */
542
- onText(regexp, callback) {
543
- this._textRegexpCallbacks.push({ regexp, callback });
544
- }
545
-
546
- /**
547
- * Remove a listener registered with `onText()`.
548
- * @param {RegExp} regexp RegExp used previously in `onText()`
549
- * @return {Object} deletedListener The removed reply listener if
550
- * found. This object has `regexp` and `callback`
551
- * properties. If not found, returns `null`.
552
- */
553
- removeTextListener(regexp) {
554
- const index = this._textRegexpCallbacks.findIndex(textListener => {
555
- return String(textListener.regexp) === String(regexp);
556
- });
557
- if (index === -1) {
558
- return null;
559
- }
560
- return this._textRegexpCallbacks.splice(index, 1)[0];
561
- }
562
-
563
- /**
564
- * Remove all listeners registered with `onText()`.
565
- */
566
- clearTextListeners() {
567
- this._textRegexpCallbacks = [];
568
- }
569
-
570
- /**
571
- * Register a reply to wait for a message response.
572
- *
573
- * @param {Number|String} chatId The chat id where the message cames from.
574
- * @param {Number|String} messageId The message id to be replied.
575
- * @param {Function} callback Callback will be called with the reply
576
- * message.
577
- * @return {Number} id The ID of the inserted reply listener.
578
- */
579
- onReplyToMessage(chatId, messageId, callback) {
580
- const id = ++this._replyListenerId;
581
- this._replyListeners.push({
582
- id,
583
- chatId,
584
- messageId,
585
- callback
586
- });
587
- return id;
588
- }
589
-
590
- /**
591
- * Removes a reply that has been prev. registered for a message response.
592
- * @param {Number} replyListenerId The ID of the reply listener.
593
- * @return {Object} deletedListener The removed reply listener if
594
- * found. This object has `id`, `chatId`, `messageId` and `callback`
595
- * properties. If not found, returns `null`.
596
- */
597
- removeReplyListener(replyListenerId) {
598
- const index = this._replyListeners.findIndex(replyListener => {
599
- return replyListener.id === replyListenerId;
600
- });
601
- if (index === -1) {
602
- return null;
603
- }
604
- return this._replyListeners.splice(index, 1)[0];
605
- }
606
-
607
- /**
608
- * Removes all replies that have been prev. registered for a message response.
609
- *
610
- * @return {Array} deletedListeners An array of removed listeners.
611
- */
612
- clearReplyListeners() {
613
- this._replyListeners = [];
614
- }
615
-
616
- /**
617
- * Return true if polling. Otherwise, false.
618
- *
619
- * @return {Boolean}
620
- */
621
- isPolling() {
622
- return this._polling ? this._polling.isPolling() : false;
623
- }
624
-
625
- /**
626
- * Open webhook.
627
- * Multiple invocations do nothing if webhook is already open.
628
- * Rejects returned promise if Polling is being used by this instance.
629
- *
630
- * @return {Promise}
631
- */
632
- openWebHook() {
633
- if (this.isPolling()) {
634
- return Promise.reject(new errors.FatalError('WebHook and Polling are mutually exclusive'));
635
- }
636
- if (!this._webHook) {
637
- this._webHook = new TelegramBotWebHook(this);
638
- }
639
- return this._webHook.open();
640
- }
641
-
642
- /**
643
- * Close webhook after closing all current connections.
644
- * Multiple invocations do nothing if webhook is already closed.
645
- *
646
- * @return {Promise} Promise
647
- */
648
- closeWebHook() {
649
- if (!this._webHook) {
650
- return Promise.resolve();
651
- }
652
- return this._webHook.close();
653
- }
654
-
655
- /**
656
- * Return true if using webhook and it is open i.e. accepts connections.
657
- * Otherwise, false.
658
- *
659
- * @return {Boolean}
660
- */
661
- hasOpenWebHook() {
662
- return this._webHook ? this._webHook.isOpen() : false;
663
- }
664
-
665
- /**
666
- * Process an update; emitting the proper events and executing regexp
667
- * callbacks. This method is useful should you be using a different
668
- * way to fetch updates, other than those provided by TelegramBot.
669
- *
670
- * @param {Object} update
671
- * @see https://core.telegram.org/bots/api#update
672
- */
673
- processUpdate(update) {
674
- debug('Process Update %j', update);
675
- const message = update.message;
676
- const editedMessage = update.edited_message;
677
- const channelPost = update.channel_post;
678
- const editedChannelPost = update.edited_channel_post;
679
- const businessConnection = update.business_connection;
680
- const businesssMessage = update.business_message;
681
- const editedBusinessMessage = update.edited_business_message;
682
- const deletedBusinessMessage = update.deleted_business_messages;
683
- const messageReaction = update.message_reaction;
684
- const messageReactionCount = update.message_reaction_count;
685
- const inlineQuery = update.inline_query;
686
- const chosenInlineResult = update.chosen_inline_result;
687
- const callbackQuery = update.callback_query;
688
- const shippingQuery = update.shipping_query;
689
- const preCheckoutQuery = update.pre_checkout_query;
690
- const poll = update.poll;
691
- const pollAnswer = update.poll_answer;
692
- const myChatMember = update.my_chat_member;
693
- const chatMember = update.chat_member;
694
- const chatJoinRequest = update.chat_join_request;
695
- const chatBoost = update.chat_boost;
696
- const removedChatBoost = update.removed_chat_boost;
697
-
698
- if (message) {
699
- debug('Process Update message %j', message);
700
- const metadata = {};
701
- metadata.type = TelegramBot.messageTypes.find(messageType => {
702
- return message[messageType];
703
- });
704
- this.emit('message', message, metadata);
705
- if (metadata.type) {
706
- debug('Emitting %s: %j', metadata.type, message);
707
- this.emit(metadata.type, message, metadata);
708
- }
709
- if (message.text) {
710
- debug('Text message');
711
- this._textRegexpCallbacks.some(reg => {
712
- debug('Matching %s with %s', message.text, reg.regexp);
713
-
714
- if (!(reg.regexp instanceof RegExp)) {
715
- reg.regexp = new RegExp(reg.regexp);
716
- }
717
-
718
- const result = reg.regexp.exec(message.text);
719
- if (!result) {
720
- return false;
721
- }
722
- // reset index so we start at the beginning of the regex each time
723
- reg.regexp.lastIndex = 0;
724
- debug('Matches %s', reg.regexp);
725
- reg.callback(message, result);
726
- // returning truthy value exits .some
727
- return this.options.onlyFirstMatch;
728
- });
729
- }
730
- if (message.reply_to_message) {
731
- // Only callbacks waiting for this message
732
- this._replyListeners.forEach(reply => {
733
- // Message from the same chat
734
- if (reply.chatId === message.chat.id) {
735
- // Responding to that message
736
- if (reply.messageId === message.reply_to_message.message_id) {
737
- // Resolve the promise
738
- reply.callback(message);
739
- }
740
- }
741
- });
742
- }
743
- } else if (editedMessage) {
744
- debug('Process Update edited_message %j', editedMessage);
745
- this.emit('edited_message', editedMessage);
746
- if (editedMessage.text) {
747
- this.emit('edited_message_text', editedMessage);
748
- }
749
- if (editedMessage.caption) {
750
- this.emit('edited_message_caption', editedMessage);
751
- }
752
- } else if (channelPost) {
753
- debug('Process Update channel_post %j', channelPost);
754
- this.emit('channel_post', channelPost);
755
- } else if (editedChannelPost) {
756
- debug('Process Update edited_channel_post %j', editedChannelPost);
757
- this.emit('edited_channel_post', editedChannelPost);
758
- if (editedChannelPost.text) {
759
- this.emit('edited_channel_post_text', editedChannelPost);
760
- }
761
- if (editedChannelPost.caption) {
762
- this.emit('edited_channel_post_caption', editedChannelPost);
763
- }
764
- } else if (businessConnection) {
765
- debug('Process Update business_connection %j', businessConnection);
766
- this.emit('business_connection', businessConnection);
767
- } else if (businesssMessage) {
768
- debug('Process Update business_message %j', businesssMessage);
769
- this.emit('business_message', businesssMessage);
770
- } else if (editedBusinessMessage) {
771
- debug('Process Update edited_business_message %j', editedBusinessMessage);
772
- this.emit('edited_business_message', editedBusinessMessage);
773
- } else if (deletedBusinessMessage) {
774
- debug('Process Update deleted_business_messages %j', deletedBusinessMessage);
775
- this.emit('deleted_business_messages', deletedBusinessMessage);
776
- } else if (messageReaction) {
777
- debug('Process Update message_reaction %j', messageReaction);
778
- this.emit('message_reaction', messageReaction);
779
- } else if (messageReactionCount) {
780
- debug('Process Update message_reaction_count %j', messageReactionCount);
781
- this.emit('message_reaction_count', messageReactionCount);
782
- } else if (inlineQuery) {
783
- debug('Process Update inline_query %j', inlineQuery);
784
- this.emit('inline_query', inlineQuery);
785
- } else if (chosenInlineResult) {
786
- debug('Process Update chosen_inline_result %j', chosenInlineResult);
787
- this.emit('chosen_inline_result', chosenInlineResult);
788
- } else if (callbackQuery) {
789
- debug('Process Update callback_query %j', callbackQuery);
790
- this.emit('callback_query', callbackQuery);
791
- } else if (shippingQuery) {
792
- debug('Process Update shipping_query %j', shippingQuery);
793
- this.emit('shipping_query', shippingQuery);
794
- } else if (preCheckoutQuery) {
795
- debug('Process Update pre_checkout_query %j', preCheckoutQuery);
796
- this.emit('pre_checkout_query', preCheckoutQuery);
797
- } else if (poll) {
798
- debug('Process Update poll %j', poll);
799
- this.emit('poll', poll);
800
- } else if (pollAnswer) {
801
- debug('Process Update poll_answer %j', pollAnswer);
802
- this.emit('poll_answer', pollAnswer);
803
- } else if (chatMember) {
804
- debug('Process Update chat_member %j', chatMember);
805
- this.emit('chat_member', chatMember);
806
- } else if (myChatMember) {
807
- debug('Process Update my_chat_member %j', myChatMember);
808
- this.emit('my_chat_member', myChatMember);
809
- } else if (chatJoinRequest) {
810
- debug('Process Update my_chat_member %j', chatJoinRequest);
811
- this.emit('chat_join_request', chatJoinRequest);
812
- } else if (chatBoost) {
813
- debug('Process Update chat_boost %j', chatBoost);
814
- this.emit('chat_boost', chatBoost);
815
- } else if (removedChatBoost) {
816
- debug('Process Update removed_chat_boost %j', removedChatBoost);
817
- this.emit('removed_chat_boost', removedChatBoost);
818
- }
819
- }
820
-
821
- /** Start Telegram Bot API methods */
822
-
823
- /**
824
- * Use this method to receive incoming updates using long polling.
825
- * This method has an [older, compatible signature][getUpdates-v0.25.0]
826
- * that is being deprecated.
827
- *
828
- * @param {Object} [options] Additional Telegram query options
829
- * @return {Promise}
830
- * @see https://core.telegram.org/bots/api#getupdates
831
- */
832
- getUpdates(form = {}) {
833
- /* The older method signature was getUpdates(timeout, limit, offset).
834
- * We need to ensure backwards-compatibility while maintaining
835
- * consistency of the method signatures throughout the library */
836
- if (typeof form !== 'object') {
837
- /* eslint-disable no-param-reassign, prefer-rest-params */
838
- deprecate('The method signature getUpdates(timeout, limit, offset) has been deprecated since v0.25.0');
839
- form = {
840
- timeout: arguments[0],
841
- limit: arguments[1],
842
- offset: arguments[2]
843
- };
844
- /* eslint-enable no-param-reassign, prefer-rest-params */
845
- }
846
-
847
- return this._request('getUpdates', { form });
848
- }
849
-
850
- /**
851
- * Specify an url to receive incoming updates via an outgoing webHook.
852
- * This method has an [older, compatible signature][setWebHook-v0.25.0]
853
- * that is being deprecated.
854
- *
855
- * @param {String} url URL where Telegram will make HTTP Post. Leave empty to
856
- * delete webHook.
857
- * @param {Object} [options] Additional Telegram query options
858
- * @param {String|stream.Stream} [options.certificate] PEM certificate key (public).
859
- * @param {String} [options.secret_token] Optional secret token to be sent in a header `X-Telegram-Bot-Api-Secret-Token` in every webhook request.
860
- * @param {Object} [fileOptions] Optional file related meta-data
861
- * @return {Promise}
862
- * @see https://core.telegram.org/bots/api#setwebhook
863
- * @see https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#sending-files
864
- */
865
- setWebHook(url, options = {}, fileOptions = {}) {
866
- /* The older method signature was setWebHook(url, cert).
867
- * We need to ensure backwards-compatibility while maintaining
868
- * consistency of the method signatures throughout the library */
869
- let cert;
870
- // Note: 'options' could be an object, if a stream was provided (in place of 'cert')
871
- if (typeof options !== 'object' || options instanceof stream.Stream) {
872
- deprecate('The method signature setWebHook(url, cert) has been deprecated since v0.25.0');
873
- cert = options;
874
- options = {}; // eslint-disable-line no-param-reassign
875
- } else {
876
- cert = options.certificate;
877
- }
878
-
879
- const opts = {
880
- qs: options
881
- };
882
- opts.qs.url = url;
883
-
884
- if (cert) {
885
- try {
886
- const sendData = this._formatSendData('certificate', cert, fileOptions);
887
- opts.formData = sendData[0];
888
- opts.qs.certificate = sendData[1];
889
- } catch (ex) {
890
- return Promise.reject(ex);
891
- }
892
- }
893
-
894
- return this._request('setWebHook', opts);
895
- }
896
-
897
- /**
898
- * Use this method to remove webhook integration if you decide to
899
- * switch back to getUpdates. Returns True on success.
900
- * @param {Object} [options] Additional Telegram query options
901
- * @return {Promise}
902
- * @see https://core.telegram.org/bots/api#deletewebhook
903
- */
904
- deleteWebHook(form = {}) {
905
- return this._request('deleteWebhook', { form });
906
- }
907
-
908
- /**
909
- * Use this method to get current webhook status.
910
- * On success, returns a [WebhookInfo](https://core.telegram.org/bots/api#webhookinfo) object.
911
- * If the bot is using getUpdates, will return an object with the
912
- * url field empty.
913
- * @param {Object} [options] Additional Telegram query options
914
- * @return {Promise}
915
- * @see https://core.telegram.org/bots/api#getwebhookinfo
916
- */
917
- getWebHookInfo(form = {}) {
918
- return this._request('getWebhookInfo', { form });
919
- }
920
-
921
- /**
922
- * A simple method for testing your bot's authentication token. Requires no parameters.
923
- *
924
- * @param {Object} [options] Additional Telegram query options
925
- * @return {Promise} basic information about the bot in form of a [User](https://core.telegram.org/bots/api#user) object.
926
- * @see https://core.telegram.org/bots/api#getme
927
- */
928
- getMe(form = {}) {
929
- return this._request('getMe', { form });
930
- }
931
-
932
- /**
933
- * This method log out your bot from the cloud Bot API server before launching the bot locally.
934
- * You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates.
935
- * After a successful call, you will not be able to log in again using the same token for 10 minutes.
936
- *
937
- * @param {Object} [options] Additional Telegram query options
938
- * @return {Promise} True on success
939
- * @see https://core.telegram.org/bots/api#logout
940
- */
941
- logOut(form = {}) {
942
- return this._request('logOut', { form });
943
- }
944
-
945
- /**
946
- * This method close the bot instance before moving it from one local server to another.
947
- * This method will return error 429 in the first 10 minutes after the bot is launched.
948
- *
949
- * @param {Object} [options] Additional Telegram query options
950
- * @return {Promise} True on success
951
- * @see https://core.telegram.org/bots/api#close
952
- */
953
- close(form = {}) {
954
- return this._request('close', { form });
955
- }
956
-
957
- /**
958
- * Send text message.
959
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
960
- * @param {String} text Text of the message to be sent
961
- * @param {Object} [options] Additional Telegram query options
962
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned
963
- * @see https://core.telegram.org/bots/api#sendmessage
964
- */
965
- sendMessage(chatId, text, form = {}) {
966
- form.chat_id = chatId;
967
- form.text = text;
968
- return this._request('sendMessage', { form });
969
- }
970
-
971
- /**
972
- * Forward messages of any kind.
973
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
974
- * or username of the target channel (in the format `@channelusername`)
975
- * @param {Number|String} fromChatId Unique identifier for the chat where the
976
- * original message was sent (or channel username in the format `@channelusername`)
977
- * @param {Number|String} messageId Unique message identifier in the chat specified in fromChatId
978
- * @param {Object} [options] Additional Telegram query options
979
- * @return {Promise}
980
- * @see https://core.telegram.org/bots/api#forwardmessage
981
- */
982
- forwardMessage(chatId, fromChatId, messageId, form = {}) {
983
- form.chat_id = chatId;
984
- form.from_chat_id = fromChatId;
985
- form.message_id = messageId;
986
- return this._request('forwardMessage', { form });
987
- }
988
-
989
- /**
990
- * Use this method to forward multiple messages of any kind.
991
- * If some of the specified messages can't be found or forwarded, they are skipped.
992
- *
993
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
994
- * or username of the target channel (in the format `@channelusername`)
995
- * @param {Number|String} fromChatId Unique identifier for the chat where the
996
- * original message was sent (or channel username in the format `@channelusername`)
997
- * @param {Array<Number|String>} messageIds Identifiers of 1-100 messages in the chat from_chat_id to forward.
998
- * The identifiers must be specified in a strictly increasing order.
999
- * @param {Object} [options] Additional Telegram query options
1000
- * @return {Promise} An array of MessageId of the sent messages on success
1001
- * @see https://core.telegram.org/bots/api#forwardmessages
1002
- */
1003
- forwardMessages(chatId, fromChatId, messageIds, form = {}) {
1004
- form.chat_id = chatId;
1005
- form.from_chat_id = fromChatId;
1006
- form.message_ids = messageIds;
1007
- return this._request('forwardMessages', { form });
1008
- }
1009
-
1010
- /**
1011
- * Copy messages of any kind. **Service messages and invoice messages can't be copied.**
1012
- * The method is analogous to the method forwardMessages, but the copied message doesn't
1013
- * have a link to the original message.
1014
- * Returns the MessageId of the sent message on success.
1015
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1016
- * @param {Number|String} fromChatId Unique identifier for the chat where the
1017
- * original message was sent
1018
- * @param {Number|String} messageId Unique message identifier
1019
- * @param {Object} [options] Additional Telegram query options
1020
- * @return {Promise} The [MessageId](https://core.telegram.org/bots/api#messageid) of the sent message on success
1021
- * @see https://core.telegram.org/bots/api#copymessage
1022
- */
1023
- copyMessage(chatId, fromChatId, messageId, form = {}) {
1024
- form.chat_id = chatId;
1025
- form.from_chat_id = fromChatId;
1026
- form.message_id = messageId;
1027
- return this._request('copyMessage', { form });
1028
- }
1029
-
1030
- /**
1031
- * Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped.
1032
- * Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
1033
- * Returns the MessageId of the sent message on success.
1034
- * @param {Number|String} chatId Unique identifier for the target chat
1035
- * @param {Number|String} fromChatId Unique identifier for the chat where the
1036
- * original message was sent
1037
- * @param {Array} messageIds Identifiers of 1-100 messages in the chat from_chat_id to copy.
1038
- * The identifiers must be specified in a strictly increasing order.
1039
- * @param {Object} [options] Additional Telegram query options
1040
- * @return {Promise} An array of MessageId of the sent messages
1041
- * @see https://core.telegram.org/bots/api#copymessages
1042
- */
1043
- copyMessages(chatId, fromChatId, messageIds, form = {}) {
1044
- form.chat_id = chatId;
1045
- form.from_chat_id = fromChatId;
1046
- form.message_ids = stringify(messageIds);
1047
- return this._request('copyMessages', { form });
1048
- }
1049
-
1050
- /**
1051
- * Send photo
1052
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1053
- * @param {String|stream.Stream|Buffer} photo A file path or a Stream. Can
1054
- * also be a `file_id` previously uploaded
1055
- * @param {Object} [options] Additional Telegram query options
1056
- * @param {Object} [fileOptions] Optional file related meta-data
1057
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned
1058
- * @see https://core.telegram.org/bots/api#sendphoto
1059
- * @see https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#sending-files
1060
- */
1061
- sendPhoto(chatId, photo, options = {}, fileOptions = {}) {
1062
- const opts = {
1063
- qs: options
1064
- };
1065
- opts.qs.chat_id = chatId;
1066
- try {
1067
- const sendData = this._formatSendData('photo', photo, fileOptions);
1068
- opts.formData = sendData[0];
1069
- opts.qs.photo = sendData[1];
1070
- } catch (ex) {
1071
- return Promise.reject(ex);
1072
- }
1073
- return this._request('sendPhoto', opts);
1074
- }
1075
-
1076
- /**
1077
- * Send audio
1078
- *
1079
- * **Your audio must be in the .MP3 or .M4A format.**
1080
- *
1081
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1082
- * @param {String|stream.Stream|Buffer} audio A file path, Stream or Buffer.
1083
- * Can also be a `file_id` previously uploaded.
1084
- * @param {Object} [options] Additional Telegram query options
1085
- * @param {Object} [fileOptions] Optional file related meta-data
1086
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned
1087
- * @see https://core.telegram.org/bots/api#sendaudio
1088
- * @see https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#sending-files
1089
- */
1090
- sendAudio(chatId, audio, options = {}, fileOptions = {}) {
1091
- const opts = {
1092
- qs: options
1093
- };
1094
-
1095
- opts.qs.chat_id = chatId;
1096
-
1097
- try {
1098
- const sendData = this._formatSendData('audio', audio, fileOptions);
1099
- opts.formData = sendData[0];
1100
- opts.qs.audio = sendData[1];
1101
- this._fixAddFileThumbnail(options, opts);
1102
- } catch (ex) {
1103
- return Promise.reject(ex);
1104
- }
1105
-
1106
- return this._request('sendAudio', opts);
1107
- }
1108
-
1109
- /**
1110
- * Send Document
1111
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1112
- * @param {String|stream.Stream|Buffer} doc A file path, Stream or Buffer.
1113
- * Can also be a `file_id` previously uploaded.
1114
- * @param {Object} [options] Additional Telegram query options
1115
- * @param {Object} [fileOptions] Optional file related meta-data
1116
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned
1117
- * @see https://core.telegram.org/bots/api#sendDocument
1118
- * @see https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#sending-files
1119
- */
1120
- sendDocument(chatId, doc, options = {}, fileOptions = {}) {
1121
- const opts = {
1122
- qs: options
1123
- };
1124
- opts.qs.chat_id = chatId;
1125
- try {
1126
- const sendData = this._formatSendData('document', doc, fileOptions);
1127
- opts.formData = sendData[0];
1128
- opts.qs.document = sendData[1];
1129
- this._fixAddFileThumbnail(options, opts);
1130
- } catch (ex) {
1131
- return Promise.reject(ex);
1132
- }
1133
-
1134
- return this._request('sendDocument', opts);
1135
- }
1136
-
1137
- /**
1138
- * Use this method to send video files, **Telegram clients support mp4 videos** (other formats may be sent as Document).
1139
- *
1140
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1141
- * @param {String|stream.Stream|Buffer} video A file path or Stream.
1142
- * Can also be a `file_id` previously uploaded.
1143
- * @param {Object} [options] Additional Telegram query options
1144
- * @param {Object} [fileOptions] Optional file related meta-data
1145
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned
1146
- * @see https://core.telegram.org/bots/api#sendvideo
1147
- * @see https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#sending-files
1148
- */
1149
- sendVideo(chatId, video, options = {}, fileOptions = {}) {
1150
- const opts = {
1151
- qs: options
1152
- };
1153
- opts.qs.chat_id = chatId;
1154
- try {
1155
- const sendData = this._formatSendData('video', video, fileOptions);
1156
- opts.formData = sendData[0];
1157
- opts.qs.video = sendData[1];
1158
- this._fixAddFileThumbnail(options, opts);
1159
- } catch (ex) {
1160
- return Promise.reject(ex);
1161
- }
1162
- return this._request('sendVideo', opts);
1163
- }
1164
-
1165
- /**
1166
- * Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).
1167
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1168
- * @param {String|stream.Stream|Buffer} animation A file path, Stream or Buffer.
1169
- * Can also be a `file_id` previously uploaded.
1170
- * @param {Object} [options] Additional Telegram query options
1171
- * @param {Object} [fileOptions] Optional file related meta-data
1172
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned
1173
- * @see https://core.telegram.org/bots/api#sendanimation
1174
- * @see https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#sending-files
1175
- */
1176
- sendAnimation(chatId, animation, options = {}, fileOptions = {}) {
1177
- const opts = {
1178
- qs: options
1179
- };
1180
- opts.qs.chat_id = chatId;
1181
- try {
1182
- const sendData = this._formatSendData('animation', animation, fileOptions);
1183
- opts.formData = sendData[0];
1184
- opts.qs.animation = sendData[1];
1185
- } catch (ex) {
1186
- return Promise.reject(ex);
1187
- }
1188
- return this._request('sendAnimation', opts);
1189
- }
1190
-
1191
- /**
1192
- * Send voice
1193
- *
1194
- * **Your audio must be in an .OGG file encoded with OPUS**, or in .MP3 format, or in .M4A format (other formats may be sent as Audio or Document)
1195
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1196
- * @param {String|stream.Stream|Buffer} voice A file path, Stream or Buffer.
1197
- * Can also be a `file_id` previously uploaded.
1198
- * @param {Object} [options] Additional Telegram query options
1199
- * @param {Object} [fileOptions] Optional file related meta-data
1200
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned
1201
- * @see https://core.telegram.org/bots/api#sendvoice
1202
- * @see https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#sending-files
1203
- */
1204
- sendVoice(chatId, voice, options = {}, fileOptions = {}) {
1205
- const opts = {
1206
- qs: options
1207
- };
1208
- opts.qs.chat_id = chatId;
1209
- try {
1210
- const sendData = this._formatSendData('voice', voice, fileOptions);
1211
- opts.formData = sendData[0];
1212
- opts.qs.voice = sendData[1];
1213
- } catch (ex) {
1214
- return Promise.reject(ex);
1215
- }
1216
- return this._request('sendVoice', opts);
1217
- }
1218
-
1219
- /**
1220
- * Use this method to send video messages
1221
- * Telegram clients support **rounded square MPEG4 videos** of up to 1 minute long.
1222
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1223
- * @param {String|stream.Stream|Buffer} videoNote A file path or Stream.
1224
- * Can also be a `file_id` previously uploaded.
1225
- * @param {Object} [options] Additional Telegram query options
1226
- * @param {Object} [fileOptions] Optional file related meta-data
1227
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned
1228
- * @info The length parameter is actually optional. However, the API (at time of writing) requires you to always provide it until it is fixed.
1229
- * @see https://core.telegram.org/bots/api#sendvideonote
1230
- * @see https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#sending-files
1231
- */
1232
- sendVideoNote(chatId, videoNote, options = {}, fileOptions = {}) {
1233
- const opts = {
1234
- qs: options
1235
- };
1236
- opts.qs.chat_id = chatId;
1237
- try {
1238
- const sendData = this._formatSendData('video_note', videoNote, fileOptions);
1239
- opts.formData = sendData[0];
1240
- opts.qs.video_note = sendData[1];
1241
- this._fixAddFileThumbnail(options, opts);
1242
- } catch (ex) {
1243
- return Promise.reject(ex);
1244
- }
1245
- return this._request('sendVideoNote', opts);
1246
- }
1247
-
1248
- /**
1249
- * Use this method to send a group of photos or videos as an album.
1250
- *
1251
- * **Documents and audio files can be only grouped in an album with messages of the same type**
1252
- *
1253
- * If you wish to [specify file options](https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#sending-files),
1254
- * add a `fileOptions` property to the target input in `media`.
1255
- *
1256
- * @param {String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1257
- * @param {Array} media A JSON-serialized array describing photos and videos to be sent, must include 2–10 items
1258
- * @param {Object} [options] Additional Telegram query options
1259
- * @return {Promise} On success, an array of the sent [Messages](https://core.telegram.org/bots/api#message)
1260
- * is returned.
1261
- * @see https://core.telegram.org/bots/api#sendmediagroup
1262
- * @see https://github.com/ZeroBot-net/@zero-bot.net/tg-bot-api/blob/master/doc/usage.md#sending-files
1263
- */
1264
- sendMediaGroup(chatId, media, options = {}) {
1265
- const opts = {
1266
- qs: options
1267
- };
1268
- opts.qs.chat_id = chatId;
1269
-
1270
- opts.formData = {};
1271
- const inputMedia = [];
1272
- let index = 0;
1273
- for (const input of media) {
1274
- const payload = Object.assign({}, input);
1275
- delete payload.media;
1276
- delete payload.fileOptions;
1277
- try {
1278
- const attachName = String(index);
1279
- const [formData, fileId] = this._formatSendData(attachName, input.media, input.fileOptions);
1280
- if (formData) {
1281
- opts.formData[attachName] = formData[attachName];
1282
- payload.media = `attach://${attachName}`;
1283
- } else {
1284
- payload.media = fileId;
1285
- }
1286
- } catch (ex) {
1287
- return Promise.reject(ex);
1288
- }
1289
- inputMedia.push(payload);
1290
- index++;
1291
- }
1292
- opts.qs.media = stringify(inputMedia);
1293
-
1294
- return this._request('sendMediaGroup', opts);
1295
- }
1296
-
1297
- /**
1298
- * Send location.
1299
- * Use this method to send point on the map.
1300
- *
1301
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1302
- * @param {Float} latitude Latitude of location
1303
- * @param {Float} longitude Longitude of location
1304
- * @param {Object} [options] Additional Telegram query options
1305
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned
1306
- * @see https://core.telegram.org/bots/api#sendlocation
1307
- */
1308
- sendLocation(chatId, latitude, longitude, form = {}) {
1309
- form.chat_id = chatId;
1310
- form.latitude = latitude;
1311
- form.longitude = longitude;
1312
- return this._request('sendLocation', { form });
1313
- }
1314
-
1315
- /**
1316
- * Use this method to edit live location messages sent by
1317
- * the bot or via the bot (for inline bots).
1318
- *
1319
- * A location **can be edited until its live_period expires or editing is explicitly disabled by a call to [stopMessageLiveLocation](https://core.telegram.org/bots/api#stopmessagelivelocation)**
1320
- *
1321
- * Note that you must provide one of chat_id, message_id, or
1322
- * inline_message_id in your request.
1323
- *
1324
- * @param {Float} latitude Latitude of location
1325
- * @param {Float} longitude Longitude of location
1326
- * @param {Object} [options] Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here)
1327
- * @return {Promise} On success, if the edited message is not an inline message, the edited [Message](https://core.telegram.org/bots/api#message) is returned, otherwise True is returned.
1328
- * @see https://core.telegram.org/bots/api#editmessagelivelocation
1329
- */
1330
- editMessageLiveLocation(latitude, longitude, form = {}) {
1331
- form.latitude = latitude;
1332
- form.longitude = longitude;
1333
- return this._request('editMessageLiveLocation', { form });
1334
- }
1335
-
1336
- /**
1337
- * Use this method to stop updating a live location message sent by
1338
- * the bot or via the bot (for inline bots) before live_period expires.
1339
- *
1340
- * Note that you must provide one of chat_id, message_id, or
1341
- * inline_message_id in your request.
1342
- *
1343
- * @param {Object} [options] Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here)
1344
- * @return {Promise} On success, if the edited message is not an inline message, the edited [Message](https://core.telegram.org/bots/api#message) is returned, otherwise True is returned.
1345
- * @see https://core.telegram.org/bots/api#stopmessagelivelocation
1346
- */
1347
- stopMessageLiveLocation(form = {}) {
1348
- return this._request('stopMessageLiveLocation', { form });
1349
- }
1350
-
1351
- /**
1352
- * Send venue.
1353
- * Use this method to send information about a venue.
1354
- *
1355
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1356
- * @param {Float} latitude Latitude of location
1357
- * @param {Float} longitude Longitude of location
1358
- * @param {String} title Name of the venue
1359
- * @param {String} address Address of the venue
1360
- * @param {Object} [options] Additional Telegram query options
1361
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned.
1362
- * @see https://core.telegram.org/bots/api#sendvenue
1363
- */
1364
- sendVenue(chatId, latitude, longitude, title, address, form = {}) {
1365
- form.chat_id = chatId;
1366
- form.latitude = latitude;
1367
- form.longitude = longitude;
1368
- form.title = title;
1369
- form.address = address;
1370
- return this._request('sendVenue', { form });
1371
- }
1372
-
1373
- /**
1374
- * Send contact.
1375
- * Use this method to send phone contacts.
1376
- *
1377
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1378
- * @param {String} phoneNumber Contact's phone number
1379
- * @param {String} firstName Contact's first name
1380
- * @param {Object} [options] Additional Telegram query options
1381
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned
1382
- * @see https://core.telegram.org/bots/api#sendcontact
1383
- */
1384
- sendContact(chatId, phoneNumber, firstName, form = {}) {
1385
- form.chat_id = chatId;
1386
- form.phone_number = phoneNumber;
1387
- form.first_name = firstName;
1388
- return this._request('sendContact', { form });
1389
- }
1390
-
1391
- /**
1392
- * Send poll.
1393
- * Use this method to send a native poll.
1394
- *
1395
- * @param {Number|String} chatId Unique identifier for the group/channel
1396
- * @param {String} question Poll question, 1-300 characters
1397
- * @param {Array} pollOptions Poll options, between 2-10 options (only 1-100 characters each)
1398
- * @param {Object} [options] Additional Telegram query options
1399
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned
1400
- * @see https://core.telegram.org/bots/api#sendpoll
1401
- */
1402
- sendPoll(chatId, question, pollOptions, form = {}) {
1403
- form.chat_id = chatId;
1404
- form.question = question;
1405
- form.options = stringify(pollOptions);
1406
- return this._request('sendPoll', { form });
1407
- }
1408
-
1409
- /**
1410
- * Send Dice
1411
- * Use this method to send an animated emoji that will display a random value.
1412
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1413
- * @param {Object} [options] Additional Telegram query options
1414
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) object is returned
1415
- * @see https://core.telegram.org/bots/api#senddice
1416
- */
1417
- sendDice(chatId, options = {}) {
1418
- const opts = {
1419
- qs: options
1420
- };
1421
- opts.qs.chat_id = chatId;
1422
- try {
1423
- const sendData = this._formatSendData('dice');
1424
- opts.formData = sendData[0];
1425
- } catch (ex) {
1426
- return Promise.reject(ex);
1427
- }
1428
- return this._request('sendDice', opts);
1429
- }
1430
-
1431
- /**
1432
- * Send chat action.
1433
- *
1434
- * Use this method when you need to tell the user that something is happening on the bot's side.
1435
- * **The status is set for 5 seconds or less** (when a message arrives from your bot, Telegram clients clear its typing status).
1436
- *
1437
- * Action `typing` for [text messages](https://core.telegram.org/bots/api#sendmessage),
1438
- * `upload_photo` for [photos](https://core.telegram.org/bots/api#sendphoto), `record_video` or `upload_video` for [videos](https://core.telegram.org/bots/api#sendvideo),
1439
- * `record_voice` or `upload_voice` for [voice notes](https://core.telegram.org/bots/api#sendvoice), `upload_document` for [general files](https://core.telegram.org/bots/api#senddocument),
1440
- * `choose_sticker` for [stickers](https://core.telegram.org/bots/api#sendsticker), `find_location` for [location data](https://core.telegram.org/bots/api#sendlocation),
1441
- * `record_video_note` or `upload_video_note` for [video notes](https://core.telegram.org/bots/api#sendvideonote).
1442
- *
1443
- *
1444
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1445
- * @param {String} action Type of action to broadcast.
1446
- * @param {Object} [options] Additional Telegram query options
1447
- * @return {Promise} True on success
1448
- * @see https://core.telegram.org/bots/api#sendchataction
1449
- */
1450
- sendChatAction(chatId, action, form = {}) {
1451
- form.chat_id = chatId;
1452
- form.action = action;
1453
- return this._request('sendChatAction', { form });
1454
- }
1455
-
1456
- /**
1457
- * Use this method to change the chosen reactions on a message.
1458
- * - Service messages can't be reacted to.
1459
- * - Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel.
1460
- * - In albums, bots must react to the first message.
1461
- *
1462
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1463
- * @param {Number} messageId Unique identifier of the target message
1464
- * @param {Object} [options] Additional Telegram query options
1465
- * @return {Promise<Boolean>} True on success
1466
- * @see https://core.telegram.org/bots/api#setmessagereaction
1467
- */
1468
- setMessageReaction(chatId, messageId, form = {}) {
1469
- form.chat_id = chatId;
1470
- form.message_id = messageId;
1471
- if (form.reaction) {
1472
- form.reaction = stringify(form.reaction);
1473
- }
1474
- return this._request('setMessageReaction', { form });
1475
- }
1476
-
1477
- /**
1478
- * Use this method to get a list of profile pictures for a user.
1479
- * Returns a [UserProfilePhotos](https://core.telegram.org/bots/api#userprofilephotos) object.
1480
- * This method has an [older, compatible signature][getUserProfilePhotos-v0.25.0]
1481
- * that is being deprecated.
1482
- *
1483
- * @param {Number} userId Unique identifier of the target user
1484
- * @param {Object} [options] Additional Telegram query options
1485
- * @return {Promise} Returns a [UserProfilePhotos](https://core.telegram.org/bots/api#userprofilephotos) object
1486
- * @see https://core.telegram.org/bots/api#getuserprofilephotos
1487
- */
1488
- getUserProfilePhotos(userId, form = {}) {
1489
- /* The older method signature was getUserProfilePhotos(userId, offset, limit).
1490
- * We need to ensure backwards-compatibility while maintaining
1491
- * consistency of the method signatures throughout the library */
1492
- if (typeof form !== 'object') {
1493
- /* eslint-disable no-param-reassign, prefer-rest-params */
1494
- deprecate('The method signature getUserProfilePhotos(userId, offset, limit) has been deprecated since v0.25.0');
1495
- form = {
1496
- offset: arguments[1],
1497
- limit: arguments[2]
1498
- };
1499
- /* eslint-enable no-param-reassign, prefer-rest-params */
1500
- }
1501
- form.user_id = userId;
1502
- return this._request('getUserProfilePhotos', { form });
1503
- }
1504
-
1505
- /**
1506
- * Get file.
1507
- * Use this method to get basic info about a file and prepare it for downloading.
1508
- *
1509
- * Attention: **link will be valid for 1 hour.**
1510
- *
1511
- * @param {String} fileId File identifier to get info about
1512
- * @param {Object} [options] Additional Telegram query options
1513
- * @return {Promise} On success, a [File](https://core.telegram.org/bots/api#file) object is returned
1514
- * @see https://core.telegram.org/bots/api#getfile
1515
- */
1516
- getFile(fileId, form = {}) {
1517
- form.file_id = fileId;
1518
- return this._request('getFile', { form });
1519
- }
1520
-
1521
- /**
1522
- * Use this method to ban a user in a group, a supergroup or a channel.
1523
- * In the case of supergroups and channels, the user will not be able to
1524
- * return to the chat on their own using invite links, etc., unless unbanned first..
1525
- *
1526
- * The **bot must be an administrator in the group, supergroup or a channel** for this to work.
1527
- *
1528
- *
1529
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1530
- * @param {Number} userId Unique identifier of the target user
1531
- * @param {Object} [options] Additional Telegram query options
1532
- * @return {Promise} True on success.
1533
- * @see https://core.telegram.org/bots/api#banchatmember
1534
- */
1535
- banChatMember(chatId, userId, form = {}) {
1536
- form.chat_id = chatId;
1537
- form.user_id = userId;
1538
- return this._request('banChatMember', { form });
1539
- }
1540
-
1541
- /**
1542
- * Use this method to unban a previously kicked user in a supergroup.
1543
- * The user will not return to the group automatically, but will be
1544
- * able to join via link, etc.
1545
- *
1546
- * The **bot must be an administrator** in the supergroup or channel for this to work.
1547
- *
1548
- * **By default**, this method guarantees that after the call the user is not a member of the chat, but will be able to join it.
1549
- * So **if the user is a member of the chat they will also be removed from the chat**. If you don't want this, use the parameter *only_if_banned*
1550
- *
1551
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1552
- * @param {Number} userId Unique identifier of the target user
1553
- * @param {Object} [options] Additional Telegram query options
1554
- * @return {Promise} True on success
1555
- * @see https://core.telegram.org/bots/api#unbanchatmember
1556
- */
1557
- unbanChatMember(chatId, userId, form = {}) {
1558
- form.chat_id = chatId;
1559
- form.user_id = userId;
1560
- return this._request('unbanChatMember', { form });
1561
- }
1562
-
1563
- /**
1564
- * Use this method to restrict a user in a supergroup.
1565
- * The bot **must be an administrator in the supergroup** for this to work
1566
- * and must have the appropriate admin rights. Pass True for all boolean parameters
1567
- * to lift restrictions from a user. Returns True on success.
1568
- *
1569
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1570
- * @param {Number} userId Unique identifier of the target user
1571
- * @param {Object} [options] Additional Telegram query options
1572
- * @return {Promise} True on success
1573
- * @see https://core.telegram.org/bots/api#restrictchatmember
1574
- */
1575
- restrictChatMember(chatId, userId, form = {}) {
1576
- form.chat_id = chatId;
1577
- form.user_id = userId;
1578
- return this._request('restrictChatMember', { form });
1579
- }
1580
-
1581
- /**
1582
- * Use this method to promote or demote a user in a supergroup or a channel.
1583
- * The bot **must be an administrator** in the chat for this to work
1584
- * and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user.
1585
- *
1586
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1587
- * @param {Number} userId
1588
- * @param {Object} [options] Additional Telegram query options
1589
- * @return {Promise} True on success.
1590
- * @see https://core.telegram.org/bots/api#promotechatmember
1591
- */
1592
- promoteChatMember(chatId, userId, form = {}) {
1593
- form.chat_id = chatId;
1594
- form.user_id = userId;
1595
- return this._request('promoteChatMember', { form });
1596
- }
1597
-
1598
- /**
1599
- * Use this method to set a custom title for an administrator in a supergroup promoted by the bot.
1600
- *
1601
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1602
- * @param {Number} userId Unique identifier of the target user
1603
- * @param {String} customTitle New custom title for the administrator; 0-16 characters, emoji are not allowed
1604
- * @param {Object} [options] Additional Telegram query options
1605
- * @return {Promise} True on success
1606
- * @see https://core.telegram.org/bots/api#setchatadministratorcustomtitle
1607
- */
1608
- setChatAdministratorCustomTitle(chatId, userId, customTitle, form = {}) {
1609
- form.chat_id = chatId;
1610
- form.user_id = userId;
1611
- form.custom_title = customTitle;
1612
- return this._request('setChatAdministratorCustomTitle', { form });
1613
- }
1614
-
1615
- /**
1616
- * Use this method to ban a channel chat in a supergroup or a channel.
1617
- *
1618
- * Until the chat is [unbanned](https://core.telegram.org/bots/api#unbanchatsenderchat), the owner of the banned chat won't be able to send messages on behalf of any of their channels.
1619
- * The bot **must be an administrator in the supergroup or channel** for this to work and must have the appropriate administrator rights
1620
- *
1621
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1622
- * @param {Number} senderChatId Unique identifier of the target user
1623
- * @param {Object} [options] Additional Telegram query options
1624
- * @return {Promise} True on success.
1625
- * @see https://core.telegram.org/bots/api#banchatsenderchat
1626
- */
1627
- banChatSenderChat(chatId, senderChatId, form = {}) {
1628
- form.chat_id = chatId;
1629
- form.sender_chat_id = senderChatId;
1630
- return this._request('banChatSenderChat', { form });
1631
- }
1632
-
1633
- /**
1634
- * Use this method to unban a previously banned channel chat in a supergroup or channel.
1635
- *
1636
- * The bot **must be an administrator** for this to work and must have the appropriate administrator rights.
1637
- *
1638
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1639
- * @param {Number} senderChatId Unique identifier of the target user
1640
- * @param {Object} [options] Additional Telegram query options
1641
- * @return {Promise} True on success
1642
- * @see https://core.telegram.org/bots/api#unbanchatsenderchat
1643
- */
1644
- unbanChatSenderChat(chatId, senderChatId, form = {}) {
1645
- form.chat_id = chatId;
1646
- form.sender_chat_id = senderChatId;
1647
- return this._request('unbanChatSenderChat', { form });
1648
- }
1649
-
1650
- /**
1651
- * Use this method to set default chat permissions for all members.
1652
- *
1653
- * The bot **must be an administrator in the group or a supergroup** for this to
1654
- * work and **must have the `can_restrict_members` admin rights.**
1655
- *
1656
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1657
- * @param {Array} chatPermissions New default chat permissions
1658
- * @param {Object} [options] Additional Telegram query options
1659
- * @return {Promise} True on success
1660
- * @see https://core.telegram.org/bots/api#setchatpermissions
1661
- */
1662
- setChatPermissions(chatId, chatPermissions, form = {}) {
1663
- form.chat_id = chatId;
1664
- form.permissions = stringify(chatPermissions);
1665
- return this._request('setChatPermissions', { form });
1666
- }
1667
-
1668
- /**
1669
- * Use this method to generate a new primary invite link for a chat. **Any previously generated primary link is revoked**.
1670
- *
1671
- * The bot **must be an administrator in the chat** for this to work and must have the appropriate administrator rights.
1672
- *
1673
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1674
- * @param {Object} [options] Additional Telegram query options
1675
- * @return {Promise} Exported invite link as String on success.
1676
- * @see https://core.telegram.org/bots/api#exportchatinvitelink
1677
- */
1678
- exportChatInviteLink(chatId, form = {}) {
1679
- form.chat_id = chatId;
1680
- return this._request('exportChatInviteLink', { form });
1681
- }
1682
-
1683
- /**
1684
- * Use this method to create an additional invite link for a chat.
1685
- *
1686
- * The bot **must be an administrator in the chat** for this to work and must have the appropriate admin rights.
1687
- *
1688
- * The link generated with this method can be revoked using the method [revokeChatInviteLink](https://core.telegram.org/bots/api#revokechatinvitelink)
1689
- *
1690
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1691
- * @param {Object} [options] Additional Telegram query options
1692
- * @return {Object} The new invite link as [ChatInviteLink](https://core.telegram.org/bots/api#chatinvitelink) object
1693
- * @see https://core.telegram.org/bots/api#createchatinvitelink
1694
- */
1695
- createChatInviteLink(chatId, form = {}) {
1696
- form.chat_id = chatId;
1697
- return this._request('createChatInviteLink', { form });
1698
- }
1699
-
1700
- /**
1701
- * Use this method to edit a non-primary invite link created by the bot.
1702
- *
1703
- * The bot **must be an administrator in the chat** for this to work and must have the appropriate admin rights.
1704
- *
1705
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1706
- * @param {String} inviteLink Text with the invite link to edit
1707
- * @param {Object} [options] Additional Telegram query options
1708
- * @return {Promise} The edited invite link as a [ChatInviteLink](https://core.telegram.org/bots/api#chatinvitelink) object
1709
- * @see https://core.telegram.org/bots/api#editchatinvitelink
1710
- */
1711
- editChatInviteLink(chatId, inviteLink, form = {}) {
1712
- form.chat_id = chatId;
1713
- form.invite_link = inviteLink;
1714
- return this._request('editChatInviteLink', { form });
1715
- }
1716
-
1717
- /**
1718
- * Use this method to revoke an invite link created by the bot.
1719
- * Note: If the primary link is revoked, a new link is automatically generated
1720
- *
1721
- * The bot **must be an administrator in the chat** for this to work and must have the appropriate admin rights.
1722
- *
1723
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1724
- * @param {String} inviteLink The invite link to revoke
1725
- * @param {Object} [options] Additional Telegram query options
1726
- * @return {Promise} The revoked invite link as [ChatInviteLink](https://core.telegram.org/bots/api#chatinvitelink) object
1727
- * @see https://core.telegram.org/bots/api#revokechatinvitelink
1728
- */
1729
- revokeChatInviteLink(chatId, inviteLink, form = {}) {
1730
- form.chat_id = chatId;
1731
- form.invite_link = inviteLink;
1732
- return this._request('revokeChatInviteLink', { form });
1733
- }
1734
-
1735
- /**
1736
- * Use this method to approve a chat join request.
1737
- *
1738
- * The bot **must be an administrator in the chat** for this to work and **must have the `can_invite_users` administrator right.**
1739
- *
1740
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1741
- * @param {Number} userId Unique identifier of the target user
1742
- * @param {Object} [options] Additional Telegram query options
1743
- * @return {Promise} True on success
1744
- * @see https://core.telegram.org/bots/api#approvechatjoinrequest
1745
- */
1746
- approveChatJoinRequest(chatId, userId, form = {}) {
1747
- form.chat_id = chatId;
1748
- form.user_id = userId;
1749
- return this._request('approveChatJoinRequest', { form });
1750
- }
1751
-
1752
- /**
1753
- * Use this method to decline a chat join request.
1754
- *
1755
- * The bot **must be an administrator in the chat** for this to work and **must have the `can_invite_users` administrator right**.
1756
- *
1757
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1758
- * @param {Number} userId Unique identifier of the target user
1759
- * @param {Object} [options] Additional Telegram query options
1760
- * @return {Promise} True on success
1761
- * @see https://core.telegram.org/bots/api#declinechatjoinrequest
1762
- */
1763
- declineChatJoinRequest(chatId, userId, form = {}) {
1764
- form.chat_id = chatId;
1765
- form.user_id = userId;
1766
- return this._request('declineChatJoinRequest', { form });
1767
- }
1768
-
1769
- /**
1770
- * Use this method to set a new profile photo for the chat. **Photos can't be changed for private chats**.
1771
- *
1772
- * The bot **must be an administrator in the chat** for this to work and must have the appropriate admin rights.
1773
- *
1774
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1775
- * @param {stream.Stream|Buffer} photo A file path or a Stream.
1776
- * @param {Object} [options] Additional Telegram query options
1777
- * @param {Object} [fileOptions] Optional file related meta-data
1778
- * @return {Promise} True on success
1779
- * @see https://core.telegram.org/bots/api#setchatphoto
1780
- */
1781
- setChatPhoto(chatId, photo, options = {}, fileOptions = {}) {
1782
- const opts = {
1783
- qs: options
1784
- };
1785
- opts.qs.chat_id = chatId;
1786
- try {
1787
- const sendData = this._formatSendData('photo', photo, fileOptions);
1788
- opts.formData = sendData[0];
1789
- opts.qs.photo = sendData[1];
1790
- } catch (ex) {
1791
- return Promise.reject(ex);
1792
- }
1793
- return this._request('setChatPhoto', opts);
1794
- }
1795
-
1796
- /**
1797
- * Use this method to delete a chat photo. **Photos can't be changed for private chats**.
1798
- *
1799
- * The bot **must be an administrator in the chat** for this to work and must have the appropriate admin rights.
1800
- *
1801
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1802
- * @param {Object} [options] Additional Telegram query options
1803
- * @return {Promise} True on success
1804
- * @see https://core.telegram.org/bots/api#deletechatphoto
1805
- */
1806
- deleteChatPhoto(chatId, form = {}) {
1807
- form.chat_id = chatId;
1808
- return this._request('deleteChatPhoto', { form });
1809
- }
1810
-
1811
- /**
1812
- * Use this method to change the title of a chat. **Titles can't be changed for private chats**.
1813
- *
1814
- * The bot **must be an administrator in the chat** for this to work and must have the appropriate admin rights.
1815
- *
1816
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1817
- * @param {String} title New chat title, 1-255 characters
1818
- * @param {Object} [options] Additional Telegram query options
1819
- * @return {Promise} True on success
1820
- * @see https://core.telegram.org/bots/api#setchattitle
1821
- */
1822
- setChatTitle(chatId, title, form = {}) {
1823
- form.chat_id = chatId;
1824
- form.title = title;
1825
- return this._request('setChatTitle', { form });
1826
- }
1827
-
1828
- /**
1829
- * Use this method to change the description of a group, a supergroup or a channel.
1830
- *
1831
- * The bot **must be an administrator in the chat** for this to work and must have the appropriate admin rights.
1832
- *
1833
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1834
- * @param {String} description New chat title, 0-255 characters
1835
- * @param {Object} [options] Additional Telegram query options
1836
- * @return {Promise} True on success
1837
- * @see https://core.telegram.org/bots/api#setchatdescription
1838
- */
1839
- setChatDescription(chatId, description, form = {}) {
1840
- form.chat_id = chatId;
1841
- form.description = description;
1842
- return this._request('setChatDescription', { form });
1843
- }
1844
-
1845
- /**
1846
- * Use this method to pin a message in a supergroup.
1847
- *
1848
- * If the chat is not a private chat, the **bot must be an administrator in the chat** for this to work and must have the `can_pin_messages` administrator
1849
- * right in a supergroup or `can_edit_messages` administrator right in a channel.
1850
- *
1851
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1852
- * @param {Number} messageId Identifier of a message to pin
1853
- * @param {Object} [options] Additional Telegram query options
1854
- * @return {Promise} True on success
1855
- * @see https://core.telegram.org/bots/api#pinchatmessage
1856
- */
1857
- pinChatMessage(chatId, messageId, form = {}) {
1858
- form.chat_id = chatId;
1859
- form.message_id = messageId;
1860
- return this._request('pinChatMessage', { form });
1861
- }
1862
-
1863
- /**
1864
- * Use this method to remove a message from the list of pinned messages in a chat
1865
- *
1866
- * If the chat is not a private chat, the **bot must be an administrator in the chat** for this to work and must have the `can_pin_messages` administrator
1867
- * right in a supergroup or `can_edit_messages` administrator right in a channel.
1868
- *
1869
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1870
- * @param {Object} [options] Additional Telegram query options
1871
- * @return {Promise} True on success
1872
- * @see https://core.telegram.org/bots/api#unpinchatmessage
1873
- */
1874
- unpinChatMessage(chatId, form = {}) {
1875
- form.chat_id = chatId;
1876
- return this._request('unpinChatMessage', { form });
1877
- }
1878
-
1879
- /**
1880
- * Use this method to clear the list of pinned messages in a chat.
1881
- *
1882
- * If the chat is not a private chat, the **bot must be an administrator in the chat** for this to work and must have the `can_pin_messages` administrator
1883
- * right in a supergroup or `can_edit_messages` administrator right in a channel.
1884
- *
1885
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1886
- * @param {Object} [options] Additional Telegram query options
1887
- * @return {Promise} True on success
1888
- * @see https://core.telegram.org/bots/api#unpinallchatmessages
1889
- */
1890
- unpinAllChatMessages(chatId, form = {}) {
1891
- form.chat_id = chatId;
1892
- return this._request('unpinAllChatMessages', { form });
1893
- }
1894
-
1895
- /**
1896
- * Use this method for your bot to leave a group, supergroup or channel
1897
- *
1898
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
1899
- * @param {Object} [options] Additional Telegram query options
1900
- * @return {Promise} True on success
1901
- * @see https://core.telegram.org/bots/api#leavechat
1902
- */
1903
- leaveChat(chatId, form = {}) {
1904
- form.chat_id = chatId;
1905
- return this._request('leaveChat', { form });
1906
- }
1907
-
1908
- /**
1909
- * Use this method to get up to date information about the chat
1910
- * (current name of the user for one-on-one conversations, current
1911
- * username of a user, group or channel, etc.).
1912
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) or channel
1913
- * @param {Object} [options] Additional Telegram query options
1914
- * @return {Promise} [ChatFullInfo](https://core.telegram.org/bots/api#chatfullinfo) object on success
1915
- * @see https://core.telegram.org/bots/api#getchat
1916
- */
1917
- getChat(chatId, form = {}) {
1918
- form.chat_id = chatId;
1919
- return this._request('getChat', { form });
1920
- }
1921
-
1922
- /**
1923
- * Use this method to get a list of administrators in a chat
1924
- *
1925
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup
1926
- * @param {Object} [options] Additional Telegram query options
1927
- * @return {Promise} On success, returns an Array of [ChatMember](https://core.telegram.org/bots/api#chatmember) objects that contains information about all chat administrators except other bots.
1928
- * If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned
1929
- * @see https://core.telegram.org/bots/api#getchatadministrators
1930
- */
1931
- getChatAdministrators(chatId, form = {}) {
1932
- form.chat_id = chatId;
1933
- return this._request('getChatAdministrators', { form });
1934
- }
1935
-
1936
- /**
1937
- * Use this method to get the number of members in a chat.
1938
- *
1939
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup
1940
- * @param {Object} [options] Additional Telegram query options
1941
- * @return {Promise} Int on success
1942
- * @see https://core.telegram.org/bots/api#getchatmembercount
1943
- */
1944
- getChatMemberCount(chatId, form = {}) {
1945
- form.chat_id = chatId;
1946
- return this._request('getChatMemberCount', { form });
1947
- }
1948
-
1949
- /**
1950
- * Use this method to get information about a member of a chat.
1951
- *
1952
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup
1953
- * @param {Number} userId Unique identifier of the target user
1954
- * @param {Object} [options] Additional Telegram query options
1955
- * @return {Promise} [ChatMember](https://core.telegram.org/bots/api#chatmember) object on success
1956
- * @see https://core.telegram.org/bots/api#getchatmember
1957
- */
1958
- getChatMember(chatId, userId, form = {}) {
1959
- form.chat_id = chatId;
1960
- form.user_id = userId;
1961
- return this._request('getChatMember', { form });
1962
- }
1963
-
1964
- /**
1965
- * Use this method to set a new group sticker set for a supergroup.
1966
- *
1967
- * The bot **must be an administrator in the chat** for this to work and must have the appropriate administrator rights.
1968
- *
1969
- * **Note:** Use the field `can_set_sticker_set` optionally returned in [getChat](https://core.telegram.org/bots/api#getchat) requests to check if the bot can use this method.
1970
- *
1971
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
1972
- * @param {String} stickerSetName Name of the sticker set to be set as the group sticker set
1973
- * @param {Object} [options] Additional Telegram query options
1974
- * @return {Promise} True on success
1975
- * @see https://core.telegram.org/bots/api#setchatstickerset
1976
- */
1977
- setChatStickerSet(chatId, stickerSetName, form = {}) {
1978
- form.chat_id = chatId;
1979
- form.sticker_set_name = stickerSetName;
1980
- return this._request('setChatStickerSet', { form });
1981
- }
1982
-
1983
- /**
1984
- * Use this method to delete a group sticker set from a supergroup.
1985
- *
1986
- * Use the field `can_set_sticker_set` optionally returned in [getChat](https://core.telegram.org/bots/api#getchat) requests to check if the bot can use this method.
1987
- *
1988
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
1989
- * @param {Object} [options] Additional Telegram query options
1990
- * @return {Promise} True on success
1991
- * @see https://core.telegram.org/bots/api#deletechatstickerset
1992
- */
1993
- deleteChatStickerSet(chatId, form = {}) {
1994
- form.chat_id = chatId;
1995
- return this._request('deleteChatStickerSet', { form });
1996
- }
1997
-
1998
- /**
1999
- * Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user.
2000
- *
2001
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
2002
- * @param {Object} [options] Additional Telegram query options
2003
- * @return {Promise} Array of [Sticker](https://core.telegram.org/bots/api#sticker) objects
2004
- * @see https://core.telegram.org/bots/api#getforumtopiciconstickers
2005
- */
2006
- getForumTopicIconStickers(chatId, form = {}) {
2007
- form.chat_id = chatId;
2008
- return this._request('getForumTopicIconStickers', { form });
2009
- }
2010
-
2011
- /**
2012
- * Use this method to create a topic in a forum supergroup chat.
2013
- * The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
2014
- *
2015
- * Returns information about the created topic as a [ForumTopic](https://core.telegram.org/bots/api#forumtopic) object.
2016
- *
2017
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
2018
- * @param {String} name Topic name, 1-128 characters
2019
- * @param {Object} [options] Additional Telegram query options
2020
- * @see https://core.telegram.org/bots/api#createforumtopic
2021
- */
2022
- createForumTopic(chatId, name, form = {}) {
2023
- form.chat_id = chatId;
2024
- form.name = name;
2025
- return this._request('createForumTopic', { form });
2026
- }
2027
-
2028
- /**
2029
- * Use this method to edit name and icon of a topic in a forum supergroup chat.
2030
- * The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic.
2031
- *
2032
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
2033
- * @param {Number} messageThreadId Unique identifier for the target message thread of the forum topic
2034
- * @param {Object} [options] Additional Telegram query options
2035
- * @return {Promise} True on success
2036
- * @see https://core.telegram.org/bots/api#editforumtopic
2037
- */
2038
- editForumTopic(chatId, messageThreadId, form = {}) {
2039
- form.chat_id = chatId;
2040
- form.message_thread_id = messageThreadId;
2041
- return this._request('editForumTopic', { form });
2042
- }
2043
-
2044
- /**
2045
- * Use this method to close an open topic in a forum supergroup chat.
2046
- * The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic.
2047
- *
2048
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
2049
- * @param {Number} messageThreadId Unique identifier for the target message thread of the forum topic
2050
- * @param {Object} [options] Additional Telegram query options
2051
- * @return {Promise} True on success
2052
- * @see https://core.telegram.org/bots/api#closeforumtopic
2053
- */
2054
- closeForumTopic(chatId, messageThreadId, form = {}) {
2055
- form.chat_id = chatId;
2056
- form.message_thread_id = messageThreadId;
2057
- return this._request('closeForumTopic', { form });
2058
- }
2059
-
2060
- /**
2061
- * Use this method to reopen a closed topic in a forum supergroup chat.
2062
- * The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic.
2063
- *
2064
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
2065
- * @param {Number} messageThreadId Unique identifier for the target message thread of the forum topic
2066
- * @param {Object} [options] Additional Telegram query options
2067
- * @return {Promise} True on success
2068
- * @see https://core.telegram.org/bots/api#reopenforumtopic
2069
- */
2070
- reopenForumTopic(chatId, messageThreadId, form = {}) {
2071
- form.chat_id = chatId;
2072
- form.message_thread_id = messageThreadId;
2073
- return this._request('reopenForumTopic', { form });
2074
- }
2075
-
2076
- /**
2077
- * Use this method to delete a forum topic along with all its messages in a forum supergroup chat.
2078
- * The bot must be an administrator in the chat for this to work and must have the can_delete_messages administrator rights.
2079
- *
2080
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
2081
- * @param {Number} messageThreadId Unique identifier for the target message thread of the forum topic
2082
- * @param {Object} [options] Additional Telegram query options
2083
- * @return {Promise} True on success
2084
- * @see https://core.telegram.org/bots/api#deleteforumtopic
2085
- */
2086
- deleteForumTopic(chatId, messageThreadId, form = {}) {
2087
- form.chat_id = chatId;
2088
- form.message_thread_id = messageThreadId;
2089
- return this._request('deleteForumTopic', { form });
2090
- }
2091
-
2092
- /**
2093
- * Use this method to clear the list of pinned messages in a forum topic.
2094
- * The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup.
2095
- *
2096
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
2097
- * @param {Number} messageThreadId Unique identifier for the target message thread of the forum topic
2098
- * @param {Object} [options] Additional Telegram query options
2099
- * @return {Promise} True on success
2100
- * @see https://core.telegram.org/bots/api#unpinallforumtopicmessages
2101
- */
2102
- unpinAllForumTopicMessages(chatId, messageThreadId, form = {}) {
2103
- form.chat_id = chatId;
2104
- form.message_thread_id = messageThreadId;
2105
- return this._request('unpinAllForumTopicMessages', { form });
2106
- }
2107
-
2108
- /**
2109
- * Use this method to edit the name of the 'General' topic in a forum supergroup chat.
2110
- * The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
2111
- * The topic will be automatically unhidden if it was hidden.
2112
- *
2113
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
2114
- * @param {String} name New topic name, 1-128 characters
2115
- * @param {Object} [options] Additional Telegram query options
2116
- * @return {Promise} True on success
2117
- * @see https://core.telegram.org/bots/api#editgeneralforumtopic
2118
- */
2119
- editGeneralForumTopic(chatId, name, form = {}) {
2120
- form.chat_id = chatId;
2121
- form.name = name;
2122
- return this._request('editGeneralForumTopic', { form });
2123
- }
2124
-
2125
- /**
2126
- * Use this method to close an open 'General' topic in a forum supergroup chat.
2127
- * The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
2128
- * The topic will be automatically unhidden if it was hidden.
2129
- *
2130
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
2131
- * @param {Object} [options] Additional Telegram query options
2132
- * @return {Promise} True on success
2133
- * @see https://core.telegram.org/bots/api#closegeneralforumtopic
2134
- */
2135
- closeGeneralForumTopic(chatId, form = {}) {
2136
- form.chat_id = chatId;
2137
- return this._request('closeGeneralForumTopic', { form });
2138
- }
2139
-
2140
- /**
2141
- * Use this method to reopen a closed 'General' topic in a forum supergroup chat.
2142
- * The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
2143
- * The topic will be automatically unhidden if it was hidden.
2144
- *
2145
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
2146
- * @param {Object} [options] Additional Telegram query options
2147
- * @return {Promise} True on success
2148
- * @see https://core.telegram.org/bots/api#reopengeneralforumtopic
2149
- */
2150
- reopenGeneralForumTopic(chatId, form = {}) {
2151
- form.chat_id = chatId;
2152
- return this._request('reopenGeneralForumTopic', { form });
2153
- }
2154
-
2155
- /**
2156
- * Use this method to hide the 'General' topic in a forum supergroup chat.
2157
- * The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
2158
- * The topic will be automatically closed if it was open.
2159
- *
2160
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
2161
- * @param {Object} [options] Additional Telegram query options
2162
- * @return {Promise} True on success
2163
- * @see https://core.telegram.org/bots/api#hidegeneralforumtopic
2164
- */
2165
- hideGeneralForumTopic(chatId, form = {}) {
2166
- form.chat_id = chatId;
2167
- return this._request('hideGeneralForumTopic', { form });
2168
- }
2169
-
2170
- /**
2171
- * Use this method to unhide the 'General' topic in a forum supergroup chat.
2172
- * The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights
2173
- *
2174
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
2175
- * @param {Object} [options] Additional Telegram query options
2176
- * @return {Promise} True on success
2177
- * @see https://core.telegram.org/bots/api#unhidegeneralforumtopic
2178
- */
2179
- unhideGeneralForumTopic(chatId, form = {}) {
2180
- form.chat_id = chatId;
2181
- return this._request('unhideGeneralForumTopic', { form });
2182
- }
2183
-
2184
- /**
2185
- * Use this method to clear the list of pinned messages in a General forum topic.
2186
- * The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup.
2187
- *
2188
- * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
2189
- * @param {Object} [options] Additional Telegram query options
2190
- * @return {Promise} True on success
2191
- * @see https://core.telegram.org/bots/api#unpinallgeneralforumtopicmessages
2192
- */
2193
- unpinAllGeneralForumTopicMessages(chatId, form = {}) {
2194
- form.chat_id = chatId;
2195
- return this._request('unhideGeneralForumTopic', { form });
2196
- }
2197
-
2198
- /**
2199
- * Use this method to send answers to callback queries sent from
2200
- * [inline keyboards](https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating).
2201
- *
2202
- * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
2203
- *
2204
- * This method has **older, compatible signatures ([1][answerCallbackQuery-v0.27.1])([2][answerCallbackQuery-v0.29.0])**
2205
- * that are being deprecated.
2206
- *
2207
- * @param {String} callbackQueryId Unique identifier for the query to be answered
2208
- * @param {Object} [options] Additional Telegram query options
2209
- * @return {Promise} True on success
2210
- * @see https://core.telegram.org/bots/api#answercallbackquery
2211
- */
2212
- answerCallbackQuery(callbackQueryId, form = {}) {
2213
- /* The older method signature (in/before v0.27.1) was answerCallbackQuery(callbackQueryId, text, showAlert).
2214
- * We need to ensure backwards-compatibility while maintaining
2215
- * consistency of the method signatures throughout the library */
2216
- if (typeof form !== 'object') {
2217
- /* eslint-disable no-param-reassign, prefer-rest-params */
2218
- deprecate('The method signature answerCallbackQuery(callbackQueryId, text, showAlert) has been deprecated since v0.27.1');
2219
- form = {
2220
- callback_query_id: arguments[0],
2221
- text: arguments[1],
2222
- show_alert: arguments[2]
2223
- };
2224
- /* eslint-enable no-param-reassign, prefer-rest-params */
2225
- }
2226
- /* The older method signature (in/before v0.29.0) was answerCallbackQuery([options]).
2227
- * We need to ensure backwards-compatibility while maintaining
2228
- * consistency of the method signatures throughout the library. */
2229
- if (typeof callbackQueryId === 'object') {
2230
- /* eslint-disable no-param-reassign, prefer-rest-params */
2231
- deprecate('The method signature answerCallbackQuery([options]) has been deprecated since v0.29.0');
2232
- form = callbackQueryId;
2233
- /* eslint-enable no-param-reassign, prefer-rest-params */
2234
- } else {
2235
- form.callback_query_id = callbackQueryId;
2236
- }
2237
- return this._request('answerCallbackQuery', { form });
2238
- }
2239
-
2240
- /**
2241
- * Use this method to get the list of boosts added to a chat by a use.
2242
- * Requires administrator rights in the chat
2243
- *
2244
- * @param {Number|String} chatId Unique identifier for the group/channel
2245
- * @param {Number} user_id Unique identifier of the target user
2246
- * @param {Object} [options] Additional Telegram query options
2247
- * @return {Promise} On success, returns a [UserChatBoosts](https://core.telegram.org/bots/api#userchatboosts) object
2248
- * @see https://core.telegram.org/bots/api#getuserchatboosts
2249
- */
2250
- getUserChatBoosts(chatId, pollId, form = {}) {
2251
- form.chat_id = chatId;
2252
- form.message_id = pollId;
2253
- return this._request('getUserChatBoosts', { form });
2254
- }
2255
-
2256
- /**
2257
- * Use this method to get information about the connection of the bot with a business account
2258
- *
2259
- * @param {Number|String} businessConnectionId Unique identifier for the group/channel
2260
- * @param {Object} [options] Additional Telegram query options
2261
- * @return {Promise} On success, returns [BusinessConnection](https://core.telegram.org/bots/api#businessconnection) object
2262
- * @see https://core.telegram.org/bots/api#getbusinessconnection
2263
- */
2264
- getBusinessConnection(businessConnectionId, form = {}) {
2265
- form.business_connection_id = businessConnectionId;
2266
- return this._request('getBusinessConnection', { form });
2267
- }
2268
-
2269
- /**
2270
- * Use this method to change the list of the bot's commands.
2271
- *
2272
- * See https://core.telegram.org/bots#commands for more details about bot commands
2273
- *
2274
- * @param {Array} commands List of bot commands to be set as the list of the [bot's commands](https://core.telegram.org/bots/api#botcommand). At most 100 commands can be specified.
2275
- * @param {Object} [options] Additional Telegram query options
2276
- * @return {Promise} True on success
2277
- * @see https://core.telegram.org/bots/api#setmycommands
2278
- */
2279
- setMyCommands(commands, form = {}) {
2280
- form.commands = stringify(commands);
2281
-
2282
- if (form.scope) {
2283
- form.scope = stringify(form.scope);
2284
- }
2285
-
2286
- return this._request('setMyCommands', { form });
2287
- }
2288
-
2289
- /**
2290
- * Use this method to delete the list of the bot's commands for the given scope and user language.
2291
- *
2292
- * After deletion, [higher level commands](https://core.telegram.org/bots/api#determining-list-of-commands) will be shown to affected users.
2293
- *
2294
- * @param {Object} [options] Additional Telegram query options
2295
- * @return {Promise} True on success
2296
- * @see https://core.telegram.org/bots/api#deletemycommands
2297
- */
2298
- deleteMyCommands(form = {}) {
2299
- return this._request('deleteMyCommands', { form });
2300
- }
2301
-
2302
- /**
2303
- * Use this method to get the current list of the bot's commands for the given scope and user language.
2304
- *
2305
- * @param {Object} [options] Additional Telegram query options
2306
- * @return {Promise} Array of [BotCommand](https://core.telegram.org/bots/api#botcommand) on success. If commands aren't set, an empty list is returned.
2307
- * @see https://core.telegram.org/bots/api#getmycommands
2308
- */
2309
- getMyCommands(form = {}) {
2310
- if (form.scope) {
2311
- form.scope = stringify(form.scope);
2312
- }
2313
- return this._request('getMyCommands', { form });
2314
- }
2315
-
2316
- /**
2317
- * Use this method to change the bot's name.
2318
- *
2319
- * @param {Object} [options] Additional Telegram query options
2320
- * @return {Promise} True on success
2321
- * @see https://core.telegram.org/bots/api#setmyname
2322
- */
2323
- setMyName(form = {}) {
2324
- return this._request('setMyName', { form });
2325
- }
2326
-
2327
- /**
2328
- * Use this method to get the current bot name for the given user language.
2329
- *
2330
- * @param {Object} [options] Additional Telegram query options
2331
- * @return {Promise} [BotName](https://core.telegram.org/bots/api#botname) on success
2332
- * @see https://core.telegram.org/bots/api#getmyname
2333
- */
2334
- getMyName(form = {}) {
2335
- return this._request('getMyName', { form });
2336
- }
2337
-
2338
- /**
2339
- * Use this method to change the bot's description, which is shown in the chat with the bot if the chat is empty.
2340
- *
2341
- * Returns True on success.
2342
- *
2343
- * @param {Object} [options] Additional Telegram query options
2344
- * @return {Promise} True on success
2345
- * @see https://core.telegram.org/bots/api#setmydescription
2346
- */
2347
- setMyDescription(form = {}) {
2348
- return this._request('setMyDescription', { form });
2349
- }
2350
-
2351
- /**
2352
- * Use this method to get the current bot description for the given user language.
2353
- *
2354
- * @param {Object} [options] Additional Telegram query options
2355
- * @return {Promise} Returns [BotDescription](https://core.telegram.org/bots/api#botdescription) on success.
2356
- * @see https://core.telegram.org/bots/api#getmydescription
2357
- */
2358
- getMyDescription(form = {}) {
2359
- return this._request('getMyDescription', { form });
2360
- }
2361
-
2362
- /**
2363
- * Use this method to change the bot's short description, which is shown on the bot's profile page
2364
- * and is sent together with the link when users share the bot.
2365
- *
2366
- * @param {Object} [options] Additional Telegram query options
2367
- * @return {Promise} Returns True on success.
2368
- * @see https://core.telegram.org/bots/api#setmyshortdescription
2369
- */
2370
- setMyShortDescription(form = {}) {
2371
- return this._request('setMyShortDescription', { form });
2372
- }
2373
-
2374
- /**
2375
- * Use this method to get the current bot short description for the given user language.
2376
- *
2377
- * @param {Object} [options] Additional Telegram query options
2378
- * @return {Promise} Returns [BotShortDescription](https://core.telegram.org/bots/api#botshortdescription) on success.
2379
- * @see https://core.telegram.org/bots/api#getmyshortdescription
2380
- */
2381
- getMyShortDescription(form = {}) {
2382
- return this._request('getMyShortDescription', { form });
2383
- }
2384
-
2385
- /**
2386
- * Use this method to change the bot's menu button in a private chat, or the default menu button.
2387
- *
2388
- * @param {Object} [options] Additional Telegram query options
2389
- * @return {Promise} True on success
2390
- * @see https://core.telegram.org/bots/api#setchatmenubutton
2391
- */
2392
- setChatMenuButton(form = {}) {
2393
- return this._request('setChatMenuButton', { form });
2394
- }
2395
-
2396
- /**
2397
- * Use this method to get the current value of the bot's menu button in a private chat, or the default menu button.
2398
- *
2399
- * @param {Object} [options] Additional Telegram query options
2400
- * @return {Promise} [MenuButton](https://core.telegram.org/bots/api#menubutton) on success
2401
- * @see https://core.telegram.org/bots/api#getchatmenubutton
2402
- */
2403
- getChatMenuButton(form = {}) {
2404
- return this._request('getChatMenuButton', { form });
2405
- }
2406
-
2407
- /**
2408
- * Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels.
2409
- *
2410
- * These rights will be suggested to users, but they are are free to modify the list before adding the bot.
2411
- *
2412
- * @param {Object} [options] Additional Telegram query options
2413
- * @return {Promise} True on success
2414
- * @see https://core.telegram.org/bots/api#getchatmenubutton
2415
- */
2416
- setMyDefaultAdministratorRights(form = {}) {
2417
- return this._request('setMyDefaultAdministratorRights', { form });
2418
- }
2419
-
2420
- /**
2421
- * Use this method to get the current default administrator rights of the bot.
2422
- *
2423
- * @param {Object} [options] Additional Telegram query options
2424
- * @return {Promise} [ChatAdministratorRights](https://core.telegram.org/bots/api#chatadministratorrights) on success
2425
- * @see https://core.telegram.org/bots/api#getmydefaultadministratorrights
2426
- */
2427
- getMyDefaultAdministratorRights(form = {}) {
2428
- return this._request('getMyDefaultAdministratorRights', { form });
2429
- }
2430
-
2431
- /**
2432
- * Use this method to edit text or [game](https://core.telegram.org/bots/api#games) messages sent by the bot or via the bot (for inline bots).
2433
- *
2434
- * Note: that **you must provide one of chat_id, message_id, or inline_message_id** in your request.
2435
- *
2436
- * @param {String} text New text of the message
2437
- * @param {Object} [options] Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here)
2438
- * @return {Promise} On success, if the edited message is not an inline message, the edited [Message](https://core.telegram.org/bots/api#message) is returned, otherwise True is returned
2439
- * @see https://core.telegram.org/bots/api#editmessagetext
2440
- */
2441
- editMessageText(text, form = {}) {
2442
- form.text = text;
2443
- return this._request('editMessageText', { form });
2444
- }
2445
-
2446
- /**
2447
- * Use this method to edit captions of messages sent by the bot or via the bot (for inline bots).
2448
- *
2449
- * Note: You **must provide one of chat_id, message_id, or inline_message_id** in your request.
2450
- *
2451
- * @param {String} caption New caption of the message
2452
- * @param {Object} [options] Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here)
2453
- * @return {Promise} On success, if the edited message is not an inline message, the edited [Message](https://core.telegram.org/bots/api#message) is returned, otherwise True is returned
2454
- * @see https://core.telegram.org/bots/api#editmessagecaption
2455
- */
2456
- editMessageCaption(caption, form = {}) {
2457
- form.caption = caption;
2458
- return this._request('editMessageCaption', { form });
2459
- }
2460
-
2461
- /**
2462
- * Use this method to edit animation, audio, document, photo, or video messages.
2463
- *
2464
- * If a message is a part of a message album, then it can be edited only to a photo or a video.
2465
- *
2466
- * Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded.
2467
- * Use previously uploaded file via its file_id or specify a URL.
2468
- *
2469
- * Note: You **must provide one of chat_id, message_id, or inline_message_id** in your request.
2470
- *
2471
- * @param {Object} media A JSON-serialized object for a new media content of the message
2472
- * @param {Object} [options] Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here)
2473
- * @return {Promise} On success, if the edited message is not an inline message, the edited [Message](https://core.telegram.org/bots/api#message) is returned, otherwise True is returned
2474
- * @see https://core.telegram.org/bots/api#editmessagemedia
2475
- */
2476
- editMessageMedia(media, form = {}) {
2477
- const regexAttach = /attach:\/\/.+/;
2478
-
2479
- if (typeof media.media === 'string' && regexAttach.test(media.media)) {
2480
- const opts = {
2481
- qs: form
2482
- };
2483
-
2484
- opts.formData = {};
2485
-
2486
- const payload = Object.assign({}, media);
2487
- delete payload.media;
2488
-
2489
- try {
2490
- const attachName = String(0);
2491
- const [formData] = this._formatSendData(attachName, media.media.replace('attach://', ''), media.fileOptions);
2492
-
2493
- if (formData) {
2494
- opts.formData[attachName] = formData[attachName];
2495
- payload.media = `attach://${attachName}`;
2496
- } else {
2497
- throw new errors.FatalError(`Failed to process the replacement action for your ${media.type}`);
2498
- }
2499
- } catch (ex) {
2500
- return Promise.reject(ex);
2501
- }
2502
-
2503
- opts.qs.media = stringify(payload);
2504
-
2505
- return this._request('editMessageMedia', opts);
2506
- }
2507
-
2508
- form.media = stringify(media);
2509
-
2510
- return this._request('editMessageMedia', { form });
2511
- }
2512
-
2513
- /**
2514
- * Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots).
2515
- *
2516
- * Note: You **must provide one of chat_id, message_id, or inline_message_id** in your request.
2517
- *
2518
- * @param {Object} replyMarkup A JSON-serialized object for an inline keyboard.
2519
- * @param {Object} [options] Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here)
2520
- * @return {Promise} On success, if the edited message is not an inline message, the edited [Message](https://core.telegram.org/bots/api#message) is returned, otherwise True is returned
2521
- * @see https://core.telegram.org/bots/api#editmessagetext
2522
- */
2523
- editMessageReplyMarkup(replyMarkup, form = {}) {
2524
- form.reply_markup = replyMarkup;
2525
- return this._request('editMessageReplyMarkup', { form });
2526
- }
2527
-
2528
- /**
2529
- * Use this method to stop a poll which was sent by the bot.
2530
- *
2531
- * @param {Number|String} chatId Unique identifier for the group/channel
2532
- * @param {Number} pollId Identifier of the original message with the poll
2533
- * @param {Object} [options] Additional Telegram query options
2534
- * @return {Promise} On success, the stopped [Poll](https://core.telegram.org/bots/api#poll) is returned
2535
- * @see https://core.telegram.org/bots/api#stoppoll
2536
- */
2537
- stopPoll(chatId, pollId, form = {}) {
2538
- form.chat_id = chatId;
2539
- form.message_id = pollId;
2540
- return this._request('stopPoll', { form });
2541
- }
2542
-
2543
- /**
2544
- * Use this method to send static .WEBP, [animated](https://telegram.org/blog/animated-stickers) .TGS,
2545
- * or [video](https://telegram.org/blog/video-stickers-better-reactions) .WEBM stickers.
2546
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
2547
- * @param {String|stream.Stream|Buffer} sticker A file path, Stream or Buffer.
2548
- * Can also be a `file_id` previously uploaded. Stickers are WebP format files.
2549
- * @param {Object} [options] Additional Telegram query options
2550
- * @param {Object} [fileOptions] Optional file related meta-data
2551
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) is returned
2552
- * @see https://core.telegram.org/bots/api#sendsticker
2553
- */
2554
- sendSticker(chatId, sticker, options = {}, fileOptions = {}) {
2555
- const opts = {
2556
- qs: options
2557
- };
2558
- opts.qs.chat_id = chatId;
2559
- try {
2560
- const sendData = this._formatSendData('sticker', sticker, fileOptions);
2561
- opts.formData = sendData[0];
2562
- opts.qs.sticker = sendData[1];
2563
- } catch (ex) {
2564
- return Promise.reject(ex);
2565
- }
2566
- return this._request('sendSticker', opts);
2567
- }
2568
-
2569
- /**
2570
- * Use this method to get a sticker set.
2571
- *
2572
- * @param {String} name Name of the sticker set
2573
- * @param {Object} [options] Additional Telegram query options
2574
- * @return {Promise} On success, a [StickerSet](https://core.telegram.org/bots/api#stickerset) object is returned
2575
- * @see https://core.telegram.org/bots/api#getstickerset
2576
- */
2577
- getStickerSet(name, form = {}) {
2578
- form.name = name;
2579
- return this._request('getStickerSet', { form });
2580
- }
2581
-
2582
- /**
2583
- * Use this method to get information about custom emoji stickers by their identifiers.
2584
- *
2585
- * @param {Array} custom_emoji_ids List of custom emoji identifiers. At most 200 custom emoji identifiers can be specified.
2586
- * @param {Object} [options] Additional Telegram query options
2587
- * @return {Promise} Array of [Sticker](https://core.telegram.org/bots/api#sticker) objects.
2588
- * @see https://core.telegram.org/bots/api#getcustomemojistickers
2589
- */
2590
- getCustomEmojiStickers(customEmojiIds, form = {}) {
2591
- form.custom_emoji_ids = stringify(customEmojiIds);
2592
- return this._request('getCustomEmojiStickers', { form });
2593
- }
2594
-
2595
- /**
2596
- * Use this method to upload a file with a sticker for later use in *createNewStickerSet* and *addStickerToSet* methods (can be used multiple
2597
- * times).
2598
- *
2599
- * @param {Number} userId User identifier of sticker file owner
2600
- * @param {String|stream.Stream|Buffer} sticker A file path or a Stream with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. Can also be a `file_id` previously uploaded.
2601
- * @param {String} stickerFormat Allow values: `static`, `animated` or `video`
2602
- * @param {Object} [options] Additional Telegram query options
2603
- * @param {Object} [fileOptions] Optional file related meta-data
2604
- * @return {Promise} On success, a [File](https://core.telegram.org/bots/api#file) object is returned
2605
- * @see https://core.telegram.org/bots/api#uploadstickerfile
2606
- */
2607
- uploadStickerFile(userId, sticker, stickerFormat = 'static', options = {}, fileOptions = {}) {
2608
- const opts = {
2609
- qs: options
2610
- };
2611
- opts.qs.user_id = userId;
2612
- opts.qs.sticker_format = stickerFormat;
2613
-
2614
- try {
2615
- const sendData = this._formatSendData('sticker', sticker, fileOptions);
2616
- opts.formData = sendData[0];
2617
- opts.qs.sticker = sendData[1];
2618
- } catch (ex) {
2619
- return Promise.reject(ex);
2620
- }
2621
- return this._request('uploadStickerFile', opts);
2622
- }
2623
-
2624
- /**
2625
- * Use this method to create new sticker set owned by a user.
2626
- *
2627
- * The bot will be able to edit the created sticker set.
2628
- *
2629
- * You must use exactly one of the fields *png_sticker*, *tgs_sticker*, or *webm_sticker*
2630
- *
2631
- * @param {Number} userId User identifier of created sticker set owner
2632
- * @param {String} name Short name of sticker set, to be used in `t.me/addstickers/` URLs (e.g., *"animals"*). Can contain only english letters, digits and underscores.
2633
- * Must begin with a letter, can't contain consecutive underscores and must end in `"_by_<bot_username>"`. `<bot_username>` is case insensitive. 1-64 characters.
2634
- * @param {String} title Sticker set title, 1-64 characters
2635
- * @param {String|stream.Stream|Buffer} pngSticker Png image with the sticker, must be up to 512 kilobytes in size,
2636
- * dimensions must not exceed 512px, and either width or height must be exactly 512px.
2637
- * @param {String} emojis One or more emoji corresponding to the sticker
2638
- * @param {Object} [options] Additional Telegram query options
2639
- * @param {Object} [fileOptions] Optional file related meta-data
2640
- * @return {Promise} True on success
2641
- * @see https://core.telegram.org/bots/api#createnewstickerset
2642
- */
2643
- createNewStickerSet(userId, name, title, pngSticker, emojis, options = {}, fileOptions = {}) {
2644
- const opts = {
2645
- qs: options
2646
- };
2647
- opts.qs.user_id = userId;
2648
- opts.qs.name = name;
2649
- opts.qs.title = title;
2650
- opts.qs.emojis = emojis;
2651
- opts.qs.mask_position = stringify(options.mask_position);
2652
- try {
2653
- const sendData = this._formatSendData('png_sticker', pngSticker, fileOptions);
2654
- opts.formData = sendData[0];
2655
- opts.qs.png_sticker = sendData[1];
2656
- } catch (ex) {
2657
- return Promise.reject(ex);
2658
- }
2659
- return this._request('createNewStickerSet', opts);
2660
- }
2661
-
2662
- /**
2663
- * Use this method to add a new sticker to a set created by the bot.
2664
- *
2665
- * You must use exactly one of the fields *png_sticker*, *tgs_sticker*, or *webm_sticker*
2666
- *
2667
- * Animated stickers can be added to animated sticker sets and only to them
2668
- *
2669
- * Note:
2670
- * - Emoji sticker sets can have up to 200 sticker
2671
- * - Static or Animated sticker sets can have up to 120 stickers
2672
- *
2673
- * @param {Number} userId User identifier of sticker set owner
2674
- * @param {String} name Sticker set name
2675
- * @param {String|stream.Stream|Buffer} sticker Png image with the sticker (must be up to 512 kilobytes in size,
2676
- * dimensions must not exceed 512px, and either width or height must be exactly 512px, [TGS animation](https://core.telegram.org/stickers#animated-sticker-requirements)
2677
- * with the sticker or [WEBM video](https://core.telegram.org/stickers#video-sticker-requirements) with the sticker.
2678
- * @param {String} emojis One or more emoji corresponding to the sticker
2679
- * @param {String} stickerType Allow values: `png_sticker`, `tgs_sticker`, or `webm_sticker`.
2680
- * @param {Object} [options] Additional Telegram query options
2681
- * @param {Object} [fileOptions] Optional file related meta-data
2682
- * @return {Promise} True on success
2683
- * @see https://core.telegram.org/bots/api#addstickertoset
2684
- */
2685
- addStickerToSet(userId, name, sticker, emojis, stickerType = 'png_sticker', options = {}, fileOptions = {}) {
2686
- const opts = {
2687
- qs: options
2688
- };
2689
- opts.qs.user_id = userId;
2690
- opts.qs.name = name;
2691
- opts.qs.emojis = emojis;
2692
- opts.qs.mask_position = stringify(options.mask_position);
2693
-
2694
- if (typeof stickerType !== 'string' || ['png_sticker', 'tgs_sticker', 'webm_sticker'].indexOf(stickerType) === -1) {
2695
- return Promise.reject(new Error('stickerType must be a string and the allow types is: png_sticker, tgs_sticker, webm_sticker'));
2696
- }
2697
-
2698
- try {
2699
- const sendData = this._formatSendData(stickerType, sticker, fileOptions);
2700
- opts.formData = sendData[0];
2701
- opts.qs[stickerType] = sendData[1];
2702
- } catch (ex) {
2703
- return Promise.reject(ex);
2704
- }
2705
- return this._request('addStickerToSet', opts);
2706
- }
2707
-
2708
- /**
2709
- * Use this method to move a sticker in a set created by the bot to a specific position.
2710
- *
2711
- * @param {String} sticker File identifier of the sticker
2712
- * @param {Number} position New sticker position in the set, zero-based
2713
- * @param {Object} [options] Additional Telegram query options
2714
- * @return {Promise} True on success
2715
- * @see https://core.telegram.org/bots/api#setstickerpositioninset
2716
- */
2717
- setStickerPositionInSet(sticker, position, form = {}) {
2718
- form.sticker = sticker;
2719
- form.position = position;
2720
- return this._request('setStickerPositionInSet', { form });
2721
- }
2722
-
2723
- /**
2724
- * Use this method to delete a sticker from a set created by the bot.
2725
- *
2726
- * @param {String} sticker File identifier of the sticker
2727
- * @param {Object} [options] Additional Telegram query options
2728
- * @return {Promise} True on success
2729
- * @see https://core.telegram.org/bots/api#deletestickerfromset
2730
- * @todo Add tests for this method!
2731
- */
2732
- deleteStickerFromSet(sticker, form = {}) {
2733
- form.sticker = sticker;
2734
- return this._request('deleteStickerFromSet', { form });
2735
- }
2736
-
2737
- /**
2738
- * Use this method to replace an existing sticker in a sticker set with a new one
2739
- *
2740
- * @param {Number} user_id User identifier of the sticker set owner
2741
- * @param {String} name Sticker set name
2742
- * @param {String} sticker File identifier of the sticker
2743
- * @param {Object} [options] Additional Telegram query options
2744
- * @return {Promise} True on success
2745
- * @see https://core.telegram.org/bots/api#replacestickerinset
2746
- * @todo Add tests for this method!
2747
- */
2748
- replaceStickerInSet(userId, name, oldSticker, form = {}) {
2749
- form.user_id = userId;
2750
- form.name = name;
2751
- form.old_sticker = oldSticker;
2752
- return this._request('deleteStickerFromSet', { form });
2753
- }
2754
-
2755
- /**
2756
- * Use this method to change the list of emoji assigned to a regular or custom emoji sticker.
2757
- *
2758
- * The sticker must belong to a sticker set created by the bot.
2759
- *
2760
- * @param {String} sticker File identifier of the sticker
2761
- * @param { Array } emojiList A JSON-serialized list of 1-20 emoji associated with the sticker
2762
- * @param {Object} [options] Additional Telegram query options
2763
- * @return {Promise} True on success
2764
- * @see https://core.telegram.org/bots/api#setstickeremojilist
2765
- */
2766
- setStickerEmojiList(sticker, emojiList, form = {}) {
2767
- form.sticker = sticker;
2768
- form.emoji_list = stringify(emojiList);
2769
- return this._request('setStickerEmojiList', { form });
2770
- }
2771
-
2772
- /**
2773
- * Use this method to change the list of emoji assigned to a `regular` or `custom emoji` sticker.
2774
- *
2775
- * The sticker must belong to a sticker set created by the bot.
2776
- *
2777
- * @param {String} sticker File identifier of the sticker
2778
- * @param {Object} [options] Additional Telegram query options
2779
- * @return {Promise} True on success
2780
- * @see https://core.telegram.org/bots/api#setstickerkeywords
2781
- */
2782
- setStickerKeywords(sticker, form = {}) {
2783
- form.sticker = sticker;
2784
- if (form.keywords) {
2785
- form.keywords = stringify(form.keywords);
2786
- }
2787
- return this._request('setStickerKeywords', { form });
2788
- }
2789
-
2790
- /**
2791
- * Use this method to change the [mask position](https://core.telegram.org/bots/api#maskposition) of a mask sticker.
2792
- *
2793
- * The sticker must belong to a sticker set created by the bot.
2794
- *
2795
- * @param {String} sticker File identifier of the sticker
2796
- * @param {Object} [options] Additional Telegram query options
2797
- * @return {Promise} True on success
2798
- * @see https://core.telegram.org/bots/api#setstickermaskposition
2799
- */
2800
- setStickerMaskPosition(sticker, form = {}) {
2801
- form.sticker = sticker;
2802
- if (form.mask_position) {
2803
- form.mask_position = stringify(form.mask_position);
2804
- }
2805
- return this._request('setStickerMaskPosition', { form });
2806
- }
2807
-
2808
- /**
2809
- * Use this method to set the title of a created sticker set.
2810
- *
2811
- * The sticker must belong to a sticker set created by the bot.
2812
- *
2813
- * @param {String} name Sticker set name
2814
- * @param {String} title Sticker set title, 1-64 characters
2815
- * @param {Object} [options] Additional Telegram query options
2816
- * @return {Promise} True on success
2817
- * @see https://core.telegram.org/bots/api#setstickersettitle
2818
- */
2819
- setStickerSetTitle(name, title, form = {}) {
2820
- form.name = name;
2821
- form.title = title;
2822
- return this._request('setStickerSetTitle', { form });
2823
- }
2824
-
2825
- /**
2826
- * Use this method to add a thumb to a set created by the bot.
2827
- *
2828
- * Animated thumbnails can be set for animated sticker sets only. Video thumbnails can be set only for video sticker sets only
2829
- *
2830
- * @param {Number} userId User identifier of sticker set owner
2831
- * @param {String} name Sticker set name
2832
- * @param {String|stream.Stream|Buffer} thumbnail A .WEBP or .PNG image with the thumbnail,
2833
- * must be up to 128 kilobytes in size and have width and height exactly 100px,
2834
- * a TGS animation with the thumbnail up to 32 kilobytes in size or a WEBM video with the thumbnail up to 32 kilobytes in size.
2835
- *
2836
- * Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram
2837
- * to get a file from the Internet, or upload a new one. Animated sticker set thumbnails can't be uploaded via HTTP URL.
2838
- * @param {Object} [options] Additional Telegram query options
2839
- * @param {Object} [fileOptions] Optional file related meta-data
2840
- * @return {Promise} True on success
2841
- * @see https://core.telegram.org/bots/api#setstickersetthumbnail
2842
- */
2843
- setStickerSetThumbnail(userId, name, thumbnail, options = {}, fileOptions = {}) {
2844
- const opts = {
2845
- qs: options
2846
- };
2847
- opts.qs.user_id = userId;
2848
- opts.qs.name = name;
2849
- opts.qs.mask_position = stringify(options.mask_position);
2850
- try {
2851
- const sendData = this._formatSendData('thumbnail', thumbnail, fileOptions);
2852
- opts.formData = sendData[0];
2853
- opts.qs.thumbnail = sendData[1];
2854
- } catch (ex) {
2855
- return Promise.reject(ex);
2856
- }
2857
- return this._request('setStickerSetThumbnail', opts);
2858
- }
2859
-
2860
- /**
2861
- * Use this method to set the thumbnail of a custom emoji sticker set.
2862
- *
2863
- * The sticker must belong to a sticker set created by the bot.
2864
- *
2865
- * @param {String} name Sticker set name
2866
- * @param {Object} [options] Additional Telegram query options
2867
- * @return {Promise} True on success
2868
- * @see https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail
2869
- */
2870
- setCustomEmojiStickerSetThumbnail(name, form = {}) {
2871
- form.name = name;
2872
- return this._request('setCustomEmojiStickerSetThumbnail', { form });
2873
- }
2874
-
2875
- /**
2876
- * Use this method to delete a sticker set that was created by the bot.
2877
- *
2878
- * The sticker must belong to a sticker set created by the bot.
2879
- *
2880
- * @param {String} name Sticker set name
2881
- * @param {Object} [options] Additional Telegram query options
2882
- * @return {Promise} True on success
2883
- * @see https://core.telegram.org/bots/api#deletestickerset
2884
- */
2885
- deleteStickerSet(name, form = {}) {
2886
- form.name = name;
2887
- return this._request('deleteStickerSet', { form });
2888
- }
2889
-
2890
- /**
2891
- * Send answers to an inline query.
2892
- *
2893
- * Note: No more than 50 results per query are allowed.
2894
- *
2895
- * @param {String} inlineQueryId Unique identifier of the query
2896
- * @param {InlineQueryResult[]} results An array of results for the inline query
2897
- * @param {Object} [options] Additional Telegram query options
2898
- * @return {Promise} On success, True is returned
2899
- * @see https://core.telegram.org/bots/api#answerinlinequery
2900
- */
2901
- answerInlineQuery(inlineQueryId, results, form = {}) {
2902
- form.inline_query_id = inlineQueryId;
2903
- form.results = stringify(results);
2904
- return this._request('answerInlineQuery', { form });
2905
- }
2906
-
2907
- /**
2908
- * Use this method to set the result of an interaction with a [Web App](https://core.telegram.org/bots/webapps)
2909
- * and send a corresponding message on behalf of the user to the chat from which the query originated.
2910
- *
2911
- * @param {String} webAppQueryId Unique identifier for the query to be answered
2912
- * @param {InlineQueryResult} result object that represents one result of an inline query
2913
- * @param {Object} [options] Additional Telegram query options
2914
- * @return {Promise} On success, a [SentWebAppMessage](https://core.telegram.org/bots/api#sentwebappmessage) object is returned
2915
- * @see https://core.telegram.org/bots/api#answerwebappquery
2916
- */
2917
- answerWebAppQuery(webAppQueryId, result, form = {}) {
2918
- form.web_app_query_id = webAppQueryId;
2919
- form.result = stringify(result);
2920
- return this._request('answerWebAppQuery', { form });
2921
- }
2922
-
2923
- /**
2924
- * Use this method to send an invoice.
2925
- *
2926
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
2927
- * @param {String} title Product name, 1-32 characters
2928
- * @param {String} description Product description, 1-255 characters
2929
- * @param {String} payload Bot defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
2930
- * @param {String} providerToken Payments provider token, obtained via `@BotFather`
2931
- * @param {String} currency Three-letter ISO 4217 currency code
2932
- * @param {Array} prices Breakdown of prices
2933
- * @param {Object} [options] Additional Telegram query options
2934
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) is returned
2935
- * @see https://core.telegram.org/bots/api#sendinvoice
2936
- */
2937
- sendInvoice(chatId, title, description, payload, providerToken, currency, prices, form = {}) {
2938
- form.chat_id = chatId;
2939
- form.title = title;
2940
- form.description = description;
2941
- form.payload = payload;
2942
- form.provider_token = providerToken;
2943
- form.currency = currency;
2944
- form.prices = stringify(prices);
2945
- form.provider_data = stringify(form.provider_data);
2946
- if (form.suggested_tip_amounts) {
2947
- form.suggested_tip_amounts = stringify(form.suggested_tip_amounts);
2948
- }
2949
- return this._request('sendInvoice', { form });
2950
- }
2951
-
2952
- /**
2953
- * Use this method to create a link for an invoice.
2954
- *
2955
- * @param {String} title Product name, 1-32 characters
2956
- * @param {String} description Product description, 1-255 characters
2957
- * @param {String} payload Bot defined invoice payload
2958
- * @param {String} providerToken Payment provider token
2959
- * @param {String} currency Three-letter ISO 4217 currency code
2960
- * @param {Array} prices Breakdown of prices
2961
- * @param {Object} [options] Additional Telegram query options
2962
- * @returns {Promise} The created invoice link as String on success.
2963
- * @see https://core.telegram.org/bots/api#createinvoicelink
2964
- */
2965
- createInvoiceLink(title, description, payload, providerToken, currency, prices, form = {}) {
2966
- form.title = title;
2967
- form.description = description;
2968
- form.payload = payload;
2969
- form.provider_token = providerToken;
2970
- form.currency = currency;
2971
- form.prices = stringify(prices);
2972
- return this._request('createInvoiceLink', { form });
2973
- }
2974
-
2975
- /**
2976
- * Use this method to reply to shipping queries.
2977
- *
2978
- * If you sent an invoice requesting a shipping address and the parameter is_flexible was specified,
2979
- * the Bot API will send an [Update](https://core.telegram.org/bots/api#update) with a shipping_query field to the bot
2980
- *
2981
- * @param {String} shippingQueryId Unique identifier for the query to be answered
2982
- * @param {Boolean} ok Specify if delivery of the product is possible
2983
- * @param {Object} [options] Additional Telegram query options
2984
- * @return {Promise} On success, True is returned
2985
- * @see https://core.telegram.org/bots/api#answershippingquery
2986
- */
2987
- answerShippingQuery(shippingQueryId, ok, form = {}) {
2988
- form.shipping_query_id = shippingQueryId;
2989
- form.ok = ok;
2990
- form.shipping_options = stringify(form.shipping_options);
2991
- return this._request('answerShippingQuery', { form });
2992
- }
2993
-
2994
- /**
2995
- * Use this method to respond to such pre-checkout queries
2996
- *
2997
- * Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of
2998
- * an [Update](https://core.telegram.org/bots/api#update) with the field *pre_checkout_query*.
2999
- *
3000
- * **Note:** The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
3001
- *
3002
- * @param {String} preCheckoutQueryId Unique identifier for the query to be answered
3003
- * @param {Boolean} ok Specify if every order details are ok
3004
- * @param {Object} [options] Additional Telegram query options
3005
- * @return {Promise} On success, True is returned
3006
- * @see https://core.telegram.org/bots/api#answerprecheckoutquery
3007
- */
3008
- answerPreCheckoutQuery(preCheckoutQueryId, ok, form = {}) {
3009
- form.pre_checkout_query_id = preCheckoutQueryId;
3010
- form.ok = ok;
3011
- return this._request('answerPreCheckoutQuery', { form });
3012
- }
3013
-
3014
- /**
3015
- * Use this method to send a game.
3016
- *
3017
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3018
- * @param {String} gameShortName name of the game to be sent. Set up your games via `@BotFather`.
3019
- * @param {Object} [options] Additional Telegram query options
3020
- * @return {Promise} On success, the sent [Message](https://core.telegram.org/bots/api#message) is returned
3021
- * @see https://core.telegram.org/bots/api#sendgame
3022
- */
3023
- sendGame(chatId, gameShortName, form = {}) {
3024
- form.chat_id = chatId;
3025
- form.game_short_name = gameShortName;
3026
- return this._request('sendGame', { form });
3027
- }
3028
-
3029
- /**
3030
- * Use this method to set the score of the specified user in a game message.
3031
- *
3032
- * @param {Number} userId Unique identifier of the target user
3033
- * @param {Number} score New score value, must be non-negative
3034
- * @param {Object} [options] Additional Telegram query options
3035
- * @return {Promise} On success, if the message is not an inline message, the [Message](https://core.telegram.org/bots/api#message) is returned, otherwise True is returned
3036
- * @see https://core.telegram.org/bots/api#setgamescore
3037
- */
3038
- setGameScore(userId, score, form = {}) {
3039
- form.user_id = userId;
3040
- form.score = score;
3041
- return this._request('setGameScore', { form });
3042
- }
3043
-
3044
- /**
3045
- * Use this method to get data for high score tables.
3046
- *
3047
- * Will return the score of the specified user and several of their neighbors in a game.
3048
- *
3049
- * @param {Number} userId Unique identifier of the target user
3050
- * @param {Object} [options] Additional Telegram query options
3051
- * @return {Promise} On success, returns an Array of [GameHighScore](https://core.telegram.org/bots/api#gamehighscore) objects
3052
- * @see https://core.telegram.org/bots/api#getgamehighscores
3053
- */
3054
- getGameHighScores(userId, form = {}) {
3055
- form.user_id = userId;
3056
- return this._request('getGameHighScores', { form });
3057
- }
3058
-
3059
- /**
3060
- * Use this method to delete a message, including service messages, with the following limitations:
3061
- * - A message can only be deleted if it was sent less than 48 hours ago.
3062
- * - A dice message can only be deleted if it was sent more than 24 hours ago.
3063
- * - Bots can delete outgoing messages in groups and supergroups.
3064
- * - Bots can delete incoming messages in groups, supergroups and channels.
3065
- * - Bots granted `can_post_messages` permissions can delete outgoing messages in channels.
3066
- * - If the bot is an administrator of a group, it can delete any message there.
3067
- * - If the bot has `can_delete_messages` permission in a supergroup, it can delete any message there.
3068
- *
3069
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
3070
- * @param {Number} messageId Unique identifier of the target message
3071
- * @param {Object} [options] Additional Telegram query options
3072
- * @return {Promise} True on success
3073
- * @see https://core.telegram.org/bots/api#deletemessage
3074
- */
3075
- deleteMessage(chatId, messageId, form = {}) {
3076
- form.chat_id = chatId;
3077
- form.message_id = messageId;
3078
- return this._request('deleteMessage', { form });
3079
- }
3080
-
3081
- /**
3082
- * Use this method to delete multiple messages simultaneously. If some of the specified messages can't be found, they are skipped.
3083
- *
3084
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
3085
- * @param {Array<Number|String>} messageIds Identifiers of 1-100 messages to delete. See deleteMessage for limitations on which messages can be deleted
3086
- * @param {Object} [options] Additional Telegram query options
3087
- * @return {Promise<Boolean>} True on success
3088
- * @see https://core.telegram.org/bots/api#deletemessages
3089
- */
3090
- deleteMessages(chatId, messageIds, form = {}) {
3091
- form.chat_id = chatId;
3092
- form.message_ids = stringify(messageIds);
3093
- return this._request('deleteMessages', { form });
3094
- }
3095
-
3096
- // ==========================================
3097
- // Bot API 7.4
3098
- // ==========================================
3099
-
3100
- /**
3101
- * Use this method to issue a refund for a payment made via Telegram Stars.
3102
- *
3103
- * @param {Number} userId Identifier of the user whose payment will be refunded
3104
- * @param {String} telegramPaymentChargeId Telegram payment identifier of the payment to refund
3105
- * @param {Object} [options] Additional Telegram query options
3106
- * @return {Promise} On success, True is returned
3107
- * @see https://core.telegram.org/bots/api#refundstarpayment
3108
- */
3109
- refundStarPayment(userId, telegramPaymentChargeId, form = {}) {
3110
- form.user_id = userId;
3111
- form.telegram_payment_charge_id = telegramPaymentChargeId;
3112
- return this._request('refundStarPayment', { form });
3113
- }
3114
-
3115
- // ==========================================
3116
- // Bot API 7.5
3117
- // ==========================================
3118
-
3119
- /**
3120
- * Use this method to get the current status of the balance of Telegram Stars
3121
- * that can be withdrawn by the bot or transferred to another business account.
3122
- *
3123
- * @param {Object} [options] Additional Telegram query options
3124
- * @return {Promise} On success, returns a StarTransactions object
3125
- * @see https://core.telegram.org/bots/api#getstartransactions
3126
- */
3127
- getStarTransactions(form = {}) {
3128
- return this._request('getStarTransactions', { form });
3129
- }
3130
-
3131
- // ==========================================
3132
- // Bot API 7.6
3133
- // ==========================================
3134
-
3135
- /**
3136
- * Use this method to send paid media.
3137
- *
3138
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3139
- * @param {Number} starCount The number of Telegram Stars that must be paid to buy access to the media
3140
- * @param {Array} media A JSON-serialized array describing the media to be sent; currently supports photos and videos
3141
- * @param {Object} [options] Additional Telegram query options
3142
- * @return {Promise} On success, the sent Message object is returned
3143
- * @see https://core.telegram.org/bots/api#sendpaidmedia
3144
- */
3145
- sendPaidMedia(chatId, starCount, media, form = {}) {
3146
- form.chat_id = chatId;
3147
- form.star_count = starCount;
3148
- form.media = stringify(media);
3149
- return this._request('sendPaidMedia', { form });
3150
- }
3151
-
3152
- // ==========================================
3153
- // Bot API 7.9
3154
- // ==========================================
3155
-
3156
- /**
3157
- * Use this method to create a subscription invite link for a channel chat.
3158
- *
3159
- * @param {Number|String} chatId Unique identifier for the target channel chat or username of the target channel (in the format `@channelusername`)
3160
- * @param {Object} [options] Additional Telegram query options
3161
- * @return {Promise} On success, the new invite link as a ChatInviteLink object is returned
3162
- * @see https://core.telegram.org/bots/api#createchatsubscriptioninvitelink
3163
- */
3164
- createChatSubscriptionInviteLink(chatId, form = {}) {
3165
- form.chat_id = chatId;
3166
- return this._request('createChatSubscriptionInviteLink', { form });
3167
- }
3168
-
3169
- /**
3170
- * Use this method to edit a subscription invite link created by the bot.
3171
- *
3172
- * @param {Number|String} chatId Unique identifier for the target channel chat or username of the target channel (in the format `@channelusername`)
3173
- * @param {String} inviteLink The invite link to edit
3174
- * @param {Object} [options] Additional Telegram query options
3175
- * @return {Promise} On success, the edited invite link as a ChatInviteLink object is returned
3176
- * @see https://core.telegram.org/bots/api#editchatsubscriptioninvitelink
3177
- */
3178
- editChatSubscriptionInviteLink(chatId, inviteLink, form = {}) {
3179
- form.chat_id = chatId;
3180
- form.invite_link = inviteLink;
3181
- return this._request('editChatSubscriptionInviteLink', { form });
3182
- }
3183
-
3184
- // ==========================================
3185
- // Bot API 8.0
3186
- // ==========================================
3187
-
3188
- /**
3189
- * Use this method to get the list of gifts that can be sent by the bot.
3190
- *
3191
- * @param {Object} [options] Additional Telegram query options
3192
- * @return {Promise} On success, returns a Gifts object
3193
- * @see https://core.telegram.org/bots/api#getavailablegifts
3194
- */
3195
- getAvailableGifts(form = {}) {
3196
- return this._request('getAvailableGifts', { form });
3197
- }
3198
-
3199
- /**
3200
- * Use this method to send a gift to a user.
3201
- *
3202
- * @param {Number} userId Unique identifier of the target user that will receive the gift
3203
- * @param {String} giftId Identifier of the gift
3204
- * @param {Object} [options] Additional Telegram query options
3205
- * @return {Promise} On success, True is returned
3206
- * @see https://core.telegram.org/bots/api#sendgift
3207
- */
3208
- sendGift(userId, giftId, form = {}) {
3209
- form.user_id = userId;
3210
- form.gift_id = giftId;
3211
- return this._request('sendGift', { form });
3212
- }
3213
-
3214
- /**
3215
- * Use this method to edit a subscription paid through Telegram Stars.
3216
- *
3217
- * @param {Number} userId Identifier of the user whose subscription will be edited
3218
- * @param {String} telegramPaymentChargeId Telegram payment identifier of the subscription payment
3219
- * @param {Boolean} isCanceled Pass True to cancel the user's subscription
3220
- * @param {Object} [options] Additional Telegram query options
3221
- * @return {Promise} On success, True is returned
3222
- * @see https://core.telegram.org/bots/api#edituserstarsubscription
3223
- */
3224
- editUserStarSubscription(userId, telegramPaymentChargeId, isCanceled, form = {}) {
3225
- form.user_id = userId;
3226
- form.telegram_payment_charge_id = telegramPaymentChargeId;
3227
- form.is_canceled = isCanceled;
3228
- return this._request('editUserStarSubscription', { form });
3229
- }
3230
-
3231
- /**
3232
- * Use this method to store an inline message that can be sent on behalf of a user.
3233
- *
3234
- * @param {Number} userId Unique identifier of the target user
3235
- * @param {Object} result An object describing the message to be sent
3236
- * @param {Object} [options] Additional Telegram query options
3237
- * @return {Promise} On success, returns a PreparedInlineMessage object
3238
- * @see https://core.telegram.org/bots/api#savepreparedinlinemessage
3239
- */
3240
- savePreparedInlineMessage(userId, result, form = {}) {
3241
- form.user_id = userId;
3242
- form.result = stringify(result);
3243
- return this._request('savePreparedInlineMessage', { form });
3244
- }
3245
-
3246
- // ==========================================
3247
- // Bot API 8.2
3248
- // ==========================================
3249
-
3250
- /**
3251
- * Use this method to verify a user that is managed by the bot.
3252
- *
3253
- * @param {Number} userId Unique identifier of the target user
3254
- * @param {Object} [options] Additional Telegram query options
3255
- * @return {Promise} On success, True is returned
3256
- * @see https://core.telegram.org/bots/api#verifyuser
3257
- */
3258
- verifyUser(userId, form = {}) {
3259
- form.user_id = userId;
3260
- return this._request('verifyUser', { form });
3261
- }
3262
-
3263
- /**
3264
- * Use this method to verify a chat that is managed by the bot.
3265
- *
3266
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3267
- * @param {Object} [options] Additional Telegram query options
3268
- * @return {Promise} On success, True is returned
3269
- * @see https://core.telegram.org/bots/api#verifychat
3270
- */
3271
- verifyChat(chatId, form = {}) {
3272
- form.chat_id = chatId;
3273
- return this._request('verifyChat', { form });
3274
- }
3275
-
3276
- /**
3277
- * Use this method to remove verification for a user that is managed by the bot.
3278
- *
3279
- * @param {Number} userId Unique identifier of the target user
3280
- * @param {Object} [options] Additional Telegram query options
3281
- * @return {Promise} On success, True is returned
3282
- * @see https://core.telegram.org/bots/api#removeuserverification
3283
- */
3284
- removeUserVerification(userId, form = {}) {
3285
- form.user_id = userId;
3286
- return this._request('removeUserVerification', { form });
3287
- }
3288
-
3289
- /**
3290
- * Use this method to remove verification for a chat that is managed by the bot.
3291
- *
3292
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3293
- * @param {Object} [options] Additional Telegram query options
3294
- * @return {Promise} On success, True is returned
3295
- * @see https://core.telegram.org/bots/api#removechatverification
3296
- */
3297
- removeChatVerification(chatId, form = {}) {
3298
- form.chat_id = chatId;
3299
- return this._request('removeChatVerification', { form });
3300
- }
3301
-
3302
- // ==========================================
3303
- // Bot API 9.0: Business Accounts + Gifts
3304
- // ==========================================
3305
-
3306
- /**
3307
- * Use this method to mark incoming messages as read on behalf of a business account.
3308
- *
3309
- * @param {String} businessConnectionId Unique identifier of the business connection
3310
- * @param {Number} messageId Unique identifier of the message to mark as read
3311
- * @param {Object} [options] Additional Telegram query options
3312
- * @return {Promise} True on success
3313
- * @see https://core.telegram.org/bots/api#readbusinessmessage
3314
- */
3315
- readBusinessMessage(businessConnectionId, messageId, form = {}) {
3316
- form.business_connection_id = businessConnectionId;
3317
- form.message_id = messageId;
3318
- return this._request('readBusinessMessage', { form });
3319
- }
3320
-
3321
- /**
3322
- * Use this method to delete messages on behalf of a business account.
3323
- *
3324
- * @param {String} businessConnectionId Unique identifier of the business connection
3325
- * @param {Array<Number>} messageIds Unique identifiers of 1-100 messages to delete
3326
- * @param {Object} [options] Additional Telegram query options
3327
- * @return {Promise} True on success
3328
- * @see https://core.telegram.org/bots/api#deletebusinessmessages
3329
- */
3330
- deleteBusinessMessages(businessConnectionId, messageIds, form = {}) {
3331
- form.business_connection_id = businessConnectionId;
3332
- form.message_ids = stringify(messageIds);
3333
- return this._request('deleteBusinessMessages', { form });
3334
- }
3335
-
3336
- /**
3337
- * Use this method to change the first and last name of a managed business account.
3338
- *
3339
- * @param {String} businessConnectionId Unique identifier of the business connection
3340
- * @param {Object} [options] Additional Telegram query options
3341
- * @return {Promise} True on success
3342
- * @see https://core.telegram.org/bots/api#setbusinessaccountname
3343
- */
3344
- setBusinessAccountName(businessConnectionId, form = {}) {
3345
- form.business_connection_id = businessConnectionId;
3346
- return this._request('setBusinessAccountName', { form });
3347
- }
3348
-
3349
- /**
3350
- * Use this method to change the username of a managed business account.
3351
- *
3352
- * @param {String} businessConnectionId Unique identifier of the business connection
3353
- * @param {Object} [options] Additional Telegram query options
3354
- * @return {Promise} True on success
3355
- * @see https://core.telegram.org/bots/api#setbusinessaccountusername
3356
- */
3357
- setBusinessAccountUsername(businessConnectionId, form = {}) {
3358
- form.business_connection_id = businessConnectionId;
3359
- return this._request('setBusinessAccountUsername', { form });
3360
- }
3361
-
3362
- /**
3363
- * Use this method to change the bio of a managed business account.
3364
- *
3365
- * @param {String} businessConnectionId Unique identifier of the business connection
3366
- * @param {Object} [options] Additional Telegram query options
3367
- * @return {Promise} True on success
3368
- * @see https://core.telegram.org/bots/api#setbusinessaccountbio
3369
- */
3370
- setBusinessAccountBio(businessConnectionId, form = {}) {
3371
- form.business_connection_id = businessConnectionId;
3372
- return this._request('setBusinessAccountBio', { form });
3373
- }
3374
-
3375
- /**
3376
- * Use this method to change the profile photo of a managed business account.
3377
- *
3378
- * @param {String} businessConnectionId Unique identifier of the business connection
3379
- * @param {Object} photo InputProfilePhoto object
3380
- * @param {Object} [options] Additional Telegram query options
3381
- * @return {Promise} True on success
3382
- * @see https://core.telegram.org/bots/api#setbusinessaccountprofilephoto
3383
- */
3384
- setBusinessAccountProfilePhoto(businessConnectionId, photo, form = {}) {
3385
- form.business_connection_id = businessConnectionId;
3386
- form.photo = stringify(photo);
3387
- return this._request('setBusinessAccountProfilePhoto', { form });
3388
- }
3389
-
3390
- /**
3391
- * Use this method to remove the profile photo of a managed business account.
3392
- *
3393
- * @param {String} businessConnectionId Unique identifier of the business connection
3394
- * @param {Object} [options] Additional Telegram query options
3395
- * @return {Promise} True on success
3396
- * @see https://core.telegram.org/bots/api#removebusinessaccountprofilephoto
3397
- */
3398
- removeBusinessAccountProfilePhoto(businessConnectionId, form = {}) {
3399
- form.business_connection_id = businessConnectionId;
3400
- return this._request('removeBusinessAccountProfilePhoto', { form });
3401
- }
3402
-
3403
- /**
3404
- * Use this method to change the gift settings of a managed business account.
3405
- *
3406
- * @param {String} businessConnectionId Unique identifier of the business connection
3407
- * @param {Object} [options] Additional Telegram query options
3408
- * @return {Promise} True on success
3409
- * @see https://core.telegram.org/bots/api#setbusinessaccountgiftsettings
3410
- */
3411
- setBusinessAccountGiftSettings(businessConnectionId, form = {}) {
3412
- form.business_connection_id = businessConnectionId;
3413
- if (form.accepted_gift_types) {
3414
- form.accepted_gift_types = stringify(form.accepted_gift_types);
3415
- }
3416
- return this._request('setBusinessAccountGiftSettings', { form });
3417
- }
3418
-
3419
- /**
3420
- * Use this method to get the current Star balance of a managed business account.
3421
- *
3422
- * @param {String} businessConnectionId Unique identifier of the business connection
3423
- * @param {Object} [options] Additional Telegram query options
3424
- * @return {Promise} Returns a StarAmount object
3425
- * @see https://core.telegram.org/bots/api#getbusinessaccountstarbalance
3426
- */
3427
- getBusinessAccountStarBalance(businessConnectionId, form = {}) {
3428
- form.business_connection_id = businessConnectionId;
3429
- return this._request('getBusinessAccountStarBalance', { form });
3430
- }
3431
-
3432
- /**
3433
- * Use this method to transfer Stars from the business account balance to the bot owner's balance.
3434
- *
3435
- * @param {String} businessConnectionId Unique identifier of the business connection
3436
- * @param {Number} starCount Number of Telegram Stars to transfer, 1-10000
3437
- * @param {Object} [options] Additional Telegram query options
3438
- * @return {Promise} Returns a StarAmount object
3439
- * @see https://core.telegram.org/bots/api#transferbusinessaccountstars
3440
- */
3441
- transferBusinessAccountStars(businessConnectionId, starCount, form = {}) {
3442
- form.business_connection_id = businessConnectionId;
3443
- form.star_count = starCount;
3444
- return this._request('transferBusinessAccountStars', { form });
3445
- }
3446
-
3447
- /**
3448
- * Use this method to get the list of gifts received by a managed business account.
3449
- *
3450
- * @param {String} businessConnectionId Unique identifier of the business connection
3451
- * @param {Object} [options] Additional Telegram query options
3452
- * @return {Promise} Returns an Array of OwnedGift objects
3453
- * @see https://core.telegram.org/bots/api#getbusinessaccountgifts
3454
- */
3455
- getBusinessAccountGifts(businessConnectionId, form = {}) {
3456
- form.business_connection_id = businessConnectionId;
3457
- return this._request('getBusinessAccountGifts', { form });
3458
- }
3459
-
3460
- /**
3461
- * Use this method to convert a given regular gift to Telegram Stars.
3462
- *
3463
- * @param {String} businessConnectionId Unique identifier of the business connection
3464
- * @param {String} ownedGiftId Identifier of the regular gift
3465
- * @param {Object} [options] Additional Telegram query options
3466
- * @return {Promise} Returns a StarAmount object
3467
- * @see https://core.telegram.org/bots/api#convertgifttostars
3468
- */
3469
- convertGiftToStars(businessConnectionId, ownedGiftId, form = {}) {
3470
- form.business_connection_id = businessConnectionId;
3471
- form.owned_gift_id = ownedGiftId;
3472
- return this._request('convertGiftToStars', { form });
3473
- }
3474
-
3475
- /**
3476
- * Use this method to upgrade a regular gift to a unique or upgrade a unique gift to an upgraded collectible gift.
3477
- *
3478
- * @param {String} businessConnectionId Unique identifier of the business connection
3479
- * @param {String} ownedGiftId Identifier of the regular gift to upgrade
3480
- * @param {Object} [options] Additional Telegram query options
3481
- * @return {Promise} Returns the updated OwnedGift object
3482
- * @see https://core.telegram.org/bots/api#upgradegift
3483
- */
3484
- upgradeGift(businessConnectionId, ownedGiftId, form = {}) {
3485
- form.business_connection_id = businessConnectionId;
3486
- form.owned_gift_id = ownedGiftId;
3487
- return this._request('upgradeGift', { form });
3488
- }
3489
-
3490
- /**
3491
- * Use this method to transfer a regular gift to another user.
3492
- *
3493
- * @param {String} businessConnectionId Unique identifier of the business connection
3494
- * @param {String} ownedGiftId Identifier of the gift to transfer
3495
- * @param {Number|String} newOwnerChatId Unique identifier of the new owner of the gift
3496
- * @param {Object} [options] Additional Telegram query options
3497
- * @return {Promise} True on success
3498
- * @see https://core.telegram.org/bots/api#transfergift
3499
- */
3500
- transferGift(businessConnectionId, ownedGiftId, newOwnerChatId, form = {}) {
3501
- form.business_connection_id = businessConnectionId;
3502
- form.owned_gift_id = ownedGiftId;
3503
- form.new_owner_chat_id = newOwnerChatId;
3504
- return this._request('transferGift', { form });
3505
- }
3506
-
3507
- /**
3508
- * Use this method to post a story on behalf of a managed business account.
3509
- *
3510
- * @param {String} businessConnectionId Unique identifier of the business connection
3511
- * @param {Object} content InputStoryContent object
3512
- * @param {Object} [options] Additional Telegram query options
3513
- * @return {Promise} Returns a Story object
3514
- * @see https://core.telegram.org/bots/api#poststory
3515
- */
3516
- postStory(businessConnectionId, content, form = {}) {
3517
- form.business_connection_id = businessConnectionId;
3518
- form.content = stringify(content);
3519
- return this._request('postStory', { form });
3520
- }
3521
-
3522
- /**
3523
- * Use this method to edit a story previously posted on behalf of a managed business account.
3524
- *
3525
- * @param {String} businessConnectionId Unique identifier of the business connection
3526
- * @param {Number} storyId Identifier of the story to edit
3527
- * @param {Object} [options] Additional Telegram query options
3528
- * @return {Promise} Returns the edited Story object
3529
- * @see https://core.telegram.org/bots/api#editstory
3530
- */
3531
- editStory(businessConnectionId, storyId, form = {}) {
3532
- form.business_connection_id = businessConnectionId;
3533
- form.story_id = storyId;
3534
- if (form.content) {
3535
- form.content = stringify(form.content);
3536
- }
3537
- return this._request('editStory', { form });
3538
- }
3539
-
3540
- /**
3541
- * Use this method to delete a story previously posted on behalf of a managed business account.
3542
- *
3543
- * @param {String} businessConnectionId Unique identifier of the business connection
3544
- * @param {Number} storyId Identifier of the story to delete
3545
- * @param {Object} [options] Additional Telegram query options
3546
- * @return {Promise} True on success
3547
- * @see https://core.telegram.org/bots/api#deletestory
3548
- */
3549
- deleteStory(businessConnectionId, storyId, form = {}) {
3550
- form.business_connection_id = businessConnectionId;
3551
- form.story_id = storyId;
3552
- return this._request('deleteStory', { form });
3553
- }
3554
-
3555
- /**
3556
- * Use this method to gift a Telegram Premium subscription to a user.
3557
- *
3558
- * @param {Number|String} userId Unique identifier of the target user
3559
- * @param {Number} monthCount Number of months the subscription will be active for, 1-36
3560
- * @param {Number} starCount Number of Telegram Stars that will be paid for the subscription, 1-10000
3561
- * @param {Object} [options] Additional Telegram query options
3562
- * @return {Promise} Returns the Gift object that was paid for
3563
- * @see https://core.telegram.org/bots/api#giftpremiumsubscription
3564
- */
3565
- giftPremiumSubscription(userId, monthCount, starCount, form = {}) {
3566
- form.user_id = userId;
3567
- form.month_count = monthCount;
3568
- form.star_count = starCount;
3569
- return this._request('giftPremiumSubscription', { form });
3570
- }
3571
-
3572
- /**
3573
- * Use this method to set the emoji status of a user.
3574
- *
3575
- * @param {Number|String} userId Unique identifier of the target user
3576
- * @param {Object} [options] Additional Telegram query options
3577
- * @return {Promise} True on success
3578
- * @see https://core.telegram.org/bots/api#setuseremojistatus
3579
- */
3580
- setUserEmojiStatus(userId, form = {}) {
3581
- form.user_id = userId;
3582
- return this._request('setUserEmojiStatus', { form });
3583
- }
3584
-
3585
- // ==========================================
3586
- // Bot API 9.1: Checklists
3587
- // ==========================================
3588
-
3589
- /**
3590
- * Use this method to send a checklist on behalf of a managed business account.
3591
- *
3592
- * @param {String} businessConnectionId Unique identifier of the business connection
3593
- * @param {String} title Title of the checklist, 1-255 characters after entities parsing
3594
- * @param {Array} tasks List of 1-100 tasks in the checklist
3595
- * @param {Object} [options] Additional Telegram query options
3596
- * @return {Promise} On success, the sent Message is returned
3597
- * @see https://core.telegram.org/bots/api#sendchecklist
3598
- */
3599
- sendChecklist(businessConnectionId, title, tasks, form = {}) {
3600
- if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3601
- if (!title) return Promise.reject(new Error('title is required'));
3602
- form.business_connection_id = businessConnectionId;
3603
- form.title = title;
3604
- form.tasks = stringify(tasks);
3605
- return this._request('sendChecklist', { form });
3606
- }
3607
-
3608
- /**
3609
- * Use this method to edit a checklist message on behalf of a managed business account.
3610
- *
3611
- * @param {String} businessConnectionId Unique identifier of the business connection
3612
- * @param {Number} messageId Unique identifier of the message to edit
3613
- * @param {Object} [options] Additional Telegram query options
3614
- * @return {Promise} On success, the edited Message is returned
3615
- * @see https://core.telegram.org/bots/api#editmessagechecklist
3616
- */
3617
- editMessageChecklist(businessConnectionId, messageId, form = {}) {
3618
- if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3619
- if (!messageId) return Promise.reject(new Error('messageId is required'));
3620
- form.business_connection_id = businessConnectionId;
3621
- form.message_id = messageId;
3622
- if (form.tasks) {
3623
- form.tasks = stringify(form.tasks);
3624
- }
3625
- return this._request('editMessageChecklist', { form });
3626
- }
3627
-
3628
- /**
3629
- * Use this method to get the current number of Telegram Stars owned by the bot.
3630
- *
3631
- * @param {Object} [options] Additional Telegram query options
3632
- * @return {Promise} Returns a StarAmount object
3633
- * @see https://core.telegram.org/bots/api#getmystarbalance
3634
- */
3635
- getMyStarBalance(form = {}) {
3636
- return this._request('getMyStarBalance', { form });
3637
- }
3638
-
3639
- // ==========================================
3640
- // Bot API 9.2: Suggested Posts
3641
- // ==========================================
3642
-
3643
- /**
3644
- * Use this method to approve a suggested post in a channel chat.
3645
- *
3646
- * @param {String} businessConnectionId Unique identifier of the business connection
3647
- * @param {Number} messageId Unique identifier of the suggested post message
3648
- * @param {Object} [options] Additional Telegram query options
3649
- * @return {Promise} True on success
3650
- * @see https://core.telegram.org/bots/api#approvesuggestedpost
3651
- */
3652
- approveSuggestedPost(businessConnectionId, messageId, form = {}) {
3653
- if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3654
- if (!messageId) return Promise.reject(new Error('messageId is required'));
3655
- form.business_connection_id = businessConnectionId;
3656
- form.message_id = messageId;
3657
- return this._request('approveSuggestedPost', { form });
3658
- }
3659
-
3660
- /**
3661
- * Use this method to decline a suggested post in a channel chat.
3662
- *
3663
- * @param {String} businessConnectionId Unique identifier of the business connection
3664
- * @param {Number} messageId Unique identifier of the suggested post message
3665
- * @param {Object} [options] Additional Telegram query options
3666
- * @return {Promise} True on success
3667
- * @see https://core.telegram.org/bots/api#declinesuggestedpost
3668
- */
3669
- declineSuggestedPost(businessConnectionId, messageId, form = {}) {
3670
- if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3671
- if (!messageId) return Promise.reject(new Error('messageId is required'));
3672
- form.business_connection_id = businessConnectionId;
3673
- form.message_id = messageId;
3674
- return this._request('declineSuggestedPost', { form });
3675
- }
3676
-
3677
- // ==========================================
3678
- // Bot API 9.3: Draft Messages, Gifts, Stories
3679
- // ==========================================
3680
-
3681
- /**
3682
- * Use this method to send a draft message to the bot's user in private chat.
3683
- *
3684
- * @param {Number|String} chatId Unique identifier of the target private chat
3685
- * @param {String} text Text of the message, 1-4096 characters after entities parsing
3686
- * @param {Object} [options] Additional Telegram query options
3687
- * @return {Promise} On success, the sent Message is returned
3688
- * @see https://core.telegram.org/bots/api#sendmessagedraft
3689
- */
3690
- sendMessageDraft(chatId, text, form = {}) {
3691
- if (!chatId) return Promise.reject(new Error('chatId is required'));
3692
- if (!text) return Promise.reject(new Error('text is required'));
3693
- form.chat_id = chatId;
3694
- form.text = text;
3695
- if (form.entities) {
3696
- form.entities = stringify(form.entities);
3697
- }
3698
- if (form.link_preview_options) {
3699
- form.link_preview_options = stringify(form.link_preview_options);
3700
- }
3701
- return this._request('sendMessageDraft', { form });
3702
- }
3703
-
3704
- /**
3705
- * Use this method to get gifts received by a user in a private chat.
3706
- *
3707
- * @param {Number|String} userId Unique identifier of the target user
3708
- * @param {Object} [options] Additional Telegram query options
3709
- * @return {Promise} Array of OwnedGift objects
3710
- * @see https://core.telegram.org/bots/api#getusergifts
3711
- */
3712
- getUserGifts(userId, form = {}) {
3713
- form.user_id = userId;
3714
- return this._request('getUserGifts', { form });
3715
- }
3716
-
3717
- /**
3718
- * Use this method to get gifts received by a chat.
3719
- *
3720
- * @param {Number|String} chatId Unique identifier of the target chat
3721
- * @param {Object} [options] Additional Telegram query options
3722
- * @return {Promise} Array of OwnedGift objects
3723
- * @see https://core.telegram.org/bots/api#getchatgifts
3724
- */
3725
- getChatGifts(chatId, form = {}) {
3726
- form.chat_id = chatId;
3727
- return this._request('getChatGifts', { form });
3728
- }
3729
-
3730
- /**
3731
- * Use this method to repost a story on behalf of a managed business account.
3732
- *
3733
- * @param {String} businessConnectionId Unique identifier of the business connection
3734
- * @param {Number} storyId Identifier of the story to repost
3735
- * @param {Array<Number|String>} targetBusinessConnectionIds Identifiers of the business connections to post the story to
3736
- * @param {Object} [options] Additional Telegram query options
3737
- * @return {Promise} Array of Story objects
3738
- * @see https://core.telegram.org/bots/api#repoststory
3739
- */
3740
- repostStory(businessConnectionId, storyId, targetBusinessConnectionIds, form = {}) {
3741
- if (!businessConnectionId) return Promise.reject(new Error('businessConnectionId is required'));
3742
- if (!storyId) return Promise.reject(new Error('storyId is required'));
3743
- form.business_connection_id = businessConnectionId;
3744
- form.story_id = storyId;
3745
- form.target_business_connection_ids = stringify(targetBusinessConnectionIds);
3746
- return this._request('repostStory', { form });
3747
- }
3748
-
3749
- // ==========================================
3750
- // Bot API 9.4: Profile Photos, Audio Stories
3751
- // ==========================================
3752
-
3753
- /**
3754
- * Use this method to set the profile photo of the bot.
3755
- *
3756
- * @param {Object} photo InputProfilePhoto object
3757
- * @param {Object} [options] Additional Telegram query options
3758
- * @return {Promise} True on success
3759
- * @see https://core.telegram.org/bots/api#setmyprofilephoto
3760
- */
3761
- setMyProfilePhoto(photo, form = {}) {
3762
- form.photo = stringify(photo);
3763
- return this._request('setMyProfilePhoto', { form });
3764
- }
3765
-
3766
- /**
3767
- * Use this method to remove the profile photo of the bot.
3768
- *
3769
- * @param {Object} [options] Additional Telegram query options
3770
- * @return {Promise} True on success
3771
- * @see https://core.telegram.org/bots/api#removemyprofilephoto
3772
- */
3773
- removeMyProfilePhoto(form = {}) {
3774
- return this._request('removeMyProfilePhoto', { form });
3775
- }
3776
-
3777
- /**
3778
- * Use this method to get the profile audios of a user.
3779
- *
3780
- * @param {Number|String} userId Unique identifier of the target user
3781
- * @param {Object} [options] Additional Telegram query options
3782
- * @return {Promise} Array of Audio objects
3783
- * @see https://core.telegram.org/bots/api#getuserprofileaudios
3784
- */
3785
- getUserProfileAudios(userId, form = {}) {
3786
- form.user_id = userId;
3787
- return this._request('getUserProfileAudios', { form });
3788
- }
3789
-
3790
- // ==========================================
3791
- // Bot API 9.5: Chat Member Tags
3792
- // ==========================================
3793
-
3794
- /**
3795
- * Use this method to set the tag that is applied to a specific user in a specific group chat.
3796
- *
3797
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target group
3798
- * @param {Number|String} userId Unique identifier of the target user
3799
- * @param {Object} [options] Additional Telegram query options
3800
- * @return {Promise} True on success
3801
- * @see https://core.telegram.org/bots/api#setchatmembertag
3802
- */
3803
- setChatMemberTag(chatId, userId, form = {}) {
3804
- form.chat_id = chatId;
3805
- form.user_id = userId;
3806
- return this._request('setChatMemberTag', { form });
3807
- }
3808
-
3809
- // ==========================================
3810
- // Bot API 9.6: Managed Bot Tokens
3811
- // ==========================================
3812
-
3813
- /**
3814
- * Use this method to get the current managable bot token for the bot.
3815
- *
3816
- * @param {Number} botId Identifier of the bot to get the token for
3817
- * @param {Object} [options] Additional Telegram query options
3818
- * @return {Promise} Returns a ManagedBotToken object
3819
- * @see https://core.telegram.org/bots/api#getmanagedbottoken
3820
- */
3821
- getManagedBotToken(botId, form = {}) {
3822
- form.bot_id = botId;
3823
- return this._request('getManagedBotToken', { form });
3824
- }
3825
-
3826
- /**
3827
- * Use this method to replace the managable bot token for the bot with a new one.
3828
- *
3829
- * @param {Number} botId Identifier of the bot whose token will be replaced
3830
- * @param {Object} [options] Additional Telegram query options
3831
- * @return {Promise} Returns a ManagedBotToken object
3832
- * @see https://core.telegram.org/bots/api#replacemanagedbottoken
3833
- */
3834
- replaceManagedBotToken(botId, form = {}) {
3835
- form.bot_id = botId;
3836
- return this._request('replaceManagedBotToken', { form });
3837
- }
3838
-
3839
- /**
3840
- * Use this method to save a prepared keyboard button for later use.
3841
- *
3842
- * @param {Object} button KeyboardButton object to save
3843
- * @param {Object} [options] Additional Telegram query options
3844
- * @return {Promise} Returns a PreparedKeyboardButton object
3845
- * @see https://core.telegram.org/bots/api#savepreparedkeyboardbutton
3846
- */
3847
- savePreparedKeyboardButton(button, form = {}) {
3848
- form.button = stringify(button);
3849
- return this._request('savePreparedKeyboardButton', { form });
3850
- }
3851
-
3852
- // ==========================================
3853
- // Bot API 10.0: Guest Mode, Live Photos, Reactions
3854
- // ==========================================
3855
-
3856
- /**
3857
- * Use this method to answer a guest query in a Telegram Web App.
3858
- *
3859
- * @param {String} guestQueryId Unique identifier for the query to be answered
3860
- * @param {String} text Text of the message
3861
- * @param {Object} [options] Additional Telegram query options
3862
- * @return {Promise} True on success
3863
- * @see https://core.telegram.org/bots/api#answerguestquery
3864
- */
3865
- answerGuestQuery(guestQueryId, text, form = {}) {
3866
- if (!guestQueryId) return Promise.reject(new Error('guestQueryId is required'));
3867
- if (!text) return Promise.reject(new Error('text is required'));
3868
- form.guest_query_id = guestQueryId;
3869
- form.text = text;
3870
- return this._request('answerGuestQuery', { form });
3871
- }
3872
-
3873
- /**
3874
- * Use this method to remove multiple reactions from a message.
3875
- *
3876
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3877
- * @param {Number} messageId Unique identifier of the target message
3878
- * @param {Object} [options] Additional Telegram query options
3879
- * @return {Promise} True on success
3880
- * @see https://core.telegram.org/bots/api#deletemessagereactions
3881
- */
3882
- deleteAllMessageReactions(chatId, messageId, form = {}) {
3883
- form.chat_id = chatId;
3884
- form.message_id = messageId;
3885
- return this._request('deleteAllMessageReactions', { form });
3886
- }
3887
-
3888
- /**
3889
- * Use this method to remove a reaction from a message.
3890
- *
3891
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3892
- * @param {Number} messageId Unique identifier of the target message
3893
- * @param {Object} [options] Additional Telegram query options
3894
- * @return {Promise} True on success
3895
- * @see https://core.telegram.org/bots/api#deletemessagereaction
3896
- */
3897
- deleteMessageReaction(chatId, messageId, form = {}) {
3898
- form.chat_id = chatId;
3899
- form.message_id = messageId;
3900
- if (form.reaction_type) {
3901
- form.reaction_type = stringify(form.reaction_type);
3902
- }
3903
- return this._request('deleteMessageReaction', { form });
3904
- }
3905
-
3906
- /**
3907
- * Use this method to send a live photo.
3908
- *
3909
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3910
- * @param {String|stream.Stream|Buffer} photo A file path, Stream, Buffer, or file_id
3911
- * @param {String|stream.Stream|Buffer} video A file path, Stream, Buffer, or file_id
3912
- * @param {Object} [options] Additional Telegram query options
3913
- * @param {Object} [fileOptions] Optional file related meta-data
3914
- * @return {Promise} On success, the sent Message object is returned
3915
- * @see https://core.telegram.org/bots/api#sendlivephoto
3916
- */
3917
- sendLivePhoto(chatId, photo, video, form = {}, fileOptions = {}) {
3918
- if (!chatId) return Promise.reject(new Error('chatId is required'));
3919
- const opts = {
3920
- qs: form
3921
- };
3922
- opts.qs.chat_id = chatId;
3923
- try {
3924
- const sendDataPhoto = this._formatSendData('photo', photo, fileOptions);
3925
- const sendDataVideo = this._formatSendData('video', video, fileOptions);
3926
- opts.formData = Object.assign({}, sendDataPhoto[0], sendDataVideo[0]);
3927
- opts.qs.photo = sendDataPhoto[1];
3928
- opts.qs.video = sendDataVideo[1];
3929
- } catch (ex) {
3930
- return Promise.reject(ex);
3931
- }
3932
- return this._request('sendLivePhoto', opts);
3933
- }
3934
-
3935
- /**
3936
- * Use this method to get the current access settings of the bot for managed bots.
3937
- *
3938
- * @param {Object} [options] Additional Telegram query options
3939
- * @return {Promise} Returns a ManagedBotAccessSettings object
3940
- * @see https://core.telegram.org/bots/api#getmanagedbotaccesssettings
3941
- */
3942
- getManagedBotAccessSettings(form = {}) {
3943
- return this._request('getManagedBotAccessSettings', { form });
3944
- }
3945
-
3946
- /**
3947
- * Use this method to change the access settings of the bot for managed bots.
3948
- *
3949
- * @param {Object} [options] Additional Telegram query options
3950
- * @return {Promise} True on success
3951
- * @see https://core.telegram.org/bots/api#setmanagedbotaccesssettings
3952
- */
3953
- setManagedBotAccessSettings(form = {}) {
3954
- if (form.restricted_channels) {
3955
- form.restricted_channels = stringify(form.restricted_channels);
3956
- }
3957
- return this._request('setManagedBotAccessSettings', { form });
3958
- }
3959
-
3960
- /**
3961
- * Use this method to get messages from a user's personal chat with the bot.
3962
- *
3963
- * @param {Number} userId Unique identifier of the target user
3964
- * @param {Object} [options] Additional Telegram query options
3965
- * @return {Promise} Array of Message objects
3966
- * @see https://core.telegram.org/bots/api#getuserpersonalchatmessages
3967
- */
3968
- getUserPersonalChatMessages(userId, form = {}) {
3969
- form.user_id = userId;
3970
- return this._request('getUserPersonalChatMessages', { form });
3971
- }
3972
-
3973
- // ==========================================
3974
- // Bot API 10.1: Rich Messages, Join Request Queries
3975
- // ==========================================
3976
-
3977
- /**
3978
- * Use this method to send a rich message.
3979
- *
3980
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3981
- * @param {Object} content An InputRichMessageContent object
3982
- * @param {Object} [options] Additional Telegram query options
3983
- * @return {Promise} On success, the sent Message object is returned
3984
- * @see https://core.telegram.org/bots/api#sendrichmessage
3985
- */
3986
- sendRichMessage(chatId, content, form = {}) {
3987
- if (!chatId) return Promise.reject(new Error('chatId is required'));
3988
- if (!content) return Promise.reject(new Error('content is required'));
3989
- form.chat_id = chatId;
3990
- form.content = stringify(content);
3991
- return this._request('sendRichMessage', { form });
3992
- }
3993
-
3994
- /**
3995
- * Use this method to send a rich message draft.
3996
- *
3997
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
3998
- * @param {Object} content An InputRichMessageContent object
3999
- * @param {Object} [options] Additional Telegram query options
4000
- * @return {Promise} On success, a Message object is returned
4001
- * @see https://core.telegram.org/bots/api#sendrichmessagedraft
4002
- */
4003
- sendRichMessageDraft(chatId, content, form = {}) {
4004
- if (!chatId) return Promise.reject(new Error('chatId is required'));
4005
- if (!content) return Promise.reject(new Error('content is required'));
4006
- form.chat_id = chatId;
4007
- form.content = stringify(content);
4008
- return this._request('sendRichMessageDraft', { form });
4009
- }
4010
-
4011
- /**
4012
- * Use this method to answer a chat join request query.
4013
- *
4014
- * @param {Number} chatJoinRequestId Unique identifier of the chat join request
4015
- * @param {String} queryId Unique identifier for the query to be answered
4016
- * @param {Object} [options] Additional Telegram query options
4017
- * @return {Promise} True on success
4018
- * @see https://core.telegram.org/bots/api#answerchatjoinrequestquery
4019
- */
4020
- answerChatJoinRequestQuery(chatJoinRequestId, queryId, form = {}) {
4021
- if (!chatJoinRequestId) return Promise.reject(new Error('chatJoinRequestId is required'));
4022
- if (!queryId) return Promise.reject(new Error('queryId is required'));
4023
- form.chat_join_request_id = chatJoinRequestId;
4024
- form.query_id = queryId;
4025
- return this._request('answerChatJoinRequestQuery', { form });
4026
- }
4027
-
4028
- /**
4029
- * Use this method to send a Web App message to a chat join request.
4030
- *
4031
- * @param {Number} chatJoinRequestId Unique identifier of the chat join request
4032
- * @param {Object} webApp A SentWebAppMessage object
4033
- * @param {Object} [options] Additional Telegram query options
4034
- * @return {Promise} True on success
4035
- * @see https://core.telegram.org/bots/api#sendchatjoinrequestwebapp
4036
- */
4037
- sendChatJoinRequestWebApp(chatJoinRequestId, webApp, form = {}) {
4038
- if (!chatJoinRequestId) return Promise.reject(new Error('chatJoinRequestId is required'));
4039
- if (!webApp) return Promise.reject(new Error('webApp is required'));
4040
- form.chat_join_request_id = chatJoinRequestId;
4041
- form.web_app = stringify(webApp);
4042
- return this._request('sendChatJoinRequestWebApp', { form });
4043
- }
4044
-
4045
- // ==========================================
4046
- // Bot API 10.2: Ephemeral Messages
4047
- // ==========================================
4048
-
4049
- /**
4050
- * Use this method to edit the text of an ephemeral message.
4051
- *
4052
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4053
- * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4054
- * @param {String} text New text of the message
4055
- * @param {Object} [options] Additional Telegram query options
4056
- * @return {Promise} On success, the edited Message object is returned
4057
- * @see https://core.telegram.org/bots/api#editephemeralmessagetext
4058
- */
4059
- editEphemeralMessageText(chatId, ephemeralMessageId, text, form = {}) {
4060
- if (!chatId) return Promise.reject(new Error('chatId is required'));
4061
- if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4062
- form.chat_id = chatId;
4063
- form.ephemeral_message_id = ephemeralMessageId;
4064
- form.text = text;
4065
- return this._request('editEphemeralMessageText', { form });
4066
- }
4067
-
4068
- /**
4069
- * Use this method to edit the media of an ephemeral message.
4070
- *
4071
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4072
- * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4073
- * @param {Object} media An InputMedia object
4074
- * @param {Object} [options] Additional Telegram query options
4075
- * @param {Object} [fileOptions] Optional file related meta-data
4076
- * @return {Promise} On success, the edited Message object is returned
4077
- * @see https://core.telegram.org/bots/api#editephemeralmessagemedia
4078
- */
4079
- editEphemeralMessageMedia(chatId, ephemeralMessageId, media, form = {}, fileOptions = {}) {
4080
- if (!chatId) return Promise.reject(new Error('chatId is required'));
4081
- if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4082
- form.chat_id = chatId;
4083
- form.ephemeral_message_id = ephemeralMessageId;
4084
- form.media = stringify(media);
4085
- return this._request('editEphemeralMessageMedia', { form });
4086
- }
4087
-
4088
- /**
4089
- * Use this method to edit the caption of an ephemeral message.
4090
- *
4091
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4092
- * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4093
- * @param {Object} [options] Additional Telegram query options
4094
- * @return {Promise} On success, the edited Message object is returned
4095
- * @see https://core.telegram.org/bots/api#editephemeralmessagecaption
4096
- */
4097
- editEphemeralMessageCaption(chatId, ephemeralMessageId, form = {}) {
4098
- if (!chatId) return Promise.reject(new Error('chatId is required'));
4099
- if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4100
- form.chat_id = chatId;
4101
- form.ephemeral_message_id = ephemeralMessageId;
4102
- this._fixEntitiesField(form);
4103
- return this._request('editEphemeralMessageCaption', { form });
4104
- }
4105
-
4106
- /**
4107
- * Use this method to edit the reply markup of an ephemeral message.
4108
- *
4109
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4110
- * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4111
- * @param {Object} [options] Additional Telegram query options
4112
- * @return {Promise} On success, the edited Message object is returned
4113
- * @see https://core.telegram.org/bots/api#editephemeralmessagereplymarkup
4114
- */
4115
- editEphemeralMessageReplyMarkup(chatId, ephemeralMessageId, form = {}) {
4116
- if (!chatId) return Promise.reject(new Error('chatId is required'));
4117
- if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4118
- form.chat_id = chatId;
4119
- form.ephemeral_message_id = ephemeralMessageId;
4120
- return this._request('editEphemeralMessageReplyMarkup', { form });
4121
- }
4122
-
4123
- /**
4124
- * Use this method to delete an ephemeral message.
4125
- *
4126
- * @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
4127
- * @param {String} ephemeralMessageId Unique identifier of the ephemeral message
4128
- * @param {Object} [options] Additional Telegram query options
4129
- * @return {Promise} True on success
4130
- * @see https://core.telegram.org/bots/api#deleteephemeralmessage
4131
- */
4132
- deleteEphemeralMessage(chatId, ephemeralMessageId, form = {}) {
4133
- if (!chatId) return Promise.reject(new Error('chatId is required'));
4134
- if (!ephemeralMessageId) return Promise.reject(new Error('ephemeralMessageId is required'));
4135
- form.chat_id = chatId;
4136
- form.ephemeral_message_id = ephemeralMessageId;
4137
- return this._request('deleteEphemeralMessage', { form });
4138
- }
4139
-
4140
- }
4141
-
4142
- module.exports = TelegramBot;