How To: Build a Trivia Game Skill for Alexa

It seems like everyone and their grandma are picking up a virtual assistant, and quite a few of them are getting devices equipped with Alexa. While Alexa has many useful skills, like updating you on the current weather, manipulating your lights, and even ordering more laundry detergent, she’s open to new suggestions. Through Amazon Web Services(AWS) and Alexa Skills Kit(ASK), you too can create a skill. I’m going to walk you through the basic steps you’ll need.

First thing you’ll need is a developer account with Amazon. Once you’ve created an account, look for the Alexa tab in your developer console and click Get Started under Alexa Skills Kit. In the top right corner, click the Add a New Skill button.

On the next page, you should see something like this:

We’ll be making a Custom Interaction Model. Fill in the name of your trivia game (I went with Game of Thrones trivia) and its invocation name. I kept these the same to keep things simple. We won’t be using any of the items in the Global Fields, so you can leave them alone for now. Click save, then next to continue.

Now your screen should look like:

This is where the real magic starts to happen. Here, we layout our intent schema and sample utterances. These are the things that Alexa will use to know what to do when you don’t know what Tywin Lannister’s last words were. For this example we’re not interested in creating anything too crazy, so I’m going to layout some basics for you. You can copy/paste the following into intent schema:

{
"intents": [
{
"intent": "AnswerIntent",
"slots": [
{
"name": "Answer",
"type": "AMAZON.NUMBER"
}
]
},
{
"intent": "DontKnowIntent"
},
{
"intent": "AMAZON.StartOverIntent"
},
{
"intent": "AMAZON.RepeatIntent"
},
{
"intent": "AMAZON.HelpIntent"
},
{
"intent": "AMAZON.YesIntent"
},
{
"intent": "AMAZON.NoIntent"
},
{
"intent": "AMAZON.StopIntent"
},
{
"intent": "AMAZON.CancelIntent"
}
]
}

And the following contains our Sample Utterances:

AnswerIntent the answer is {Answer}
AnswerIntent my answer is {Answer}
AnswerIntent is it {Answer}
AnswerIntent {Answer} is my answer
AnswerIntent {Answer}
AMAZON.StartOverIntent start game
AMAZON.StartOverIntent new game
AMAZON.StartOverIntent start
AMAZON.StartOverIntent start new game
DontKnowIntent i don't know
DontKnowIntent don't know
DontKnowIntent skip
DontKnowIntent i don't know that
DontKnowIntent who knows
DontKnowIntent i don't know this question
DontKnowIntent i don't know that one
DontKnowIntent dunno

This will tell Alexa what to do when she hears certain phrases. These are pretty generic, and adding to them can make your game seem more life-like and user friendly. Go ahead and save (this will take a minute), and once its successful, click next.

Now we need to change gears and actually create our game. You can do this part from scratch, or you can head to this repo for the template(it also contains the long version of these directions). Fork, copy, and clone the repo to your own workspace, and execute the following command:

npm install --save alexa-sdk

In this file you can update the questions and other things to make it your own.

Zip up all the files inside the src directory, and get excited! We’re getting close.

Next, you’ll need an AWS account and to head to their console. On the main page, head to their lambda services (if you can’t find it, you can just search from the top bar) and click Create a Lambda function. We’ll be using a Blank Function blueprint, and on the next page the Alexa Skills Kit trigger. Click, next, and you should see this page:

Fill in your game’s name, description, and chose the Node.js 4.3 runtime. In code entry type, chose upload a .ZIP file, and upload your zipped file. The only other thing we’ll need to change is the role under Lambda function handler and role. Change it to Create a custom role, which will put you in a new window. Change the IAM Role to Create a new IAM Role, and the Role Name will change automatically. Go ahead and allow. Click next for the millionth time, review the next page, and create your function. You’ll be given and ARN on the next page in the top right corner. Copy this, and head back to your developer account.

We’re back where we left off. Now, click the buttons that are clicked in the image above, and paste your ARN in the blank field. You can mess around with the other settings, but its easiest to leave them for now. Click next(haha) and you’re set!

You are now on the testing page, where you can check, modify, and just play with your new game! Enjoy!