This is the Recipe Skill. Go here for the Local Recommendations skill guide.
This lab will teach you how to use a database to persist information so users can pause and resume a skill, or exit then return to the same place in the conversation that they had left off.
Have you ever played music and needed to pause in the middle of a song? What about ordering a pizza online? If you've started an order, then leave the page, when you come back you have the option to complete your previous order. In both cases, upon our return, we have the option of continuing right where we left off, or starting over from the beginning. By persisting information in a database, we can give Alexa the capability to store a memory of a recent conversation just as a human would. Which will lead to a more natural, conversational feel to your skill from a user's perspective.
Create your skill using the Lambda code given in src/index.js and the Interaction Model (We've also included a simple test file for your lambda function). If you're comfortable completing this step on your own, feel free to complete it with the steps below as a reference and move to Task 2 once complete. Otherwise, follow the steps in the Detailed Setup Instructions.
1.1 Create a new AWS Lambda function:
- Choose the Fact blueprint template.
- Setup "Alexa Skills Kit" as the function trigger.
- Name the function
BreakfastSandwich
- Replace the existing code by pasting in the code from src/index.js.
- Choose your default role
lambda_basic_execution
- Click "Create Function"
1.2 Create a new skill
- Call the skill "Breakfast Sandwich" with invocation name
breakfast sandwich
- Launch "Skill Builder Beta"
- Click the Code Editor tab (just below the turqoise Dashboard tab on the top left)
- Copy and paste the
speechAssets/InteractionModel.json
contents into the field over the existing text. - Click Save, then click Build
- Advance to the Configuration page, choose AWS Lambda ARN, and paste in the ARN from the function you just created.
We can configure a DynamoDB database table to remember which step the user was on when they stop or pause the skill. When you create a new skill, the default permissions are set to the lowest-needed to run a basic skill. We want our skill to do more, so we will need to add the permission to have full access to DynamoDB. Once our database is configured, we can have our skill prompt the user to continue with the next step when re-launching the skill.
We will need to prepare our skill's Lambda function to use a database called DynamoDB.
If you've never done this before or need a refresher, follow the steps below which walk you through how to enable permission for a database before we define it within our Lambda function. If you're comfortable doing this on your own, go ahead and move on to Task 3 once you've added the permission.
Steps:
- Open a browser to the AWS Console. Or, simply go to that tab if you've still got it open, then click the orange cube in the top left corner to return to the AWS main page.
- In the search box titled AWS services, type
IAM
then click the option reading IAM (Manage User Access and Encryption Keys) - On the new page reading Welcome To Identity and Access Management your navbar to the left should have an option called Roles. Click that.
- On this page, you should see the name of your standard Lambda role,
lambda_basic_execution
. Click the role name. - In the Permissions tab, under "Managed Policies", click the blue button titled "Attach Policy"
- In the filter field, type "dynamo" and then locate the policy named
DynamoDBFullAccess
and click the checkbox. - Click "Attach Policy"
Now that we've added permission to our database, it's time to enable it within our Lambda function. In the source code provided, uncomment the line that looks like this: // alexa.dynamoDBTableName = 'RecipeSkillTable';
Again, if you are familiar with this process or understand what you just did, move on to the next step. If not, refer to the section below.
Steps:
- Review your Lambda function code within the AWS Lambda console.
- Locate the line
// alexa.dynamoDBTableName = 'RecipeSkillTable';
- Uncomment this line by removing the first two
//
characters. - Scroll up and click the blue "Save" button.
- Click Save.
- Click Test.
- Open the skill using echosim.io. Once it's up and ready, say "begin cooking", and then say "stop". You may encounter errors the first couple of times the skill runs. This is okay. The skill code is setting up a new table in DynamoDB which may take 60 seconds to complete.
Practice speaking to the skill a few times to learn all the features of the skill. When you ask for "ingredients", you will hear both a list of ingredients, and see a picture of a breakfast sandwich on your Alexa app or Echo Show screen, if you have one. When you ask to "begin cooking", the skill will guide you through each step in the process.
These are some suggestions for building and customizing this recipe skill
Currently this skill tells you how to make one kind of sandwich. Expand your skill to allow users to choose a recipe first, and then hear the recipe. You'll probably want to add some new intents to prompt your users for a type of sandwich if they fail to specify (Hint: If you opt for a custom slot, you may want to make it required to fulfill the intent. The skill builder tool has a way to do this.) Reading and understanding the code provided, then modifying it is a great way to understand what you just built.
If you looked through the source code for this skill, you probably noticed that we have a welcome card image being used. Enhance your current skill by displaying different images according to the state of your skill.