src/polling: Add options to TelegramBot#stopPolling()

Feature:

  * Simply, pass through options to TelegramBot#stopPolling(options)
    to TelegramBotPolling#stop(options)

References:

  * Related PR: https://github.com/yagop/node-telegram-bot-api/pull/456
release
GochoMugo 8 years ago
parent ce9ff57a63
commit b1f0ebaf17
No known key found for this signature in database
GPG Key ID: 7B6A01CB57AA39E4
  1. 1
      CHANGELOG.md
  2. 11
      doc/api.md
  3. 7
      src/telegram.js
  4. 2
      src/telegramPolling.js

@ -12,6 +12,7 @@ Added:
* (#440) *TelegramBot#setChatStickerSet*, *TelegramBot#deleteChatStickerSet* (by @kamikazechaser) * (#440) *TelegramBot#setChatStickerSet*, *TelegramBot#deleteChatStickerSet* (by @kamikazechaser)
1. Support Bot API v3.5: 1. Support Bot API v3.5:
* Support `provider_data` parameter in *TelegramBot#sendInvoice* (by @GochoMugo) * Support `provider_data` parameter in *TelegramBot#sendInvoice* (by @GochoMugo)
1. Add options to *TelegramBot#stopPolling()* (by @GochoMugo)
1. Add `metadata` argument in `message` event (and 1. Add `metadata` argument in `message` event (and
friends e.g. `text`, `audio`, etc.) (#409) (by @jlsjonas, @GochoMugo) friends e.g. `text`, `audio`, etc.) (#409) (by @jlsjonas, @GochoMugo)
1. Add forward-compatibility i.e. support future additional Telegram options (by @GochoMugo) 1. Add forward-compatibility i.e. support future additional Telegram options (by @GochoMugo)

@ -16,7 +16,7 @@ TelegramBot
* [.on(event, listener)](#TelegramBot+on) * [.on(event, listener)](#TelegramBot+on)
* [.startPolling([options])](#TelegramBot+startPolling) ⇒ <code>Promise</code> * [.startPolling([options])](#TelegramBot+startPolling) ⇒ <code>Promise</code>
* ~~[.initPolling([options])](#TelegramBot+initPolling) ⇒ <code>Promise</code>~~ * ~~[.initPolling([options])](#TelegramBot+initPolling) ⇒ <code>Promise</code>~~
* [.stopPolling()](#TelegramBot+stopPolling) ⇒ <code>Promise</code> * [.stopPolling([options])](#TelegramBot+stopPolling) ⇒ <code>Promise</code>
* [.isPolling()](#TelegramBot+isPolling) ⇒ <code>Boolean</code> * [.isPolling()](#TelegramBot+isPolling) ⇒ <code>Boolean</code>
* [.openWebHook()](#TelegramBot+openWebHook) ⇒ <code>Promise</code> * [.openWebHook()](#TelegramBot+openWebHook) ⇒ <code>Promise</code>
* [.closeWebHook()](#TelegramBot+closeWebHook) ⇒ <code>Promise</code> * [.closeWebHook()](#TelegramBot+closeWebHook) ⇒ <code>Promise</code>
@ -169,12 +169,19 @@ Alias of `TelegramBot#startPolling()`. This is **deprecated**.
<a name="TelegramBot+stopPolling"></a> <a name="TelegramBot+stopPolling"></a>
### telegramBot.stopPolling() ⇒ <code>Promise</code> ### telegramBot.stopPolling([options]) ⇒ <code>Promise</code>
Stops polling after the last polling request resolves. Stops polling after the last polling request resolves.
Multiple invocations do nothing if polling is already stopped. Multiple invocations do nothing if polling is already stopped.
Returning the promise of the last polling request is **deprecated**. Returning the promise of the last polling request is **deprecated**.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code> **Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
| Param | Type | Description |
| --- | --- | --- |
| [options] | <code>Object</code> | Options |
| [options.cancel] | <code>Boolean</code> | Cancel current request |
| [options.reason] | <code>String</code> | Reason for stopping polling |
<a name="TelegramBot+isPolling"></a> <a name="TelegramBot+isPolling"></a>
### telegramBot.isPolling() ⇒ <code>Boolean</code> ### telegramBot.isPolling() ⇒ <code>Boolean</code>

@ -375,13 +375,16 @@ class TelegramBot extends EventEmitter {
* Stops polling after the last polling request resolves. * Stops polling after the last polling request resolves.
* Multiple invocations do nothing if polling is already stopped. * Multiple invocations do nothing if polling is already stopped.
* Returning the promise of the last polling request is **deprecated**. * Returning the promise of the last polling request is **deprecated**.
* @param {Object} [options] Options
* @param {Boolean} [options.cancel] Cancel current request
* @param {String} [options.reason] Reason for stopping polling
* @return {Promise} * @return {Promise}
*/ */
stopPolling() { stopPolling(options) {
if (!this._polling) { if (!this._polling) {
return Promise.resolve(); return Promise.resolve();
} }
return this._polling.stop(); return this._polling.stop(options);
} }
/** /**

@ -49,7 +49,7 @@ class TelegramBotPolling {
/** /**
* Stop polling * Stop polling
* @param {Object} [options] * @param {Object} [options] Options
* @param {Boolean} [options.cancel] Cancel current request * @param {Boolean} [options.cancel] Cancel current request
* @param {String} [options.reason] Reason for stopping polling * @param {String} [options.reason] Reason for stopping polling
* @return {Promise} * @return {Promise}

Loading…
Cancel
Save