forked from boybundit/linebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
echo-express-long.js
37 lines (31 loc) · 937 Bytes
/
echo-express-long.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const linebot = require('../index.js');
const express = require('express');
const bodyParser = require('body-parser');
const bot = linebot({
channelId: process.env.CHANNEL_ID,
channelSecret: process.env.CHANNEL_SECRET,
channelAccessToken: process.env.CHANNEL_ACCESS_TOKEN
});
const app = express();
const parser = bodyParser.json({
verify: function (req, res, buf, encoding) {
req.rawBody = buf.toString(encoding);
}
});
app.post('/linewebhook', parser, function (req, res) {
if (!bot.verify(req.rawBody, req.get('X-Line-Signature'))) {
return res.sendStatus(400);
}
bot.parse(req.body);
return res.json({});
});
bot.on('message', function (event) {
event.reply(event.message.text).then(function (data) {
console.log('Success', data);
}).catch(function (error) {
console.log('Error', error);
});
});
app.listen(process.env.PORT || 80, function () {
console.log('LineBot is running.');
});