Skip to content

Commit

Permalink
Bugfix: correctly encode request data as JSON body
Browse files Browse the repository at this point in the history
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
  • Loading branch information
acran committed Feb 9, 2019
1 parent 76a2aae commit b09a7e6
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions lib/telegram-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'sendMessage'
})
.then(function(body)
Expand Down Expand Up @@ -304,7 +304,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'forwardMessage'
})
.then(function(body)
Expand Down Expand Up @@ -379,7 +379,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'sendPhoto'
})
.then(function(body)
Expand Down Expand Up @@ -467,7 +467,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'sendAudio'
})
.then(function(body)
Expand Down Expand Up @@ -543,7 +543,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'sendVoice'
})
.then(function(body)
Expand Down Expand Up @@ -613,7 +613,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'sendDocument'
})
.then(function(body)
Expand Down Expand Up @@ -683,7 +683,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'sendSticker'
})
.then(function(body)
Expand Down Expand Up @@ -765,7 +765,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'sendVideo'
})
.then(function(body)
Expand Down Expand Up @@ -820,7 +820,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'sendLocation'
})
.then(function(body)
Expand Down Expand Up @@ -860,7 +860,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: params,
body: params,
uri: _baseurl + 'sendVenue'
})
.then(function(body)
Expand Down Expand Up @@ -898,7 +898,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: params,
body: params,
uri: _baseurl + 'sendContact'
})
.then(function(body)
Expand Down Expand Up @@ -930,7 +930,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: params,
body: params,
uri: _baseurl + 'kickChatMember'
})
.then(function(body)
Expand Down Expand Up @@ -962,7 +962,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: params,
body: params,
uri: _baseurl + 'unbanChatMember'
})
.then(function(body)
Expand Down Expand Up @@ -993,7 +993,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: params,
body: params,
uri: _baseurl + 'leaveChat'
})
.then(function(body)
Expand Down Expand Up @@ -1024,7 +1024,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: params,
body: params,
uri: _baseurl + 'getChat'
})
.then(function(body)
Expand Down Expand Up @@ -1055,7 +1055,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: params,
body: params,
uri: _baseurl + 'getChatAdministrators'
})
.then(function(body)
Expand Down Expand Up @@ -1086,7 +1086,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: params,
body: params,
uri: _baseurl + 'getChatMembersCount'
})
.then(function(body)
Expand Down Expand Up @@ -1118,7 +1118,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: params,
body: params,
uri: _baseurl + 'getChatMember'
})
.then(function(body)
Expand Down Expand Up @@ -1157,7 +1157,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'sendChatAction'
})
.then(function(body)
Expand Down Expand Up @@ -1195,7 +1195,7 @@ var TelegramApi = function (params)
_rest({
method: 'GET',
json: true,
formData: args,
body: args,
uri: _baseurl + 'getUserProfilePhotos'
})
.then(function(body)
Expand Down Expand Up @@ -1236,7 +1236,7 @@ var TelegramApi = function (params)
_rest({
method: 'GET',
json: true,
formData: args,
body: args,
uri: _baseurl + 'getUpdates'
})
.then(function(body)
Expand Down Expand Up @@ -1280,7 +1280,7 @@ var TelegramApi = function (params)
return _rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'setWebhook'
})
.then(commonResponseHandler)
Expand All @@ -1300,7 +1300,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'setWebhook'
})
.then(function(body)
Expand Down Expand Up @@ -1397,7 +1397,7 @@ var TelegramApi = function (params)
_rest({
method: 'GET',
json: true,
formData: args,
body: args,
uri: _baseurl + 'getFile'
})
.then(function(body)
Expand Down Expand Up @@ -1451,7 +1451,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'answerInlineQuery'
})
.then(function(body)
Expand Down Expand Up @@ -1493,7 +1493,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'answerCallbackQuery'
})
.then(function (body) {
Expand Down Expand Up @@ -1541,7 +1541,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'editMessageText'
})
.then(function (body) {
Expand Down Expand Up @@ -1584,7 +1584,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'editMessageCaption'
})
.then(function (body) {
Expand Down Expand Up @@ -1625,7 +1625,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'editMessageReplyMarkup'
})
.then(function (body) {
Expand Down Expand Up @@ -1654,7 +1654,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'exportChatInviteLink'
})
.then(function(body) {
Expand Down Expand Up @@ -1685,7 +1685,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'deleteMessage'
})
.then(function (body) {
Expand Down Expand Up @@ -1724,7 +1724,7 @@ var TelegramApi = function (params)
_rest({
method: 'POST',
json: true,
formData: args,
body: args,
uri: _baseurl + 'sendGame'
})
.then(function (body) {
Expand Down

0 comments on commit b09a7e6

Please sign in to comment.