-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.js
More file actions
27 lines (21 loc) · 799 Bytes
/
server.js
File metadata and controls
27 lines (21 loc) · 799 Bytes
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
const express = require('express')
const bodyParser = require('body-parser')
const runLogic = require('./src/runLogic')
const sendLogicResult = require('./src/sendLogicResult')
const app = express()
const {PORT = 3022} = process.env
app.use(bodyParser.json())
app.post('/', ({body: {event_type, data}, hostname}, res) => {
console.log(`[${hostname}]: "${event_type}" webhook received from Init.ai`)
if (event_type === 'LogicInvocation') {
runLogic(data)
.then(function (data) {
console.log("DATA: ", data.payload.messages[0]);
return data;
})
.then(sendLogicResult(data.payload))
.catch((error) => {console.log('[ERROR]:\n', error)})
}
res.sendStatus(200)
})
app.listen(PORT, () => console.log(`Webhook server is running on port ${PORT}!`))