Skip to main content

After Matches

After Matches are actions which are executed and evaluated only after the trigger or transition has been triggered. This page provides information related to the various After Match actions available in Teneo Studio, including step-by-step guides on how to add, edit or delete an After Match.

The sections on this page provide information about the various aspects of After Matches:

Concept

After Matches are used to perform an action in a trigger or transition that has been triggered through matching. An After Match can be set for a trigger or transition and they are only executed after the trigger or transition has been triggered. This means that a Match must match before the After Match is performed.

An After Match can be used to perform the following actions:

  • Transfer information from a Language Object to a Flow.
  • Define a specific condition to be met before the Flow executes a Script.
  • Trigger a Listener in a trigger or transition.
  • Extract an Entity mentioned by the user.

The After Matches are executed in the same order as they are listed, just like regular Matches. Once triggered, an After Match will execute an action depending on what has been selected.

A common use case of After Matches is extracting entities from user input in order to avoid repetitive questions, for example when slot-filling. Sometimes the end-user will tell the bot the answers of certain questions before they are expected and, to make conversations flow more naturally, the bot can be told not to ask questions when the answer to these are already known.

This can be done as follows:

  • add an After Match after the User Intent trigger to ensure that the bot listens for information.
  • add a User Intent transition where the question is only asked in situations where the answer was not already given.
  • add an additional path to skip the question in the Flow for cases where the answer is already known.
note

Note that an After Match action is optional, where the input is not forced to trigger it. Once triggered, After Match actions will execute your Mapping or Script depending on which you've selected. If you want to ensure an After Match action is executed, you will need to ensure that the Match preceding that After Match is met.

For Entity or Language Object After Matches, the action executed will be a variable Mapping. For Listener and Script After Matches, this action will include an execution Script.

When handling variables in Mapping, the 'Source' field denotes the value of the NLU variable of the entity that we want to store and the 'Target' field denotes the name of the variable where the extracted value is to be stored.

desktop after match

Choose an After Match

Choosing an After Match or the combination of various After Matches always depends on the particular use case and the dialogue requirements. The following sub-sections intend to provide guidance for deciding which After Match action to use.

After Match Types

There are four After Match types available in Teneo Studio:

  • Entity
  • Language Object
  • Listener
  • Script
Entity

An Entity After Match is executed only for inputs that match the selected Entity.

When an Entity After Match is added, it is possible to add a number of mappings from one of the NLU Variables of the Entity; every time a new input matches the Entity, the values in the source are stored in the selected targets. The same source can be selected multiple times, but each target can just be selected once (as multiple values would overwrite previous ones).

It is possible to use After Match actions to extract the values stored inside an entity. If the user selects Entity as an After Match, they will need to define which Entity they are interested in. Once that is defined, the user will have the option to 'Add Mapping' and transfer the values from 'Source' to 'Target'.

info

There is no mandatory connection between Entities matched in the list of Matches and those added to the After Matches, i.e. Entity After Matches can be defined even if no Entity Match is defined or even for different Entities.

Language Object

The Language Object After Match is executed only for inputs that match the syntax of the selected Language Object.

When a Language Object After Match is added, it is possible to add a number of mappings from one of the NLU Variables of the Language Object to Global or Flow Variables; every time a new input matches the Language Object's syntax, the value in the source is stored in the selected target. The same source can be selected multiple times, but each target can be selected only once (as multiple values would overwrite the previous ones).

There are some cases where the Language Objects store NLU values inside them. The user has the option to access these by using After Match actions on Language Objects. While selected, the user must define which Language Object they are interested in. Once that's defined, the user will have the option to 'Add Mapping' and transfer the values from 'Source' to 'Target'.

info

There is no mandatory connection between Language Objects matched in the list of Matches and those added as After Matches, i.e. Language Object After Matches can be defined even if no Language Object Match is defined or even for different Language Objects.

Listener

The Listener After Matches are activated whenever the User Intent trigger or transition is triggered and the TLML syntax of the Listener matches the user input. In those cases, the Groovy script expression of the Listener is executed.

A Listener After Match is helpful when you want to extract information from the user input based on TLML syntax.

FLOW LISTENER

If you do not know when the user input you want to extract will be present in the Flow, it is better to use a Flow Listener instead. This will listen to user inputs throughout the Flow and not only for specific triggers or transitions.

MULTIPLE LISTENER AFTER MATCHES

If a Flow should pick up two dates from a user (like an arrival and departure date for a holiday), you can add one Listener After Match to the transition where the user is asked for the arrival date and another Listener After Match to the transition for the departure date. This way you ensure that the dates do not get mixed up in the Flow.

Script

In Script After Matches, the user can write Groovy scripts which are executed whenever the User Intent trigger or transition is matched.

How To

Add an After Match

In the Flow editor, follow the below steps to add a new After Match:

  1. Click the Plus icon where you want to extract info or execute a script.
  2. In the After Match group, choose to either:
    • extract the value of a Language Object (if it matches the input) (Language Object) by selecting a Language Object and adding a Variable Mapping; start writing the name of the wanted Language Object to filter the list by Language Object name
    • execute a script when the input matches an additional TLML Syntax rule (Listener) by defining a syntactic condition which should be met for the defined Groovy script to be executed
    • extract the value of an Entity variable (if present in the input) (Entity) by selecting an Entity and adding a Variable Mapping; start writing the name of the wanted Entity to filter the list by Entity name
    • execute a script (Script) by entering a Groovy script.
  3. Remember to Save the Flow to preserve the changes.
note

When adding an After Match Language Object or Entity, the initially displayed list of suggestions (before writing anything in the text field) contains a list of the 20 most recently added or modified Language Objects/Entities.

