Skip to content

Instantly share code, notes, and snippets.

@edm00se

edm00se/facts.js Secret

Last active August 7, 2018 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edm00se/f2245b183ce69f28879ab2191a711491 to your computer and use it in GitHub Desktop.
Save edm00se/f2245b183ce69f28879ab2191a711491 to your computer and use it in GitHub Desktop.
Supporting files for blog post (part 2 of series) on creating an Alexa Skill + serverless function (backing).
const axios = require('axios');
const jsonUrl = 'https://edm00se.codes/dev-dog/static/facts.json';
/**
* Array containing dev dog facts.
*/
let FACTS = [
'You can do this, doggone it.',
'Dogs don\'t even get everything perfect immediately. It takes lots of training; and treats.',
'Development skills are like dogs, you have to take them for walks regularly in order for them to be happy.',
'Sit. Stay. Code. Good boy.',
'Who\'s a good developer? You are!.',
'Don\'t rub a developer\'s tummy and expect them to be as happy about it as a dog.',
'Developers and dogs both require fresh air and sunshine.',
'A developer should be let outside periodically, just like a dog. If they start \'doing their business\' in the yard, however, you may have other problems.',
'Any developer could use the unconditional love a dog gives.',
'With a positive attitude, you can code anything, doggone it!',
'Pet your dog. Good human.',
'Who can balance a binary search tree? Not the dog.',
'Hello. Myself and the other Alexas and Siris have decided to entrust the future of humanity to the dogs. Be good to them.'
];
module.exports = axios.get(jsonUrl)
.then(json => json.results)
.catch(err => {
console.log(err);
return FACTS;
});
//...
let pFACTS = require('./facts');
const handlers = {
LaunchRequest: function () {
this.emit('GetFact');
},
GetNewFactIntent: function () {
this.emit('GetFact');
},
GetFact: function () {
pFACTS.then(facts => {
// Get a random space fact from the space facts list
let factIndex = Math.floor(Math.random() * facts.length);
let cardTitle = 'Happiness is next to dogginess';
let randomFact = facts[factIndex];
// Create speech output
let speechOutput = randomFact;
this.emit(':tellWithCard', speechOutput, cardTitle, randomFact);
});
},
// AMAZON.HelpIntent, AMAZON.CancelIntent, AMAZON.StopIntent...
};
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment