From b09a7e6a9088fa2ed38d28ea7ae75ac90931df43 Mon Sep 17 00:00:00 2001 From: Roman Anasal Date: Sat, 9 Feb 2019 14:01:58 +0100 Subject: [PATCH] Bugfix: correctly encode request data as JSON body The request data was actually serialized as multipart/form-data instead of a JSON body. Passing JSON data with a boolean value then throw an error while serializing: bot.sendMessage({ chat_id: user.id, text: text, disable_web_page_preview: false, // throws an error }); // > TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string or Buffer. Received type boolean --- lib/telegram-bot.js | 64 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/telegram-bot.js b/lib/telegram-bot.js index 9b2a598..658667f 100644 --- a/lib/telegram-bot.js +++ b/lib/telegram-bot.js @@ -266,7 +266,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'sendMessage' }) .then(function(body) @@ -304,7 +304,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'forwardMessage' }) .then(function(body) @@ -379,7 +379,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'sendPhoto' }) .then(function(body) @@ -467,7 +467,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'sendAudio' }) .then(function(body) @@ -543,7 +543,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'sendVoice' }) .then(function(body) @@ -613,7 +613,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'sendDocument' }) .then(function(body) @@ -683,7 +683,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'sendSticker' }) .then(function(body) @@ -765,7 +765,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'sendVideo' }) .then(function(body) @@ -820,7 +820,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'sendLocation' }) .then(function(body) @@ -860,7 +860,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: params, + body: params, uri: _baseurl + 'sendVenue' }) .then(function(body) @@ -898,7 +898,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: params, + body: params, uri: _baseurl + 'sendContact' }) .then(function(body) @@ -930,7 +930,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: params, + body: params, uri: _baseurl + 'kickChatMember' }) .then(function(body) @@ -962,7 +962,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: params, + body: params, uri: _baseurl + 'unbanChatMember' }) .then(function(body) @@ -993,7 +993,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: params, + body: params, uri: _baseurl + 'leaveChat' }) .then(function(body) @@ -1024,7 +1024,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: params, + body: params, uri: _baseurl + 'getChat' }) .then(function(body) @@ -1055,7 +1055,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: params, + body: params, uri: _baseurl + 'getChatAdministrators' }) .then(function(body) @@ -1086,7 +1086,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: params, + body: params, uri: _baseurl + 'getChatMembersCount' }) .then(function(body) @@ -1118,7 +1118,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: params, + body: params, uri: _baseurl + 'getChatMember' }) .then(function(body) @@ -1157,7 +1157,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'sendChatAction' }) .then(function(body) @@ -1195,7 +1195,7 @@ var TelegramApi = function (params) _rest({ method: 'GET', json: true, - formData: args, + body: args, uri: _baseurl + 'getUserProfilePhotos' }) .then(function(body) @@ -1236,7 +1236,7 @@ var TelegramApi = function (params) _rest({ method: 'GET', json: true, - formData: args, + body: args, uri: _baseurl + 'getUpdates' }) .then(function(body) @@ -1280,7 +1280,7 @@ var TelegramApi = function (params) return _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'setWebhook' }) .then(commonResponseHandler) @@ -1300,7 +1300,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'setWebhook' }) .then(function(body) @@ -1397,7 +1397,7 @@ var TelegramApi = function (params) _rest({ method: 'GET', json: true, - formData: args, + body: args, uri: _baseurl + 'getFile' }) .then(function(body) @@ -1451,7 +1451,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'answerInlineQuery' }) .then(function(body) @@ -1493,7 +1493,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'answerCallbackQuery' }) .then(function (body) { @@ -1541,7 +1541,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'editMessageText' }) .then(function (body) { @@ -1584,7 +1584,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'editMessageCaption' }) .then(function (body) { @@ -1625,7 +1625,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'editMessageReplyMarkup' }) .then(function (body) { @@ -1654,7 +1654,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'exportChatInviteLink' }) .then(function(body) { @@ -1685,7 +1685,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'deleteMessage' }) .then(function (body) { @@ -1724,7 +1724,7 @@ var TelegramApi = function (params) _rest({ method: 'POST', json: true, - formData: args, + body: args, uri: _baseurl + 'sendGame' }) .then(function (body) {