Skip to content

Latest commit

 

History

History
208 lines (167 loc) · 14 KB

File metadata and controls

208 lines (167 loc) · 14 KB

Color Changer Skill for Echo Buttons

Important: The Gadgets Skill API is in beta and is subject to change at any time without notice. We welcome your feedback.

This sample skill uses:

Table of Contents

Preparation

Before you create the Color Changer skill, you must take the following steps:

  • Create an Amazon developer account – If you don't already have an Amazon developer account, go to the developer portal and select Sign In in the upper right to create a free account.
  • Sign up for AWS – If you haven't already, sign up for AWS by going to AWS Free Tier. For most developers, the AWS Lambda Free Tier and Amazon DynamoDB Free Tier are sufficient for the function that supports an Alexa skill.
  • Get Echo Buttons – This skill requires two Echo Buttons.
  • This skill sample uses NodeJS v6. If you do not have NodeJS already installed on your computer, install it now. The simplest way to install NodeJS is to use nvm a Node Version Manager command line tool, with instructions here: https://nodejs.org/en/download/package-manager/#nvm

Step 1-Setup Local Development Environment

In this step, you will get a copy of the sample skill code on your local computer and prepare a deployment package (a zip file that you create out of the Color Changer skill code) to upload to Lambda in the next step.

  1. Get a local copy of the Color Changer skill code from alexa-sample-nodejs-buttons-colorchanger GitHub. You may clone the repository locally, or simply download and unzip the sample code from GitHub.
  2. After downloading the code, you will have to run npm install in the skill-sample-nodejs-buttons-colorchanger/lambda/custom folder to download and install the NodeJS package dependencies that this skill uses such as the Alexa SDK. NPM will be available on your computer if you have NodeJS installed (see the Preparation step above).
  3. Zip up all of the files that are in the skill-sample-nodejs-buttons-colorchanger/lambda/custom folder. This zip file will be your deployment package. Be sure to only zip the files and folders that are inside the skill-sample-nodejs-buttons-colorchanger/lambda/custom folder, not the skill-sample-nodejs-buttons-colorchanger/lambda/custom folder itself. AWS Lambda must be able to find the index.js file at the root of the zip file.

Step 2-Upload the Deployment Package to AWS Lambda

In this step, you upload the deployment package to AWS Lambda. Later, when you set up the skill in the developer portal, you will specify that this function is the endpoint for the skill.

  1. Sign in to the AWS Management Console and navigate to the AWS Lambda console, which is located under Compute services.
  2. Select Create function.
  3. Make sure that you are on the Author from scratch page.
  4. For Name, enter ColorChanger.
  5. For Runtime, select Node.js 6.10.
  6. For Role, select Create a custom role. This will take you to the IAM console.
  7. In the IAM console, expand View Policy Document.
  8. Click Edit, click OK in the dialog box, and then replace the entire policy with the following JSON (the dynamodb permissions in the policy below are only needed if you choose to enable session attributes to be stored in DynamoDB, in the skill code (index.js)):
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:PutLogEvents",
                "logs:CreateLogStream",
                "iam:GetRole",
                "iam:ListRoles",  
                "dynamodb:GetItem",
                "dynamodb:PutItem",
                "dynamodb:DeleteItem",
                "dynamodb:Scan",
                "dynamodb:Query",
                "dynamodb:UpdateItem",
                "dynamodb:CreateTable",                
                "dynamodb:DescribeTable"
            ],
            "Resource": "*"
        }        
      ]
}
  1. At the bottom right of the page, click the Allow button. This will take you back to the Lambda console.
  2. Back in the Lambda console, for Role, select Choose an Existing Role.
  3. For Existing Role, select the role you just created.
  4. In the lower right, click the Create function button. The function might take a moment to create.
  5. Scroll down a bit. Under the Function code section, for Code entry type, select Upload a .ZIP file. Then click Upload and choose the ColorChanger zip file that you created in the first step.
  6. For Runtime, select Node.js 6.10.
  7. At the top of the page, under the Designer section, under Add triggers, select Alexa Skills Kit.
  8. At the bottom of the page, under Configure Triggers, select Disable for Skill ID verification.
  9. At the bottom of the page, click Add.
  10. At the top of the page, click Save.

Step 3-Find the ARN of the Lambda function

In this step, you find the Amazon Resource Name (ARN) of the Lambda function that you just created. The ARN serves as the ID of the function. You can find the ARN at the top right of the Color Changer function page in the AWS Lambda console. The ARN will look something like arn:aws:lambda:us-east-1:012345678910:function:ColorChanger.

Copy the ARN. Later, when you set up the Color Changer skill in the developer portal, you will provide this ARN as the endpoint for the skill.

Step 4-Create the Skill

Next, create the skill in the developer console by using the following steps:

  1. Sign in to the Alexa Skills Kit developer console.
  2. Select Create Skill.
  3. For Skill Name, enter Color Changer, and then select Next in the upper right.
  4. For Choose a model to add to your skill, select Custom, and then select Create Skill in the upper right.

