Writing an Alexa Skill — Part 2: Data Storage

Part 1 of my story is here.

If you recall from my previous post, I created an Alexa skill to tell me when I should take out the garbage.

But the skill can only respond in a generic manner because it lacked 2 key pieces of information: the address the user is located at, and the garbage zone associated with that address.

There may be ways to find the address via an Echo device’s profile, but it’s not clear if there is any API to retrieve an address’ garbage zone. The last thing I would want to do is to maintain some internal mapping between an address and its zone… or so I thought…

And that’s when it hit me: while I do need to store a mapping between a device and its zone, the address part is actually irrelevant because the user can simply tell Alexa what zone they are in.

Now it became clear what the skill needed:

  • First, a new intent with a slot parameter for the zone, something like “Alexa, I live in a yellow zone”
  • Second, a way to store the information provided by the user
  • Lastly, a way to clear the stored information when it is no longer needed

Adding an intent with a slot was straightforward and can be done directly in the Alexa developer console. For zone information storage, naturally a backend datastore is needed. Since we’re working in Amazon’s ecosystem, DynamoDB was the goto choice.

I already had an AWS account created when I first dabbled in creating a skill — I said AWS would come in handy didn’t I? — so provisioning a DynamoDB table in AWS was also quite straightforward. But in order for my skill to read/write to this table, I needed to associate with it a role with the AmazonDynamoDBFullAccess permission. I won’t go into details on how this is done, as it is well documented here.

Back in my skill, I can now perform operations on the DynamoDB table with the provided AWS-sdk APIs. For example, an insert operation looks something like this:

Now when a user asks my skill “Is it garbage pickup week?”, it can give a more definitive answer:

“Yes, it is garbage pickup week.”

— provided the user has previously told the skill what zone they are in using the new intent. Otherwise, Alexa will fallback to giving a generic response.

The last part, clearing the zone data when it’s no longer needed, sounds simple but actually involves learning a few new things, so I’ll save that article for another time.

Updates:

--

--

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