boybundit / linebot

đŸ¤– SDK for the LINE Messaging API for Node.js
https://www.npmjs.com/package/linebot
MIT License
216 stars 93 forks source link

TypeError: Data must be a string or a buffer #21

Closed EkiFauziFirdaus closed 7 years ago

EkiFauziFirdaus commented 7 years ago

I got error:

TypeError: Data must be a string or a buffer
    at TypeError (native)
    at Hmac.Hash.update (crypto.js:74:16)
    at LineBot.verify (C:\GitRepo\Warframe-Alert-BOT-LINE\node_modules\linebot\lib\linebot.js:30:5)
    at parser (C:\GitRepo\Warframe-Alert-BOT-LINE\node_modules\linebot\lib\linebot.js:149:38)
    at jsonParser (C:\GitRepo\Warframe-Alert-BOT-LINE\node_modules\body-parser\lib\types\json.js:103:7)
    at C:\GitRepo\Warframe-Alert-BOT-LINE\node_modules\linebot\lib\linebot.js:148:4
    at Layer.handle [as handle_request] (C:\GitRepo\Warframe-Alert-BOT-LINE\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\GitRepo\Warframe-Alert-BOT-LINE\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\GitRepo\Warframe-Alert-BOT-LINE\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\GitRepo\Warframe-Alert-BOT-LINE\node_modules\express\lib\router\layer.js:95:5)

I'm using linebot v1.3.0... My code:

const express = require('express');
const app = express();
const linebot = require('linebot');
var bot = linebot({
    channelId: '15xxxxxxxx',
    channelSecret: '16f6862afec3d23b0ee02exxxxxxxxxx',
    channelAccessToken: '6x57DzbyGaSMEj9S4hTfhYsJERvwothosBwAoEJTwDqLuOncgvaWShD59OLpYFf9WdIZlgga5XjnyrTHIVPjLNGaHi7V0H4wGpI9w/0IyEjQtFmBVo74fCNjTiuwwSNAqZNa9fNlVaiRk5zTBsNaNAdB04t89/1O/xxxxxxxxxx=',
    verify: true
});

const linebotParser = bot.parser();
app.get('/linewebhook', linebotParser);
app.get('/test', function(req, res) {
  res.json({notes: "Hello"})
})
app.listen(3000);
boybundit commented 7 years ago

@EkiFauziFirdaus LINE webhook URL is called via POST method instead of GET.

app.post('/linewebhook', linebotParser);`

Also, it assumes that the request body has never been parsed by any body parser before, so it must be placed BEFORE any generic body parser, if there is any.

app.post('/linewebhook', linebotParser);
app.use(bodyParser.json());
EkiFauziFirdaus commented 7 years ago

My bad... I'm sorry...