Store what the user said

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:

Final result of how to get UserName

We will start from the 'User wants to order coffee' flow and perform the following steps:

  • Add an intermediate output node to prompt for the user's name.
  • Catch the user's words in a condition.
  • Make use of the user's words in an output text.

Add an intermediate output node

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:

  1. Open the 'User wants to order coffee' flow in edit mode.
  2. Click on the 'User responds with coffee type' transition. Right-click to open a pop-up menu. Select 'Insert after' and then 'Output' to add an intermediate output node between this transition and the 'Summarize order' node.
  3. Select the new output node.
  4. Add a name for the node, for example Ask for name.
  5. Add Ok, what name shall I note for the order? as an answer.

Catch the user's words

Before we can actually catch the user's name, we have to define a flow variable to store it:

  1. Open the 'Flow' Panel on the left hand side.
  2. Select 'Variables'.
  3. Add a new variable.
  4. Name it userNameForOrder.
  5. Set its default value to the empty string ("").
  6. Use the back arrow to go back to the Flow view.

When this variable is in place, we need a condition on the transition:

  1. Select the transition going from the 'Ask for name' node to the 'Summarize order' node.
  2. Add a name for the transition, for example Get user name.
  3. In the 'Match Requirements' section, add a 'Condition'.
  4. Add (*)^{userNameForOrder = _USED_WORDS} in the condition field.
  5. Make sure 'Get input before continuing' and 'Match conditionally' are both selected.

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:

Example usage for special used words variable

Return the user's words in the output

Finally, we can use the variable userNameForOrder in the order summary that we return to the user:

  1. Select the output node Summarize order.
  2. Replace the existing text with the following: Thanks for your order, ${userNameForOrder}. Your ${orderedCoffeeType} will be ready for pickup in 5 minutes.
  3. Hit 'Save'.

Try it out!

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.

Enhance robustness

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:

Use person annotation in combination with used words

This is how you use it in your flow:

  1. Open the 'Get user name' transition.
  2. Replace the existing condition with %$PERSON.NER^{userNameForOrder = _USED_WORDS} / (! %$PERSON.NER & (*)^{userNameForOrder = _USED_WORDS} ).
  3. Hit 'Save'.

Note that this step is only supported when developing for a language with Lexical Resources.

Try it out again!

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?