Creating an Alexa Skill in 2021

Structure of a voice command

At first it is important to understand how a voice command is interpreted by Alexa. It consists of four parts:

  1. Wake word (“Alexa”)
  2. Invocation name (name of your skill)
  3. Utterance (certain words that lead to specific actions)
  4. Slots (optional variables)
How Alexa structures your input
Different utterances trigger different intents

Creating your skill

Now that you know this, we will try to develop an example skill that has two features:

  • Say your name (which we predefine)
  • Repeat a name we tell alexa

The Developer Console

Head over to the Alexa Developer Console and (if not already done) sign up with them. Click on “Create skill” and choose a a name for it. For demonstration purposes I’m going to use name sayer. Enter the desired skill name and leave everything else empty. Leave the model at “Custom” and the hosting method at “Alexa-hosted (Nodejs)”. You can also select python, but I’m going to cover the Node.js-version in this tutorial.

Configure your variable, aka “slot”

Coding the logic

The setup preparations are finished and we can start coding. If you are familiar with Nodejs, you’ll have an advantage for sure. In the top navigation bar, click on Code and you are redirected to the index.js file. In this tutorial, this is the only file we’ll need.

Please notice the name of the handler SayMyNameIntentHandler and the appropriate name of the intent “SayMyNameIntent
Notice that we added SayMyNameIntentHandler to addRequestHandlers()

Working with slots

Let’s start implementing our RepeatMyNameIntent and find out how slots work. Copy the previously created handler and rename it to RepeatMyNameIntentHandler. Don’t forget to add it to the requestHandler-section.

  1. The user tells Alexa to repeat a name without specifying which. In this case, Alexa has to ask for the name
  2. The user tells Alexa immediately to repeat a specific name. In this case, Alexa parses the slot and reacts directly.
Alexa.getSlotValue() does the job

Skill testing

Since we are done for now, click Save and Deploy in the menu. You can now head to the Test section in the upper menu band and change the skill testing enabled to Development. Alexa provides a simulator so that you can test the behaviour of your skill in different situations.

Test results of SayMyNameIntent and RepeatNameIntent

Tips and tricks

During developing my skill I experienced a few problems that cost me quite a lot of time. Maybe you can avoid these and save some time with the following tips.

Have a look at the json output

When testing your skill, all input and output is printed in json format. This information can be extremely useful during debugging, as it also shows the complete request content such as intent and slots.

"request": {
"type": "IntentRequest",
"requestId": "amzn1.echo-api.request.8d3ed5dc-4d8f-460e-9480-d932c465211f",
"locale": "de-DE",
"timestamp": "2021-04-22T16:22:48Z",
"intent": {
"name": "RepeatNameIntent",
"confirmationStatus": "NONE",
"slots": {
"nameToRepeat": {
"name": "nameToRepeat",
"value": "martin",
"confirmationStatus": "NONE",
"source": "USER"
}
}
},

Debug using console.log()

Sometimes the json output is not enough our you just get a generic error while testing like “something went wrong” or “an error occured” without giving you specific information. Use console.log() to track your progress, position and variables. To see your log files, click on CloudWatch Logs.

You can’t find your log files

Although logging everything is a great way to debug, I just could not find the log output in the CloudWatch log console. Errors like “Protocol group does not exist” occured and none of the buttons lead to the appropiate log group.

Change location until logs appear
Chances are high that your logs are saved on one of these locations

Develop offline as long as possible

If you’re trying to find an error in your skill, it can be painful to do console.log() and switch between code and log section all the time. Alternatively, you could develop and test the core functionality of your skill in an offline Nodejs environment. Just install Nodejs on your local computer and create a local .js-file which you can run using the command node index.js.

Starter template to get going offline

Save time using the utterance evaluation

Sometimes you keep on coding in circles although the code logic is correct. Instead, there might be a problem with your utterances. Alexa offers an utterance evaluation function which makes it easy to test different variations of inputs. As a result, you’ll see which utterances trigger which intents and which slot values are detected.

Left: correctly called intent based on utterance. Right: randomly, wrong input calls the FallbackIntent

Final Words

Developing an Alexa skill has become quite easy if you know these fundamentals. This tutorial is supposed to give you a quick and easy introduction and was therefore pretty basic.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store