Building Conversations With Alexa
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:
{ "outputSpeech":{ "type":"PlainText", "text":"Ready? What is 4 plus 5?" }, "directives":[ { "type":"Dialog.ElicitSlot", "slotToElicit":"Number" } ], "shouldEndSession":"false" }
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!
Pingback: The Alexa Prize, Socialbots, and Automated Home Technology