Skip to content

Instantly share code, notes, and snippets.

@memodoring
Last active September 5, 2018 19:02
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 memodoring/ed95fdf5c3535ca407de850fc51b44d6 to your computer and use it in GitHub Desktop.
Save memodoring/ed95fdf5c3535ca407de850fc51b44d6 to your computer and use it in GitHub Desktop.
Datos del espacio multilenguaje
/* eslint-disable func-names */
/* eslint-disable no-console */
const Alexa = require('ask-sdk');
const ESLaunchRequestHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return (request.type === 'LaunchRequest'
&& request.locale === `es-MX` );
},
handle(handlerInput) {
return handlerInput.responseBuilder
.speak(`Bienvenido a la skill de Memo. Puedes decir 'dame un dato o ayuda ¿Que quieres hacer?'`)
.withSimpleCard(SKILL_NAME, `Bienvenidos`)
.reprompt(`Di, quiero un dato para escuchar un dato del espacio `)
.getResponse();
},
};
const ESGetNewFactHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return (request.type === 'IntentRequest'
&& request.intent.name === 'GetNewFactIntent'
&& request.locale === `es-MX` );
},
handle(handlerInput) {
const factArr = dataES;
const factIndex = Math.floor(Math.random() * factArr.length);
const randomFact = factArr[factIndex];
const speechOutput = randomFact;
const planeta = handlerInput.requestEnvelope.request.intent.slots.planeta.value;
return handlerInput.responseBuilder
.speak(`Aqui esta tu dato de ${planeta}: ${speechOutput}`)
.withSimpleCard(SKILL_NAME, randomFact)
.getResponse();
},
};
const ENGetNewFactHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'LaunchRequest'
|| (request.type === 'IntentRequest'
&& request.intent.name === 'GetNewFactIntent'
&& request.locale === `en-US` );
},
handle(handlerInput) {
const factArr = dataEN;
const factIndex = Math.floor(Math.random() * factArr.length);
const randomFact = factArr[factIndex];
const speechOutput = randomFact;
return handlerInput.responseBuilder
.speak(speechOutput)
.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
.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(`Session ended with reason: ${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('Sorry, an error occurred.')
.reprompt('Sorry, an error occurred.')
.getResponse();
},
};
const SKILL_NAME = 'Space Facts';
const GET_FACT_MESSAGE = 'Here\'s your fact:' ;
const HELP_MESSAGE = 'You can say tell me a space fact, or, you can say exit... What can I help you with?';
const HELP_REPROMPT = 'What can I help you with?';
const STOP_MESSAGE = 'Goodbye!';
const dataES = [
`Estoy en Guadalajara`,
`Ayer estuve en CDMX`,
`Mañana voy a Monterrey`
];
const dataEN = [
'A year on Mercury is just 88 days long.',
'Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.',
'Venus rotates counter-clockwise, possibly because of a collision in the past with an asteroid.',
'On Mars, the Sun appears about half the size as it does on Earth.',
'Earth is the only planet not named after a god.',
'Jupiter has the shortest day of all the planets.',
'The Milky Way galaxy will collide with the Andromeda Galaxy in about 5 billion years.',
'The Sun contains 99.86% of the mass in the Solar System.',
'The Sun is an almost perfect sphere.',
'A total solar eclipse can happen once every 1 to 2 years. This makes them a rare event.',
'Saturn radiates two and a half times more energy into space than it receives from the sun.',
'The temperature inside the Sun can reach 15 million degrees Celsius.',
'The Moon is moving approximately 3.8 cm away from our planet every year.',
];
const skillBuilder = Alexa.SkillBuilders.standard();
exports.handler = skillBuilder
.addRequestHandlers(
ESLaunchRequestHandler,
ESGetNewFactHandler,
ENGetNewFactHandler,
HelpHandler,
ExitHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment