alexa/skill-sample-nodejs-buttons-colorchanger

Name: skill-sample-nodejs-buttons-colorchanger

Owner: Alexa

Description: Color Changer buttons skill opens with buttons roll call and asks the user to push buttons to change their colors with various animations. It covers roll call, starting and stopping the Input Handler, and defining animations for different button events. It also demonstrates how Echo Buttons can interrupt text-to-speech (TTS).

Created: 2018-03-06 21:28:34.0

Updated: 2018-05-17 16:54:55.0

Pushed: 2018-05-17 16:54:53.0

Homepage: null

Size: 30

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

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.

These instructions show how to create a skill called Color Changer, which demonstrates the core functionality of an Echo Button skill. It covers roll call, starting and stopping the Input Handler, and defining animations for different button events. It also demonstrates how Echo Buttons can interrupt text-to-speech (TTS).

This sample skill uses:

Table of Contents
Skill Flow

When the Color Changer skill begins, Alexa will ask you to press the Echo Buttons that you want to use. This is called roll call. After you press the buttons, Alexa will ask you to select a color: red, blue, or green. When you select a color, the skill will send animation directives to all the Echo Buttons. Once you have selected your color, Alexa will ask you to press the buttons. When you press a button, the skill will interrupt Alexa's speech and change the button's LED color to the color that you selected previously.

Click on the following diagram to see a voice user interface (VUI) that shows how a user interacts with the skill. To zoom in, click on the diagram again when it opens in the browser window.

Color Changer VUI

Preparation

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

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)):
    
    sion": "2012-10-17",
    tement": [
    {
        "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": "*"
    }        
    
    
    
  9. At the bottom right of the page, click the Allow button. This will take you back to the Lambda console.
  10. Back in the Lambda console, for Role, select Choose an Existing Role.
  11. For Existing Role, select the role you just created.
  12. In the lower right, click the Create function button. The function might take a moment to create.
  13. 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.
  14. For Runtime, select Node.js 6.10.
  15. At the top of the page, under the Designer section, under Add triggers, select Alexa Skills Kit.
  16. At the bottom of the page, under Configure Triggers, select Disable for Skill ID verification.
  17. At the bottom of the page, click Add.
  18. 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:
  4. On the left side, select Intents.
  5. Select Add Intent.
  6. Select Use an existing intent from Alexa's built-in library.
  7. In the search box, type yes. The search results should come up with AMAZON.YesIntent.
  8. Next to AMAZON.YesIntent, select Add Intent.
  9. Using a similar procedure, add AMAZON.NoIntent.
  10. At the top of the page, select Save Model.
  11. 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:
  12. On the left, select Slot Types.
  13. Select Add Slot Type.
  14. Under Create custom slot type, type COLORS, and then select Create custom slot type.
  15. Under Slot Values, enter green, and then, on the right side of the text field, select the + sign.
  16. Add Slot Values for red and blue also. Do not save the model yet; it might return an error.
  17. On the left, select Slot Types.
  18. At the top of the page, select Save Model.
  19. Add a custom intent as follows:
  20. On the left side, select Intents.
  21. Select Add Intent.
  22. Under Create custom intent, enter colorIntent, and then select Create custom intent.
  23. Scroll down to the Intent Slots section of the page.
  24. For NAME, enter color and then, to the right of the name, select the + sign.
  25. 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.
  26. Scroll up to Sample Utterances.
  27. In the Sample Utterances field, enter { (that is, a left brace), select color, and then select the + sign.
  28. In the Sample Utterances field, enter I like {, select color, and then select the + sign.
  29. In the Sample Utterances field, enter Let's go with {, select color, and then select the + sign.
  30. In the Sample Utterances field, enter How about {, select color, and then select the + sign.
  31. On the left side, select Intents.
  32. At the top of the page, select Save Model.
  33. 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.

License

This library is licensed under the Amazon Software License.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.