- FreeSWITCH 1.8
- Anthony Minessale II Giovanni Maruzzelli
- 359字
- 2025-04-04 18:52:56
Conditions (and "patterns")
Conditions are, broadly speaking, the building blocks for the "patterns" we talked about before in this chapter.
Conditions are contained by "extension". Conditions contain "action". Conditions have the following generic appearance:
<extension name="this_extension"> <condition field="destination_number" expression=""^1234$"> <!-- action --> <!-- action --> </condition> </extension>
Inside a dialplan "context" (that is, it would be inside "default" or "public" context in demo configuration) we have a opening "extension" tag, then conditions begin. Between the opening and closing condition tag, we find actions.
In this case the condition will check if the "destination_number" call variable is matched by the "expression" (regular expression, or regex) "^1234$". If the number called was actually 1234, then the action(s) contained between this one condition opening and closing tags will be added to the TODO list (at the end of dialplan traversal all actions in the TODO list will be executed).
<extension name="that_extension"> <condition field="ani" expression=""^5551212$"/> <condition field="destination_number" expression=""^1234$"> <!-- action --> <!-- action --> </condition> </extension>
In "that_extension" we actually have two conditions, one after the other (conditions are "stacked"). The first one has no "action" between the opening and closing tags (closing tag is implied by the trailing "/", in XML).
This means: first condition will check if the "ani" variable (eg, calling party phone number) is 5551212. If that first condition was evaluated to "true", then the second condition will be evaluated. If destination number is 1234, then this second condition's actions will be added to call's TODO list.
Stacked conditions are in AND relation, they must both be true, for the second condition's actions to be eventually executed. This because in a condition is implied by default the "break='on-false'" attribute.
<extension name="other_extension"> <condition field="ani" expression=""^5551212$" break="on-true"/> <condition field="destination_number" expression=""^1234$"> <!-- action --> <!-- action --> </condition> </extension>
In "other_extension", we see the "break" attribute at work. Here the condition breaks the flow if the expression evaluate to true. So, in this case: if calling party number is different from 5551212, then second condition will be evaluated.
Following are the possible values for the break (meaning: it breaks out from checking further conditions - it breaks out of the extension) attribute:
- on-false: this is default, if expression evaluate false, it will not check next conditions
- on-true: if expression evaluate to true, it will not check next conditions
- never: will never break out, it will do check next conditions
- always: will sure break out, will not check next conditions