Response rules evaluate the operand designated by the RuleSet type. In the example below, we see that a Wait for Response RuleSet evaluates the incoming message, or the @step.value operand.
Response rules provide a series of tests that you can run against the selected operand.
For example, the 'has any of these words' response rule tests the operand for any of the words you designate. Response rules are executed from top to bottom–the first rule that matches takes effect and no other rules are evaluated after there is a match.
If the operand matches a response rule, the contact will pass through the category assigned to that rule. In the example below, the RuleSet is waiting for an incoming message, which it will evaluate against the response rules assigned to the Teens, Adults, Older Adults, Special Needs, Children & Families, and Other* categories.
*Note that a flow will always match at least one response rule in a RuleSet as the last response rule must always be a catch-all (the "Other" rule).
Passage through categories is represented in the analytics tab as well as the flow editor. For example, the number of times a contact passed through the Yes or No categories of a RuleSet that evaluates responses to yes or no questions.
Multiple response rules that share the same category name will be represented as one category within a RuleSet from the view of the flow editor.
Response rules allow you to:
- Categorize multiple responses into one category. For example, if you are asking Contacts what their favorite type of soda is, you can create rules that allow Coke and Pepsi to be categorized as Cola.
- Change numeric responses to narrative responses, or vice versa. For example, if you ask your Contacts to rate their satisfaction with a service on a scale of 1 to 5, you can create a rule that allows the response 1 to be categorized as Poor, and 5 to be categorized as Excellent.
- Define an acceptable range for a numerical answer.
- Direct unexpected responses to an Other category. For example, if you are asking your Contacts for their gender and receive the response Cat, this answer is categorized as Other.
- Translate responses so that affirmative answers such Yego (Kinyarwanda) or Si (Spanish) are categorized as Yes.
Special Response Rules
Has a phone number
You can use the Has a phone number response rule to validate that the response includes something that looks like a valid phone number. The response itself will be saved as a fully qualified number. For example, if someone responds with 415 555 1111 the number will be saved as +14155551111. If a valid number isn't submitted you can follow-up asking contacts to respond again.
In some cases, like validating an ID number or coupon code, you may need a more complicated rule to determine if a response is valid. Regular expressions (regex) are a standard used to describe an acceptable submission format. A great resource for testing your regular expressions is Regex101, which allows you to test any of the responses you expect against a regular expression.
For example, say we are asking someone to enter a serial number for a device they are registering:
We know that valid serial numbers must begin with the letter "U" and be exactly nine digits, so we can match the serial numbers using:
Notes on regular expressions:
- Matches are case insensitive, so you do not need to put different options based on case.
- Regular expression groups are available after a match using @extra. The 0 group is available as @extra.0, the 1st group as @extra.1 and so on. The value saved for the step in the flow will be group 0.