mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-28 12:57:38 +00:00
[polling] Allow enabling/disabling polling auto-start
Feature: Currently, if the constructor option 'options.polling' is passed, the bot begins polling immediately! There's NO way to disable this behavior, which might be useful in cases such as: * providing custom polling parameters without starting the polling immediately The boolean option, 'autoStart', can now be used to control this behavior. For example, ```js const bot = new TelegramBot(token, { polling: { autoStart: false, }, }); ``` If set to 'false', the bot does NOT begin polling immediately. You'll have to use TelegramBot#initPolling(). If not provided, its value defaults to 'true'. Implementation: * Backwards-compatible: the behavior of starting polling immediately remains, when the parameter is NOT provided
This commit is contained in:
parent
daab34d98d
commit
e2f095fc52
@ -125,6 +125,7 @@ Emits `message` when a message arrives.
|
||||
| [options.polling] | <code>Boolean</code> | <code>Object</code> | <code>false</code> | Set true to enable polling or set options |
|
||||
| [options.polling.timeout] | <code>String</code> | <code>Number</code> | <code>10</code> | Timeout in seconds for long polling |
|
||||
| [options.polling.interval] | <code>String</code> | <code>Number</code> | <code>300</code> | Interval between requests in miliseconds |
|
||||
| [options.polling.autoStart] | <code>Boolean</code> | <code>true</code> | Start polling immediately |
|
||||
| [options.webHook] | <code>Boolean</code> | <code>Object</code> | <code>false</code> | Set true to enable WebHook or set options |
|
||||
| [options.webHook.port] | <code>Number</code> | <code>8443</code> | Port to bind to |
|
||||
| [options.webHook.key] | <code>String</code> | | Path to file with PEM private key for webHook server. (Read synchronously!) |
|
||||
|
@ -43,6 +43,7 @@ class TelegramBot extends EventEmitter {
|
||||
* @param {Boolean|Object} [options.polling=false] Set true to enable polling or set options
|
||||
* @param {String|Number} [options.polling.timeout=10] Timeout in seconds for long polling
|
||||
* @param {String|Number} [options.polling.interval=300] Interval between requests in miliseconds
|
||||
* @param {Boolean} [options.polling.autoStart=true] Start polling immediately
|
||||
* @param {Boolean|Object} [options.webHook=false] Set true to enable WebHook or set options
|
||||
* @param {Number} [options.webHook.port=8443] Port to bind to
|
||||
* @param {String} [options.webHook.key] Path to file with PEM private key for webHook server. (Read synchronously!)
|
||||
@ -59,7 +60,10 @@ class TelegramBot extends EventEmitter {
|
||||
this._onReplyToMessages = [];
|
||||
|
||||
if (options.polling) {
|
||||
this.initPolling();
|
||||
const autoStart = options.polling.autoStart;
|
||||
if (typeof autoStart === 'undefined' || autoStart === true) {
|
||||
this.initPolling();
|
||||
}
|
||||
}
|
||||
|
||||
if (options.webHook) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user