In this example we’ll build a chatbot for Alexa to turn on the home lights. The chatbot will also ask for the room and the color of the lights and will be smart enough to not ask if these are already specified in the first sentence. The chatbot will also request confirmation for each step (yes, it’s overzealous but this is just an example to test the potential).
First some definitions before proceeding: * model: text recognition must be trained with some sentences and variations of the same user’s intention, the more the better. One saved and compiled it will be used at runtime (by Alexa) to understand what the user is saying * intent: it’s label for a group of training sentences that means a specific intention of the user (for example switch_lights
) * slot: it’s a bit of a sentence that can vary inside a sentence and need to be extracted into a variable (for example the room in the sentence “switch on the lights in the kitchen”) * slot type: the allowed values for a slot (for example a date, a number or a predefined list of values)
First thing is to train a model model for the intent switch_lights, start writing some sentences like
switch on the lights
switch lights in the {room}
switch on lights in {color} in the {room}
switch on {room} lights in {color}
In curly brackets are the slots: as soon as you type the {
the editor ask to pick up an existing slot or to create a new one. We’ll create to new slot: room and color. It’s not possible to save the model yet since the two new slots are not assigned to any slot type: * color: select the predefined type AMAZON.color * room: create a custom slot type for room with these elements: kitchen, bedroom, dining room, basement, restroom
Then, to make the example more complex will make both slots required and to be confirmed:
Slot configuration
In this way, if not specified in the first sentence, Alexa will ask for the slot room
(make sure to fill in the the “Alexa speech prompts” field under Slot Filling) and after that will ask a confirmation (make sure to fill “Alexa speech prompts” field under Slot Confirmation and include the {room}
slot in the string to have it automatically replaced with the chosen value).
Repeat a similar configuration with the color
slot, also turn on the intent confirmation and provide a prompt for it (that should include include the slot placeholders to make the sentence more meaningful)
Intent Confirmation
The Alexa chatbot is different compared to other chatbot platforms, the [[Alexa Receiver node|Alexa-Receiver-node]] will only send out message of type [[intent|Intents]] which is the result of the natural language processing of the user’s speech, it basically contains:
So basically when the user says something like “Alexa, switch on the lights”, the chatbot will receive a message like
{
payload: {
type: 'intent',
variables: {
room: null,
color: null
},
confirmationStatus: 'none',
slotConfirmationStatus: {
room: null,
color: null
},
dialogState: 'started'
}
}