Configuring your skill

So now that we’ve discussed the code, it’s time to go over how to create a skill and have it run this code on your device.

Creating a skill on the Amazon Developer Portal

The first step in creating our skill is setting it up on the Amazon Developer Portal. This is where you configure your skill’s details such as its invocation name, utterances, slots, and point it at your Lambda function or your web service.

Rather than me regurgitating the many fine guides out there on how to create and configure a skill, please open the tutorial “Build an Alexa Skill in 6 Steps” and complete steps 1 through 8, noting the following:

For the name and invocation name fields, use “Recipe Organizer”.

Once your skill gets created it will be assigned an application id that is visible on the first tab, “Skill Information”. Copy that and update the string “‘REPLACE WITH YOUR SKILL APPLICATION ID” in your index.js file with it.

When you get to step 9, return to here and I will detail how to set up the intents we will need. Go ahead, I’ll wait…

Interaction model

You should now be on the “Interaction Model” configuration screen. It should look like this:

The Skill Builder tool

Click on the button that reads “Launch Skill Builder”. This is basically a UI for generating your intent schema. I highly recommend using this tool instead of typing out a couple hundred lines of JSON. Once it loads, you’ll see something like this:

Adding our first intent

For our first intent, make the name of it “AddRecipeIntent”. Once you’ve added it, you’ll be taken to a screen where you can add the utterances that trigger it and its slots. For the utterance, add “Add a recipe”.

Adding our first slot

Now on the right-hand side there is a list of intent slots. Create a new one called “RecipeName”. After you add it you will see it appear in the list and underneath the slot name it will say “Choose a slot type…” Click that and select “Amazon.Food”.

Using Dialog Models

Next we are going to set up a dialog for this slot. This allows us to prompt the user for slot values and we will use it to obtain the RecipeName slot’s value.

In our code, there are 2 ways to prompt the user for slot values using a dialog. One is to delegate Alexa to prompt for it and indicate when it’s been filled by updating the dialogState of the request. The other way is to explicitly handle the prompting and confirmation for the slot. I chose to go with the latter so I didn’t have to create all of the dialogs in the Skill Builder and I also felt it made my code a little bit more transparent and thus easier to follow.

Since we are not using the first approach, we don’t have to create a dialog for all of our intents that need them. However, we do need to set up at least one or our app won’t support dialogs at all. So for that reason, set the RecipeName slot to be required and add a prompt of “What is the name of the recipe?” and an utterance the user will say to pass the slot. The utterance will just be “{RecipeName}”. It should look this below:

RecipeLocation slot

Next, create a slot called “RecipeLocation”. For its slot type, this time we are going to create a custom slot type. Enter “RecipeLocation” in the box that says “Create a new slot type…”

For the last slot, create one called “LongOrQuick” and give it a custom slot type of “LongOrQuick” by entering that into the box that says “Create a new slot type..”.

Your final intent should look like this:

DeleteRecipeIntent

This intent has an utterance of “Delete a recipe” and a RecipeName slot:

GetRecipeIntent

This intent has an utterance of “Get a recipe” and RecipeName slot:

GetAllRecipesIntent

This intent has multiple utterances mapped to it such as “Get all”, “List all” and a few more. For the slot, GetRecipeQuickOrLong is the only one and it has a custom slot type of the same name:

GetRandomRecipeIntent

This intent has 2 utterances: “Get random” and “Get a random recipe”. It has a GetRecipeQuickOrLong slot which has a custom slot type of the same name. It should look like below:

Now for our custom slot types, we need to add some acceptable values.

GetRecipeQuickOrLong slot values

On the bottom left of the screen, click on the GetRecipeQuickOrLong slot. Add “Don’t Care”, “Long” and “Quick”:

LongOrQuick slot values

This slot has values of “Long” and “Quick”:

RecipeLocation slot values

And finally for RecipeLocation, add “ “Bookmark”, “Cookbook”, and “Index Card”:

Now click on the “Save Model” button up top and once that’s completed click on the “Build Model” button. Your interaction model is now ready to be used by your skill. If you’re curious, you can view your generated JSON by clicking on the “Code Editor” on the left-hand sidebar above your intents.

Setting up your Lambda function

We just built the Voice User Interface (VUI) for our Alexa skill. Next we need to set up the Lambda function to run our skill’s code. AWS Lambda lets you run code without provisioning or managing servers. You can configure your code to be triggered by other AWS services or call it directly from the web.

There are some steps involved to set it up and once again I am going to delegate to one of the official tutorials for that. Starting at step 2 of the tutorial from earlier (https://developer.amazon.com/alexa-skills-kit/tutorials/fact-skill-2). Follow all of the steps on that page with the following exceptions:

For part 5, instead of choosing the blueprint they recommend, click the “Author from Scratch” button instead:

For part 7, enter “Recipe-Organizer” and choose the latest version of Node.js as the runtime. For me that was version 6.10.

Once step 2 is completed, click the “Next” button at the bottom of the page and move on to step 3. Complete all parts of step 3 and then stop and return here.

Setting up DynamoDB

Before you can run your code, we need to set up the database. Back on https://console.aws.amazon.com/ where you created your Lambda function, click the “Services” button at the top and search for “DynamoDB”. Create a table called “Recipes” with a primary partition key of “Name” and a primary sort key of “UserId”. This is going to be essentially our composite primary key.

Now we need to grant access to DynamoDB for our Lambda function. Click the “Services” button again and search for “IAM” or just click here https://console.aws.amazon.com/iam/. Click on the lambda_basic_execution role. Under permissions, click “Attach Policy” and add AmazonDynamoDBFullAccess. You can of course choose to grant the role less permissions if you’d like.

Deploying to Lambda

Ok, we are now ready to deploy our code and test it on our Echo. Lambda gives you a few ways to do that. You can edit it inline in their web editor, upload a zip package, or use either the AWS CLI or the new Skills CLI. One important thing to note is that editing your code inline means that you will be forced to use the version of the Alexa SDK that is installed on Lambda and that is generally behind the latest version and may be lacking some major features. Therefore, I recommend zipping up your index.js and node_modules folder which should include a more recent version of the SDK pulled down from NPM.

First create the archive of your code. Again, it should only contain your index.js file and your node_modules folder. Return to Lambda and click on your function. Under the first tab choose “Upload a .ZIP file”. Select your zip and click the save button. Or if you’re using the AWS CLI, you can deploy it by issuing the following command, provided that your zip is named Archive.zip: