A condition is a test that can be evaluated to either true or false.
You can find conditions in different sections of your skill:
In this example, we test:
- if the intent is greetings
- if the sentiment analyzed in the sentence is negative
- if in the conversation memory, the value saved for city is Paris
Composition of a condition
A condition is made of three parts: one operator and two operands.
In the condition if #location.raw is Paris, the left operand is #location.raw, is is the operator and Paris is the right operand.
A few rules to distinguish the left operands categories:
- operands starting by @ will get the associated intent (for example @greetings)
- operands starting by # will get the associated entity (for example #location), and will test the raw field unless you’ve specified one
- operands starting by _ will get the associated field in the text analyze JSON or in the conversation state
Note: you can write the entire path if you need, like: #location.lat (if you need the latitude) is the same as nlp.entities.location.lat. Or if you need to access the description of the first intent detected: nlp.intents.description.
There’s a finite list of operators you can use:
- is to test equality between two values
- is-not to test inequality between two values
- in to check if a value is in a list of elements
- not-in to check if a value is not in a list of elements
- matches to match a value with a regular expression
- matches-not to check if the value doesn’t match with a regular expression
- lower-than to test if the value is lower than another
- greater-than to test if the value is greater than another
- is-present to test if the value is present in the conversation state
- is-asbent to test if the value is asbent in the conversation state
Note: the regex syntax follows the Ruby regex syntax
Note bis: greater-than and lower-than only works with numerical values.
The right value can either be a free input or a finite list depending on what you’ve picked as the left operand.
For example, if you’ve picked sentiment, the right operand will be limited to what the SAP Conversational AI API can return (in this case, from “very positive” to “very negative”). But if you’ve picked _memory.my_value.my_key, any format is supported because it’s not dependent on the SAP Conversational AI API.
You can find more details on the entities’ enrichment and the other keys with a finite list of possible values in the MAN.
Create complex conditions
You can create multiple layers of condition using and and or.
You can see in this example two groups:
- the first group (in line) is an `and` condition group
- the second group (the entire block) is an `or` condition group