Studio uses Widgets to represent various parts of Twilio's API that can then be stitched together in your Studio Flow to build out robust applications that require no coding on your part.
New to Twilio Studio? Check out our Getting Started guide!
The Split Based On... Widget allows you to split your Flow and connect to specific Widgets based on user conditions. Use this Widget to deal with conditions like a user replying "YES" to a SMS, or pressing "1" on their keypad while on a call.
The Split Based On... Widget requires a Variable to Test to function properly. The Variable to Test is the value that is tested to determine what happens next in your Flow when a certain condition is met.
Name | Description | Example | Default |
---|---|---|---|
Variable to Test | The value (or expression) that is being tested.For example, if you want to branch on message body, the Input would be the variable you stored the message in. Select a predefined variable from the drop-down, or type a dynamic variable directly with curly braces: {{widgets.http_1.parsed.foo}} | {{widgets.send_msg.incoming.Body}} | None |
You can add Transitions to the Split Based On... Widget that trigger another Widget in your Flow. Transitions can be triggered by a variety of conditions that you can configure. For more information on working with Studio transitions, see this guide.
Name | Description |
---|---|
Condition Matches | Example: "YES" for when text matches "YES" |
No Match | Input does not match any of the user-defined conditions |
Conditions take the form: Subject, Predicate, [value] and can be set in the Widget configuration menu in the right-side panel on the Canvas.
subject:
The configuration parameter defined as Input.predicate:
The operator to use. For example: equals, greater than, less than and more.[value]:
The value you are comparing against. Constants, variables, and expressions are supported. Value can be null for certain conditions, such as "is blank" or "has any value".In order to save the Conditions you set for the Split Based On... Widget, you must click the red Save button at the bottom of the Widget. Conditions are not auto-saved, and will not persist unless saved.
Predicates are operators used by the Split Based On... Widget to evaluate the given value against a comparison value and determine what transition should be used.
Studio conditions are not case-sensitive and automatically trim leading and trailing whitespace characters.
Equal To
The values are equivalent.
Not Equal To
The values are not equivalent.
Matches Any Of
Value is equivalent to any of the values in the given list.
Does Not Match Any Of
Value is not equivalent to any of the values in the given list.
Is Blank
Value contains only white-space characters or is blank.
Is Not Blank
Value contains characters that are not white-space characters.
Regex
Value matches the regex pattern specified. For more information on regular expressions and how to use them, view this cheatsheet.
Omit leading and trailing slashes with the Regex Predicate. Matching is case insensitive, and will only match if the provided regular expression matches the entire string.
Contains
Value contains the value given. For example, aab
contains aa
and A
.
Does Not Contain
Value does not contain the value given.
Starts With
Value starts with the given value. For example, Hoot
starts with hoo
.
Does Not Start With
Value does not start with the value given.
Less Than
Value is less than the number provided. Operator does not perform comparisons on letters.
Greater Than
Value is greater than the number provided. Operator does not perform comparisons on letters.
Is Before Time
Value is before the time provided. Times must be in 24-hour notation (HH:MM) where single digit values are written with a leading 0.
Is After Time
Value is after the time provided. Times must be in 24-hour notation (HH:MM) where single digit values are written with a leading 0.
Is Before Date
Value is before the date provided. Dates must be in the format YYYY-MM-DD where single digit values are written with a leading 0.
Is After Date
Value is after the date provided. Dates must be in the format YYYY-MM-DD where single digit values are written with a leading 0.
Here are some usage examples for predicates.
Subject | Subject Value | Predicate | Value | Output |
---|---|---|---|---|
{{flow.data.appointment_date}} | 2019-08-12 | Is After Date | 2017-09-04 | True |
{{flow.data.appointment_time}} | 17:00 | Is Before Time | 16:35 | False |
{{flow.data.reward_points}} | 900 | Greater Than | 1000 | False |
{{flow.data.first_name}} | Twilio | Is Blank | N/A | False |
{{trigger.message.Body}} | YES | Matches Any Of | yes,yeah,yup | True |
{{flow.data.survey_result}} | 6 | Regex | [1-5] | False |
In the following example, we have asked the user if they would like to receive reminders. Following the Send & Wait For Reply Widget is a Split Based On... Widget that evaluates the user's response.
We have three conditions:
Subject | Predicate | Value | Transition |
---|---|---|---|
{{widgets.reminders_response.inbound.Body}} | Equals | Y | REMINDERS_CONFIRM |
{{widgets.reminders_response.inbound.Body}} | Equals | N | REMINDERS_OPTOUT |
{{widgets.reminders_response.inbound.Body}} | Equals | 123 (NO MATCH) | REMINDERS_OPTOUT |
The following screenshot outlines the example SMS Reminders Flow. The YES condition Transitions to a Send SMS Widget called REMINDERS_CONFIRM, while the NO and NO CONDITION MATCHES conditions Transition to a Send SMS Widget called REMINDERS_OPTOUT.
Now that you know the basics of the Split Based On... Widget, you may want to explore the Transitions documentation to learn more about how Transitions help power the Split Based On... Widget.
Happy building!