-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (37 loc) · 1.22 KB
/
app.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
44
45
require('module-alias/register')
const config = require('config')
const utils = require('@utils')
const webhookPort = config.get('app.webhook.port')
const webhookSecret = config.get('app.webhook.secret')
const controllers = require('./controllers')
const services = require('@services')
const response = utils.lineMessageSender
const linebotHelper = utils.linebotHelper
linebotHelper.listen(`/linewebhook?secret=${webhookSecret}`, webhookPort, function () {
console.info(`====== [WEBHOOK] Line Bot Webhook Endpoint is running on ${webhookPort} =======`)
})
linebotHelper.on('message', async (event) => {
response.data = event
const messageType = event.message.type
switch (messageType) {
case 'text':
controllers.text({ event, response })
break
case 'location':
controllers.location({ event, response })
break
}
})
linebotHelper.on('follow', (event) => {
response.data = event
services.userOnFollow({ res: response })
})
;(async () => {
try {
await require('./database/models').testConnection()
console.info('=== PostgreSQL is connected ===')
} catch (error) {
console.error(error)
throw new Error('Database Connection Error: Failed to connect to the database.')
}
})()