Skip to content

Instantly share code, notes, and snippets.

@myke11j
Created July 18, 2018 08:57
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 myke11j/53c21154b8bdb686a4a8d0bbc235a152 to your computer and use it in GitHub Desktop.
Save myke11j/53c21154b8bdb686a4a8d0bbc235a152 to your computer and use it in GitHub Desktop.
Alexa skills with Alexa SDK using Node.js
AWS_ENVIRONMENT=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_ROLE_ARN=
AWS_REGION=
AWS_FUNCTION_NAME=skill-name
AWS_HANDLER=index.handler
AWS_MEMORY_SIZE=128
AWS_TIMEOUT=10
AWS_DESCRIPTION=
AWS_RUNTIME=nodejs6.10
PACKAGE_DIRECTORY=build

Running The Alexa Skill

npm i -g node-lambda
node-lambda run

Deploying The Alexa Skill

node-lambda deploy
const Alexa = require('alexa-sdk');
const APP_ID = process.env.APP_ID;
const messages = {
greeting: 'Welcome to the Skill!',
goodBytMsg: 'Thanks for using the Skill!',
reprompt: 'Would you like me to repeat that again?',
help: 'Give a help message to User'
}
const handlers = {
'LaunchRequest': function () {
this.attributes['asked'] = 'launch';
const cardTitle = 'Welcome to your Skill!';
let content = messages.greeting;
this.emit(':askWithCard', content, messages.reprompt, cardTitle, content, null)
},
'AMAZON.HelpIntent': function () {
const content = messages.help;
this.attributes['asked'] = 'launch';
this.emit(':askWithCard', content, 'Help from Skill', content, null)
},
'AMAZON.StopIntent': function () {
const cardTitle= messages.goodBytMsg;
const content = messages.goodBytMsg;
this.emit(':tellWithCard', content, cardTitle, content, null)
},
'AMAZON.CancelIntent': function () {
this.emit('AMAZON.StopIntent');
}
};
exports.handler = function (event, context, callback) {
try {
const alexa = Alexa.handler(event, context, callback);
alexa.registerHandlers(handlers);
alexa.appId = APP_ID // APP_ID is your skill id which can be found in the Amazon developer console where you create the skill.
alexa.execute();
} catch (error) {
console.log(`Error in Hinky Pinky Skill, ${error}`);
}
};
{
"name": "your-skill-name",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Mukul<@mukul1904>",
"license": "ISC",
"dependencies": {
"alexa-sdk": "^1.0.25"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment