Skip to content

Instantly share code, notes, and snippets.

@LucioMSP
Created March 26, 2019 22:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save LucioMSP/40689ed1456d5fb75c4594dd65499c70 to your computer and use it in GitHub Desktop.
Save LucioMSP/40689ed1456d5fb75c4594dd65499c70 to your computer and use it in GitHub Desktop.
Alexa, abre frases geeks y dime una frase
{
"interactionModel": {
"languageModel": {
"invocationName": "frases geeks",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": [
"cancela"
]
},
{
"name": "AMAZON.HelpIntent",
"samples": [
"ayuda"
]
},
{
"name": "AMAZON.StopIntent",
"samples": [
"para",
"alto"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": [
"regresa al inicio"
]
},
{
"name": "FraseIntent",
"slots": [],
"samples": [
"dame una frase geek",
"cuéntame una frase geek",
"cuéntame una frase",
"dame una frase",
"dime una frase",
"dime una frase geek"
]
}
],
"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 FraseGeekHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest'
&& request.intent.name === 'FraseIntent';
},
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 Frases Geeks." ;
const SKILL_NAME = 'Frases Geeks';
const GET_FACT_MESSAGE = 'COFFEE.EXE no encontrado – Ponga una taza, presione cualquier tecla y escuche detenidamente: ';
const HELP_MESSAGE_START = 'Para comenzar puedes decir: dime una frase geek... o si deseas detenerme solo di: ¡Cancela!... entonces, ¿Cómo te puedo ayudar?';
const HELP_REPROMPT = 'Si quieres escuchar otra frase solo hazmelo saber diciendo: dime una frase, o para detenerme: Cancela, ¿cómo te puedo ayudar?';
const STOP_MESSAGE = 'Sólo cierra y reinicia - hasta luego!';
const data = [
//TODO - Agrega tu contenido de aqui...
'Bienaventurados los Pesimistas. Por que hacen BACKUPS',
'En un principio el Universo por nosotros conocido, fue una versión beta.',
'Si no consigues encontrar el problema, seguro es el BIOS (Bichito Ignorante Operando Sistema)',
'HardWare: Todo Aquel Artefacto que Resive Nuestros Golpes y SoftWare de código cerrado: La Causa',
'',
'',
'',
'',
'',
'',
'',
];
const skillBuilder = Alexa.SkillBuilders.standard();
exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
FraseGeekHandler,
HelpHandler,
ExitHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment