Last active
December 14, 2018 18:38
-
-
Save softwarechido/073aa2e3e131856d9afade57edd79fa7 to your computer and use it in GitHub Desktop.
Alexa, abre ayudante de santa y pide un mensaje para Carolina
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 MensajeDeSantaHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'IntentRequest' | |
&& request.intent.name === 'MensajeDeSantaIntent'; | |
}, | |
handle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
var nombre = request.intent.slots.nombre.value; | |
const speechOutput = | |
"<say-as interpret-as='interjection'>jo jojojojó</say-as> <break strength='strong'/>"+ | |
"<say-as interpret-as='interjection'>Feliz Navidad</say-as> <break strength='strong'/>"+ | |
"He encontrado este mensaje para ti."+ | |
"<voice name='Enrique'>Hola" + nombre + "</voice>" + | |
"<audio src='https://s3.amazonaws.com/missonidos/MensajeDeSantaIntro.mp3'/> " + | |
"<voice name='Enrique'> muy bien, felicitaciones </voice>"+ | |
" <break strength='strong'/> Un mensaje de Santa!! <say-as interpret-as='interjection'>qué alegría</say-as> "+ | |
HELP_MESSAGE; | |
const textOutput = "Mensaje de Santa" | |
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, un mensaje de santa 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, | |
MensajeDeSantaHandler, | |
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" | |
] | |
}, | |
{ | |
"name": "MensajeDeSantaIntent", | |
"slots": [ | |
{ | |
"name": "nombre", | |
"type": "AMAZON.FirstName" | |
} | |
], | |
"samples": [ | |
"mensaje de santa para {nombre}", | |
"aviso para {nombre}", | |
"mensaje de navidad para {nombre}", | |
"mensaje para {nombre}", | |
"quiero un mensaje para {nombre}" | |
] | |
} | |
], | |
"types": [] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment