Przeglądaj źródła

Alexa (Alejandro part)

Todos los files que componen mi parte del Alexa Skill. Incluye los Json con todas las palabras de activación en ambos idios y la función lambda principal en Python
alejandrororo 4 lat temu
rodzic
commit
88cb75bd26

BIN
Alexa Alejandro/.DS_Store Wyświetl plik


BIN
Alexa Alejandro/interactionModels/.DS_Store Wyświetl plik


+ 141
- 0
Alexa Alejandro/interactionModels/custom/en-US.json Wyświetl plik

@@ -0,0 +1,141 @@
1
+{
2
+  "interactionModel": {
3
+    "languageModel": {
4
+      "invocationName": "full menu",
5
+      "intents": [
6
+        {
7
+          "name": "AMAZON.CancelIntent",
8
+          "samples": []
9
+        },
10
+        {
11
+          "name": "AMAZON.HelpIntent",
12
+          "samples": [
13
+            "Es o Es",
14
+            "Help"
15
+          ]
16
+        },
17
+        {
18
+          "name": "AMAZON.StopIntent",
19
+          "samples": []
20
+        },
21
+        {
22
+          "name": "AMAZON.NavigateHomeIntent",
23
+          "samples": []
24
+        },
25
+        {
26
+          "name": "MenuIntent",
27
+          "slots": [],
28
+          "samples": [
29
+            "Tell me the menu",
30
+            "Menu please",
31
+            "See menu"
32
+          ]
33
+        },
34
+        {
35
+          "name": "PastaIntent",
36
+          "slots": [],
37
+          "samples": [
38
+            "Pastas",
39
+            "Pasta categoria"
40
+          ]
41
+        },
42
+        {
43
+          "name": "PizzaIntent",
44
+          "slots": [],
45
+          "samples": [
46
+            "Pizzas",
47
+            "Pizza categoria"
48
+          ]
49
+        },
50
+        {
51
+          "name": "DessertIntent",
52
+          "slots": [],
53
+          "samples": [
54
+            "categoria de postres",
55
+            "menu de postres",
56
+            "postres"
57
+          ]
58
+        },
59
+        {
60
+          "name": "LinguiniOrderFoodIntent",
61
+          "slots": [],
62
+          "samples": [
63
+            "Order food",
64
+            "Foodie",
65
+            "Hungry"
66
+          ]
67
+        },
68
+        {
69
+          "name": "LinguiniOrderDrinkIntent",
70
+          "slots": [],
71
+          "samples": [
72
+            "add a drink",
73
+            "thirsty",
74
+            "drink",
75
+            "order drink"
76
+          ]
77
+        },
78
+        {
79
+          "name": "LinguiniOrderReviewIntent",
80
+          "slots": [],
81
+          "samples": [
82
+            "review please",
83
+            "review"
84
+          ]
85
+        },
86
+        {
87
+          "name": "LinguiniOrderFinishIntent",
88
+          "slots": [],
89
+          "samples": [
90
+            "Order is finished",
91
+            "Done"
92
+          ]
93
+        },
94
+        {
95
+          "name": "LinguiniOrderNothingIntent",
96
+          "slots": [],
97
+          "samples": [
98
+            "No more"
99
+          ]
100
+        },
101
+        {
102
+          "name": "SaladIntent",
103
+          "slots": [],
104
+          "samples": [
105
+            "Categoria de Ensaladas",
106
+            "Menu de Ensaladas",
107
+            "Ensaladas"
108
+          ]
109
+        },
110
+        {
111
+          "name": "DrinkIntent",
112
+          "slots": [],
113
+          "samples": [
114
+            "Categoria Bebidas",
115
+            "Menu de bebidas",
116
+            "Bebidas"
117
+          ]
118
+        },
119
+        {
120
+          "name": "JokeTestIntent",
121
+          "slots": [],
122
+          "samples": [
123
+            "Chuck Norris Joke",
124
+            "Joke"
125
+          ]
126
+        },
127
+        {
128
+          "name": "HamburgerIntent",
129
+          "slots": [],
130
+          "samples": [
131
+            "Give me a burger",
132
+            "Hamburger category",
133
+            "Hamburgers"
134
+          ]
135
+        }
136
+      ],
137
+      "types": []
138
+    }
139
+  },
140
+  "version": "20"
141
+}

+ 108
- 0
Alexa Alejandro/interactionModels/custom/es-US.json Wyświetl plik

