Building Conversations With Alexa

Having an Amazon Echo Dot in my office is quite fun, and I’ve accidentally started writing more skills and giving a few talks about building skills for the Alexa toolchain. Today I created a skill that uses multiple steps to make a conversation and thought I’d better write down what I did so I’d be able to remember!

The basic idea is that when creating the “intent”, i.e. the action that you want Alexa to do, you also define “slots”. The slots are the variables; if this were a command line tool, they’d be the arguments you typed. It’s possible to include both intent and slots in your wording when you speak to Alexa, but equally you can just invoke the skill and have it prompt you for the rest of the information.

Prompting the user for information

This model of having multiple steps in the exchange between the human and Alexa is what Amazon calls a “Dialog” and to define this, you need to use their new graphical skill builder tool rather than just a JSON structure describing your intents and slots (a bit tedious for those of us who struggle with graphical interfaces). When you add a slot, you can specify the data type and the “prompt”, so the words that the device will say when asking the human to supply the information. You can have one or many of these. In the request object that arrives when the skill is invoked you should also see a dialogState element has appeared.

If this says STARTED then you can ask Alexa to go ahead and prompt for the information from the user by sending a Dialog.Delegate directive (note that you must not send output speech with this directive, it gets upset). Once all the slots are filled you’ll get another IntentRequest and the dialogState will say COMPLETED. At this point, you should have all the information you’d need to figure out a response and send it back.

Dynamic user prompts

Sometimes, we don’t want to use automatic wording. For example I have a skill that challenges the user to answer a simple maths question – so the user input still needs to go into a slot, but I need to ask a different question every time. For that, we can use the Dialog.ElicitSlot and send some output speech to use as the prompt. Here’s the response I send to achieve this:

      "text":"Ready? What is 4 plus 5?"

Using this approach you can nominate whichever slots up front, and then prompt the user as appropriate, either using predefined wording or using your application to create and prompt. Once I understood how all the moving parts moved, this was fairly simple to get working so hopefully it helps someone else get quickly started to making something awesome too!

One thought on “Building Conversations With Alexa

  1. Pingback: The Alexa Prize, Socialbots, and Automated Home Technology

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.