Teneo Developers

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 flow

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 Syntax 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.
  2. Click on the Plus icon after the 'User responds with coffee type' transition, Continue with 'Transaction element' and 'Output'. This will add an Output under the transition..
  3. Add a name for the output node, for example Ask for name.
  4. 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. Click on the 'Variable' button, located under the minimap, followed up with the Plus icon.
  2. Name it userNameForOrder.
  3. Set its default value to the empty string ("").
  4. Finally, click on 'Confirm' to create it.

No that the variable is in place, we need to add a TLML Syntax Match on the transition to capture the mentioned name:

  1. Locate the transition below 'Ask for name'.
  2. Select the Plus icon under the transition and add a 'Match' for 'TLML Syntax'.
  3. Add (*)^{userNameForOrder = _USED_WORDS} in the Syntax editor.

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:

Build - Store what the user said: used words6

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. Click on the Plus icon below the 'Ask for name' node, followed up with 'Continue', transaction element and 'Response'. This will make sure the transition waits for an input before continuing.
  2. Now, go ahead and finish the flow by navigating to the 'Summarize order' output node.
  3. Replace the existing text with the following: Thanks for your order, ${userNameForOrder}. Your ${orderedCoffeeType} will be ready for pickup in 5 minutes.
  4. Hit 'Save'.

Try it out!

You are now all set to try out whether the bot can pick up your name! Just open Tryout 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 cappuccino.
Bot: Ok, what name shall I note for the order?
User: My name is Amber.
Bot: Thanks for your order, My! A 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 TLML Syntax condition language, this is what such a condition will look like: %$PERSON.NER^{userNameForOrder = _USED_WORDS}. This Syntax 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:

Build - Store what the user said: annotationUsedWord3Resized

This is how you use it in your flow:

  1. Navigate back to the 'Get user name' transition.
  2. Replace the existing TLML Syntax Condition with %$PERSON.NER^{userNameForOrder = _USED_WORDS} / (! %$PERSON.NER & (*)^{userNameForOrder = _USED_WORDS} ).
  3. Hit 'Save'.

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

Try it out again!

That's it, now go ahead and give it a go in Tryout. With this new Syntax 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.