-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (32 loc) · 1.15 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
'use strict';
// REQUIREMENTS
const bodyParser = require('body-parser');
const server = require('express')();
const request = require('request');
const Card = require('dialogflow-fulfillment').Card;
var io = require("./io.js");
// INIT
server.use(bodyParser.urlencoded({
extended: true
}));
server.use(bodyParser.json());
// SERVER POST ACTIONS
server.post('/answers', (request, response) => {
// Debug
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
console.log('Intent name' + request.body.result.metadata.intentName);
// 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);
}
});
// LISTEN
server.listen((process.env.PORT || 8000), () => {
console.log("Server is up and running...");
});