Skip to content

Instantly share code, notes, and snippets.

@frivas
frivas / index1.py
Last active October 23, 2018 12:55
ASK SDK Imports (Basic). Medium Article. Creating an Alexa Skill Using Python
# -*- coding: utf-8 -*-
from ask_sdk_core.skill_builder import SkillBuilder
from ask_sdk_core.dispatch_components import AbstractRequestHandler, AbstractExceptionHandler
from ask_sdk_core.utils import is_request_type, is_intent_name
from ask_sdk_core.handler_input import HandlerInput
import logging
import six
@frivas
frivas / index2.py
Created October 23, 2018 12:56
ASK SDK Imports (Basic). Medium Article. Creating an Alexa Skill Using Python
sb = SkillBuilder()
@frivas
frivas / index3.py
Created October 23, 2018 12:56
ASK SDK Imports (Basic). Medium Article. Creating an Alexa Skill Using Python
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
@frivas
frivas / index4.py
Last active October 23, 2018 13:00
LaunchRequestHandler. Medium Article. Creating an Alexa Skill Using Python
class LaunchRequestHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
return is_request_type("LaunchRequest")(handler_input)
def handle(self, handler_input):
speechText = "<say-as interpret-as=\"interjection\">Hey Exploradores!</say-as>, espero estéis listos para una nueva aventura. ¿Cuántos objetos queréis buscar hoy?."
rePrompt = "<say-as interpret-as=\"interjection\">Venga exploradores!</say-as>. A la aventura, ¿Cuantos objetos queréis buscar hoy?"
return handler_input.response_builder.speak(speechText).ask(rePrompt).set_should_end_session(False).response
@frivas
frivas / index5.py
Created October 23, 2018 13:00
HelpIntentHandler. Medium Article. Creating an Alexa Skill Using Python
class HelpIntentHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
return is_intent_name("AMAZON.HelpIntent")(handler_input)
def handle(self, handler_input):
speechText = "Bienvenidos a la ayuda de Exploradores Fantásticos!. Sólo debes decirme una número o dejar que decida yo el número de objetos que buscaréis"
return handler_input.response_builder.speak(speechText).response
@frivas
frivas / index6.py
Created October 23, 2018 13:01
CancelAndStopIntentHandler. Medium Article. Creating an Alexa Skill Using Python
class CancelAndStopIntentHandler(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):
speechText = "Hasta la próxima aventura exploradores!."
return handler_input.response_builder.speak(speechText).response
@frivas
frivas / index7.py
Created October 23, 2018 13:01
SessionEndedRequestHandler. Medium Article. Creating an Alexa Skill Using Python
class SessionEndedRequestHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
return is_request_type("SessionEndedRequest")(handler_input)
def handle(self, handler_input):
handler_input.response_builder.response
@frivas
frivas / index8.py
Created October 23, 2018 13:02
AllExceptionsHandler. Medium Article. Creating an Alexa Skill Using Python
class AllExceptionsHandler(AbstractExceptionHandler):
def can_handle(self, handler_input, exception):
return True
def handle(self, handler_input, exception):
speechText = "Lo siento, no he comprendido lo que me has dicho. Di, ayuda, para obtener más información sobre cómo jugar."
return handler_input.response_builder.speak(speechText).response
@frivas
frivas / index9.py
Last active October 23, 2018 15:37
ListItemsIntentHandler. Medium Article. Creating an Alexa Skill Using Python
class ListItemsIntent(AbstractRequestHandler):
def can_handle(self, handler_input):
return is_intent_name("ListItemsIntent")(handler_input)
def handle(self, handler_input):
slots = handler_input.request_envelope.request.intent.slots
defaultObjsToSearch = 3
for slotName, currentSlot in six.iteritems(slots):
if slotName == 'numObj':
@frivas
frivas / index9_1.py
Created October 23, 2018 13:04
ListItemsIntentHandler. Medium Article. Creating an Alexa Skill Using Python
from random import sample