-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkompose-webhook.js
65 lines (49 loc) · 1.53 KB
/
kompose-webhook.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
global["__basedir"] = __dirname;
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
const port = 3000;
const cors = require("cors");
app.use(cors());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json({ limit: "50mb" }));
app.post('/single-bot', function (req, res) {
console.log("Req body: ", req.body.matchedIntentName);
const replies = {
"Brand-1": {
"Q1-intent": "A1 of Brand-1 from backend",
"Q2-intent": "A2 of Brand-1 from backend"
},
"Brand-2": {
"Q1-intent": "A1 of Brand-2 from backend",
"Q2-intent": "A2 of Brand-2 from backend"
},
};
const reply = replies[req.body.metadata.KM_CHAT_CONTEXT.brand][req.body.matchedIntentName]
if (reply) {
return res.status(200).send([{
"platform": "kommunicate",
"message": reply
}]);
}
return res.status(200).end();
});
app.post('/welcome', function (req, res) {
console.log("Req body: ", req.body);
return res.status(200).send(response);
});
app.post('/welcome', function (req, res) {
console.log("Req body: ", req.body);
return res.status(200).send(response);
});
app.use((err, req, res, next) => {
console.log("executing error handler", err);
return res.status(500).send(err);
});
function startApp() {
app.listen(port, function() {
console.log("Express server listening on port : " + port);
});
}
startApp();
module.exports = app;