-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
43 lines (34 loc) · 1.06 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
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
const lineConfig = require('./src/line.config');
const eventMessageHandler = require('./src/event-message.handler');
const express = require('express');
const firebase = require('./src/firebase');
const app = express();
app.post('/callback', lineConfig.middleware, (req, res) => {
req.body.events.map(event => {
if (event.type !== 'message' || event.message.type !== 'text') {
// ignore non-text-message event
return;
}
const sourceId = (event.source.groupId) ? event.source.groupId : event.source.userId;
return eventMessageHandler(event).then(message => {
if(message) {
console.log('Reply :' + JSON.stringify(message));
lineConfig.client.replyMessage(event.replyToken, message)
.catch((err) => {
console.error(err);
});
}
});
});
res.sendStatus(200)
});
app.get('/',(req, res) => {
res.send('hello kafra')
})
// listen on port
const port = process.env.PORT || 3200;
app.listen(port, () => {
console.log(`listening on ${port}`);
firebase.getAppConfig();
});