Skip to content

Instantly share code, notes, and snippets.

@panzerstadt
Last active November 30, 2018 05:40
Show Gist options
  • Save panzerstadt/b016e620403548a5d68ea68ec0565d34 to your computer and use it in GitHub Desktop.
Save panzerstadt/b016e620403548a5d68ea68ec0565d34 to your computer and use it in GitHub Desktop.
starter code, with a simple example function, labelled for quick start
// 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