-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (30 loc) · 1 KB
/
index.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
const line=require('@line/bot-sdk');
const express=require('express');
const dotenv=require('dotenv')
dotenv.config();
const app=express();
const config={
channelSecret:process.env.CHANNEL_SECRET,
channelAccessToken:process.env.CHANNEL_ACCESS_TOKEN
}
function handleEvent(event) {
if (event.type !== 'message' || event.message.type !== 'text') {
return Promise.resolve(null);
}
const echo = { type: 'text', text: event.message.text };
return client.replyMessage(event.replyToken, echo);
}
app.post('/callback', line.middleware(config), (req, res) => {
console.log(req, res)
Promise
.all(req.body.events.map(handleEvent))
.then((result) => res.json(result))
.catch((err) => {
console.error(err);
res.status(500).end();
});
});
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`listening on ${port}`);
});