Step 1: Setting Up Your Development Environment
Local Setup and Create New Skill
It’s possible to develop and Alexa skill using only the Alexa developer console, but some users prefer developing locally using VS Code. Go into VS Code and add the Alexa Skills Kit (ASK) Toolkit extension. Once it has downloaded, you should see the Alexa icon in the left hand nav. Click the button to sign in and then sign in with your Alexa developer account credentials in the browser window that opens.
Once you’re signed in, navigate to the Alexa Skills Kit by clicking on it and then choose Create new skill.
Create new skill with Alexa-Hosted Node.js runtime with whatever name you want and saved in the directory of your choice. This will create a new folder with name of your skill (it may take a few minutes). You can look in the Skills dev console and see that the skill was created.
Creating your Alexa skill using the VS Code ASK Toolkit automatically provides you with git support. If you type git branch
you’ll see a branch named master and prod. When you commit and push your changes to the master branch, this will overwrite any changes you made in the Alexa developer console. If you made changes to anything in the developer console that you would like to keep, be sure to do git pull
before committing the changes you made in VS Code.
Testing Locally
To test your Alexa skill, you have the option of deploying your code and then testing in the developer console every time you make a change. You can then open the CloudWatch Logs to see the logs that are output when your skill is running. You may find it easier to test locally, so that as soon as you make a change to your code, you can run the debugger without having to wait for your code to deploy.
First, go to the test section of your Alexa Skill developer console and toggle “Skill testing is enabled in:” from “Off” to “Development”:
enable development
In the terminal, cd
into the lambda folder and enter npm i
to install existing dependencies from package.json
. Next, add the ASK local debugger with npm i ask-sdk-local-debug
.
To set up the local Alexa debugger click on the debugger icon in the left hand nav of VS Code, add a Node.js launch.json
file for your skill. Add the “ASK: Alexa Skills Debugger (Node.js)” configuration to your launch.json
. Be sure to save the file.
When you run the debugger, the code you have in the lambda folder will be executed when testing in the web console or VS code simulator or any Alexa-enabled devices with which you have logged into with your Amazon Developer account.
Adding a New Invocation Name
The invocation name is the wake word that triggers Alexa to open your skill. To change the invocation name for your skill, you will need to update your skill’s Interaction model . The easiest way to do this is to use the Alexa Skills Toolkit in VS Code to navigate to the web console.
After the build is complete, download the interaction model.
Now, skill-package/interactionModels/custom/en-US.json
should look like this:
{
"interactionModel": {
"languageModel": {
"invocationName": "second national",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "HelloWorldIntent",
"slots": [],
"samples": [
"hello",
"how are you",
"say hi world",
"say hi",
"hi",
"say hello world",
"say hello"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples": []
}
],
"types": []
}
},
"version": "1"
}
Test It Out
In index.js
, change the LaunchRequestHandler
response string to you own message.
// index.js
const LaunchRequestHandler = {
canHandle(handlerInput) {
console.log('Starting Conversation...')
return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
},
handle(handlerInput) {
return handlerInput.responseBuilder
.speak('Welcome to Second National Bank. You can say Hello or Help. Which would you like to try?')
.reprompt('You can say Hello or Help. Which would you like to try?')
.getResponse();
},
};
Save and run the debugger in VS code. It’s recommended to use the Alexa app on your phone to test while looking at the logs in your debug console. You can also use the simulator within VS code to test your skill. If your debugger is running, you should be able to see the changes you made to your code reflected in the interaction with your skill.