-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
321 lines (273 loc) · 14.5 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
'use strict';
var request = require('request');
//var urllib = require('urllib');
var Alexa = require("alexa-sdk");
var http = require("http");
var https = require("https");
// For detailed tutorial on how to making a Alexa skill,
// please visit us at http://alexa.design/build
exports.handler = function(event, context) {
var alexa = Alexa.handler(event, context);
//skill-id
alexa.appId = 'amzn1.ask.skill.fc654c34-567a-4059-a7d1-c98c8bc4bb98';
alexa.registerHandlers(handlers);
alexa.execute();
};
var handlers = {
'LaunchRequest': function () {
//ask="Welcome to Team. What would you like to know?";
//reprompt= "What would you like to know?";
//this.emit(':ask', ask, reprompt);
this.emit('GetNumber');
},
'Unhandled' : function() {
this.response.speak("Sorry, I didn't get that. You can try: 'alexa, hello world'" +
" or 'alexa, ask hello world my name is awesome Aaron'");
this.emit(':responseReady');
},
'HelloWorldIntent': function () {
this.emit('SayHello');
},
'MyNameIsIntent': function () {
this.emit('SayHelloName');
},
'GetNumberFactIntent': function () {
this.emit('GetNumber');
},
'GetValueFactIntent': function () {
const theNumber = this.event.request.intent.slots.valNumber.value;
var myRequest = parseInt(theNumber);
const url = `http://ft-everkool82.oraclecloud2.dreamfactory.com/api/v2/demo31OST/_table/akash_ticket/${myRequest}?&format-json&api_key=30ee4b81b5435f37a6673717ef639cdc92a03ecc1090d95e76b9e78991928254`;
request.get(url, (error, response, body) => {
let json = JSON.parse(body);
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the body
const theFact = json;
const speechOutput = "Ticket number "+`${theFact.number}`+" has status "+`${theFact.status_id}`;
/*
if (speechOutput == 1) {
this.response.speak("Your Ticket number "+`${theFact.number}`+" Opened");
this.emit(':responseReady');
} else if (speechOutput == 2) {
this.response.speak("Your Ticket number "+`${theFact.number}`+" Resolved");
this.emit(':responseReady');
} else if (speechOutput == 3) {
this.response.speak("Your Ticket number "+`${theFact.number}`+" Closed");
this.emit(':responseReady');
}
else if (speechOutput == 4) {
this.response.speak("Your Ticket number "+`${theFact.number}`+" Archived");
this.emit(':responseReady');
}
else if (speechOutput == 5) {
this.response.speak("Your Ticket number "+`${theFact.number}`+" Deleted");
this.emit(':responseReady');
}
*/
// this.response.cardRenderer(SKILL_NAME, theFact);
this.response.speak(speechOutput + " Would you like another ticket?").listen("Would you like another ticket?");
this.emit(':responseReady');
});
},
'GetNumberIntent': function () {
//const ticket = 2;
//const theNumber = 299740;
const theNumber = this.event.request.intent.slots.getNumber.value;
//var myRequest = String(theNumber);
//var myRequest = parseInt(theNumber);
console.log('value:', theNumber); // Print the user value
//const url = 'http://ft-everkool82.oraclecloud2.dreamfactory.com/api/v2/demo31OST/_table/akash_ticket/?fields=status_id&api_key=30ee4b81b5435f37a6673717ef639cdc92a03ecc1090d95e76b9e78991928254&filter=number='+theNumber;
const url = 'http://ft-everkool82.oraclecloud2.dreamfactory.com/api/v2/demo31OST/_table/akash_ticket?&format-json&filter=number='+theNumber+'&api_key=30ee4b81b5435f37a6673717ef639cdc92a03ecc1090d95e76b9e78991928254';
console.log('url:', url);
// const url = `http://ft-everkool82.oraclecloud2.dreamfactory.com/api/v2/demo31OST/_table/akash_ticket/${myRequest}?&format-json&api_key=30ee4b81b5435f37a6673717ef639cdc92a03ecc1090d95e76b9e78991928254`;
request.get(url, (error, response, body) => {
let json = JSON.parse(body);
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the body
const theFact = json;
const ticket = theFact.resource[0].number;
const speechOutput = theFact.resource[0].status_id;
if (speechOutput == 1) {
this.response.speak("Your Ticket number "+`${ticket}`+" with ticket status, Opened");
this.emit(':responseReady');
} else if (speechOutput == 2) {
this.response.speak("Your Ticket number "+`${ticket}`+" with ticket status, Resolved");
this.emit(':responseReady');
} else if (speechOutput == 3) {
this.response.speak("Your Ticket number "+`${ticket}`+" with ticket status, Closed");
this.emit(':responseReady');
}
else if (speechOutput == 4) {
this.response.speak("Your Ticket number "+`${ticket}`+" with ticket status, Archived");
this.emit(':responseReady');
}
else if (speechOutput == 5) {
this.response.speak("Your Ticket number "+`${ticket}`+" with ticket status, Deleted");
this.emit(':responseReady');
}
//this.response.cardRenderer(SKILL_NAME, theFact);
//this.response.speak(speechOutput + " Would you like another ticket?").listen("Would you like another ticket?");
//this.emit(':responseReady');
});
},
'SayHello': function () {
let self=this;
//let value = 5;
let value = self.event.request.intent.slots.number.value;
var myRequest = parseInt(value);
var options = {
host: 'ft-everkool82.oraclecloud2.dreamfactory.com',
port: 80,
method: 'GET',
path: `/api/v2/demo31OST/_table/akash_ticket/${myRequest}?&format-json&api_key=30ee4b81b5435f37a6673717ef639cdc92a03ecc1090d95e76b9e78991928254`,
json: true
}
var req = http.request(options, res => {
res.setEncoding('utf8');
var returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
var result = JSON.parse(returnData);
/*
if (speechOutput == 1) {
this.response.speak("Your Ticket number "+`${theFact.number}`+" Opened");
this.emit(':responseReady');
} else if (speechOutput == 2) {
this.response.speak("Your Ticket number "+`${theFact.number}`+" Resolved");
this.emit(':responseReady');
} else if (speechOutput == 3) {
this.response.speak("Your Ticket number "+`${theFact.number}`+" Closed");
this.emit(':responseReady');
}
else if (speechOutput == 4) {
this.response.speak("Your Ticket number "+`${theFact.number}`+" Archived");
this.emit(':responseReady');
}
else if (speechOutput == 5) {
this.response.speak("Your Ticket number "+`${theFact.number}`+" Deleted");
this.emit(':responseReady');
}
*/
//callback(result);
self.response.speak(` ${result.number} `+ " Would you like another ticket?").listen("Would you like another ticket?");;
self.emit(':responseReady');
});
});
req.end();
},
/*
'Get': function () {
const theNumber = this.event.request.intent.slots.getNumber.value;
var myRequest = parseInt(theNumber);
const url = 'http://ft-everkool82.oraclecloud2.dreamfactory.com/api/v2/demo31OST/_table/akash_ticket?&filter=number='+myRequest+'&api_key=30ee4b81b5435f37a6673717ef639cdc92a03ecc1090d95e76b9e78991928254';
request.get(url, (error, response, body) => {
let json = JSON.parse(body);
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the body
const theFact = json;
const speechOutput = `${theFact}`;
// this.response.cardRenderer(SKILL_NAME, theFact);
this.response.speak(speechOutput + " Would you like another ticket?").listen("Would you like another ticket?");
this.emit(':responseReady');
});
},
*/
'GetNumber': function () {
const theNumber = this.event.request.intent.slots.theNumber.value;
console.log('value:', theNumber); // Print the user value
//const url = 'http://ft-everkool82.oraclecloud2.dreamfactory.com/api/v2/demo31OST/_table/akash_ticket/?fields=status_id&api_key=30ee4b81b5435f37a6673717ef639cdc92a03ecc1090d95e76b9e78991928254&filter=number='+theNumber;
const url = 'http://ft-everkool82.oraclecloud2.dreamfactory.com/api/v2/demo31OST/_table/akash_ticket?&format-json&filter=number='+theNumber+'&api_key=30ee4b81b5435f37a6673717ef639cdc92a03ecc1090d95e76b9e78991928254';
console.log('url:', url);
// const url = `http://ft-everkool82.oraclecloud2.dreamfactory.com/api/v2/demo31OST/_table/akash_ticket/${myRequest}?&format-json&api_key=30ee4b81b5435f37a6673717ef639cdc92a03ecc1090d95e76b9e78991928254`;
request.get(url, (error, response, body) => {
let json = JSON.parse(body);
console.log('error:', error); // Print the error if one occurred
console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the body
const theFact = json;
const speechOutput = theFact.resource[0].status_id;
const ticket = theFact.resource[0].number;
if (speechOutput == 1) {
this.response.speak("Your Ticket number "+`${ticket}`+" with ticket status, Opened");
this.emit(':responseReady');
} else if (speechOutput == 2) {
this.response.speak("Your Ticket number "+`${ticket}`+" with ticket status, Resolved");
this.emit(':responseReady');
} else if (speechOutput == 3) {
this.response.speak("Your Ticket number "+`${ticket}`+" with ticket status, Closed");
this.emit(':responseReady');
}
else if (speechOutput == 4) {
this.response.speak("Your Ticket number "+`${ticket}`+" with ticket status, Archived");
this.emit(':responseReady');
}
else if (speechOutput == 5) {
this.response.speak("Your Ticket number "+`${ticket}`+" with ticket status, Deleted");
this.emit(':responseReady');
}
//this.response.cardRenderer(SKILL_NAME, theFact);
this.response.speak(speechOutput + " Would you like another ticket?").listen("Would you like another ticket?");
this.emit(':responseReady');
});
},
/*
'GetValue': function (query, callback) {
var options = {
host: 'ft-everkool82.oraclecloud2.dreamfactory.com',
port: 80,
path: '/api/v2/demo31OST/_table/akash_ticket/'+ encodeURIComponent(query)+'?&format-json&api_key=30ee4b81b5435f37a6673717ef639cdc92a03ecc1090d95e76b9e78991928254',
method: 'GET',
json: true
};
var req = http.request(options, res => {
res.setEncoding('utf8');
var responseString = "";
//accept incoming data asynchronously
res.on('data', chunk => {
responseString = responseString + chunk;
});
//return the data when streaming is complete
res.on('end', () => {
//console.log(responseString);
//callback(responseString);
var data = JSON.parse(responseString);
this.response.speak(` ${data.number} `);
this.emit(`${data.number}`);
});
});
req.end();
},
*/
'SayHelloName': function () {
var name = this.event.request.intent.slots.name.value;
this.response.speak('Hello ' + name)
.cardRenderer('hello world', 'hello ' + name);
this.emit(':responseReady');
},
'SessionEndedRequest' : function() {
console.log('Session ended with reason: ' + this.event.request.reason);
},
'AMAZON.StopIntent' : function() {
this.response.speak('Bye');
this.emit(':responseReady');
},
'AMAZON.HelpIntent' : function() {
this.response.speak("You can try: 'alexa, hello world' or 'alexa, ask hello world my" +
" name is awesome Aaron'");
this.emit(':responseReady');
},
'AMAZON.CancelIntent' : function() {
this.response.speak('Bye');
this.emit(':responseReady');
},
'Unhandled' : function() {
this.response.speak("Sorry, I didn't get that. You can try: 'alexa, hello world'" +
" or 'alexa, ask hello world my name is awesome Aaron'");
this.emit(':responseReady');
}
};