Created
September 21, 2020 16:51
-
-
Save vidanov/185d1fdc1f857f2e431a149efd578c71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable func-names */ | |
/* eslint-disable no-console */ | |
const Alexa = require('ask-sdk-core'); | |
const GetNewFactHandler = { | |
canHandle(handlerInput) { | |
const request = handlerInput.requestEnvelope.request; | |
return request.type === 'LaunchRequest' | |
|| (request.type === 'IntentRequest'); | |
}, | |
handle(handlerInput) { | |
const factArr = data; | |
const factArrScreen = dataScreen; | |
const factIndex = Math.floor(Math.random() * factArr.length); | |
const randomFact = factArr[factIndex]; | |
const randomFactDisplay = factArrScreen[factIndex]; | |
const speechOutput = GET_FACT_MESSAGE + randomFact; | |
return handlerInput.responseBuilder | |
.speak(speechOutput) | |
.withSimpleCard(SKILL_NAME, randomFactDisplay) | |
.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 = 'Haiku Reader'; | |
const GET_FACT_MESSAGE = 'I have a haiku for you: '; | |
const HELP_MESSAGE = 'You can say tell me a haiku... or, you can say stop... What can I help you with?'; | |
const HELP_REPROMPT = 'You can ask me to tell a haiku or exit to stop. What can I help you with?'; | |
const STOP_MESSAGE = 'Goodbye!'; | |
const dataScreen = [ | |
`Up the wall he crawls | |
Moving with a spider’s ease | |
Slinging sticky webs | |
Spiderman`, | |
`He hides in shadows. | |
Roaming the nighttime darkness. | |
Savior in the black. | |
Batman`, | |
`He’s the man of steel. | |
Sailing through the air, bird-like. | |
Defending the Earth. | |
Superman`, | |
`A lawyer by day. | |
Who fights crime in Hell's Kitchen. | |
The Man Without Fear. | |
Batman`, | |
`A streak of lightning. | |
Gone before you can see him. | |
Protector of good. | |
The Flash`, | |
`A mercenary. | |
Who's mentally unstable. | |
The fourth wall breaker. | |
Deadpool`, | |
`I haunt your darkness. | |
While Gotham City slumbers. | |
I am its nightmares. | |
The Joker`, | |
`He's patriotic. | |
His shield's indestructible. | |
Fought in World War II. | |
Captain America`, | |
`Amazon princess. | |
Whose weapon's Lasso of Truth. | |
Fights for compassion. | |
Wonder Woman`, | |
`Weapon's a hammer. | |
His brother's his nemesis. | |
He is a Norse God. | |
Thor`, | |
`Fish man swims quickly. | |
Telepathy controls fish. | |
King of Atlantis. | |
Aquaman`, | |
`He is a fine shot. | |
His bow is very special. | |
He is hot tempered. | |
Hawkeye`, | |
`If he gets angry. | |
He'll get into purple pants. | |
And then turn to green. | |
The Hulk`, | |
`His armor is great. | |
He has strong repulsor rays. | |
He can fly quickly. | |
Iron man`, | |
`His fists contain claws. | |
Had the alias Logan. | |
Was born James Howlett. | |
Wolverine`, | |
`Giant flapping wings. | |
Feathered bird faced mask. | |
Ancient mace in hand. | |
Hawkman` | |
]; | |
const data = [ | |
`<voice name="Justin">Up the wall he crawls<break time="0.5s"/> | |
Moving with a spider’s ease<break time="0.5s"/> | |
Slinging sticky webs</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">Spiderman</voice>`, | |
`<voice name="Justin">He hides in shadows.<break time="0.5s"/> | |
Roaming the nighttime darkness.<break time="0.5s"/> | |
Savior in the black.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">Batman</voice>`, | |
`<voice name="Justin">He’s the man of steel.<break time="0.5s"/> | |
Sailing through the air, bird-like.<break time="0.5s"/> | |
Defending the Earth.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">Superman</voice>`, | |
`<voice name="Justin">A lawyer by day.<break time="0.5s"/> | |
Who fights crime in Hell's Kitchen.<break time="0.5s"/> | |
The Man Without Fear.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Daredevil">Batman</voice>`, | |
`<voice name="Justin">A streak of lightning.<break time="0.5s"/> | |
Gone before you can see him.<break time="0.5s"/> | |
Protector of good.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">The Flash</voice>`, | |
`<voice name="Justin">A mercenary.<break time="0.5s"/> | |
Who's mentally unstable.<break time="0.5s"/> | |
The fourth wall breaker.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">Deadpool</voice>`, | |
`<voice name="Justin">I haunt your darkness.<break time="0.5s"/> | |
While Gotham City slumbers.<break time="0.5s"/> | |
I am its nightmares.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">The Joker</voice>`, | |
`<voice name="Justin">He's patriotic.<break time="0.5s"/> | |
His shield's indestructible.<break time="0.5s"/> | |
Fought in World War II.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">Captain America</voice>`, | |
`<voice name="Justin">Amazon princess.<break time="0.5s"/> | |
Whose weapon's Lasso of Truth.<break time="0.5s"/> | |
Fights for compassion.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">Wonder Woman</voice>`, | |
`<voice name="Justin">Weapon's a hammer.<break time="0.5s"/> | |
His brother's his nemesis.<break time="0.5s"/> | |
He is a Norse God.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">Thor</voice>`, | |
`<voice name="Justin">Fish man swims quickly.<break time="0.5s"/> | |
Telepathy controls fish.<break time="0.5s"/> | |
King of Atlantis.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">Aquaman</voice>`, | |
`<voice name="Justin">He is a fine shot.<break time="0.5s"/> | |
His bow is very special.<break time="0.5s"/> | |
He is hot tempered.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">Hawkeye</voice>`, | |
`<voice name="Justin">If he gets angry.<break time="0.5s"/> | |
He'll get into purple pants.<break time="0.5s"/> | |
And then turn to green.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">The Hulk</voice>`, | |
`<voice name="Justin">His armor is great.<break time="0.5s"/> | |
He has strong repulsor rays.<break time="0.5s"/> | |
He can fly quickly.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">Iron man</voice>`, | |
`<voice name="Justin">His fists contain claws.<break time="0.5s"/> | |
Had the alias Logan.<break time="0.5s"/> | |
Was born James Howlett.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">Wolverine</voice>`, | |
`<voice name="Justin">Giant flapping wings.<break time="0.5s"/> | |
Feathered bird faced mask.<break time="0.5s"/> | |
Ancient mace in hand.</voice> | |
<audio src="soundbank://soundlibrary/aircrafts/futuristic/futuristic_02"/> | |
<voice name="Justin">Hawkman</voice>` | |
] | |
const skillBuilder = Alexa.SkillBuilders.custom(); | |
exports.handler = skillBuilder | |
.addRequestHandlers( | |
GetNewFactHandler, | |
HelpHandler, | |
ExitHandler, | |
SessionEndedRequestHandler | |
) | |
.addErrorHandlers(ErrorHandler) | |
.lambda(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment