mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-28 21:07:39 +00:00
[webhook] Allow enabling/disabling webhook auto-open
Feature: Currently, if the constructor option 'options.webHook' is passed, the bot opens the webHook immediately! There's NO way to disable this behavior, which might be useful in cases such as: * providing custom webhook parameters without opening the webhook immediately The new boolean option, 'autoOpen', can now be used to control this behavior. For example, ```js const bot = new TelegramBot(token, { webHook: { autoOpen: false, }, }); ``` If set to 'false', the bot does NOT open the web-hook immediately. Currently, there's NO way to open the web-hook in this case. I'm working on that. Expect a feature to add a method to open the web-hook manually! If not provided, its value defaults to 'true'. Implementation: * Backwards-compatible: the behavior of opening the web-hook immediately remains, when the parameter is NOT provided.
This commit is contained in:
parent
e2f095fc52
commit
69b059a4d7
@ -130,6 +130,7 @@ Emits `message` when a message arrives.
|
||||
| [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!) |
|
||||
| [options.webHook.cert] | <code>String</code> | | Path to file with PEM certificate (public) for webHook server. (Read synchronously!) |
|
||||
| [options.webHook.autoOpen] | <code>Boolean</code> | <code>true</code> | Open webHook immediately |
|
||||
| [options.onlyFirstMatch] | <code>Boolean</code> | <code>false</code> | Set to true to stop after first match. Otherwise, all regexps are executed |
|
||||
| [options.request] | <code>Object</code> | | Options which will be added for all requests to telegram api. See https://github.com/request/request#requestoptions-callback for more information. |
|
||||
|
||||
|
@ -48,6 +48,7 @@ class TelegramBot extends EventEmitter {
|
||||
* @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!)
|
||||
* @param {String} [options.webHook.cert] Path to file with PEM certificate (public) for webHook server. (Read synchronously!)
|
||||
* @param {Boolean} [options.webHook.autoOpen=true] Open webHook immediately
|
||||
* @param {Boolean} [options.onlyFirstMatch=false] Set to true to stop after first match. Otherwise, all regexps are executed
|
||||
* @param {Object} [options.request] Options which will be added for all requests to telegram api. See https://github.com/request/request#requestoptions-callback for more information.
|
||||
* @see https://core.telegram.org/bots/api
|
||||
@ -67,7 +68,10 @@ class TelegramBot extends EventEmitter {
|
||||
}
|
||||
|
||||
if (options.webHook) {
|
||||
this._WebHook = new TelegramBotWebHook(token, options.webHook, this.processUpdate.bind(this));
|
||||
const autoOpen = options.webHook.autoOpen;
|
||||
if (typeof autoOpen === 'undefined' || autoOpen === true) {
|
||||
this._WebHook = new TelegramBotWebHook(token, options.webHook, this.processUpdate.bind(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user