The response rules will evaluate the operator designated for the rule set. Remember the RuleSets article, for each RuleSet, is designated a different operator. On the example below, a RuleSet response evaluates the received message or the operator @step.value. A ruleset provides a series of tests that can be executed on the selected operator. For example, the ‘has any of these words’ try the operator for any designated word. RuleSets are executed from left to right (top-down). The first rule correspondent will start the execution. RapidPro evaluates word-by-word, and just once in an individual rule using the original string order.

If the operator corresponds to a RuleSet, the contact will pass through the category attributed to a rule. On the example below, the RuleSet is waiting for a received message, that will evaluate the response rules attributed to an adult, child and other categories. Notice that a flow will always correspond to at least a response rule in a rule set, and the last response rule will always be a catch-all(other). The passage for the categories is represented on the analises guide, as the flow editor (for example, how many times a contact passed for Yes or No in a RuleSet that evaluate the yes or no questions).

Notice that, the response rule combining with categories names will be represented as a category into the rule set from a flow editor.

Examples:

The response rules allow you:

Categorize multiples responses in an unique category. For example, if you are asking for your contacts their favorite drink, you can create rules to allow “Coca” and “Pepsi”, be categorized as “Cola”. Alter the numerical answers to narrative answer or the opposite. For example, if you ask to your contacts about your satisfaction using a service in a 1 to 5 scale, you can create a rule to allow the answer “1” be classified as “bad” and “5” can be classified as “excellent”.Define an acceptable interval to a numerical answer. Inesparated responses are sent directly to the “Others” category. For example, if you are asking your contacts about gender and receive the answer “Cat”, this answer will be categorized as “Others”. Translate the answers, so the affirmative answers like “Yego” (Kinyarwanda) or “Si” (Spanish) are categorized as “Yes”.

Special Response Rules

Has a phone number

You can use the “has a phone number” to validates the answer including something that looks like a valid phone number. The answer will be saved as a qualified number. For example, if someone answers with the number 0788123123, this number will be saved as 250.788.123.123. If the valid phone number is not presented, you can ask the contacts to answer again.

Matches Regex

In some cases, to validate an identification number or a coupon code, you can need a more complicated rule to determine if this is a validate answer. Regex is a standard used to describe an acceptable presentation format. A big resource to test your regular expressions is Regex101, that allow you to test any answer waited for a regular expression. For example, if we are asking someone to introduce a serial number from the registered device.

We know that the validates serial number should start with the “U” and has exactly nine digits, so we can verificate the serial numbers using:

Observations about regular expressions:

They are not case sensitive (they don’t differ upper and lower case), so you don’t need to put different options on the box base. The “groups” of regular expressions are available after the register using @extra. The group 0 is available as @extra.0, the first group as @extra.1. The value saved on the flow will be the group 0.

Collect different selections:

Notice that, although collect a unique response to a question with various options, you can use the “has a number equal to” to catch multiple choose with an only one answer. There is an example: Choose your favorite color: “Send a message” below ask the user to choose his favorite color, or select multiples if he has more than one. Each choose is coded by a number, that allows you to collect different selections in numerical order. This will avoid the necessity to answer all possible combinations.

The split step correspondent could use “has a number equal to” to categorize all possible answers:

Any answer that not corresponds to the response rules above will be classified as “Other”. You can redirect a loop to connect the “Other” with a message reaffirming an acceptable answer format, so give the user the opportunity to answer correctly.

Did this answer your question?