-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
30 lines (24 loc) · 948 Bytes
/
server.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
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(express.static('public'));
app.use(bodyParser.json());
// To give out some informations on the current project
app.get('/', function(request, response) {
response.sendFile(__dirname + '/views/index.html');
});
// the DialogFlow fulfillment endpoint
app.post('/', function(request, response) {
const dialogflowRequest = request.body;
const queryResult = dialogflowRequest.queryResult;
const whatTheUserSaid = queryResult.queryText;
const entity = queryResult.parameters.fruits;
const afterTheEntity = whatTheUserSaid.split(entity).pop();
return response.json({
fulfillmentText: `What was said after the captured entity: "${afterTheEntity}"`
});
});
// listen for requests :)
var listener = app.listen(process.env.PORT, function() {
console.log('Your app is listening on port ' + listener.address().port);
});