Step 3: Slots and Parameters

by Jan König on Nov 24, 2018

In this step, we're addressing a problem that has come up in the previous step: BlueDoorIntent and RedDoorIntent are so similar, why do I have to do all the work twice? And what would happen if there were even more doors with more colors? Meet slots and parameters.

Changing the Interaction Model

As previously mentioned, the intents BlueDoorIntent and RedDoorIntent are pretty similar to each other, as in the utterances are the same, with only the color being different.

This comes with two main problems:

  • It's a lot of redundant work setting up the language models
  • It could confuse the natural language understanding service from the voice platforms, as the example phrases are too close to each other

So, wouldn't it be great to merge the both intents to one, say, EnterDoorIntent?

It would look like this:

With only one intent left, how can we train the language model to help the voice service understand the difference between the blue and the red door?

This is what parameters (slots on Alexa and entities on Dialogflow) are about:

Introduction to Slots and Parameters

Slots are one of the 3 Elements of Voice Interactions (Project 1 Step 2: Introduction to Language Models). Depending on the platform, they are also often referred to as parameters or entities. For this course, we are going to call them slots most of the time.

These slots are additional elements of input within an intent that a user provides. In this example, the differences are only in the color, so we're going to add a slot called Color to our interaction model.

Let's go to the platforms and create the new intent EnterDoorIntent with slots called Color.

Creating an EnterDoorIntent

In this section, we're going to merge the BlueDoorIntent and RedDoorIntent to a single EnterDoorIntent on Amazon Alexa and Dialogflow. If you prefer to only use one platform for testing, you can jump right to it:

Creating Slots on Amazon Alexa

On the Amazon Developer Portal, let's delete one of the existing intents. In our example, the BlueDoorIntent:

Instead of having to create a whole new intent with all the utterances, let's modify the RedDoorIntent and add a slot there. Rename the intent to EnterDoorIntent:

Next, select the color in one the utterances:

Create a new intent slot called color. Then, you can select all elements that say red and assign them to this intent slot. It should now look like this:

It is likely that a person could also answer with "the red one" or "the blue one", so let's add something like this as well:

Now that we have created an intent slot, we need to tell Alexa what values to expect for it. At the bottom of the screen, you can see that it's possible to choose a slot type:

By clicking on it, you can see all the options Amazon provides as built-in slots.

If you search for color, you can see that Amazon already provides a slot type called AMAZON.Color. Although we only have two colors to select from, let's use this for convenience:

You can now see that this slot type is selected:

You're done! Click on Build Model to finish the process of adding a slot to your EnterDoorIntent.  

Creating Entities on Dialogflow

We're doing the same thing on Dialogflow: Delete one slot and renaming the other to EnterDoorIntent.

As already mentioned in the last step, Dialogflow automatically detected "red" as a color in the sample phrases. Let's click on it:

As you can see in the screenshot above, a built-in entity called @sys.color:color is suggested, which is similar to Alexa's AMAZON.Color slot type.

So, Dialogflow saved us some time by attaching the slot itself. It also named the parameter color, which matches the name of the intent slot on the Alexa platform. This will come in quite handy in our next step, when we're updating the code.

Updating the App Logic for EnterDoorIntent and Parameters

Now that we updated our interaction models, let's take a look at our voice app's code.

Remember that our app logic looked something like this:

Let's merge the two intents. The response could look something like this:

However, how can we access the values a user provided with a slot or entity? With the Jovo Framework they are stored in the $inputs object:

Also, let's add some error handling, so that users are asked again if they miss to provide either blue or red:

That's it!

Let's test it on the platforms.


Save your code and restart your local server in your command line with ctrl + c and jovo run.

Then, go to your preferred platform to do some testing (or talk to the device next to you).

Amazon Alexa

Go to the Service Simulator and type in different phrases to see if they return the expected response. For example, "go through the red door":

Now let's try something else. What if the user is confused and wants to go through a green door instead? Then our app should ask for either red or blue again. And it works:

That's it!  

Google Assistant

On Dialogflow, you can see compare different responses in the testing panel to the right:

Next Steps

Step 4: Built-in Intents and intentMap

Jan König

Co-founder at Jovo

Comments and Questions

Any specific questions? Just drop them below or join the Jovo Community Forum.

Join Our Newsletter

Be the first to get our free tutorials, courses, and other resources for voice app developers.