More about conditions

Conditions are the control elements in XML dialplan. Inside each extension there is at least one "condition" tag where the characteristics of the configuration/system/incoming call, represented by variables, are checked against a (regular) expression. If the condition is evaluated as true, the actions inside the condition are added to the call's TODO list. If evaluated as false, anti-actions (if present) are added to the TODO list. The general format is:

<extension name="is_looking_for_2900" continue="true"> 
  <condition field="destination_number" expression="^2900$" break="on-true"> 
    <action application="log" data="WARNING first TRUE"/> 
    <anti-action application="log" data="ERR first FALSE"/> 
  </condition> 
  <condition field="destination_number" expression=".*"> 
    <action application="log" data="WARNING second TRUE"/> 
    <action application="set" data="var01=value01" inline="true"/> 
    <action application="set" data="var02=value02"/> 
    <anti-action application="log" data="ERR second FALSE"/> 
  </condition> 
  <condition field="${var01}" expression="^value01$"> 
    <action application="log" data="WARNING third TRUE"/> 
    <anti-action application="log" data="ERR third FALSE"/> 
  </condition> 
  <condition field="${var02}" expression="^value02$"> 
    <action application="log" data="WARNING fourth TRUE"/> 
    <anti-action application="log" data="ERR fourth FALSE"/> 
  </condition> 
</extension> 
<extension name="after_is_looking_for_2900"> 
  <condition field="destination_number" expression="^2900$"> 
    <action application="log" data="WARNING first of after TRUE"/> 
    <anti-action application="log" data="ERR first of after FALSE"/> 
  </condition> 
</extension> 
 

Let's have a quick look at this example, and please re-read previous chapters for more details.

The first extension has a "continue" parameter set to true, so if this extension is found "matching" (that is, its first condition is evaluated as true), the next extension will be checked for a match. The default is the "continue" parameter set to false, so traversing the dialplan looking for matches will stop at the first matching extension.
The first condition has a parameter "break" set to "on-true". So, if the expression is evaluated as true, the next condition(s) will not be checked. The default is to break "on-false" (eg, if the condition is false, do not check the next condition); other options include "always" and "never".

The first condition expression can be read as "a string exactly matching '2900'", because caret means "beginning-of-string" and dollar sign means "end-of-string".

The second condition will only be checked if the first condition is evaluated as false. The second condition's anti-action will never be sent to the TODO list (because the second condition expression ".*" will always match whatever the destination number is).

The third condition will be true if the destination number is anything different from 2900 (because the variable in expression is set by the second condition and the second condition is always true but is only tested if the first condition is false) while the fourth condition will never be true: this because only the variable checked by the third condition was set using the "inline" parameter. Your action of setting a variable takes place after dialplan traversing is completed, if you don't use the "inline" parameter of the "set" action.

The second extension is there just to show you that the first extension, because of the "continue" parameter, will not stop dialplan traversing even when it is matching. The following screenshot shows what happens when you call something other than "2900".

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.137.240