Last active
November 30, 2018 05:40
-
-
Save panzerstadt/b016e620403548a5d68ea68ec0565d34 to your computer and use it in GitHub Desktop.
starter code, with a simple example function, labelled for quick start
This file contains 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
// this code is edited from the original: | |
// https://medium.com/iotforall/build-your-first-custom-alexa-skill-in-10-minutes-2d27485727ed | |
// import | |
var alexa = require("alexa-app"); | |
// 1. DEFINE APP | |
// ------------- | |
// your app, on the first time it opens, does this | |
const App = (request, response) => { | |
// Alexa says this at the beginning | |
response.say( | |
"Hello there, I am a bot template that doesn't really do anything. Try asking me about the answer to life, universe and everything." | |
); | |
// don't go exit the program yet | |
response.shouldEndSession(false); | |
}; | |
// the primary function alexa should call | |
const getAnswer = (request, response) => { | |
generate_suggestions(response); | |
return; | |
}; | |
// secondary function(s) | |
const generate_suggestions = response => { | |
const answer = [ | |
"42", | |
"42", | |
"I told you it's 42", | |
"go watch Hitchhiker's Guide to the Galaxy", | |
"it really is 42" | |
]; | |
const rand = answer[Math.floor(Math.random() * answer.length)]; | |
// what is Alexa's output after running this function? | |
response.say(rand); | |
response.send(); | |
return; | |
}; | |
// 2. MAKE APP | |
// ----------- | |
// make a new app | |
var app = new alexa.app(); | |
// run the app | |
app.launch(App); | |
// tell it what to do | |
// app.intent("name of function", {what it should listen to}, the function that gets called) | |
app.intent( | |
"GetAnswer", | |
{ | |
slots: {}, | |
utterances: [ | |
"what is my number", | |
"what do i like to think about when i'm asleep", | |
"what is the answer to life universe and everything" | |
] | |
}, | |
getAnswer | |
); | |
// 3. CONNECT TO AMAZON'S LAMBDA | |
// ----------------------------- | |
exports.handler = app.lambda(); | |
if (process.argv.length === 3 && process.argv[2] === "schema") { | |
console.log(app.schema()); | |
console.log(app.utterances()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment