Conditions
Using logic conditions, you can control which steps come next in the flow based on the user's selections.
Step Selection Values
When a user selects a step item, the selected value(s) are accessible from the flow.
Step values are used in the flow:
{
"title": "It's Trendy",
"value": "Trendy"
}
Step values are referenced in conditions like:
{
"condition":
{
"op": "all_of",
"values": ["Trendy", "Rad"]
}
}
Operators
Actions have two available condition operator options under the op property: all_of and any_of.
Keep in mind that:
opis just short for the word "operator"- You should always include a catchall next action when using operator logic as the last action in you actions list
- Only step item values can be used in the flow
{
"next": "red_info",
"condition": {
"op": "all_of",
"values": ["Trendy", "Rad"]
}
}
all_of
The all_of operator behaves similarly to the AND && logical operator, which acts as a logical conjunction for a set of boolean operands. The condition is only true if and only if all of the values are true, or in our case, if all of the step values are selected.
Color Preference Example
Let's say we want to know how users feel about red. We'll ask them a multi-select question asking them how they feel about it, but we only want to tell them more about the color red if they select all of the choices that are positively associated with it.
In the following example, if the user selects both It's Trendy and It's Rad from the color_preference multi-select our flow takes them to the red_info step. Otherwise, it takes them to the locations.
{
"steps":{
"color_preference": {
"title": "How do you feel about the color red?",
"dialogue_title": "Select all that apply.",
"type": "multi-select",
"layout": "cards",
"items": [
{
"title": "It's Trendy",
"value": "Trendy"
},
{
"title": "It's Rad",
"value": "Rad"
},
{
"title": "It's Not My Fav",
"value": "Not My Fav"
},
{
"title": "I'm Indifferent",
"value": "Indifferent"
}
]
},
"red_info": {...},
"locations": {...},
},
"flow": {
"normal": {
"color_preference": {
"actions": [
{
"next": "red_info",
"condition": {
"op": "all_of",
"values": ["Trendy", "Rad"]
}
},
{
"next": "select_location"
}
]
},
"red_info": {
"next": "select_location"
},
"select_location": {...},
...
}
}
}
any_of
The any_of operator behaves similarly to the OR || logical operator, which acts similarly to a logical disjunction for a set of boolean operands. If the condition is true, one or more of its operands is true, or in our case, if any of the step values in the values array were selected.
Color Preference Example
Let's say we want to know how users feel about red. We'll ask them a multi-select question, asking them how they feel about it. If they select any of the choices positively associated with it, we want to tell them more about the color red.
In the following example, if the user selects either It's Trendy or It's Rad from the color_preference multi-select our flow takes them to the red_info step. Otherwise, it takes them to the locations.
{
"steps":{
"color_preference": {
"title": "How do you feel about the color red?",
"dialogue_title": "Select all that apply.",
"type": "multi-select",
"layout": "cards",
"items": [
{
"title": "It's Trendy",
"value": "Trendy"
},
{
"title": "It's Rad",
"value": "Rad"
},
{
"title": "It's Not My Fav",
"value": "Not My Fav"
},
{
"title": "I'm Indifferent",
"value": "Indifferent"
}
]
},
"red_info": {...},
"locations": {...},
},
"flow": {
"normal": {
"color_preference": {
"actions": [
{
"next": "red_info",
"condition": {
"op": "any_of",
"values": ["Trendy", "Rad"]
}
},
{
"next": "select_location"
}
]
},
"red_info": {
"next": "select_location"
},
"select_location": {...},
...
}
}
}
Catchall Logic
When using action conditions, you should always include a catch-all next action at the very end of the actions list as a catch-all to cover logical outcomes not covered by previously defined action conditions.
{
"color_preference": {
"actions": [
{
"next": "red_info",
"condition": {
"op": "all_of",
"values": ["Trendy", "Rad"]
}
},
"red_info": {
"next": "select_location"
},
{"next": "select_location"}
]
},
"select_location": {...},
...
}