Sometimes it's not enough to recognize which flow to trigger. Your bot may also need to extract some piece of information from the input to respond appropriately. Let's assume that the user wants to know where our Longberry Baristas stores are located. This is how such a conversation could go about:
User: Where are your stores located?
Bot: Currently our only store is in New York.
Another possible conversation is the following, where the user asks whether Longberry Baristas have a store in a specific city. Here, the first part of the answer is the same, but then in the second part, the bot picked up the city the user is interested in and used it in the response:
User: Do you have a store in London?
Bot: Currently our only store is in New York. We might consider opening additional stores in London in the future.
On this page we will first build the basic flow that handles questions about where our stores are located. Then, we will extend it to pick up the city the user mentioned and re-use it in the bot's answer. This is what our final flow will look like:
User wants to know if we have a store in city
. (If you need guidance on how to add a new flow, please check Your first flow).Where are your stores located?
Where are your shops located
Where are your cafes located?
Where do you have cafes?
Where do you have stores
Where do you have shops?
Where is Longberry Baristas?
Where can I find you?
Where can I find your cafes
Where can we find you?
Where do you have stores?
.Currently our only store is in New York.
in the answer text field. Then, name the output node Our only store is in...
.That's it! You have now created the basic flow that can handle the following kind of conversations:
User: Where are your stores located?
Bot: Currently our only store is in New York.
Now we will go ahead and extend this basic flow in order to recognize a city that the user mentioned and re-use it in the bot's reply. To do this we'll do the following:
In order to be able to store the city mentioned by the user, we need to create a flow variable:
city
by replacing the word 'Variable 1'.""
.We will now make sure that this flow triggers for inputs in which the user asks whether we have a store in a particular city. We can either add additional learning examples to the already existing trigger or add a second trigger. In this case we'll go for the latter:
Do you have a store in London?
Do you run a cafe in New York
Are there any of your stores in Sydney?
Do you have a branch in San Francisco
Have you got a cafe in Utrecht?
Is there a cafe in London
Do you have a coffee shop in Tokyo?
Have you shops in Berlin
Do you have any cafes in Paris?
In London, do you have a store there?
Is there a cafe of yours in Stockholm.
Do you have a cafe in Stockholm
Is there a store in Stockholm?
Do you have a store in city?
.Now that we have the trigger in place it is time to pick up the city that the user mentioned. We will do so by using a flow listener:
Pick up city
and paste %LOCATION.ENTITY^{city = _USED_WORDS}
in the condition field. This will store the part of the user input that matched '%LOCATION.ENTITY' in the flow variable city.
The LOCATION.ENTITY is pretty generous, it recognizes not only cities but also other locations like countries. If you want to be more precise and restrict the recognition to cities, you may use the language object CITIES.LIST instead. However, you risk that a particular city might be missing on this list.
The only thing that remains to be done now, is to add another output node after the existing one:
We might consider opening additional stores in ${city} in the future.
We might consider opening a store in city
.Have you noticed that the flow variable is used in the answer? When you embrace something in an answer text with ${ and } it will be programmatically evaluated before it is displayed to the user. Here that means that 'city' will be replaced with its current value.
If at this point you try the example conversation, you will notice it will not work. The flow will get stuck after the first output node. In order to fix it, we have to configure the transition between the two output nodes. As you can see, the transition is displayed as a solid line, which means it is waiting for an input of the user. But here we do not expect a user input between the two output nodes. Instead, we want the second output to be given only if the user has mentioned a city when asking for our stores. We thus have make the transition 'Conditional'. This is how we proceed:
{city}
. This is the name of our flow variable in which we store the city mentioned by the user. Adding the variable to the condition means that this transition will only be traversed if this variable has a value, which is the case if the user mentioned a city. City mentioned
.Now we are almost there. The only thing remaining to do is to add a node that allows us to properly exit the flow for the cases where the user did not mention a city. This is what we do:
No city mentioned, drop the flow
.That's it. Now go to Try-out and give it a go! Depending on whether or not you mention a city in your request, you should get either the short or the extended answer.
User: Where are your stores located?
Bot: Currently our only store is in New York.User: Do you have a store in London?
Bot: Currently our only store is in New York. We might consider opening additional stores in London in the future.
Was this page helpful?