From 86e0cdabf6bef25db174e2a0bb340b67c7ea39e9 Mon Sep 17 00:00:00 2001 From: Roman Anasal Date: Fri, 1 Feb 2019 06:28:30 +0100 Subject: [PATCH] Add missing parameters to answerInlineQuery and implement exportChatInviteLink method (#58) * Added missing parameters to answerInlineQuery method * Implemented exportChatInviteLink method * Fix runaway promise warning Not returning any value in the promise chain resulted in a warning like this: (node:165) Warning: a promise was created in a handler at app/node_modules/telegram-bot-api/lib/telegram-bot.js:1680:13 but was not returned from it, see http://goo.gl/rRqMUw at new Promise (/app/node_modules/bluebird/js/release/promise.js:79:10) --- README.md | 1 + lib/telegram-bot.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/README.md b/README.md index 0d7b14c..72af4c8 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ editMessageCaption editMessageReplyMarkup kickChatMember unbanChatMember +exportChatInviteLink leaveChat getChat getChatAdministrators diff --git a/lib/telegram-bot.js b/lib/telegram-bot.js index db0a783..b552a87 100644 --- a/lib/telegram-bot.js +++ b/lib/telegram-bot.js @@ -1396,6 +1396,8 @@ var TelegramApi = function (params) if (params.cache_time !== undefined) args.cache_time = params.cache_time; if (params.is_personal !== undefined) args.is_personal = params.is_personal; if (params.next_offset !== undefined) args.next_offset = params.next_offset; + if (params.switch_pm_text !== undefined) args.switch_pm_text = params.switch_pm_text; + if (params.switch_pm_parameter !== undefined) args.switch_pm_parameter = params.switch_pm_parameter; _rest({ method: 'POST', @@ -1573,6 +1575,34 @@ var TelegramApi = function (params) }).nodeify(cb); }; + /** + * METHOD: exportChatInviteLink + * PARAMS: + * chat_id Unique identifier for the target chat or username of the target channel — User or GroupChat id + */ + this.exportChatInviteLink = function (params, cb) { + var args = {}; + + if (params.chat_id !== undefined) args.chat_id = params.chat_id; + + return new Promise(function(resolve, reject) { + _rest({ + method: 'POST', + json: true, + formData: args, + uri: _baseurl + 'exportChatInviteLink' + }) + .then(function(body) { + return commonResponseHandler(body); + }) + .then(function(data) { + resolve(data); + }) + .catch(function(err) { + reject(err); + }); + }).nodeify(cb); + }; /** * METHOD: deleteMessage @@ -1648,6 +1678,7 @@ var TelegramApi = function (params) this.deleteWebhook() .then(function() { internalGetUpdates(); + return null; // avoid runaway promise warning, see http://goo.gl/rRqMUw }) .catch(function(err) { throw new Error(err)