Edit an After Match

To edit an existing After Match follow the below steps:

  1. Select the After Match node in the Flow.
  2. Edit the wanted details.
  3. Remember to Save the Flow to preserve the changes.

Delete an After Match

  1. Go to the After Match node in the Flow.
  2. In the node, click the Recycle Bin in the sidebar.
  3. Remember to Save the Flow to preserve the changes.

UI

Plus Icons

Plus IconsDescriptionRelated Pages
web plus iconThe Plus icon below the trigger node allows to define After Matches for the selected trigger.User Intent
Flows
web plus icon transitionPlus icons throughout the Flow graph allows to define After Matches for the selected transition.Transitions
Flows

After Matches

After Match TypeDescriptionRelated Pages
web entity after match web node entity after matchAny values from the mapped source variables will be stored in the selected target variables if the user input matches the Entity.Entities
Entity Match
web lob after matchweb node lob after matchAny values from the mapped source variables will be stored in the selected target variables if the user input matches the Language Object.Language Objects
Language Object Match
web listener after matchweb node listener after matchThe script of the Listener After Match will be executed if the user input matches the TLML syntax.TLML Syntax Match
Flow Listeners
Scripting
TLML Syntax
web script after match web node script after matchA Script After Match is unconditional and will always be executed once the Trigger or Transition is matched.Scripting

Practical Examples

Adapt to User Input

Extract Entities from User Input

Sometimes the user tells you the answer to certain questions earlier than expected. As mentioned in the concept section, we can make use of After Matches to define an additional path and to make the conversation flow more naturally.

Let's take a look at an example solution, where we are implementing a Flow to handle coffee orders. Before adding the additional path, we may run into conversations like this:

Example 1

User: I'd like to order a Cappuccino

Bot: Ok, what coffee would you like?

User: I already told you, a Cappuccino!

Bot: Ok, a cappuccino will be ready for pickup in 5 minutes.

After adding the additional path, we can avoid the above and get more natural conversations, like this:

Example 2

User: I'd like to order a Cappuccino.

Bot: Ok, a cappuccino will be ready for pickup in 5 minutes.

Our example Flow is called "User wants to order a coffee". To pick up a coffee type if mentioned in the first user input, we will use an Entity After Match on the User Intent trigger.

Add Flow variable

First, we need a variable in our Flow to hold the coffee type mentioned by the user.

  1. In the flow's main window, move to the 'FLOW' tab, and select 'Variables'.
  2. Add a variable and name it orderedCoffeeType.
  3. Put "" in the 'Initial Value' field. This initializes the variable with the empty string.
Add Entity

Next, we will create an Entity to define what coffee types we want our solution to recognize when mentioned in the user input.

  1. In the main solution window, click on the Entity icon in the ribbon bar.
  2. A new window will open. Name the entity COFFEES_SERVED (the type .ENTITY is automatically defined).
  3. Click on the back arrow to go to the Home tab of the Entity, where you will be able to edit it.
  4. Copy the following table onto the clipboard:
    Coffee namecoffeeType
    %AMERICANO.NN.LEXamericano
    %CAPPUCCINO.NN.LEXcappuccino
    %CORTADO.NN.LEXcortado
    %ESPRESSO.NN.LEXespresso
    %FRAPPUCCINO.NN.LEXfrappuccino
    %LATTE.NN.LEXlatte
    %LUNGO.NN.LEXlungo
    %MACCHIATO.NN.LEXmacchiato
    %RISTRETTO.NN.LEXristretto
    %MACCHIATO.NN.LEXmacchiato
    brewed coffeebrewed coffee
    filtered coffeebrewed coffee
  5. Inside the Entity, select the cell marked 'Click here to add a new entry'.
  6. Paste the table you copied earlier.
  7. You will now be prompted to say whether the data you pasted includes a row of headers or consists purely of data. In our case, the first row consists of headers, so select 'First row is variable names'. If you experience unexpected behavior in this step try copying the table by highlighting it rather than using the 'copy' button.
  8. Hit 'Save'.
Add After Match

Now that we have a Flow variable and an Entity to store coffee types, we just need an After Match in our Flow:

  1. Open the Flow.
  2. Under the first User Intent node, click on the Plus icon followed by 'After Match' and 'Entity'. We will use this to extract values from an Entity.
  3. Paste in the Entity name, COFFEES_SERVED.ENTITY.
  4. Click on 'Add Variable Mapping' below the entity name.
  5. Now use the drop-down menu below to determine the source variable, which is the string variable in our Entity, 'coffeeType'. Then do the same for the target variable, which is the Flow variable, 'orderedCoffeeType'. This transfers the value from the source and assigns it to the target.

Specify when outputs should be skipped or given

This example shows how to specify when an Output should be skipped or given:

  1. Click on the Plus icon below the Raise label, followed by Continue with and Junction
  2. Click on the Plus icon below the Raise label again, this time selecting Match and Flow variable
  3. In the dropdown menu, select the variable name (for the sake of the example, let's say orderedCoffeeType).
  4. In the Evaluation script, paste ""

The existing path will now only be executed if the value of the variable is empty. Now, let's also add the path the bot should take if the variable has already been assigned a value in the After Match where the coffee type, for example, is picked up from the user's first input:

  1. Hover over the arrow beneath the junction that does not go to the existing path, there should be a small green dot.
  2. Click and drag to create a new path from the junction to the next node which the user should visit.
  3. Remember to Save the Flow to preserve the changes.

To summarize, we check whether the first user input contains a coffee type and, if it does, we store that in the variable set up for this. After the junction, the user is then either asked for the coffee type or the path is skipped until the selected node.