|
@@ -0,0 +1,554 @@
|
|
1
|
+# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+# This sample demonstrates handling intents from an Alexa skill using the Alexa Skills Kit SDK for Python.
|
|
4
|
+# Please visit https://alexa.design/cookbook for additional examples on implementing slots, dialog management,
|
|
5
|
+# session persistence, api calls, and more.
|
|
6
|
+# This sample is built using the handler classes approach in skill builder.
|
|
7
|
+
|
|
8
|
+import requests
|
|
9
|
+import csv
|
|
10
|
+import logging
|
|
11
|
+import ask_sdk_core.utils as ask_utils
|
|
12
|
+
|
|
13
|
+from ask_sdk_core.skill_builder import SkillBuilder
|
|
14
|
+from ask_sdk_core.dispatch_components import AbstractRequestHandler
|
|
15
|
+from ask_sdk_core.dispatch_components import AbstractExceptionHandler
|
|
16
|
+from ask_sdk_core.handler_input import HandlerInput
|
|
17
|
+
|
|
18
|
+from ask_sdk_model import Response
|
|
19
|
+
|
|
20
|
+logger = logging.getLogger(__name__)
|
|
21
|
+logger.setLevel(logging.INFO)
|
|
22
|
+
|
|
23
|
+global ordernum
|
|
24
|
+ordernum = 0
|
|
25
|
+
|
|
26
|
+class LaunchRequestHandler(AbstractRequestHandler):
|
|
27
|
+ """Handler for Skill Launch."""
|
|
28
|
+ def can_handle(self, handler_input):
|
|
29
|
+ # type: (HandlerInput) -> bool
|
|
30
|
+ return ask_utils.is_request_type("LaunchRequest")(handler_input)
|
|
31
|
+
|
|
32
|
+ def handle(self, handler_input):
|
|
33
|
+ # type: (HandlerInput) -> Response
|
|
34
|
+ speak_output = "Welcome to Linguini."
|
|
35
|
+
|
|
36
|
+ return (
|
|
37
|
+ handler_input.response_builder
|
|
38
|
+ .speak(speak_output)
|
|
39
|
+ .ask(speak_output)
|
|
40
|
+ .response
|
|
41
|
+ )
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+#_________________________Alejandro Rodriguez's functions______________________________
|
|
48
|
+
|
|
49
|
+class MenuIntentHandler(AbstractRequestHandler):
|
|
50
|
+ """Handler for Menu Intent."""
|
|
51
|
+ def can_handle(self, handler_input):
|
|
52
|
+ return ask_utils.is_intent_name("MenuIntent")(handler_input)
|
|
53
|
+
|
|
54
|
+ def handle(self, handler_input):
|
|
55
|
+
|
|
56
|
+ url = 'http://136.145.231.48:5000/retrieveMenu'
|
|
57
|
+ menuitems = requests.get(url).json()
|
|
58
|
+
|
|
59
|
+ categories = ""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+ Maxsize = len(menuitems['bebidas']) + len(menuitems['comidas'])
|
|
63
|
+ counter = 0
|
|
64
|
+ for BigCategory in menuitems:
|
|
65
|
+ for category in menuitems[BigCategory]:
|
|
66
|
+
|
|
67
|
+ if counter == (Maxsize - 1):
|
|
68
|
+
|
|
69
|
+ categories += "and " + category + "."
|
|
70
|
+ else:
|
|
71
|
+ categories += category + ", "
|
|
72
|
+
|
|
73
|
+ counter = counter + 1
|
|
74
|
+
|
|
75
|
+ speak_output = "The menu categories are: " + categories
|
|
76
|
+
|
|
77
|
+ return (
|
|
78
|
+ handler_input.response_builder
|
|
79
|
+ .speak(speak_output)
|
|
80
|
+ .ask(speak_output)
|
|
81
|
+ .response
|
|
82
|
+ )
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+class PizzaIntentHandler(AbstractRequestHandler):
|
|
86
|
+ """Handler for Pizza Intent."""
|
|
87
|
+ def can_handle(self, handler_input):
|
|
88
|
+ # type: (HandlerInput) -> bool
|
|
89
|
+
|
|
90
|
+ return ask_utils.is_intent_name("PizzaIntent")(handler_input)
|
|
91
|
+
|
|
92
|
+ def handle(self, handler_input):
|
|
93
|
+ # type: (HandlerInput) -> Response
|
|
94
|
+
|
|
95
|
+ url = 'http://136.145.231.48:5000/retrieveMenu'
|
|
96
|
+ menuitems = requests.get(url).json()
|
|
97
|
+
|
|
98
|
+ categories = ""
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+ Maxsize = len(menuitems['comidas']['Pizza'])
|
|
102
|
+ counter = 0
|
|
103
|
+ for item in menuitems['comidas']['Pizza']:
|
|
104
|
+
|
|
105
|
+ if counter == (Maxsize - 1):
|
|
106
|
+
|
|
107
|
+ categories += "and " + menuitems['comidas']['Pizza'][item]['nombre'] + "."
|
|
108
|
+ else:
|
|
109
|
+ categories += menuitems['comidas']['Pizza'][item]['nombre'] + ", "
|
|
110
|
+
|
|
111
|
+ counter = counter + 1
|
|
112
|
+
|
|
113
|
+ speak_output = "The pizzas categories are: " + categories
|
|
114
|
+
|
|
115
|
+ return (
|
|
116
|
+ handler_input.response_builder
|
|
117
|
+ .speak(speak_output)
|
|
118
|
+ .ask(speak_output)
|
|
119
|
+ .response
|
|
120
|
+ )
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+class PastaIntentHandler(AbstractRequestHandler):
|
|
126
|
+ """Handler for Pasta Intent."""
|
|
127
|
+ def can_handle(self, handler_input):
|
|
128
|
+ # type: (HandlerInput) -> bool
|
|
129
|
+
|
|
130
|
+ return ask_utils.is_intent_name("PastaIntent")(handler_input)
|
|
131
|
+
|
|
132
|
+ def handle(self, handler_input):
|
|
133
|
+ # type: (HandlerInput) -> Response
|
|
134
|
+
|
|
135
|
+ url = 'http://136.145.231.48:5000/retrieveMenu'
|
|
136
|
+ menuitems = requests.get(url).json()
|
|
137
|
+
|
|
138
|
+ categories = ""
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+ Maxsize = len(menuitems['comidas']['Pasta'])
|
|
142
|
+ counter = 0
|
|
143
|
+ for item in menuitems['comidas']['Pasta']:
|
|
144
|
+
|
|
145
|
+ if counter == (Maxsize - 1):
|
|
146
|
+
|
|
147
|
+ categories += "and " + menuitems['comidas']['Pasta'][item]['nombre'] + "."
|
|
148
|
+ else:
|
|
149
|
+ categories += menuitems['comidas']['Pasta'][item]['nombre'] + ", "
|
|
150
|
+
|
|
151
|
+ counter = counter + 1
|
|
152
|
+
|
|
153
|
+ speak_output = "The pastas categories are: " + categories
|
|
154
|
+ return (
|
|
155
|
+ handler_input.response_builder
|
|
156
|
+ .speak(speak_output)
|
|
157
|
+ .ask(speak_output)
|
|
158
|
+ .response
|
|
159
|
+ )
|
|
160
|
+
|
|
161
|
+class HamburgerIntentHandler(AbstractRequestHandler):
|
|
162
|
+ """Handler for Pasta Intent."""
|
|
163
|
+ def can_handle(self, handler_input):
|
|
164
|
+ # type: (HandlerInput) -> bool
|
|
165
|
+
|
|
166
|
+ return ask_utils.is_intent_name("HamburgerIntent")(handler_input)
|
|
167
|
+
|
|
168
|
+ def handle(self, handler_input):
|
|
169
|
+ # type: (HandlerInput) -> Response
|
|
170
|
+
|
|
171
|
+ url = 'http://136.145.231.48:5000/retrieveMenu'
|
|
172
|
+ menuitems = requests.get(url).json()
|
|
173
|
+
|
|
174
|
+ categories = ""
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+ Maxsize = len(menuitems['comidas']['Hamburguesa'])
|
|
178
|
+ counter = 0
|
|
179
|
+ for item in menuitems['comidas']['Hamburguesa']:
|
|
180
|
+
|
|
181
|
+ if counter == (Maxsize - 1):
|
|
182
|
+
|
|
183
|
+ categories += "and " + menuitems['comidas']['Hamburguesa'][item]['nombre'] + "."
|
|
184
|
+ else:
|
|
185
|
+ categories += menuitems['comidas']['Hamburguesa'][item]['nombre'] + ", "
|
|
186
|
+
|
|
187
|
+ counter = counter + 1
|
|
188
|
+
|
|
189
|
+ speak_output = "The Hamburger categories are: " + categories
|
|
190
|
+ return (
|
|
191
|
+ handler_input.response_builder
|
|
192
|
+ .speak(speak_output)
|
|
193
|
+ .ask(speak_output)
|
|
194
|
+ .response
|
|
195
|
+ )
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+class DrinksIntentHandler(AbstractRequestHandler):
|
|
201
|
+ """Handler for Pasta Intent."""
|
|
202
|
+ def can_handle(self, handler_input):
|
|
203
|
+ # type: (HandlerInput) -> bool
|
|
204
|
+
|
|
205
|
+ return ask_utils.is_intent_name("DrinkIntent")(handler_input)
|
|
206
|
+
|
|
207
|
+ def handle(self, handler_input):
|
|
208
|
+ # type: (HandlerInput) -> Response
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+ url = 'http://136.145.231.48:5000/retrieveMenu'
|
|
212
|
+ menuitems = requests.get(url).json()
|
|
213
|
+
|
|
214
|
+ categories = ""
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+ Maxsize = len(menuitems['bebidas'][''])
|
|
218
|
+ counter = 0
|
|
219
|
+ for item in menuitems['comidas']['Hamburguesa']:
|
|
220
|
+
|
|
221
|
+ if counter == (Maxsize - 1):
|
|
222
|
+
|
|
223
|
+ categories += "and " + menuitems['comidas']['Hamburguesa'][item]['nombre'] + "."
|
|
224
|
+ else:
|
|
225
|
+ categories += menuitems['comidas']['Hamburguesa'][item]['nombre'] + ", "
|
|
226
|
+
|
|
227
|
+ counter = counter + 1
|
|
228
|
+
|
|
229
|
+ speak_output = "The Hamburger categories are: " + categories
|
|
230
|
+ return (
|
|
231
|
+ handler_input.response_builder
|
|
232
|
+ .speak(speak_output)
|
|
233
|
+ .ask(speak_output)
|
|
234
|
+ .response
|
|
235
|
+ )
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+#________________________________________________________________
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+#Esta proxima seccion de codigo fue hecha por Pablo Loyola
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+class LinguiniOrderFoodIntentHandler(AbstractRequestHandler):
|
|
245
|
+ """Handler for Linguini Order Food Intent."""
|
|
246
|
+ global ordernum
|
|
247
|
+ ordernum = ordernum + 1
|
|
248
|
+ global food_dict
|
|
249
|
+ global order
|
|
250
|
+ def can_handle(self, handler_input):
|
|
251
|
+ # type: (HandlerInput) -> bool
|
|
252
|
+ return ask_utils.is_intent_name("LinguiniOrderFoodIntent")(handler_input)
|
|
253
|
+
|
|
254
|
+ def handle(self, handler_input):
|
|
255
|
+ # type: (HandlerInput) -> Response
|
|
256
|
+ slots = handler_input.request_envelope.request.intent.slots
|
|
257
|
+ food_type = slots["food_type"].value
|
|
258
|
+ food_category = slots["food_category"].value
|
|
259
|
+ speak_output = f"One {food_type} {food_category} added to your order. What else would you like to add?"
|
|
260
|
+ food = f"{food_type} {food_category}"
|
|
261
|
+
|
|
262
|
+ if food == "gardenia pasta":
|
|
263
|
+ orderstr = 'orden' + str(ordernum)
|
|
264
|
+ order[orderstr] = 2
|
|
265
|
+ else:
|
|
266
|
+ orderstr = 'orden' + str(ordernum)
|
|
267
|
+ order[ordernum] = 1
|
|
268
|
+
|
|
269
|
+ if food in order_names:
|
|
270
|
+ order_names[food] += 1
|
|
271
|
+ else:
|
|
272
|
+ order_names[food] = 1
|
|
273
|
+
|
|
274
|
+ handler_input.response_builder.speak(speak_output).ask("What else would you like to add?")
|
|
275
|
+ return (handler_input.response_builder.response)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+class LinguiniOrderDrinkIntentHandler(AbstractRequestHandler):
|
|
279
|
+ """Handler for Linguini Order Drink Intent."""
|
|
280
|
+ global ordernum
|
|
281
|
+ ordernum = ordernum + 1
|
|
282
|
+ global drink_dict
|
|
283
|
+ global order
|
|
284
|
+ global order_names
|
|
285
|
+ def can_handle(self, handler_input):
|
|
286
|
+ # type: (HandlerInput) -> bool
|
|
287
|
+ return ask_utils.is_intent_name("LinguiniOrderDrinkIntent")(handler_input)
|
|
288
|
+
|
|
289
|
+ def handle(self, handler_input):
|
|
290
|
+ # type: (HandlerInput) -> Response
|
|
291
|
+ slots = handler_input.request_envelope.request.intent.slots
|
|
292
|
+ drink_type = slots["drink_type"].value
|
|
293
|
+ speak_output = f"One {drink_type} added to your order. What else would you like to add?"
|
|
294
|
+
|
|
295
|
+ if drink_type == "water":
|
|
296
|
+ orderstr = 'orden' + str(ordernum)
|
|
297
|
+ order[orderstr] = 10
|
|
298
|
+ else:
|
|
299
|
+ orderstr = 'orden' + str(ordernum)
|
|
300
|
+ order[orderstr] = 9
|
|
301
|
+
|
|
302
|
+ if drink_type in order_names:
|
|
303
|
+ order_names[drink_type] += 1
|
|
304
|
+ else:
|
|
305
|
+ order_names[drink_type] = 1
|
|
306
|
+ handler_input.response_builder.speak(speak_output).ask("What else would you like to add?")
|
|
307
|
+ return (handler_input.response_builder.response)
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+class HelpIntentHandler(AbstractRequestHandler):
|
|
311
|
+ """Handler for Help Intent."""
|
|
312
|
+ def can_handle(self, handler_input):
|
|
313
|
+ # type: (HandlerInput) -> bool
|
|
314
|
+ return ask_utils.is_intent_name("AMAZON.HelpIntent")(handler_input)
|
|
315
|
+
|
|
316
|
+ def handle(self, handler_input):
|
|
317
|
+ # type: (HandlerInput) -> Response
|
|
318
|
+ speak_output = "You can say hello to me! How can I help?"
|
|
319
|
+
|
|
320
|
+ return (
|
|
321
|
+ handler_input.response_builder
|
|
322
|
+ .speak(speak_output)
|
|
323
|
+ .ask(speak_output)
|
|
324
|
+ .response
|
|
325
|
+ )
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+class CancelIntentHandler(AbstractRequestHandler):
|
|
329
|
+ """Handler for Cancel Intent."""
|
|
330
|
+ global order
|
|
331
|
+ def can_handle(self, handler_input):
|
|
332
|
+ # type: (HandlerInput) -> bool
|
|
333
|
+ return (ask_utils.is_intent_name("AMAZON.CancelIntent")(handler_input))
|
|
334
|
+
|
|
335
|
+ def handle(self, handler_input):
|
|
336
|
+ # type: (HandlerInput) -> Response
|
|
337
|
+ speak_output = "Your order has been canceled."
|
|
338
|
+ order.clear()
|
|
339
|
+ return (
|
|
340
|
+ handler_input.response_builder
|
|
341
|
+ .speak(speak_output)
|
|
342
|
+ .ask("reprompt")
|
|
343
|
+ .response
|
|
344
|
+ )
|
|
345
|
+
|
|
346
|
+class LinguiniOrderNothingIntentHandler(AbstractRequestHandler):
|
|
347
|
+ """Handler for Stop Intent."""
|
|
348
|
+ def can_handle(self, handler_input):
|
|
349
|
+ # type: (HandlerInput) -> bool
|
|
350
|
+ return (ask_utils.is_intent_name("LinguiniOrderNothingIntent")(handler_input))
|
|
351
|
+
|
|
352
|
+ def handle(self, handler_input):
|
|
353
|
+ # type: (HandlerInput) -> Response
|
|
354
|
+ speak_output = "Alright! Your order is complete. Would you like to review, finish, or cancel your order"
|
|
355
|
+
|
|
356
|
+ return (
|
|
357
|
+ handler_input.response_builder
|
|
358
|
+ .speak(speak_output)
|
|
359
|
+ .ask(speak_output)
|
|
360
|
+ .response
|
|
361
|
+ )
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+class LinguiniOrderReviewIntentHandler(AbstractRequestHandler):
|
|
365
|
+ global order
|
|
366
|
+ """Handler for Hello World Intent."""
|
|
367
|
+ def can_handle(self, handler_input):
|
|
368
|
+ # type: (HandlerInput) -> bool
|
|
369
|
+ return ask_utils.is_intent_name("LinguiniOrderReviewIntent")(handler_input)
|
|
370
|
+
|
|
371
|
+ def handle(self, handler_input):
|
|
372
|
+ # type: (HandlerInput) -> Response
|
|
373
|
+ speak_output = "You have "
|
|
374
|
+ for i in order_names:
|
|
375
|
+ speak_output += f"{order_names[i]} {i}, "
|
|
376
|
+ speak_output = speak_output[:-2]
|
|
377
|
+ speak_output += ". If everything seems okay, say finish to submit order or say cancel to cancel and restart order."
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+ return (
|
|
381
|
+ handler_input.response_builder
|
|
382
|
+ .speak(speak_output)
|
|
383
|
+ .ask("add a reprompt if you want to keep the session open for the user to respond")
|
|
384
|
+ .response
|
|
385
|
+ )
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+class LinguiniOrderFinishIntentHandler(AbstractRequestHandler):
|
|
389
|
+ global order
|
|
390
|
+ global order_names
|
|
391
|
+ """Handler for Hello World Intent."""
|
|
392
|
+ def can_handle(self, handler_input):
|
|
393
|
+ # type: (HandlerInput) -> bool
|
|
394
|
+ return ask_utils.is_intent_name("LinguiniOrderFinishIntent")(handler_input)
|
|
395
|
+
|
|
396
|
+ def handle(self, handler_input):
|
|
397
|
+ # type: (HandlerInput) -> Response
|
|
398
|
+ #Send order to Restaurant lmao
|
|
399
|
+
|
|
400
|
+ full_order = [{'nombre': 'Aranpompano','celular': '(555)-555-5555', 'ordenCompleta': order, 'peticiones': {}}]
|
|
401
|
+ #full_order = [{'nombre': 'Scott Pilgrim','celular': '(555)-555-5555', 'ordenCompleta': {'orden1':1, 'orden2': 10}, 'peticiones': {}}]
|
|
402
|
+
|
|
403
|
+ try:
|
|
404
|
+ r = requests.post('http://136.145.231.48:5000/papelonDeComida', json=full_order)
|
|
405
|
+ except:
|
|
406
|
+ r = None
|
|
407
|
+
|
|
408
|
+ if r == None:
|
|
409
|
+ speak_output = "Sorry, I couldn't connect to the restaurant. Please try again later."
|
|
410
|
+
|
|
411
|
+ elif(r.status_code == 200):
|
|
412
|
+ speak_output = f'Alright! {r.text}'
|
|
413
|
+ else:
|
|
414
|
+ speak_output = "Uh oh! I couldn't place your order, please try again later."
|
|
415
|
+
|
|
416
|
+ #REPLACE THIS WHEN API IS IMPLEMENTED
|
|
417
|
+ order.clear()
|
|
418
|
+ order_names.clear()
|
|
419
|
+ #REPLACE THIS WHEN API IS IMPLEMENTED
|
|
420
|
+
|
|
421
|
+ return (
|
|
422
|
+ handler_input.response_builder
|
|
423
|
+ .speak(speak_output)
|
|
424
|
+ # .ask("add a reprompt if you want to keep the session open for the user to respond")
|
|
425
|
+ .response
|
|
426
|
+ )
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+#________________________________________________________________
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+class HelpIntentHandler(AbstractRequestHandler):
|
|
436
|
+ """Handler for Help Intent."""
|
|
437
|
+ def can_handle(self, handler_input):
|
|
438
|
+ # type: (HandlerInput) -> bool
|
|
439
|
+ return ask_utils.is_intent_name("AMAZON.HelpIntent")(handler_input)
|
|
440
|
+
|
|
441
|
+ def handle(self, handler_input):
|
|
442
|
+ # type: (HandlerInput) -> Response
|
|
443
|
+ speak_output = "Las categorias son: pizzas, pastas, ensaladas, postres y por ultimo las bebidas. Cual desea saber mas?"
|
|
444
|
+
|
|
445
|
+ return (
|
|
446
|
+ handler_input.response_builder
|
|
447
|
+ .speak(speak_output)
|
|
448
|
+ .ask(speak_output)
|
|
449
|
+ .response
|
|
450
|
+ )
|
|
451
|
+
|
|
452
|
+class CancelOrStopIntentHandler(AbstractRequestHandler):
|
|
453
|
+ """Single handler for Cancel and Stop Intent."""
|
|
454
|
+ def can_handle(self, handler_input):
|
|
455
|
+ # type: (HandlerInput) -> bool
|
|
456
|
+ return (ask_utils.is_intent_name("AMAZON.CancelIntent")(handler_input) or
|
|
457
|
+ ask_utils.is_intent_name("AMAZON.StopIntent")(handler_input))
|
|
458
|
+
|
|
459
|
+ def handle(self, handler_input):
|
|
460
|
+ # type: (HandlerInput) -> Response
|
|
461
|
+ speak_output = "Tenga buen dia!"
|
|
462
|
+
|
|
463
|
+ return (
|
|
464
|
+ handler_input.response_builder
|
|
465
|
+ .speak(speak_output)
|
|
466
|
+ .response
|
|
467
|
+ )
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+class SessionEndedRequestHandler(AbstractRequestHandler):
|
|
471
|
+ """Handler for Session End."""
|
|
472
|
+ def can_handle(self, handler_input):
|
|
473
|
+ # type: (HandlerInput) -> bool
|
|
474
|
+ return ask_utils.is_request_type("SessionEndedRequest")(handler_input)
|
|
475
|
+
|
|
476
|
+ def handle(self, handler_input):
|
|
477
|
+ # type: (HandlerInput) -> Response
|
|
478
|
+
|
|
479
|
+ # Any cleanup logic goes here.
|
|
480
|
+
|
|
481
|
+ return handler_input.response_builder.response
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+class IntentReflectorHandler(AbstractRequestHandler):
|
|
485
|
+ """The intent reflector is used for interaction model testing and debugging.
|
|
486
|
+ It will simply repeat the intent the user said. You can create custom handlers
|
|
487
|
+ for your intents by defining them above, then also adding them to the request
|
|
488
|
+ handler chain below.
|
|
489
|
+ """
|
|
490
|
+ def can_handle(self, handler_input):
|
|
491
|
+ # type: (HandlerInput) -> bool
|
|
492
|
+ return ask_utils.is_request_type("IntentRequest")(handler_input)
|
|
493
|
+
|
|
494
|
+ def handle(self, handler_input):
|
|
495
|
+ # type: (HandlerInput) -> Response
|
|
496
|
+ intent_name = ask_utils.get_intent_name(handler_input)
|
|
497
|
+ speak_output = "You just triggered " + intent_name + "."
|
|
498
|
+
|
|
499
|
+ return (
|
|
500
|
+ handler_input.response_builder
|
|
501
|
+ .speak(speak_output)
|
|
502
|
+ # .ask("add a reprompt if you want to keep the session open for the user to respond")
|
|
503
|
+ .response
|
|
504
|
+ )
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+class CatchAllExceptionHandler(AbstractExceptionHandler):
|
|
508
|
+ """Generic error handling to capture any syntax or routing errors. If you receive an error
|
|
509
|
+ stating the request handler chain is not found, you have not implemented a handler for
|
|
510
|
+ the intent being invoked or included it in the skill builder below.
|
|
511
|
+ """
|
|
512
|
+ def can_handle(self, handler_input, exception):
|
|
513
|
+ # type: (HandlerInput, Exception) -> bool
|
|
514
|
+ return True
|
|
515
|
+
|
|
516
|
+ def handle(self, handler_input, exception):
|
|
517
|
+ # type: (HandlerInput, Exception) -> Response
|
|
518
|
+ logger.error(exception, exc_info=True)
|
|
519
|
+
|
|
520
|
+ speak_output = "Sorry, I had trouble doing what you asked, please try again. "
|
|
521
|
+
|
|
522
|
+ return (
|
|
523
|
+ handler_input.response_builder
|
|
524
|
+ .speak(speak_output)
|
|
525
|
+ .ask(speak_output)
|
|
526
|
+ .response
|
|
527
|
+ )
|
|
528
|
+
|
|
529
|
+# The SkillBuilder object acts as the entry point for your skill, routing all request and response
|
|
530
|
+# payloads to the handlers above. Make sure any new handlers or interceptors you've
|
|
531
|
+# defined are included below. The order matters - they're processed top to bottom.
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+sb = SkillBuilder()
|
|
535
|
+
|
|
536
|
+sb.add_request_handler(LaunchRequestHandler())
|
|
537
|
+sb.add_request_handler(DrinksIntentHandler())
|
|
538
|
+sb.add_request_handler(MenuIntentHandler())
|
|
539
|
+sb.add_request_handler(PastaIntentHandler())
|
|
540
|
+sb.add_request_handler(PizzaIntentHandler())
|
|
541
|
+sb.add_request_handler(HamburgerIntentHandler())
|
|
542
|
+sb.add_request_handler(LinguiniOrderFoodIntentHandler())
|
|
543
|
+sb.add_request_handler(LinguiniOrderDrinkIntentHandler())
|
|
544
|
+sb.add_request_handler(LinguiniOrderNothingIntentHandler())
|
|
545
|
+sb.add_request_handler(LinguiniOrderReviewIntentHandler())
|
|
546
|
+sb.add_request_handler(LinguiniOrderFinishIntentHandler())
|
|
547
|
+sb.add_request_handler(HelpIntentHandler())
|
|
548
|
+sb.add_request_handler(CancelOrStopIntentHandler())
|
|
549
|
+sb.add_request_handler(SessionEndedRequestHandler())
|
|
550
|
+sb.add_request_handler(IntentReflectorHandler()) # THIS ONE HAS TO GO LAST
|
|
551
|
+
|
|
552
|
+sb.add_exception_handler(CatchAllExceptionHandler())
|
|
553
|
+
|
|
554
|
+lambda_handler = sb.lambda_handler()
|