This Alexa sample skill is a template for a basic high-low game skill. Guess a number, and Alexa will tell you whether the number she has in mind is higher or lower.
NOTE: This sample is subject to change during the beta period.
This sample shows how to create a Lambda function for handling Alexa Skill requests that:
- Use Persistence attributes and Persistence adapter, to store and retrieve attributes on AWS DynamoDB table.
- Demonstrates using a custom slot type.
To run this example skill you need to do two things. The first is to deploy the example code in lambda, and the second is to configure the Alexa skill to use Lambda.
Please follow the
prerequisites section and the
adding ASK SDK
section in
Getting Started documentation. For this sample skill, you need
the ASK SDK Standard
package.
In addition to the SDK, the skill also needs a DynamoDb table. Go to AWS Console and click on the DynamoDB Service. In the dashboard, click on 'Create table', provide 'High-Low-Game' as table name and 'id' as partition key. Leave all settings as default and click 'Create'.
Refer to Hosting a Custom Skill as an AWS Lambda Function reference for a walkthrough on creating a AWS Lambda function with the correct role for your skill. When creating the function, select the "Author from scratch" option, and select Python 2.7 or Python 3.6 runtime.
To prepare the skill for upload to AWS Lambda, create a zip file that contains high_low_game.py, the SDK and it's dependencies. Make sure to compress all files directly, NOT the project folder. You can check the AWS Lambda docs to get more information on creating a deployment package.
Once you’ve created your AWS Lambda function and configured "Alexa
Skills Kit" as a trigger, upload the ZIP file produced in the previous
step and set the handler to the fully qualified class name of your
handler function. In this example, it would be high_low_game.handler
.
Finally, copy the ARN for your AWS Lambda function
because you’ll need it when configuring your skill in the Amazon
Developer console.
Now that the skill code has been uploaded to AWS Lambda we’re ready to configure the skill with Alexa. First, navigate to the Alexa Skills Kit Developer Console. Click the "Create Skill" button in the upper right. Enter "HighLowGame" as your skill name. On the next page, select "Custom" and click "Create skill".
Now we’re ready to define the interaction model for the skill. Under
"Invocation" tab on the left side, define your Skill Invocation Name to
be high low game
.
Now it’s time to add the required intents to the skill. Copy the interactionSchema JSON provided in the speech_assets folder and paste it under the "JSON Editor" tab. Alternatively, you can also upload the JSON to the JSON Editor.
{
"interactionModel": {
"languageModel": {
"invocationName": "high low game",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "AMAZON.YesIntent",
"samples": []
},
{
"name": "AMAZON.FallbackIntent",
"samples": []
},
{
"name": "AMAZON.NoIntent",
"samples": []
},
{
"name": "NumberGuessIntent",
"slots": [
{
"name": "number",
"type": "AMAZON.NUMBER"
}
],
"samples": [
"{number}",
"is it {number}",
"how about {number}",
"could be {number}"
]
}
],
"types": []
}
}
}
As can be observed from the JSON, we add the built-in AMAZON.YesIntent, AMAZON.NoIntent and a custom NumberGuessIntent. The NumberGuessIntent is for providing utterances for guessing the number. The "Yes" and "No" intents are for skill users to confirm if they want to play the game.
Once you’re done editing the interaction model don’t forget to save and build the model.
Let’s move on to the skill configuration section. Under "Endpoint" select "AWS Lambda ARN" and paste in the ARN of the function you created previously. The rest of the settings can be left at their default values. Click "Save Endpoints" and proceed to the next section.
Under the AWS lambda function "Alexa Skills Kit" trigger, enable the "Skill Id verification" and provide the Skill Id from the skill endpoint screen. Save the lambda function.
Finally you’re ready to test the skill! In the "Test" tab of the developer console you can simulate requests, in text and voice form, to your skill. Use the invocation name along with one of the sample utterances we just configured as a guide. You should also be able to go to the Echo webpage and see your skill listed under "Your Skills", where you can enable the skill on your account for testing from an Alexa enabled device.
At this point, feel free to start experimenting with your Intent Schema as well as the corresponding request handlers in your skill’s implementation. Once you’re finished iterating, you can optionally choose to move on to the process of getting your skill certified and published so it can be used by Alexa users worldwide.
- Amazon Developer Forums : Join the conversation!
- Hackster.io - See what others are building with Alexa.
- Voice Design Guide - A great resource for learning conversational and voice user interface design.