From 3722c7182cfd8f6480d74904fb83859cb9cc1b5f Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Sat, 18 Nov 2017 20:31:01 +0300 Subject: [PATCH] src/telegram: Fix TelegramBot#answerCallbackQuery() signature Bug: `callbackQueryId` is a required argument. All other options are optional. References: * Telegram API doc: https://core.telegram.org/bots/api#answercallbackquery * Blame: https://github.com/yagop/node-telegram-bot-api/pull/368 --- CHANGELOG.md | 3 +++ doc/api.hbs | 1 + doc/api.md | 10 ++++++---- src/telegram.js | 20 ++++++++++++++++---- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 166c077..5e1fcaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ Added: * Add support for Node.js v9 +Changed: + +1. Update *TelegramBot#answerCallbackQuery()* signature (by @GochoMugo) * * * diff --git a/doc/api.hbs b/doc/api.hbs index 0d1fed8..2793b2e 100644 --- a/doc/api.hbs +++ b/doc/api.hbs @@ -16,3 +16,4 @@ [getUpdates-v0.25.0]:https://github.com/yagop/node-telegram-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#TelegramBot+getUpdates [getUserProfilePhotos-v0.25.0]:https://github.com/yagop/node-telegram-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#TelegramBot+getUserProfilePhotos [answerCallbackQuery-v0.27.1]:https://github.com/yagop/node-telegram-bot-api/blob/v0.27.1/doc/api.md#TelegramBot+answerCallbackQuery +[answerCallbackQuery-v0.29.0]:https://github.com/yagop/node-telegram-bot-api/blob/v0.29.0/doc/api.md#TelegramBot+answerCallbackQuery diff --git a/doc/api.md b/doc/api.md index 41108ca..6f3676a 100644 --- a/doc/api.md +++ b/doc/api.md @@ -49,7 +49,7 @@ TelegramBot * [.setChatDescription(chatId, description)](#TelegramBot+setChatDescription) ⇒ Promise * [.pinChatMessage(chatId, messageId)](#TelegramBot+pinChatMessage) ⇒ Promise * [.unpinChatMessage(chatId)](#TelegramBot+unpinChatMessage) ⇒ Promise - * [.answerCallbackQuery([options])](#TelegramBot+answerCallbackQuery) ⇒ Promise + * [.answerCallbackQuery(callbackQueryId, [options])](#TelegramBot+answerCallbackQuery) ⇒ Promise * [.editMessageText(text, [options])](#TelegramBot+editMessageText) ⇒ Promise * [.editMessageCaption(caption, [options])](#TelegramBot+editMessageCaption) ⇒ Promise * [.editMessageReplyMarkup(replyMarkup, [options])](#TelegramBot+editMessageReplyMarkup) ⇒ Promise @@ -597,20 +597,21 @@ Returns True on success. -### telegramBot.answerCallbackQuery([options]) ⇒ Promise +### telegramBot.answerCallbackQuery(callbackQueryId, [options]) ⇒ Promise Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned. -This method has an [older, compatible signature][answerCallbackQuery-v0.27.1] -that is being deprecated. +This method has **older, compatible signatures ([1][answerCallbackQuery-v0.27.1])([2][answerCallbackQuery-v0.29.0])** +that are being deprecated. **Kind**: instance method of [TelegramBot](#TelegramBot) **See**: https://core.telegram.org/bots/api#answercallbackquery | Param | Type | Description | | --- | --- | --- | +| callbackQueryId | String | Unique identifier for the query to be answered | | [options] | Object | Additional Telegram query options | @@ -1134,3 +1135,4 @@ TelegramBot.Promise = myPromise; [getUpdates-v0.25.0]:https://github.com/yagop/node-telegram-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#TelegramBot+getUpdates [getUserProfilePhotos-v0.25.0]:https://github.com/yagop/node-telegram-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#TelegramBot+getUserProfilePhotos [answerCallbackQuery-v0.27.1]:https://github.com/yagop/node-telegram-bot-api/blob/v0.27.1/doc/api.md#TelegramBot+answerCallbackQuery +[answerCallbackQuery-v0.29.0]:https://github.com/yagop/node-telegram-bot-api/blob/v0.29.0/doc/api.md#TelegramBot+answerCallbackQuery diff --git a/src/telegram.js b/src/telegram.js index 9a4abb2..daa62f0 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -1041,15 +1041,16 @@ class TelegramBot extends EventEmitter { * a notification at the top of the chat screen or as an alert. * On success, True is returned. * - * This method has an [older, compatible signature][answerCallbackQuery-v0.27.1] - * that is being deprecated. + * This method has **older, compatible signatures ([1][answerCallbackQuery-v0.27.1])([2][answerCallbackQuery-v0.29.0])** + * that are being deprecated. * + * @param {String} callbackQueryId Unique identifier for the query to be answered * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#answercallbackquery */ - answerCallbackQuery(form = {}) { - /* The older method signature was answerCallbackQuery(callbackQueryId, text, showAlert). + answerCallbackQuery(callbackQueryId, form = {}) { + /* The older method signature (in/before v0.27.1) was answerCallbackQuery(callbackQueryId, text, showAlert). * We need to ensure backwards-compatibility while maintaining * consistency of the method signatures throughout the library */ if (typeof form !== 'object') { @@ -1062,6 +1063,17 @@ class TelegramBot extends EventEmitter { }; /* eslint-enable no-param-reassign, prefer-rest-params */ } + /* The older method signature (in/before v0.29.0) was answerCallbackQuery([options]). + * We need to ensure backwards-compatibility while maintaining + * consistency of the method signatures throughout the library. */ + if (typeof callbackQueryId === 'object') { + /* eslint-disable no-param-reassign, prefer-rest-params */ + deprecate('The method signature answerCallbackQuery([options]) has been deprecated since v0.29.0'); + form = callbackQueryId; + /* eslint-enable no-param-reassign, prefer-rest-params */ + } else { + form.callback_query_id = callbackQueryId; + } return this._request('answerCallbackQuery', { form }); }