Skip to content

Instantly share code, notes, and snippets.

@anthonymoralez
Last active May 20, 2019 17:45
Show Gist options
  • Save anthonymoralez/2975f15ea4cd4770de60143df26c5141 to your computer and use it in GitHub Desktop.
Save anthonymoralez/2975f15ea4cd4770de60143df26c5141 to your computer and use it in GitHub Desktop.
Part of the Alexa Fact Skill Template

User: Open [skill name]

Alexa: [says random fact]

User: Spin

Alexa: [says random fact]

User: Open [skill name].

Alexa: Welcome to [skill name]. You can spin the wheel. Would you like to play?

User: Spin the wheel.

Alexa: [says random thing]. Would you like to play again?

User: Let's play again!

Alexa: [says random thing]. Should we spin it one more time? ...

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();
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment