telegram-bot-starter 0.0.1-security → 1.3.7

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.

Potentially problematic release.


This version of telegram-bot-starter might be problematic. Click here for more details.

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