Last active
December 1, 2025 03:22
-
-
Save alan80avalos/8fffa787fd0b505200ebaba7d4d7abf5 to your computer and use it in GitHub Desktop.
Segunda entrega de codigo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from ask_sdk_core.dispatch_components import AbstractRequestHandler | |
| from ask_sdk_core.utils import is_intent_name | |
| #inicio de bienvenida a el modo cumpleaños y pregunta nombre | |
| class CumpleanosHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("ModeCumpleIntent")(handler_input) | |
| def handle(self, handler_input): | |
| speak = "¡Wujuuu! Bienvenido al modo cumpleaños. ¿Quién es el festejado?" | |
| session_attr = handler_input.attributes_manager.session_attributes | |
| session_attr["last_question"] = "ask_nombre_festejado" | |
| return handler_input.response_builder.speak(speak).ask(speak).response | |
| #Se captura el nombre y se inicia primera accion | |
| class CapturaNombreHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("CapturaNombreIntent")(handler_input) | |
| def handle(self, handler_input): | |
| slots = handler_input.request_envelope.request.intent.slots | |
| nombre = slots["nombreFestejado"].value | |
| session_attr = handler_input.attributes_manager.session_attributes | |
| session_attr["festejado"] = nombre | |
| speak = f""" | |
| ¡Perfecto! Hoy que celebramos a {nombre}. | |
| A la bio, a la bao, a la bim bom ba, | |
| ¡{nombre}! ¡{nombre}! ¡Ra ra ra! | |
| ¿Que te gustaria hacer ahora? | |
| puedo: | |
| - Cantar las mañanitas | |
| - Contar chistes | |
| """ | |
| #<audio src="https://fiesta-audio.s3.amazonaws.com/mananitas.mp3" /> | |
| return handler_input.response_builder.speak(speak).ask("Entonces ¿Qué hacemos para celebrar?").response | |
| #Se pone a cantar las mañanitas | |
| class CantarMananitasHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("CantarMananitasIntent")(handler_input) | |
| def handle(self, handler_input): | |
| session_attr = handler_input.attributes_manager.session_attributes | |
| nombre = session_attr.get("festejado", "el festejado") | |
| speak = f""" | |
| Va. Cantemos las mañanitas para {nombre}" | |
| Estas son las mañanitas... | |
| Demos nuestros mejores deseos a {nombre}!" | |
| </speak>" | |
| """ | |
| return handler_input.response_builder.speak(speak).response | |
| class ChistesCumpleHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("ChistesCumpleIntent")(handler_input) | |
| def handle(self, handler_input): | |
| #Elegira un chiste al azar | |
| chistes = [ | |
| "¿Sabes por qué los cumpleaños siempre tienen globos?............. Porque explotan de emoción.", | |
| "¿Qué hace una torta bailando?...... ¡La torta-ruga!", | |
| "¿Qué le dijo una vela a otra en el pastel?......... No te apagues, que la fiesta sigue." | |
| ] | |
| import random | |
| speak = random.choice(chistes) + " ¿Quieres otro chiste o cantamos las mañanitas?" | |
| return handler_input.response_builder.speak(speak).ask("¿Chistes o mañanitas?").response | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "interactionModel": { | |
| "languageModel": { | |
| "invocationName": "modo fiesta", | |
| "intents": [ | |
| { | |
| "name": "AMAZON.CancelIntent", | |
| "samples": [] | |
| }, | |
| { | |
| "name": "AMAZON.HelpIntent", | |
| "samples": [] | |
| }, | |
| { | |
| "name": "AMAZON.StopIntent", | |
| "samples": [] | |
| }, | |
| { | |
| "name": "AMAZON.NavigateHomeIntent", | |
| "samples": [] | |
| }, | |
| { | |
| "name": "SelectorIntent", | |
| "slots": [ | |
| { | |
| "name": "modo", | |
| "type": "TipoFiesta" | |
| } | |
| ], | |
| "samples": [ | |
| "quiero {modo}", | |
| "vamos a {modo}", | |
| "modo {modo}" | |
| ] | |
| }, | |
| { | |
| "name": "AMAZON.YesIntent", | |
| "samples": [ | |
| "si", | |
| "claro", | |
| "va", | |
| "perfecto", | |
| "simon", | |
| "claro que si", | |
| "por supuesto", | |
| "acepto", | |
| "dale", | |
| "órale", | |
| "sí señor", | |
| "está bien", | |
| "de acuerdo" | |
| ] | |
| }, | |
| { | |
| "name": "AMAZON.NoIntent", | |
| "samples": [ | |
| "no", | |
| "para nada", | |
| "nel", | |
| "cancela", | |
| "nunca", | |
| "no gracias", | |
| "nop", | |
| "nanai", | |
| "mejor no", | |
| "no quiero" | |
| ] | |
| }, | |
| { | |
| "name": "CapturaNombreIntent", | |
| "slots": [ | |
| { | |
| "name": "nombreFestejado", | |
| "type": "AMAZON.SearchQuery" | |
| } | |
| ], | |
| "samples": [ | |
| "el es es {nombreFestejado}", | |
| "ella es {nombreFestejado}", | |
| "es {nombreFestejado}", | |
| "se llama {nombreFestejado}", | |
| "el festejado es {nombreFestejado}", | |
| "es para {nombreFestejado}" | |
| ] | |
| }, | |
| { | |
| "name": "ModeCumpleIntent", | |
| "slots": [], | |
| "samples": [ | |
| "cumpleaños", | |
| "modo cumpleaños", | |
| "vamos a celebrar cumpleaños", | |
| "fiesta de cumpleaños", | |
| "quiero fiesta de cumpleaños" | |
| ] | |
| }, | |
| { | |
| "name": "ModeMexicanaIntent", | |
| "slots": [], | |
| "samples": [ | |
| "noche mexicana", | |
| "modo fiesta mexicana", | |
| "fiesta mexicana", | |
| "celebración mexicana", | |
| "quiero noche mexicana", | |
| "modo mexicano" | |
| ] | |
| }, | |
| { | |
| "name": "ModeNavidadIntent", | |
| "slots": [], | |
| "samples": [ | |
| "modo navidad", | |
| "fiesta de navidad", | |
| "celebración navideña", | |
| "modo fiesta navideña", | |
| "quiero modo navideño" | |
| ] | |
| }, | |
| { | |
| "name": "ModeJuegosIntent", | |
| "slots": [], | |
| "samples": [ | |
| "noche de juegos", | |
| "modo noche de juegos", | |
| "quiero jugar", | |
| "fiesta de juegos", | |
| "vamos a jugar", | |
| "modo juegos" | |
| ] | |
| }, | |
| { | |
| "name": "CantarMananitasIntent", | |
| "slots": [], | |
| "samples": [ | |
| "cantar", | |
| "mejor canta", | |
| "canta mejor", | |
| "las mañanitas", | |
| "pon las mañanitas", | |
| "cantar las mañanitas" | |
| ] | |
| }, | |
| { | |
| "name": "ChistesCumpleIntent", | |
| "slots": [], | |
| "samples": [ | |
| "cuentame un chiste", | |
| "me gusta chistes", | |
| "haber chistes", | |
| "chistes", | |
| "quiero chistes", | |
| "cuentame chistes de cumpleaños", | |
| "contar chistes" | |
| ] | |
| }, | |
| { | |
| "name": "SalirIntent", | |
| "slots": [], | |
| "samples": [ | |
| "cerrar todo", | |
| "cerrar modo noche mexicana", | |
| "cerrar modo noche de juegos", | |
| "cerrar modo navidad", | |
| "cerrar modo fiesta", | |
| "cerrar el mdo", | |
| "hasta luego", | |
| "cerrar modo cumpleaños", | |
| "adios", | |
| "gracias eso es todo", | |
| "ya terminé", | |
| "salir" | |
| ] | |
| }, | |
| { | |
| "name": "ElegirJuegoIntent", | |
| "slots": [ | |
| { | |
| "name": "juego", | |
| "type": "AMAZON.SearchQuery" | |
| } | |
| ], | |
| "samples": [ | |
| "pirino", | |
| "piri nola", | |
| "piri", | |
| "el {juego}", | |
| "un dado", | |
| "dos dados", | |
| "la {juego}", | |
| "me gustaria {juego}", | |
| "dos {juego}", | |
| "dado", | |
| "pirinola" | |
| ] | |
| }, | |
| { | |
| "name": "OtraVezIntent", | |
| "slots": [], | |
| "samples": [ | |
| "sip", | |
| "de una", | |
| "dale", | |
| "de nuevo", | |
| "si", | |
| "sí" | |
| ] | |
| }, | |
| { | |
| "name": "CambiarJuegoIntent", | |
| "slots": [], | |
| "samples": [ | |
| "otro", | |
| "otra cosa", | |
| "otro juego", | |
| "nop", | |
| "no" | |
| ] | |
| }, | |
| { | |
| "name": "DatoMexIntent", | |
| "slots": [], | |
| "samples": [ | |
| "otro dato curioso", | |
| "otro dato", | |
| "un dato curioso", | |
| "un dato", | |
| "dato curioso", | |
| "dato" | |
| ] | |
| }, | |
| { | |
| "name": "AdivinanzaMexIntent", | |
| "slots": [], | |
| "samples": [ | |
| "otra adivinanza", | |
| "la adivina", | |
| "adivina", | |
| "dos adivinanzas", | |
| "las adivinanza ", | |
| "las adivinanzas", | |
| "la adivinanza ", | |
| "una adivinanza ", | |
| "adivinanza " | |
| ] | |
| }, | |
| { | |
| "name": "OtroIntent", | |
| "slots": [], | |
| "samples": [ | |
| "otra adivinanza ", | |
| "otro dato aleatorio", | |
| "otro dato porfavor", | |
| "otro dato", | |
| "otro", | |
| "otro porfavor", | |
| "otro este es de mexicana" | |
| ] | |
| }, | |
| { | |
| "name": "RegresarIntent", | |
| "slots": [], | |
| "samples": [ | |
| "regresa", | |
| "cambiar modo", | |
| "cambiar de modo", | |
| "salir del modo", | |
| "quiero regresar", | |
| "volver al inicio", | |
| "volver", | |
| "regresar" | |
| ] | |
| }, | |
| { | |
| "name": "VillancicoIntent", | |
| "slots": [], | |
| "samples": [ | |
| "villancico porfa", | |
| "unos villancicos", | |
| "para villancico", | |
| "que villancico", | |
| "a villancico", | |
| "un villancico", | |
| "villancico" | |
| ] | |
| } | |
| ], | |
| "types": [ | |
| { | |
| "name": "TipoFiesta", | |
| "values": [ | |
| { | |
| "name": { | |
| "value": "cumpleaños" | |
| } | |
| }, | |
| { | |
| "name": { | |
| "value": "noche mexicana" | |
| } | |
| }, | |
| { | |
| "name": { | |
| "value": "navidad" | |
| } | |
| }, | |
| { | |
| "name": { | |
| "value": "noche de juegos" | |
| } | |
| } | |
| ] | |
| } | |
| ] | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #lambda_function.py | |
| # -*- coding: utf-8 -*- | |
| import logging | |
| #import ask_sdk_core.utils as ask_utils | |
| from ask_sdk_core.skill_builder import SkillBuilder | |
| from ask_sdk_core.dispatch_components import AbstractRequestHandler | |
| from ask_sdk_core.dispatch_components import AbstractExceptionHandler | |
| from ask_sdk_core.handler_input import HandlerInput | |
| from ask_sdk_core.utils import is_request_type, is_intent_name | |
| from ask_sdk_model.response import Response | |
| #importar funciones de otros archivos | |
| #de modo fiesta | |
| from cumpleanos import CumpleanosHandler, CapturaNombreHandler, CantarMananitasHandler, ChistesCumpleHandler | |
| #de modo noche de juegos | |
| from noche_juegos import NocheJuegosHandler, ElegirJuegoHandler, PirinolaHandler, OtraVezHandler, CambiarJuegoHandler, NoIntentHandler | |
| #de mexicana | |
| from mexicana import MexicanaHandler, DatoMexHandler, AdivinanzaMexHandler, OtroHandler | |
| #archivos separados con importacion | |
| #from cumpleanos import CumpleanosHandler | |
| #from mexicana import MexicanaHandler | |
| from navidad import NavidadHandler | |
| #from noche_juegos import NocheJuegosHandler | |
| logger = logging.getLogger(__name__) | |
| logger.setLevel(logging.INFO) | |
| # Lanzamiento | |
| class LaunchRequestHandler(AbstractRequestHandler): | |
| #Manejador para cuando el usuario abre la skill | |
| def can_handle(self, handler_input): | |
| return is_request_type("LaunchRequest")(handler_input) | |
| #Preguntar al usuario que fiesta es su preferencia | |
| def handle(self, handler_input): | |
| #speak = "prueba este es el codigo correcto" | |
| speak = "Bienvenido a la skill fiesta, dime que tipo de fiesta quieres: cumpleaños, noche mexicana, navidad o noche de juegos" | |
| return handler_input.response_builder.speak(speak).ask(speak).response | |
| #Ver que tipo de fiesta quiere el usuario | |
| class SelectorIntentHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("SelectorIntent")(handler_input) | |
| def handle(self, handler_input): | |
| slots = handler_input.request_envelope.request.intent.slots | |
| modo = slots["modo"].value if slots["modo"] else None | |
| if modo is None: | |
| speak = "No entendí qué modo querías. Dime: cumpleaños, noche mexicana, navidad o noche de juegos." | |
| return handler_input.response_builder.speak(speak).ask(speak).response | |
| modo = modo.lower() | |
| if "cumple" in modo: | |
| return CumpleanosHandler().handle(handler_input) | |
| if "mexican" in modo: | |
| return MexicanaHandler().handle(handler_input) | |
| if "navi" in modo: | |
| return NavidadHandler().handle(handler_input) | |
| if "juego" in modo: | |
| return NocheJuegosHandler().handle(handler_input) | |
| speak = "Ese modo no lo tengo todavía, dime: cumpleaños, noche mexicana, navidad o noche de juegos." | |
| return handler_input.response_builder.speak(speak).ask(speak).response | |
| #Usuario quiere regresar al menu | |
| class RegresarHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("RegresarIntent")(handler_input) | |
| def handle(self, handler_input): | |
| session_attr = handler_input.attributes_manager.session_attributes | |
| if "mode" in session_attr: | |
| del session_attr["mode"] | |
| speak = "Listo, volvemos al menu inicial. ¿Qué tipo de fiesta quieres ahora? cumpleaños, noche mexicana, navidad o noche de juegos." | |
| reprompt = "Dime qué tipo de fiesta quieres: cumpleaños, noche mexicana, navidad o noche de juegos." | |
| return handler_input.response_builder.speak(speak).ask(reprompt).response | |
| #quiere salir de la skill | |
| class SalirHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return (is_intent_name("SalirIntent")(handler_input) or | |
| is_intent_name("AMAZON.StopIntent")(handler_input) or | |
| is_intent_name("AMAZON.CancelIntent")(handler_input)) | |
| def handle(self, handler_input): | |
| speak = "Esta bien, ¡nos vemos en la próxima fiesta!" | |
| return handler_input.response_builder.speak(speak).set_should_end_session(True).response | |
| #En caso de que no se alla entendido la respuesta que dio el usuario al menu | |
| class FallbackHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("AMAZON.FallbackIntent")(handler_input) | |
| def handle(self, handler_input): | |
| speak = "No entendi tu respuesta. Solo dime: cumpleaños, noche mexicana, navidad o noche de juegos" | |
| return handler_input.response_builder.speak(speak).ask(speak).response | |
| #Para cueando el usuario decida terminar la interaccion | |
| class ExitHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("AMAZON.CancelIntent")(handler_input) or \ | |
| is_intent_name("AMAZON.StopIntent")(handler_input) | |
| def handle(self, handler_input): | |
| return handler_input.response_builder.speak("Adios, que la fiesta continue").response | |
| sb = SkillBuilder() | |
| # handleres más específicos primero | |
| sb.add_request_handler(LaunchRequestHandler()) | |
| sb.add_request_handler(SelectorIntentHandler()) | |
| #cumpleaños funciones | |
| sb.add_request_handler(CumpleanosHandler()) | |
| sb.add_request_handler(CapturaNombreHandler()) | |
| sb.add_request_handler(CantarMananitasHandler()) | |
| sb.add_request_handler(ChistesCumpleHandler()) | |
| #fiesta mexicana funciones | |
| sb.add_request_handler(MexicanaHandler()) | |
| sb.add_request_handler(DatoMexHandler()) | |
| sb.add_request_handler(AdivinanzaMexHandler()) | |
| sb.add_request_handler(OtroHandler()) | |
| #sb.add_request_handler(OtroHandler()) | |
| #navidad funciones | |
| sb.add_request_handler(NavidadHandler()) | |
| #noche de juegos funciones | |
| sb.add_request_handler(NocheJuegosHandler()) | |
| sb.add_request_handler(ElegirJuegoHandler()) | |
| sb.add_request_handler(PirinolaHandler()) | |
| sb.add_request_handler(OtraVezHandler()) | |
| sb.add_request_handler(CambiarJuegoHandler()) | |
| sb.add_request_handler(NoIntentHandler())##uno por defecto | |
| #sb.add_request_handler(YesIntentHandler()) | |
| #sb.add_request_handler(NoIntentHandler()) | |
| #sb.add_request_handler(HelpIntentHandler()) | |
| #sb.add_request_handler(CancelOrStopIntentHandler()) | |
| #sb.add_request_handler(SessionEndedRequestHandler()) | |
| #sb.add_exception_handler(CatchAllExceptionHandler()) | |
| sb.add_request_handler(RegresarHandler()) | |
| sb.add_request_handler(SalirHandler()) | |
| sb.add_request_handler(FallbackHandler()) | |
| sb.add_request_handler(ExitHandler()) | |
| # AWS LAMBDA | |
| lambda_handler = sb.lambda_handler() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from ask_sdk_core.dispatch_components import AbstractRequestHandler | |
| from ask_sdk_core.utils import is_intent_name | |
| import random | |
| class MexicanaHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("ModeMexicanaIntent")(handler_input) | |
| def handle(self, handler_input): | |
| #Guardamos el estado para que no se equivoque el codigo | |
| attributes_manager = handler_input.attributes_manager | |
| session_attr = attributes_manager.session_attributes | |
| session_attr["mode"] = "mexicana" | |
| speak = "¡Ajúa! Bienvenido al modo noche mexicana. ¿Quieres un dato curioso o una adivinanza" | |
| return handler_input.response_builder.speak(speak).ask(speak).response | |
| #datos random | |
| class DatoMexHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("DatoMexIntent")(handler_input) | |
| def handle(self, handler_input): | |
| datos = [#despues se agregan mas | |
| "¿Sabías que México tiene 68 idiomas oficiales además del español?", | |
| "El chocolate se originó en México gracias a las civilizaciones prehispánicas.", | |
| "La ciudad de México está construida sobre un lago y sigue hundiéndose cada año." | |
| ] | |
| speak = random.choice(datos) + " ¿Quieres otro dato o algo diferente?" | |
| return handler_input.response_builder.speak(speak).ask("¿Otro dato o adivinanza?").response | |
| # | |
| #adivinanzas | |
| class AdivinanzaMexHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("AdivinanzaMexIntent")(handler_input) | |
| def handle(self, handler_input): | |
| adivinanzas = [ | |
| "Blanca por dentro, verde por fuera. Si quieres que te lo diga, espera. ¿Qué es? ....... ¡El aguacate!", | |
| "Agua pasa por mi casa, cate de mi corazón. ¿Qué es? .......... ¡El aguacate!", | |
| ] | |
| speak = random.choice(adivinanzas) + " ¿Quieres otra adivinanza o un dato?" | |
| return handler_input.response_builder.speak(speak).ask("¿Adivinanza o dato?").response | |
| # | |
| class OtroHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("OtroIntent")(handler_input) | |
| def handle(self, handler_input): | |
| session_attr = handler_input.attributes_manager.session_attributes | |
| #Si estamos en modo mexicana seguimos con sus opciones | |
| if session_attr.get("mode") == "mexicana": | |
| speak = "¿Quieres otra adivinanza o un dato?" | |
| return handler_input.response_builder.speak(speak).ask(speak).response | |
| # Si no está en modo mexicana, que responda lo que ya hacía antes | |
| speak = "Parece que hubo un error en la skill" | |
| return handler_input.response_builder.speak(speak).ask(speak).response | |
| # | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from ask_sdk_core.dispatch_components import AbstractRequestHandler | |
| from ask_sdk_core.utils import is_intent_name | |
| import random | |
| class NocheJuegosHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("ModeJuegosIntent")(handler_input) | |
| def handle(self, handler_input): | |
| speak = "Esooo, que inicie la noche donde las amistades se refuerzan o se pierden. ¿Con qué empezamos? ¿Un dado, dos dados, pirinola o botella?" | |
| return handler_input.response_builder.speak(speak).ask(speak).response | |
| #Eleccion del juego | |
| class ElegirJuegoHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("ElegirJuegoIntent")(handler_input) | |
| def handle(self, handler_input): | |
| slots = handler_input.request_envelope.request.intent.slots | |
| #formatear a solo el juego | |
| slot_juego = slots["juego"].value | |
| if slot_juego is None: | |
| speak = "No entendí el juego que elegiste. ¿Quieres pirinola, dado, dos dados o botella?" | |
| return handler_input.response_builder.speak(speak).ask(speak).response | |
| juego = slot_juego.lower().replace("la ", "").replace("el ", "").strip() | |
| session_attr = handler_input.attributes_manager.session_attributes | |
| session_attr["juego_actual"] = juego | |
| #if ("pirinola" or "piri" or "piri nola") in juego:#parece que en voz no detecta pirinola | |
| if any(word in juego for word in ["pirinola", "pi", "pir", "piri", "piri nola", "pirino"]):#parece que en voz no detecta pirinolaaaaaaa | |
| speak = "Vaa perfecto, ahí va la pirinola." | |
| return PirinolaHandler().handle(handler_input) | |
| elif "dado" in juego: | |
| speak = "Perfecto, juegemos a el dado." | |
| return handler_input.response_builder.speak(speak).response | |
| elif "botella" in juego: | |
| speak = "Bien, jugemos a la botella"#falta este caso | |
| return handler_input.response_builder.speak(speak).response | |
| else: | |
| speak = "Mmm no entendí ese juego. ¿Quieres pirinola, un dado, dos dados o botella?" | |
| return handler_input.response_builder.speak(speak).ask(speak).response | |
| # | |
| class PirinolaHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| session_attr = handler_input.attributes_manager.session_attributes | |
| return session_attr.get("juego_actual", "").startswith("pirinola") | |
| def handle(self, handler_input): | |
| opciones = [ | |
| "Toma 1", | |
| "Toma 2", | |
| "Pon 1", | |
| "Pon 2", | |
| "Todos ponen", | |
| "Toma todo" | |
| ] | |
| resultado = random.choice(opciones) | |
| speak = f"Pirinolaaa gira... Resultado: {resultado}. ¿Va de nuevo?" | |
| return handler_input.response_builder.speak(speak).ask("¿Jugamos otra vez o cambiamos de juego?").response | |
| #El usuario quiere jugar de nuevo simulando un while | |
| class OtraVezHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("OtraVezIntent")(handler_input) | |
| def handle(self, handler_input): | |
| session_attr = handler_input.attributes_manager.session_attributes | |
| juego = session_attr.get("juego_actual", None) | |
| if juego == "pirinola": | |
| return PirinolaHandler().handle(handler_input) | |
| speak = "Ok, seguimos. ¿Qué juego ahora?" | |
| return handler_input.response_builder.speak(speak).ask(speak).response | |
| #Otro juego | |
| class CambiarJuegoHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("CambiarJuegoIntent")(handler_input) | |
| def handle(self, handler_input): | |
| speak = "Va, ¿con qué seguimos? ¿Un dado, dos dados, pirinola o botella?" | |
| return handler_input.response_builder.speak(speak).ask(speak).response | |
| #Cuando se diga que no | |
| class NoIntentHandler(AbstractRequestHandler): | |
| def can_handle(self, handler_input): | |
| return is_intent_name("AMAZON.NoIntent")(handler_input) | |
| def handle(self, handler_input): | |
| session_attr = handler_input.attributes_manager.session_attributes | |
| juego = session_attr.get("juego_actual", "") | |
| # Si está jugando pirinola y dice NO → parar pirinola | |
| if juego == "pirinola": | |
| session_attr["juego_actual"] = "" | |
| speak = "Perfecto, dejamos la pirinola por ahora. ¿Quieres cambiar de juego o terminar la noche?" | |
| return handler_input.response_builder.speak(speak).ask("¿Qué hacemos ahora?").response | |
| # Si no hay juego activo → salir | |
| speak = "Perfecto, que siga la fiesta. ¡Hasta la próxima!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment