@zero-bot.net/tg-bot-api 1.3.0 → 1.5.0

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