-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.js
111 lines (90 loc) · 3.5 KB
/
io.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* WEBHOOK IO */
var functions = require("./functions.js");
// SHOW WORKS ACTION
module.exports.showWorks = function showWorks(request, response, askForAdditionalFilters) {
var parameters;
var filterCounter = 0;
// GET PARAMETERS
if (askForAdditionalFilters) {
parameters = request.body.result.parameters;
// COUNT OF THE FILTER SET BY THE USER
for (var key in parameters) {
if (typeof parameters[key] === "string" && parameters[key] !== "") {
filterCounter++;
} else if (typeof parameters[key] !== "string" && parameters[key].length != 0) {
filterCounter++;
}
}
} else {
var contexts = request.body.result.contexts
console.log("*** Retrieving an old context...");
//var context = contexts.filter( context => context["name"] == "works-by-followup");
for (var i = 0; i < contexts.length; i++) {
if (contexts[i].name === "works-by-followup") {
console.log("I found the context");
console.log(contexts[i]);
parameters = contexts[i].parameters;
break;
}
}
}
if (filterCounter <= 2 && askForAdditionalFilters == true) {
return response.json({
speech: "Uhm... you told me few filters. Do you want to add something?",
displayText: "Uhm... you told me few filters. Do you want to add something?"
})
} else {
// YEAR CHECK AND PARSING
var startyear = null;
var endyear = null;
if (parameters["date-period"] !== "") {
startyear = parseInt(parameters["date-period"].split("/")[0]);
endyear = parseInt(parameters["date-period"].split("/")[1]);
// SWAP IF PROVIDED IN THE INVERSE ORDER
if (startyear > endyear) {
var tmp = startyear;
startyear = endyear;
endyear = tmp;
}
}
// ARTIST PARSING
if (parameters["doremus-artist"] == "" && parameters["doremus-artist-prev"] !== "") {
parameters["doremus-artist"] = parameters["doremus-artist-prev"];
}
// DO THE QUERY (WITH ALL THE INFOS)
functions.doWorksByQuery(response, parameters["doremus-artist"],
parameters.number, parameters["doremus-instrument"],
parameters["doremus-strictly"],
startyear,
endyear,
parameters["doremus-genre"]);
}
}
// SHOW PERFORMANCES ACTION
module.exports.showPerformances = function showPerformances(request, response) {
// ACTION COMPLETE (the date has been provided)
if (request.body.result['actionIncomplete'] === false) {
var date = request.body.result.parameters["date-period"];
var place = request.body.result.parameters["geo-city"];
var number = request.body.result.parameters["number"];
var city = "";
if (place !== "") {
city = place.toLowerCase();
}
var num = 1;
if (number !== "") {
num = parseInt(number);
}
var startdate = date.split("/")[0];
var enddate = date.split("/")[1];
// DO THE QUERY (WITH ALL THE INFOS)
functions.doQueryPerformance(response, num, city, startdate, enddate);
}
// ACTION INCOMPLETE (missing date)
else {
return response.json({
speech: "Sure! In which period?",
displayText: "Sure! In which period?"
})
}
}