Last active
December 14, 2018 18:16
-
-
Save softwarechido/d705a3f4551869937d2612ffbcddf77d to your computer and use it in GitHub Desktop.
V1: Alexa, abre ayudante de santa y dame una opción de regalo
This file contains 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 | |
const Alexa = require('ask-sdk'); | |
const LaunchRequestHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'LaunchRequest' | |
}, | |
handle(handlerInput) { | |
return handlerInput.responseBuilder | |
.speak(WELCOME_MESSAGE+" "+HELP_MESSAGE) | |
.withSimpleCard(SKILL_NAME) | |
.reprompt(HELP_REPROMPT) | |
.getResponse(); | |
}, | |
}; | |
const IdeaDeRegaloHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'IntentRequest' | |
&& request.intent.name === 'IdeaDeRegaloIntent'; | |
}, | |
handle(handlerInput) { | |
const ideas = ["<lang xml:lang='en-US'>Echo</lang>", "<lang xml:lang='en-US'>Echo Dot</lang>", "<lang xml:lang='en-US'>Echo Spot</lang>"]; | |
const ideasArr = ideas; | |
const ideasIndex = Math.floor(Math.random() * ideasArr.length); | |
const randomIdea = ideasArr[ideasIndex]; | |
const speechOutput = PRE_GIFT_MESSAGE + randomIdea + POST_GIFT_MESSAGE + HELP_MESSAGE; | |
const textOutput = "Idea de Regalo"; | |
return handlerInput.responseBuilder | |
.speak(speechOutput) | |
.reprompt(HELP_REPROMPT) | |
.withSimpleCard(SKILL_NAME, textOutput) | |
.getResponse(); | |
}, | |
}; | |
const HelpHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'IntentRequest' | |
&& request.intent.name === 'AMAZON.HelpIntent'; | |
}, | |
handle(handlerInput) { | |
return handlerInput.responseBuilder | |
.speak(HELP_MESSAGE) | |
.reprompt(HELP_REPROMPT) | |
.getResponse(); | |
}, | |
}; | |
const ExitHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'IntentRequest' | |
&& (request.intent.name === 'AMAZON.CancelIntent' | |
|| request.intent.name === 'AMAZON.StopIntent'); | |
}, | |
handle(handlerInput) { | |
return handlerInput.responseBuilder | |
.speak(STOP_MESSAGE) | |
.getResponse(); | |
}, | |
}; | |
const SessionEndedRequestHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'SessionEndedRequest'; | |
}, | |
handle(handlerInput) { | |
console.log(`Se ha terminado la sesión por las siguientes causas: ${handlerInput.requestEnvelope.request.reason}`); | |
return handlerInput.responseBuilder.getResponse(); | |
}, | |
}; | |
const ErrorHandler = { | |
canHandle() { | |
return true; | |
}, | |
handle(handlerInput, error) { | |
console.log(`Error handled: ${error.message}`); | |
return handlerInput.responseBuilder | |
.speak('<say-as interpret-as="interjection">épale ocurrió un error</say-as>') | |
.reprompt('Lo siento, ocurrió un error') | |
.getResponse(); | |
}, | |
}; | |
const WELCOME_MESSAGE= "¡Hola! bienvenido a ayudante de santa. <audio src='soundbank://soundlibrary/foley/amzn_sfx_sleigh_bells_01'/>" | |
const SKILL_NAME = 'Ayudante de Santa'; | |
const PRE_GIFT_MESSAGE = '<s>Yo pediría </s>'; | |
const POST_GIFT_MESSAGE = '<s>es una excelente opción para aprender, jugar y divertirse. ¿No? </s>'; | |
const HELP_MESSAGE = '<s>te puedo dar ideas de regalos, o para detenerme puedes decir: ¡Cancela!... ¿Cómo te puedo ayudar?</s>'; | |
const HELP_REPROMPT = '¿Cómo te puedo ayudar?'; | |
const STOP_MESSAGE = '<s>Adios y <say-as interpret-as="interjection">felices fiestas</say-as> </s>'; | |
const skillBuilder = Alexa.SkillBuilders.standard(); | |
exports.handler = skillBuilder | |
.addRequestHandlers( | |
LaunchRequestHandler, | |
IdeaDeRegaloHandler, | |
HelpHandler, | |
ExitHandler, | |
SessionEndedRequestHandler | |
) | |
.addErrorHandlers(ErrorHandler) | |
.lambda(); |
This file contains 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": "ayudante de santa", | |
"intents": [ | |
{ | |
"name": "AMAZON.CancelIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.HelpIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.StopIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "AMAZON.NavigateHomeIntent", | |
"samples": [] | |
}, | |
{ | |
"name": "IdeaDeRegaloIntent", | |
"slots": [], | |
"samples": [ | |
"alternativas de regalo", | |
"opciones de regalo", | |
"opción de regalo", | |
"qué debo pedir", | |
"sugerencia de obsequio", | |
"sugerencia de regalo", | |
"dame un regalo", | |
"un regalo", | |
"pide un regalo" | |
] | |
} | |
], | |
"types": [] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment