From ec354925d688b6b2de355c1c17cb36ac07d5042f Mon Sep 17 00:00:00 2001 From: Mikhail Burshteyn Date: Wed, 25 May 2016 18:48:19 +0300 Subject: [PATCH 1/2] JSON-stringify reply_markup when it is sent in qs --- src/telegram.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/telegram.js b/src/telegram.js index 2a0a49e..cde1858 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -140,6 +140,14 @@ class TelegramBot extends EventEmitter { throw new Error(`Error parsing Telegram response: ${String(json)}`); } } + + _fixReplyMarkup(obj) { + const replyMarkup = obj.reply_markup; + if (replyMarkup && typeof replyMarkup !== 'string') { + // reply_markup must be passed as JSON stringified to Telegram + obj.reply_markup = JSON.stringify(replyMarkup); + } + } // request-promise _request(_path, options = {}) { @@ -148,11 +156,10 @@ class TelegramBot extends EventEmitter { } if (options.form) { - const replyMarkup = options.form.reply_markup; - if (replyMarkup && typeof replyMarkup !== 'string') { - // reply_markup must be passed as JSON stringified to Telegram - options.form.reply_markup = JSON.stringify(replyMarkup); - } + this._fixReplyMarkup(options.form); + } + if (options.qs) { + this._fixReplyMarkup(options.qs); } options.url = this._buildURL(_path); options.simple = false; From 82ee13e953e6330b9fb9d2170a44c6b3da8cb105 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 10 Oct 2016 13:23:12 +0300 Subject: [PATCH 2/2] Add accompanying test for PR #133 References: * Test retrieved from PR #182 --- test/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/index.js b/test/index.js index 4ed771d..207a015 100644 --- a/test/index.js +++ b/test/index.js @@ -205,6 +205,18 @@ describe('Telegram', function telegramSuite() { assert.ok(is.object(resp)); }); }); + + it('should send a photo along with reply_markup', function test() { + const bot = new Telegram(TOKEN); + const photo = fs.readFileSync(`${__dirname}/bot.gif`); + return bot.sendPhoto(USERID, photo, { + reply_markup: { + hide_keyboard: true + } + }).then(resp => { + assert.ok(is.object(resp)); + }); + }); }); describe('#sendChatAction', function sendChatActionSuite() {