In Teneo you can add constraints to a trigger or transition by using context restrictions. The role of a contextual restriction is to make sure an input not only matches a trigger or a transition, but that additional information is evaluated before the flow is triggered or the transition is traversed. This contextual information varies depending on the current conversation.
There are two different types of context restrictions:
- Scripted context restrictions, which use a script to evaluate if a context is true.
- Variable-based context restrictions, which evaluate if a variable exists or has a particular value.
For example, the Class below contains a scripted context restriction that prevents it from triggering if the confidence score of the input is lower than 0.60 (which corresponds to 60%):
You add a restriction to a trigger or a transition by clicking on the 'Plus' button, followed up with 'Match' and 'Scripted Context':
The Teneo Dialogue Resources (TDR) template come with a number of predefined (scripted) contexts out of the box, you can find their definitions in the globals section of your solution:
- Class Confidence High - Restricts classes to only fire when the confidence score is 0.80 or higher.
- Class Confidence Medium - Restricts classes to only fire when the confidence score is 0.60 or higher.
- Disable Match - Assign this context to disable a trigger or a transition from matching.
- Follow up of Flow - Checks if the previous input triggered the same flow as the trigger that is currently evaluated. This allows you to determine if an input is a follow up of the same flow.
- Follow up of Folder - Checks if the previous input triggered a flow in the same folder as the current one. This allows you to determine if an input is a follow up of a flow in the same folder.
- Input Sentences - The Context if fulfilled if the number of sentences in the user input matches selected state.
- Input Words - The Context if fulfilled if the number of words in the user input matches selected state(s).
For a practical example of how to use a predefined context, please read How to deal with Follow-ups.
Variable-based context restrictions evaluate if a global or a flow variable matches a particular value. They are applied to triggers and transitions. Only if the input of the user matches the trigger or transition and if the variable that is used in the context restriction matches the desired value, then the trigger or transition will be traversed.
In the image above the trigger 'Can I have one of those?' is context restricted by the global variable 'coffeTypeInFocus'. If an input matches the trigger, it can only fire if the variable 'coffeTypeInFocus' is not empty, and the context thus evaluates to true.
The predefined contexts that come with the Teneo Dialogue Resources are essentially scripted contexts. However, you are not limited to using just those. You can create your own scripted contexts too. They are created and maintained in the same place (in the Globals section of your solution) where you find the predefined contexts.
A scripted context consists of a script and one or more expected states (outcomes). Once a trigger or transition with the applied scripted context is up for evaluation, the script is executed. If the outcome of the script matches the desired state of the context restriction, the trigger or transition will fire.
For a practical example of creating a custom scripted context, see How to define a scripted context.