diff --git a/doc/api.hbs b/doc/api.hbs index 4f56831..0d1fed8 100644 --- a/doc/api.hbs +++ b/doc/api.hbs @@ -15,3 +15,4 @@ [setWebHook-v0.25.0]:https://github.com/yagop/node-telegram-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#telegrambotsetwebhookurl-cert [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 diff --git a/doc/api.md b/doc/api.md index 0cd1369..510b455 100644 --- a/doc/api.md +++ b/doc/api.md @@ -47,7 +47,7 @@ TelegramBot * [.setChatDescription(chatId, description)](#TelegramBot+setChatDescription) ⇒ Promise * [.pinChatMessage(chatId, messageId)](#TelegramBot+pinChatMessage) ⇒ Promise * [.unpinChatMessage(chatId)](#TelegramBot+unpinChatMessage) ⇒ Promise - * [.answerCallbackQuery(callbackQueryId, text, showAlert, [options])](#TelegramBot+answerCallbackQuery) ⇒ Promise + * [.answerCallbackQuery([options])](#TelegramBot+answerCallbackQuery) ⇒ Promise * [.editMessageText(text, [options])](#TelegramBot+editMessageText) ⇒ Promise * [.editMessageCaption(caption, [options])](#TelegramBot+editMessageCaption) ⇒ Promise * [.editMessageReplyMarkup(replyMarkup, [options])](#TelegramBot+editMessageReplyMarkup) ⇒ Promise @@ -569,20 +569,20 @@ Returns True on success. -### telegramBot.answerCallbackQuery(callbackQueryId, text, showAlert, [options]) ⇒ Promise +### telegramBot.answerCallbackQuery([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. + **Kind**: instance method of [TelegramBot](#TelegramBot) **See**: https://core.telegram.org/bots/api#answercallbackquery | Param | Type | Description | | --- | --- | --- | -| callbackQueryId | Number | String | Unique identifier for the query to be answered | -| text | String | Text of the notification. If not specified, nothing will be shown to the user | -| showAlert | Boolean | Whether to show an alert or a notification at the top of the screen | | [options] | Object | Additional Telegram query options | @@ -981,3 +981,4 @@ Use this method to confirm shipping of a product. [setWebHook-v0.25.0]:https://github.com/yagop/node-telegram-bot-api/tree/4e5a493cadfaad5589a8d79e55d9e0d103000ce4#telegrambotsetwebhookurl-cert [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 diff --git a/src/telegram.js b/src/telegram.js index e43766b..c7a5314 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -1001,17 +1001,27 @@ class TelegramBot extends EventEmitter { * a notification at the top of the chat screen or as an alert. * On success, True is returned. * - * @param {Number|String} callbackQueryId Unique identifier for the query to be answered - * @param {String} text Text of the notification. If not specified, nothing will be shown to the user - * @param {Boolean} showAlert Whether to show an alert or a notification at the top of the screen + * This method has an [older, compatible signature][answerCallbackQuery-v0.27.1] + * that is being deprecated. + * * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#answercallbackquery */ - answerCallbackQuery(callbackQueryId, text, showAlert, form = {}) { - form.callback_query_id = callbackQueryId; - form.text = text; - form.show_alert = showAlert; + answerCallbackQuery(form = {}) { + /* The older method signature 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') { + /* eslint-disable no-param-reassign, prefer-rest-params */ + deprecate('The method signature answerCallbackQuery(callbackQueryId, text, showAlert) has been deprecated since v0.27.1'); + form = { + callback_query_id: arguments[0], + text: arguments[1], + show_alert: arguments[2], + }; + /* eslint-enable no-param-reassign, prefer-rest-params */ + } return this._request('answerCallbackQuery', { form }); }