@@ -0,0 +1,108 @@
1
+{
2
+  "interactionModel": {
3
+    "languageModel": {
4
+      "invocationName": "menu completo",
5
+      "intents": [
6
+        {
7
+          "name": "AMAZON.CancelIntent",
8
+          "samples": []
9
+        },
10
+        {
11
+          "name": "AMAZON.HelpIntent",
12
+          "samples": [
13
+            "Ese o Ese",
14
+            "Ayuda"
15
+          ]
16
+        },
17
+        {
18
+          "name": "AMAZON.StopIntent",
19
+          "samples": []
20
+        },
21
+        {
22
+          "name": "AMAZON.NavigateHomeIntent",
23
+          "samples": []
24
+        },
25
+        {
26
+          "name": "MenuIntent",
27
+          "slots": [],
28
+          "samples": [
29
+            "Dime el menu por favor",
30
+            "Menu por favor",
31
+            "ver menu"
32
+          ]
33
+        },
34
+        {
35
+          "name": "PastaIntent",
36
+          "slots": [],
37
+          "samples": [
38
+            "Pastas",
39
+            "Pasta categoria"
40
+          ]
41
+        },
42
+        {
43
+          "name": "PizzaIntent",
44
+          "slots": [],
45
+          "samples": [
46
+            "Pizzas",
47
+            "Categoria pizza"
48
+          ]
49
+        },
50
+        {
51
+          "name": "LinguiniOrderFoodIntent",
52
+          "slots": [],
53
+          "samples": [
54
+            "Ordenar comida",
55
+            "comida",
56
+            "Hambre"
57
+          ]
58
+        },
59
+        {
60
+          "name": "LinguiniOrderDrinkIntent",
61
+          "slots": [],
62
+          "samples": [
63
+            "agregar bebida",
64
+            "sed",
65
+            "bebida",
66
+            "ordernar bebida"
67
+          ]
68
+        },
69
+        {
70
+          "name": "LinguiniOrderReviewIntent",
71
+          "slots": [],
72
+          "samples": [
73
+            "recapitular",
74
+            "recapitulacion"
75
+          ]
76
+        },
77
+        {
78
+          "name": "LinguiniOrderFinishIntent",
79
+          "slots": [],
80
+          "samples": [
81
+            "Orden terminada"
82
+          ]
83
+        },
84
+        {
85
+          "name": "LinguiniOrderNothingIntent",
86
+          "slots": [],
87
+          "samples": [
88
+            "Eso es todo",
89
+            "todo",
90
+            "nada mas",
91
+            "nada"
92
+          ]
93
+        },
94
+        {
95
+          "name": "DrinkIntent",
96
+          "slots": [],
97
+          "samples": [
98
+            "Categoria Bebidas",
99
+            "Menu de bebidas",
100
+            "Bebidas"
101
+          ]
102
+        }
103
+      ],
104
+      "types": []
105
+    }
106
+  },
107
+  "version": "12"
108
+}

+ 554
- 0
Alexa Alejandro/lambda/lambda_function.py Wyświetl plik

@@ -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()

+ 2
- 0
Alexa Alejandro/lambda/requirements.txt Wyświetl plik

@@ -0,0 +1,2 @@
1
+boto3==1.9.216
2
+ask-sdk-core==1.11.0

+ 27
- 0
Alexa Alejandro/lambda/utils.py Wyświetl plik

@@ -0,0 +1,27 @@
1
+import logging
2
+import os
3
+import boto3
4
+from botocore.exceptions import ClientError
5
+
6
+
7
+def create_presigned_url(object_name):
8
+    """Generate a presigned URL to share an S3 object with a capped expiration of 60 seconds
9
+
10
+    :param object_name: string
11
+    :return: Presigned URL as string. If error, returns None.
12
+    """
13
+    s3_client = boto3.client('s3',
14
+                             region_name=os.environ.get('S3_PERSISTENCE_REGION'),
15
+                             config=boto3.session.Config(signature_version='s3v4',s3={'addressing_style': 'path'}))
16
+    try:
17
+        bucket_name = os.environ.get('S3_PERSISTENCE_BUCKET')
18
+        response = s3_client.generate_presigned_url('get_object',
19
+                                                    Params={'Bucket': bucket_name,
20
+                                                            'Key': object_name},
21
+                                                    ExpiresIn=60*1)
22
+    except ClientError as e:
23
+        logging.error(e)
24
+        return None
25
+
26
+    # The response contains the presigned URL
27
+    return response

+ 52
- 0
Alexa Alejandro/skill.json Wyświetl plik

@@ -0,0 +1,52 @@
1
+{
2
+  "manifest": {
3
+    "apis": {
4
+      "custom": {
5
+        "endpoint": {
6
+          "uri": "arn:aws:lambda:us-east-1:381623920890:function:787dd3a0-aeb1-41ef-9966-170ae5c66f73:Release_0"
7
+        },
8
+        "interfaces": [],
9
+        "regions": {
10
+          "NA": {
11
+            "endpoint": {
12
+              "uri": "arn:aws:lambda:us-east-1:381623920890:function:787dd3a0-aeb1-41ef-9966-170ae5c66f73:Release_0"
13
+            }
14
+          },
15
+          "EU": {
16
+            "endpoint": {
17
+              "uri": "arn:aws:lambda:eu-west-1:381623920890:function:787dd3a0-aeb1-41ef-9966-170ae5c66f73:Release_0"
18
+            }
19
+          },
20
+          "FE": {
21
+            "endpoint": {
22
+              "uri": "arn:aws:lambda:us-west-2:381623920890:function:787dd3a0-aeb1-41ef-9966-170ae5c66f73:Release_0"
23
+            }
24
+          }
25
+        }
26
+      }
27
+    },
28
+    "manifestVersion": "1.0",
29
+    "publishingInformation": {
30
+      "category": "KNOWLEDGE_AND_TRIVIA",
31
+      "distributionCountries": [],
32
+      "isAvailableWorldwide": true,
33
+      "locales": {
34
+        "en-US": {
35
+          "description": "Sample Full Description",
36
+          "examplePhrases": [
37
+            "Alexa open hello world",
38
+            "hello",
39
+            "help"
40
+          ],
41
+          "keywords": [],
42
+          "name": "Prueba",
43
+          "summary": "Sample Short Description"
44
+        },
45
+        "es-US": {
46
+          "name": "Prueba"
47
+        }
48
+      },
49
+      "testingInstructions": "Sample Testing Instructions."
50
+    }
51
+  }
52
+}