Gathering information with IBM Watson Assistant

Simon Burns
Mar 31, 2017 · 7 min read
Image for post
Image for post

IBM Watson Assistant is a service that enables the building of chatbots, and other applications that need natural language processing capabilities. A common pattern needed in chatbots is to gather a set of information, much like you would on a traditional web form.

With a chatbot, the complication is that you want to be able to accept all pieces of information up front if provided, and then only prompt for the missing pieces. If you have read one of my previous articles, Conversation Patterns with IBM Watson, you may remember there was a section on exactly this, but you had to handcraft a set of nodes to do it. Watson Assistant has been updated with a new capability which makes it much easier to build this pattern.

If you are not already familiar with Watson Assistant then you may want to read Getting Chatty with IBM Watson and Conversation Patterns with IBM Watson first.

For the purpose of this article, we’ll be creating a simple version of a pizza ordering bot.

The Basics

Image for post
Image for post

and our entities:

Image for post
Image for post

Now we create a node that responds to the user asking to order a pizza:

Image for post
Image for post

Now let’s use the new capability to make sure the user tells us the size of pizza that they want. We can enable it by clicking on the “Customize” link at the top of the node editor, and then selecting “Slots” in the Customize modal.

Image for post
Image for post

You will now see a new section in the node editor that allows us to define the information we want to gather.

Image for post
Image for post

So now we can gather information about the size of pizza being ordered.

Image for post
Image for post

This is saying, if the input contains @size then save it in the $size context variable. If @size is not specified then ask the user for it using the question text.

Now we can update the node response to indicate what size was chosen.

Image for post
Image for post

Let’s see this in action. If I ask for a pizza but don’t give the size, it asks me for it:

Image for post
Image for post

But if we give the size upfront then it doesn’t need to prompt:

Image for post
Image for post

I want to know more!

We can create an entity for our toppings:

Image for post
Image for post

and add another prompt to capture them:

Image for post
Image for post

Now this will only capture the first topping the user says, so we need to adjust this to get all of them. We can simply use the values property of the entity to get them:

Image for post
Image for post

And update our response to show the toppings:

Image for post
Image for post

Now let’s see this in action. Notice that the ordering of prompts affects the behavior as it will prompt for the earlier ones first.

Image for post
Image for post

Tell me everything straight away!

Image for post
Image for post

This will add a section just below the slots:

Image for post
Image for post

Here we can add text to ask for all the information we want to collect:

Image for post
Image for post

And let’s see it in action:

Image for post
Image for post

So now the user knows upfront what information we want, and we will still prompt for anything they don’t provide.

Optionally…

We can do this with an optional slot, so if the information is provided then it is captured but it won’t be asked for. So for our pizza bot we can define an entity for dairy-free:

Image for post
Image for post

And then add an optional slot to handle this:

Image for post
Image for post

Note that there is no prompt, and it says “Optional”. Leaving the prompt empty like this makes the slot optional. Adding the $dairy_free variable to our response then gives us:

Image for post
Image for post

That’s not what I want to know

Click the little cog icon in the slot. This will bring up an editor where we can define additional behaviour when users responds. We can add behavior for “Found” and “Not found” to have different responses when the user provides correct or incorrect information respectively.

Let’s add a “Not found” response to provide some more information on what we want to know. Note if you want to add conditions to these found and not found responses, click on the 3 dot button at the top right and select “Enable conditional responses”.

Image for post
Image for post

So now, if the user doesn’t provide a size, we will re-prompt them but providing more information about what sizes are available.

Image for post
Image for post

You got it!

Image for post
Image for post

Which results in this:

Image for post
Image for post

Are you sure?

We can do this by adding another slot like this:

Image for post
Image for post

Notice that we have added a “Not found” response which clears the $size and $toppings variables. This tells the node that it has to reprompt for these.

Image for post
Image for post

So let’s try it out:

Image for post
Image for post

Or maybe we changed out minds:

Image for post
Image for post

But what about this other thing?

Image for post
Image for post

The bot doesn’t understand and just carries on prompting. We can add some additional responses to handle these situations. First we need to add an intent for the delivery question. Then we can add handlers. Click on the “Manage handlers” link above the slots, and add a handler conditioned on #delivery and provide a suitable answer:

Image for post
Image for post

And let’s see how this works:

Image for post
Image for post

Go gather info!

Find more of my Watson articles in the Conversational Directory.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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