Editor’s note: This tutorial is out of date. You can view the most recent tutorial here.
This tutorial has been updated to reflect the Alexa SDK for Node.js as well as some updates to AWS Lambda and our GitHub repositories.
This fact skill template that makes it easy for developers or non-developers to create a skill similar to “Fact of the Day”, “Joke of the Day”, “Daily Reading” etc. The template leverages AWS Lambda, the Alexa Skills Kit (ASK), and the ASK SDK, while providing the business logic, use cases, error handling and help functions for your skill. You just need to come up with a fact idea (like “Food Facts”), plug in your fact list and edit the sample provided (we walk you through how it’s done). It's a valuable way to quickly learn the end-to-end process for building and publishing an Alexa skill.
This tutorial will walk first-time Alexa skills developers through all the required steps involved in creating a skill using this fact skill template, called ‘SpaceGeek’. This post assumes you have some familiarity with JavaScript/Node.js (or a similar programming language) and the Alexa Skills Kit.
Using the Alexa Skills Kit, you can build an application that can receive and respond to voice requests made on the Alexa platform. In this tutorial, you’ll build a web service to handle notifications from Alexa and map this service to a Skill in the Amazon Developer Portal, making it available on your device and to all Alexa users after certification.
After completing this tutorial, you'll know how to do the following:
Skills are managed through the Amazon Developer Portal. You’ll link the Lambda function you created above to a Skill defined in the Developer Portal.
Next, we need to define our skill’s interaction model. Let’s begin with the intent schema. In the context of Alexa, an intent represents an action that fulfills a user’s spoken request. Intents can optionally have arguments called slots. We will not be using custom slots in this template, but they are very useful if you want to parameterize your intents.
Below you will see the intents for getting a new fact, and then a collection of built-in intents to simplify handling common user tasks. Help intent will handle any time the user asks for help, stop and cancel are built-in intents to make it easier for you to handle when a user wants to exit the application. For more on the use of built-in intents, go here.
JSON { "intents": [ { "intent": "GetNewFactIntent" }, { "intent": "AMAZON.HelpIntent" }, { "intent": "AMAZON.StopIntent" }, { "intent": "AMAZON.CancelIntent" } ] }
The next step is to build the utterance list.
Given the flexibility and variation of spoken language in the real world, there will often be many different ways to express the same request. Providing these different phrases in your sample utterances will help improve voice recognition for the abilities you add to Alexa. It is important to include as wide a range of representative samples as you can -– all the phrases that you can think of that are possible in use (though do not include samples that users will never speak). Alexa also attempts to generalize based on the samples you provide to interpret spoken phrases that differ in minor ways from the samples specified.
Now its time to add the Utterances. Copy/paste the sample utterances from GitHub. An example of utterances is listed below. Once they are copied, the screen should look similar to the following image:
GetNewFactIntent a fact GetNewFactIntent a space fact GetNewFactIntent tell me a fact GetNewFactIntent tell me a space fact GetNewFactIntent give me a fact GetNewFactIntent give me a space fact GetNewFactIntent tell me trivia GetNewFactIntent tell me a space trivia GetNewFactIntent give me trivia GetNewFactIntent give me a space trivia GetNewFactIntent give me some information GetNewFactIntent give me some space information GetNewFactIntent tell me something GetNewFactIntent give me something
Select Save. You should see the interaction model being built (this might a take a minute or 2). If you select next, your changes will be saved and you will go directly to the test screen. After selecting Save, it should now look like this:
Next we will configure the AWS Lambda function that will host the logic for our skill.
To make the development of skills easier, we have created the ASK SDK for Node.js.We will be using this module to deploy the sample. The alexa-sdk is immediately available on github here and can be deployed as a node package from within your Node.js environment.
To leverage the SDK for ASK you will need to install Node.js and update npm. To set this up on your machine, follow these steps.
Once you have the source downloaded, node installed and npm updated, you are ready to install the ASK-SDK. Install this in the same directory as your src/index.js file for your skill. Change the directory to the src directory of your skill, and then in the command line, type:
npm install --save alexa-sdk
Once this is installed you will need to include the node_modules directory with the source code for your skill when you compress the src for uploading to AWS Lambda. Let's do this with the example.
Navigate to where you downloaded the sample respository and installed the Alexa SDK in step 3. Select the src directory.
Compress the files inside the src directory into a zip file. Remember, do not compress the src directory itself, just the files within the directory, the index.js file and the node_modules folder. Your compressed file should show up in the src directory. You will use this file in a later step.
Open aws.amazon.com and then choose ‘Create a Free Account’
Sign in to the AWS Console
AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume - there is no charge when your code is not running. With Lambda, you can run code for virtually any type of application or backend service - all with zero administration. Just upload your code and Lambda takes care of everything required to run and scale your code with high availability.
Note: If you are new to Lambda and would like more information, visit the Lambda Getting Started Guide.
Select “Create a Lambda Function” to begin the process of defining your Lambda function.
At the bottom of the ‘Select Blueprint’ page, select “Next”
Set your handler and role as follows:
In the Test area, we are going to enter a sample utterance in the service simulator section and see how Alexa will respond. In this example, we have called the skill ‘Space Geek’. This is the ‘Invocation Name’ we set up on the Skill Information line in the “Skill Information” section.
Do you have the right ARN copied from your Lambda function into your Developer Portal / Skill? * Are you calling the right invocation name? * Are you saying launch, start or open? * Are you sure you have no other skills in your accounts with the same invocation name? * For this template specifically, you should have a minimum of 20 facts for a good customer experience.
In the Skill Information section in the Developer Console, edit the Skill Information Tab to reflect your new Fact Skill:
Create a fun icon. Be sure you have the rights to whatever icons you are uploading – you will need to provide both 108x108px and 512x512px images. Need help finding an image, see PixelBay as a possible source for royalty-free images. Use an image editor (such as Paint on Windows or Preview on Mac to change the size of the image.
Everything else can stay as-is for now in the Developer Portal
JSON var SKILL_NAME = 'Space Facts'
Edit the strings to contain what ever facts or information you would like to make randomly available when a user invokes your skill. A few suggestions:
You will also want to make sure to change the “Space Geek” references to the name of your skill. You don’t have to edit them all, but the following reference changes are required for certification.
'AMAZON.HelpIntent': function () {
var speechOutput = "You can say tell me a space fact, or, you can say exit... What can I help you with?";
var reprompt = "What can I help you with?";
this.emit(':ask', speechOutput, reprompt);
},
In order to control who accesses your web service, we should validate the application id in requests made to your web service. Let’s go back to your Alexa skill in your Developer Portal for a moment. Copy in your Application ID from the ‘Skill Information’ section in your developer portal / skill:
Copy the application id into the value of the APP_ID variable. Make sure to place the app id in quotation marks. JSON var APP_ID = undefined; //OPTIONAL: replace with "amzn1.echo-sdk-ams.app.[your-unique-value-here]";
A minimum of 20 facts is needed to get started, about 100 is a good number to keep users engaged. The more the better.
Be sure to select SAVE when you are all done. Note: we test initially in the Developer Portal, not in our Lambda function (AWS).
Log back into your AWS console and upload the changes you have just made. First you will need to zip up the files into a new archive. You can do this by selecting the files that you need in the src directory (the node_modules directory and your updated index.js) into a new archive. Be sure that you compress the files in the folder, not the folder itself.
Select your Lambda function and on the Code tab, select “Upload” to add the archive you just created.
Once you have successfully added the file you will see it on the screen, then select “Save”.
Repeat the tests you performed earlier to ensure your changes are functioning properly. See step 4 for a review of how to performs functional tests.
Now we need to go back to our Developer Portal to test and edit our skill and we will be ready for certification.
In your skills Test section, enter your Utterances into the Simulator to make sure everything is working with your new facts.
Optionally, you can test with your Alexa-enabled device to make sure everything is working correctly. You may find a few words that need to be changed for a better user experience.
Some things to think about:
Because we are randomizing our facts, this could take a while. Instead, you can use the Voice Simulator in the Test section to simulate Alexa’s responses. In the Voice Simulator, type in each fact that you are using to test how Alexa will say it. Use additional punctuation or possibly SSML if you need to better control how Alexa responds. You can find out more about SSML here.
Once you have uploaded your icons, you should see a success message at the bottom of the screen.
IMPORTANT: Add the text “This is based on the Fact Skill Template” to the Testing Instructions section. This alerts the Certification team of your submission using this standardized template, smoothing the road to a faster publish. Finally, select Next.
Privacy and Compliance.
Select “Submit for Certification”
Finally, confirm your submission. Select “Yes” to submit your skill.
Congratulations! You have successfully sumbitted your skill for publication. You will receive progress e-mails and possibly other suggestions from the team on how you can make your skill even better. You can update your skills at any time.