From 4af06356e86325901e61be7c0008139baec63b0a Mon Sep 17 00:00:00 2001 From: Alfan Zain Date: Sat, 6 Sep 2025 07:55:12 +0700 Subject: [PATCH 1/2] fix: stringify allowed_updates if it's an array on getUpdates --- doc/api.md | 1 + src/telegram.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/doc/api.md b/doc/api.md index 1f530d4d..f0b02f8a 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 | | 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..d9906ee4 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 }); } From 947805496841876232dee26f5f0f4696ad1e9c8c Mon Sep 17 00:00:00 2001 From: Alfan Zain Date: Sat, 6 Sep 2025 07:59:28 +0700 Subject: [PATCH 2/2] docs: update api documentation --- doc/api.md | 2 +- src/telegram.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api.md b/doc/api.md index f0b02f8a..4bf14f70 100644 --- a/doc/api.md +++ b/doc/api.md @@ -209,7 +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 | | 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.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 d9906ee4..ff6c16e5 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -130,7 +130,7 @@ 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. + * @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