diff --git a/CHANGELOG.md b/CHANGELOG.md index c4cbf75..08deb09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Added: * (#440) *TelegramBot#setChatStickerSet*, *TelegramBot#deleteChatStickerSet* (by @kamikazechaser) 1. Support Bot API v3.5: * 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 friends e.g. `text`, `audio`, etc.) (#409) (by @jlsjonas, @GochoMugo) 1. Add forward-compatibility i.e. support future additional Telegram options (by @GochoMugo) diff --git a/doc/api.md b/doc/api.md index 8f6ece7..adb8c25 100644 --- a/doc/api.md +++ b/doc/api.md @@ -16,7 +16,7 @@ TelegramBot * [.on(event, listener)](#TelegramBot+on) * [.startPolling([options])](#TelegramBot+startPolling) ⇒ Promise * ~~[.initPolling([options])](#TelegramBot+initPolling) ⇒ Promise~~ - * [.stopPolling()](#TelegramBot+stopPolling) ⇒ Promise + * [.stopPolling([options])](#TelegramBot+stopPolling) ⇒ Promise * [.isPolling()](#TelegramBot+isPolling) ⇒ Boolean * [.openWebHook()](#TelegramBot+openWebHook) ⇒ Promise * [.closeWebHook()](#TelegramBot+closeWebHook) ⇒ Promise @@ -169,12 +169,19 @@ Alias of `TelegramBot#startPolling()`. This is **deprecated**. -### telegramBot.stopPolling() ⇒ Promise +### telegramBot.stopPolling([options]) ⇒ Promise Stops polling after the last polling request resolves. Multiple invocations do nothing if polling is already stopped. Returning the promise of the last polling request is **deprecated**. **Kind**: instance method of [TelegramBot](#TelegramBot) + +| Param | Type | Description | +| --- | --- | --- | +| [options] | Object | Options | +| [options.cancel] | Boolean | Cancel current request | +| [options.reason] | String | Reason for stopping polling | + ### telegramBot.isPolling() ⇒ Boolean diff --git a/src/telegram.js b/src/telegram.js index d3e2cbc..b69fa59 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -375,13 +375,16 @@ class TelegramBot extends EventEmitter { * Stops polling after the last polling request resolves. * Multiple invocations do nothing if polling is already stopped. * 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} */ - stopPolling() { + stopPolling(options) { if (!this._polling) { return Promise.resolve(); } - return this._polling.stop(); + return this._polling.stop(options); } /** diff --git a/src/telegramPolling.js b/src/telegramPolling.js index 0c43bd2..d3f102f 100644 --- a/src/telegramPolling.js +++ b/src/telegramPolling.js @@ -49,7 +49,7 @@ class TelegramBotPolling { /** * Stop polling - * @param {Object} [options] + * @param {Object} [options] Options * @param {Boolean} [options.cancel] Cancel current request * @param {String} [options.reason] Reason for stopping polling * @return {Promise}