For many applications, it is useful to store exactly what the user said: for example, the user's name:
User: I want a cappuccino.
Bot: Ok, what name shall I note for the order?
User: Amber.
Bot: Thanks for your order, Amber! A cappuccino will be ready for pickup in 5 minutes.
We start from the existing 'User wants to order a coffee' flow and extend it. We will show you how you can catch the user's words and reuse them in your bot's reply. This is what the final flow will look like:
We will start from the 'User wants to order coffee' flow and perform the following steps:
We start from the existing 'User wants to order coffee' flow. In order to ask for the user's name, we have to add an additional output node before the order is summarized in the final output node:
Ask for name
.Ok, what name shall I note for the order?
as an answer.Before we can actually catch the user's name, we have to define a flow variable to store it:
userNameForOrder
.""
).When this variable is in place, we need a condition on the transition:
Get user name
.(*)^{userNameForOrder = _USED_WORDS}
in the condition field.The condition "(*)" on the transition matches any input word. This input word (in this case, the user's name) is assigned to the flow variable userNameForOrder via the special variable _USED_WORDS:
Finally, we can use the variable userNameForOrder in the order summary that we return to the user:
Thanks for your order, ${userNameForOrder}. Your ${orderedCoffeeType} will be ready for pickup in 5 minutes.
You are now all set to try out whether the bot can pick up your name! Just open Try Out and go ahead and type something along the lines of:
User: I want a cappuccino.
Bot: Ok, what name shall I note for the order?
User: Amber
Bot: Thanks for your order, Amber! A cappuccino will be ready for pickup in 5 minutes.
This conversation works fine as long as the user replies only with one name. As soon as the user's answer differs, the bot will get it wrong, as in:
User: I want a small cappuccino.
Bot: Ok, what name shall I note for the order?
User: My name is Amber.
Bot: Thanks for your order, My! A small cappuccino will be ready for pickup in 5 minutes.
This happens, because the bot currently only picks up the first word of the user's answer. In the following, we will show you how to make your bot more robustly recognize names in the user input.
Until now we have simply assumed that the first word of the user's answer is the user's name and proceeded without checking. While this may work for many cases, it is not a very robust approach, as we have seen for the "My name is Amber" input above. We will here show you how you can pick up the user's name from a sequence of words in the user input using annotations. If a person name has been annotated in the user input, then we want to assign this word(s) to the variabe userNameForOrder. Translated into Teneo's condition language, this is what such a condition will look like: %$PERSON.NER^{userNameForOrder = _USED_WORDS}
. This condition will work for all names that are recognized and annotated by Teneo's named entity recognizer. Now, just to play safe, we will add a second part to this condition, namely if no person name has been annotated in the user input, then simply fall back to our initial way to pickup the user name using the first word of the input '(*)'. The final condition will then look as follows:
This is how you use it in your flow:
%$PERSON.NER^{userNameForOrder = _USED_WORDS} / (! %$PERSON.NER & (*)^{userNameForOrder = _USED_WORDS} )
.Note that this step is only supported when developing for a language with Lexical Resources.
That's it, now go ahead and give it a go in Try Out. With this new condition in place, you should get the following conversation going:
User: I want a small cappuccino.
Bot: Ok, what name shall I note for the order?
User: My name is Amber.
Bot: Thanks for your order, Amber! A small cappuccino will be ready for pickup in 5 minutes.
Was this page helpful?