diff --git a/doc/api.md b/doc/api.md index 1f530d4d..4bf14f70 100644 --- a/doc/api.md +++ b/doc/api.md @@ -209,6 +209,7 @@ Emits `message` when a message arrives. | [options.polling.autoStart] | Boolean | true | Start polling immediately | | [options.polling.params] | Object | | Parameters to be used in polling API requests. See https://core.telegram.org/bots/api#getupdates for more information. | | [options.polling.params.timeout] | Number | 10 | Timeout in seconds for long polling. | +| [options.polling.params.allowed_updates] | Array \| String | | A JSON-serialized list of the update types you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. | | [options.webHook] | Boolean \| Object | false | Set true to enable WebHook or set options | | [options.webHook.host] | String | "0.0.0.0" | Host to bind to | | [options.webHook.port] | Number | 8443 | Port to bind to | diff --git a/src/telegram.js b/src/telegram.js index f2e41efe..ff6c16e5 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -130,6 +130,8 @@ class TelegramBot extends EventEmitter { * @param {Object} [options.polling.params] Parameters to be used in polling API requests. * See https://core.telegram.org/bots/api#getupdates for more information. * @param {Number} [options.polling.params.timeout=10] Timeout in seconds for long polling. + * @param {Array|String} [options.polling.params.allowed_updates] A JSON-serialized list of the update types you want your bot to receive. + * For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. * @param {Boolean|Object} [options.webHook=false] Set true to enable WebHook or set options * @param {String} [options.webHook.host="0.0.0.0"] Host to bind to * @param {Number} [options.webHook.port=8443] Port to bind to @@ -923,6 +925,12 @@ class TelegramBot extends EventEmitter { /* eslint-enable no-param-reassign, prefer-rest-params */ } + // If allowed_updates is present and is an array, stringify it. + // If it's already a string (e.g., user did JSON.stringify), leave as is. + if (form.allowed_updates) { + form.allowed_updates = stringify(form.allowed_updates); + } + return this._request('getUpdates', { form }); }