User: Open [skill name]
Alexa: [says random fact]
User: Spin
Alexa: [says random fact]
const enData = { | |
translation: { | |
SKILL_NAME: 'Space Facts', | |
WELCOME_MESSAGE: 'Welcome to the space facts game. You can spin the wheel to hear a random fact. Would you like to play?', | |
GET_FACT_MESSAGE: 'Here\'s your fact: ', | |
HELP_MESSAGE: 'You can say tell me a space fact, or, you can say exit... What can I help you with?', | |
HELP_REPROMPT: 'What can I help you with?', | |
FALLBACK_MESSAGE: 'The Space Facts skill can\'t help you with that. It can help you discover facts about space if you say tell me a space fact. What can I help you with?', | |
FALLBACK_REPROMPT: 'What can I help you with?', | |
ERROR_MESSAGE: 'Sorry, an error occurred.', | |
STOP_MESSAGE: 'Goodbye!', | |
FACTS: | |
[ | |
'A year on Mercury is just 88 days long.', | |
'Despite being farther from the Sun, Venus experiences higher temperatures than Mercury.', | |
'On Mars, the Sun appears about half the size as it does on Earth.', | |
'Jupiter has the shortest day of all the planets.', | |
'The Sun is an almost perfect sphere.', | |
], | |
}, | |
}; |
const GetNewFactHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
// checks request type | |
return request.type === 'LaunchRequest' | |
|| (request.type === 'IntentRequest' | |
&& request.intent.name === 'GetNewFactIntent'); | |
}, | |
handle(handlerInput) { | |
const requestAttributes = handlerInput.attributesManager.getRequestAttributes(); | |
// gets a random fact by assigning an array to the variable | |
// the random item from the array will be selected by the i18next library | |
// the i18next library is set up in the Request Interceptor | |
var speakOutput; | |
// For a launch request, we only state the welcome message. | |
if (request.type === 'LaunchRequest' || (request.type === 'IntentRequest') { | |
speakOutput = requestAttributes.t('WELCOME_MESSAGE'); | |
} else { | |
const randomFact = requestAttributes.t('FACTS'); | |
// concatenates a standard message with the random fact | |
speakOutput = requestAttributes.t('GET_FACT_MESSAGE') + randomFact; | |
} | |
return handlerInput.responseBuilder | |
.speak(speakOutput) | |
// Uncomment the next line if you want to keep the session open so you can | |
// ask for another fact without first re-opening the skill | |
// .reprompt(requestAttributes.t('HELP_REPROMPT')) | |
.withSimpleCard(requestAttributes.t('SKILL_NAME'), randomFact) | |
.getResponse(); | |
}, | |
}; |