Skip to content

Commit 8126b1d

Browse files
authored
Fix params allowed_updates on Telegram bot polling whenever it's an array (#1270)
* fix: stringify allowed_updates if it's an array on getUpdates * docs: update api documentation
1 parent f7c94b6 commit 8126b1d

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

doc/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ Emits `message` when a message arrives.
209209
| [options.polling.autoStart] | <code>Boolean</code> | <code>true</code> | Start polling immediately |
210210
| [options.polling.params] | <code>Object</code> | | Parameters to be used in polling API requests. See https://core.telegram.org/bots/api#getupdates for more information. |
211211
| [options.polling.params.timeout] | <code>Number</code> | <code>10</code> | Timeout in seconds for long polling. |
212+
| [options.polling.params.allowed_updates] | <code>Array</code> \| <code>String</code> | | 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. |
212213
| [options.webHook] | <code>Boolean</code> \| <code>Object</code> | <code>false</code> | Set true to enable WebHook or set options |
213214
| [options.webHook.host] | <code>String</code> | <code>&quot;0.0.0.0&quot;</code> | Host to bind to |
214215
| [options.webHook.port] | <code>Number</code> | <code>8443</code> | Port to bind to |

src/telegram.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ class TelegramBot extends EventEmitter {
130130
* @param {Object} [options.polling.params] Parameters to be used in polling API requests.
131131
* See https://core.telegram.org/bots/api#getupdates for more information.
132132
* @param {Number} [options.polling.params.timeout=10] Timeout in seconds for long polling.
133+
* @param {Array<String>|String} [options.polling.params.allowed_updates] A JSON-serialized list of the update types you want your bot to receive.
134+
* For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types.
133135
* @param {Boolean|Object} [options.webHook=false] Set true to enable WebHook or set options
134136
* @param {String} [options.webHook.host="0.0.0.0"] Host to bind to
135137
* @param {Number} [options.webHook.port=8443] Port to bind to
@@ -923,6 +925,12 @@ class TelegramBot extends EventEmitter {
923925
/* eslint-enable no-param-reassign, prefer-rest-params */
924926
}
925927

928+
// If allowed_updates is present and is an array, stringify it.
929+
// If it's already a string (e.g., user did JSON.stringify), leave as is.
930+
if (form.allowed_updates) {
931+
form.allowed_updates = stringify(form.allowed_updates);
932+
}
933+
926934
return this._request('getUpdates', { form });
927935
}
928936

0 commit comments

Comments
 (0)