Skip to content

Instantly share code, notes, and snippets.

@LucioMSP
Created February 8, 2019 02:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LucioMSP/dad3414e6811ee782728e59a183ac37f to your computer and use it in GitHub Desktop.
Save LucioMSP/dad3414e6811ee782728e59a183ac37f to your computer and use it in GitHub Desktop.
Piropos Mexicanos
{
"interactionModel": {
"languageModel": {
"invocationName": "piropos mexicanos",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": [
"cancela eso",
"olvidalo",
"cancela"
]
},
{
"name": "AMAZON.HelpIntent",
"samples": [
"puedes ayudarme",
"ayudame",
"ayuda"
]
},
{
"name": "AMAZON.StopIntent",
"samples": [
"para por favor",
"para",
"detente"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": [
"regresa al inicio"
]
},
{
"name": "PiropoIntent",
"slots": [],
"samples": [
"dime un piropo",
"dime una piropo mexicano",
"cuéntame un piropo",
"cuéntame un piropo mexicano",
"cuéntame otro",
"dame un piropo",
"dame un piropo"
]
}
],
"types": []
}
}
}
//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_START)
.reprompt(" " +HELP_REPROMPT)
.getResponse();
},
};
const PiropoHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest'
&& request.intent.name === 'PiropoIntent';
},
handle(handlerInput) {
const factArr = data;
const factIndex = Math.floor(Math.random() * factArr.length);
const randomFact = factArr[factIndex];
const speechOutput = GET_FACT_MESSAGE + randomFact;
return handlerInput.responseBuilder
.speak(speechOutput + " " +HELP_REPROMPT)
.reprompt(HELP_REPROMPT)
.withSimpleCard(SKILL_NAME, randomFact)
.getResponse();
},
};
const HelpHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest'
&& request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
return handlerInput.responseBuilder
.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 Piropos Mexicanos. " ;
const SKILL_NAME = 'Piropos Mexicanos';
const GET_FACT_MESSAGE = 'El mejor piropo mexicano es: ';
const HELP_MESSAGE_START = 'Para comenzar puedes decir: dime un piropo mexicano... o simplemente para detenerme solo di: ¡Cancela!... entonces, ¿Cómo te puedo ayudar?';
const HELP_REPROMPT = 'Si quieres escuchar otro piropo solo hazmelo saber diciendo: dime un piropo, o para detenerme: Cancela, ¿cómo te puedo ayudar?';
const STOP_MESSAGE = '¡El cielo ha perdido un ángel, hasta luego!';
const data = [
//TODO agrega tu contenido de aqui...
'Todavía hay angelitas y lo mejor es que son mexicanas',
'Ojalá y fueras quesadilla, para comerte a mordidas...',
'Bendito sea el camión que trajo el cemento para crear el pavimento, donde esta parado este monumento',
'¿Cómo hacen los bistecitos? sssshhhhh...',
'Yo Querétaro mi Chilpancingo Acapulco en tu Culiacán aunque Zacatecas tu Cacahuamilpa',
];
const skillBuilder = Alexa.SkillBuilders.standard();
exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
PiropoHandler,
HelpHandler,
ExitHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment