-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathindex.js
44 lines (34 loc) · 1.27 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
44
'use strict';
// REQUIREMENTS
const bodyParser = require('body-parser');
const express = require('express');
const request = require('request');
var io = require("./io.js");
module.exports = function(port) {
var server = express();
// INIT
server.use(bodyParser.urlencoded({
extended: true
}));
server.use(bodyParser.json());
// SERVER POST ACTIONS
server.post('/answers', (request, response) => {
// console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
// console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
// Run the proper function handler based on the matched Dialogflow intent name
var intent = request.body.result.metadata.intentName;
if (intent === "works-by") {
io.showWorks(request, response, true);
} else if (intent === "works-by - no") {
io.showWorks(request, response, false);
} else if (intent === "find-performance") {
io.showPerformances(request, response);
} else if (intent === "reset") {
io.resetIntent(request, response);
}
});
// LISTEN
server.listen(port, () => {
console.log("info: ** Dialogflow webhook server running on port " + port);
});
}