-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
41 lines (34 loc) · 1.02 KB
/
server.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
38
39
40
41
const line = require('@line/bot-sdk');
const express = require('express');
const axios = require('axios');
const config = {
channelAccessToken: "",
channelSecret: "",
};
// create LINE SDK client
const client = new line.Client(config);
const app = express();
// register a webhook handler with middleware
// about the middleware, please refer to doc
app.post('/callback', line.middleware(config), (req, res) => {
Promise
.all(req.body.events.map(handleEvent))
.then((result) => res.json(result))
.catch((e)=>{
console.log(e);
});
});
function handleEvent(event) {
var string = event.message.text
if(string.includes("hai")){
const echo = { type: 'text', text: "Halo juga :)·" };
return client.replyMessage(event.replyToken, echo);
}
const echo = { type: 'text', text: "Saya tidak mengerti, saya simpan dulu" };
return client.replyMessage(event.replyToken, echo);
}
// listen on port
const port = 3000;
app.listen(port, () => {
console.log(`listening on ${port}`);
});