Important: If you get an 'unspecified error' when performing any of the remaining steps, try logging out and then logging back in to the developer console.

Step 5-Create an Interaction Model

Continuing from the previous step, do the following:

  1. On the left side, select Invocation.
  2. For Skill Invocation Name, enter color changer, and then select Save Model.
  3. Add built-in intents for "yes" and "no" as follows:
    1. On the left side, select Intents.
    2. Select Add Intent.
    3. Select Use an existing intent from Alexa's built-in library.
    4. In the search box, type yes. The search results should come up with AMAZON.YesIntent.
    5. Next to AMAZON.YesIntent, select Add Intent.
    6. Using a similar procedure, add AMAZON.NoIntent.
    7. At the top of the page, select Save Model.
  4. You will now create slots for a custom intent. (You will create the custom intent in the next step.) Think of a slot as a variable that your intents can use. Create slots for colors as follows:
    1. On the left, select Slot Types.
    2. Select Add Slot Type.
    3. Under Create custom slot type, type COLORS, and then select Create custom slot type.
    4. Under Slot Values, enter green, and then, on the right side of the text field, select the + sign.
    5. Add Slot Values for red and blue also. Do not save the model yet; it might return an error.
    6. On the left, select Slot Types.
    7. At the top of the page, select Save Model.
  5. Add a custom intent as follows:
    1. On the left side, select Intents.
    2. Select Add Intent.
    3. Under Create custom intent, enter colorIntent, and then select Create custom intent.
    4. Scroll down to the Intent Slots section of the page.
    5. For NAME, enter color and then, to the right of the name, select the + sign.
    6. For the slot you just created, select SLOT TYPE and then select COLORS, which is a slot type that you created in a previous step.
    7. Scroll up to Sample Utterances.
    8. In the Sample Utterances field, enter { (that is, a left brace), select color, and then select the + sign.
    9. In the Sample Utterances field, enter I like {, select color, and then select the + sign.
    10. In the Sample Utterances field, enter Let's go with {, select color, and then select the + sign.
    11. In the Sample Utterances field, enter How about {, select color, and then select the + sign.
    12. On the left side, select Intents.
    13. At the top of the page, select Save Model.
    14. Select Build Model. The model might take a moment to build.

Step 6-Select Gadget Interfaces

Continuing from the previous step, do the following:

  1. On the left side, select Interfaces.
  2. In the Alexa Gadget row of the interface list, select Gadget Controller and Game Engine.
  3. At the top of the page, select Save Interfaces.

Step 7-Enter the Endpoint

Continuing from the previous step, do the following:

  1. On the left side, select Endpoint.
  2. For Service Endpoint Type, select AWS Lambda ARN.
  3. In the Default Region field, paste the ARN of the Lambda function that you created in an earlier step. Leave the other options at their default values.
  4. At the top of the page, select Save Endpoints.

Step 8-Enter Publishing Information

Continuing from the previous step, do the following:

  1. At the top of the page, select Launch.
  2. For One Sentence Description and Detailed Description, enter This is a sample skill for Echo Buttons.
  3. For Example Phrases, enter Alexa, open Color Changer.
  4. For Echo Button Use, select Required.
  5. For Number of Echo Buttons, select a Min of 2 and a Max of 2.
  6. For Number of Players, select 1 for both Min and Max.
  7. Skip the icon part for now.
  8. For Category, select Games.
  9. At the bottom of the page, select Save and continue.

Step 9-Enter Privacy and Compliance Information

Continuing from the previous step, do the following:

  1. For Does this skill allow users to make purchases or spend real money?, select No.

  2. For Does this Alexa skill collect users' personal information?, select No.

  3. For Is this skill directed to or does it target children under the age of 13?, select No.

  4. For Does this skill contain advertising? select No.

  5. For Export Compliance, select the checkbox.

  6. For Testing Instructions, enter None.

  7. At the bottom of the page, select Save and continue.

  8. Again, select Save and continue. This will accept the default options on the Availability page.

    You should now be on the Submission page, which will tell you that fixes are required (to add icons). You don't need to add icons now because you can test the skill without submitting it for certification.

Step 10-Enable the Skill in the Alexa App

Your Color Changer skill is in the development state and available for you to test with your Amazon Echo device and your Echo Buttons. First, you must ensure that the skill is enabled in the Alexa app. To check this, do the following:

  1. Go to the web version of the Alexa app (alexa.amazon.com) and sign in with your Amazon developer account.
  2. Choose Skills from the main menu.
  3. In the upper right, choose Your Skills.
  4. Using the search bar, search for the Color Changer skill.
  5. Select the skill. If the skill is already enabled, the button next to the skill name says DISABLE SKILL. In that case, you are finished with this step. If the button says ENABLE, then select that button.

Step 11-Invoke the Skill

Pair your Echo Buttons to your Amazon Echo device, and then invoke the skill by saying "Alexa, open Color Changer". The skill should run as described in the skill flow.