This example shows how to ensure that all expressions match before executing actions, otherwise the anti-actions will be executed. In this case, the SIP gateway must be the default provider, and it must be an emergency call, and the auto-answer option must be enabled and stored in the database:

<condition regex="all">
    <regex field="${sip_gateway}" expression="^${default_provider}$"/>
    <regex field="${emergency_call}" expression="^true$"/>
    <regex field="${db(select/emergency/autoanswer)}" expression="^1$"/>
 
    <!-- the following actions get executed if all regexes PASS -->
    <action application="set" data="call_timeout=60"/>
    <action application="set" data="effective_caller_id_name=${regex(${caller_id_name}|^Emerg(_.*)$|Auto%1)}"/>
    <action application="set" data="autoanswered=true"/>
    <action application="bridge" data="user/1000@${domain_name},sofia/gateway/1006_7217/${mobile_number}"/>
 
    <!-- the following anti-actions are executed if any of the regexes FAIL -->
    <anti-action application="set" data="effective_caller_id_name=${regex(${caller_id_name}|^Emerg(_.*)$|NotAuto%1)}"/>
    <anti-action application="set" data="call_timeout=30"/>
    <anti-action application="set" data="autoanswered=false"/>
    <anti-action application="bridge" data="user/1000@${domain_name},sofia/gateway/1006_7217/${mobile_number}"/>
</condition>

 

Caller Profile Fields vs. Channel Variables

One thing that may seem confusing is the distinction between a caller profile field (the built-in variables) and a channel variable.

Caller profile fields are accessed like this:

<condition field="destination_number" attributes...>

 

While channel variables are accessed like this:

<condition field="${sip_has_crypto}" attributes...>

 

Please take note of the ${variable_name} syntax. Channel variables may also be used in action statements.

In addition, API functions can be called from inside a condition statement to provide dynamic data.

For example, you can use the cond API:

<condition field="${cond(${my_var} > 12 ? YES : NO)}" expression="^YES$">
    <action application="log" data="INFO ${my_var} is indeed greater than 12"/>
</condition>

 

This example tests ${my_var}. If it is more than 12, «YES» is returned. Otherwise «NO» is returned. The condition tests the results for «YES» and logs the resulting message to the FreeSWITCH log.

Availability of Variables

Asterisk users must read!

 

The XML Dialplan has the ability to test a number of conditions based upon variables with expressions; however, it needs to be understood that some variables may not be available for conditional testing until the first transfer or execute_extension is performed (see workarounds below).

Why

In essence the XML Dialplan is to be used for Call Routing rather than for complex or extensive conditional tests and evaluations. This is why FreeSWITCH makes Lua, JavaScript, Perl, Python and other APIs available since they are far better alternatives than coming up with a convoluted XML solution, or worse yet some arcane and convoluted acronym such as «AEL».

This may be confusing to former Asterisk users since the info application such as <action application=«info»/> will in fact display the variables as if they are available for a conditional test when in fact they may not.

The reason for this is that FreeSWITCH does the hunting and the executing in two separate steps. First - based on conditions, actions and anti-actions - all applications that need to be executed are gathered. Second, that sequence of applications is executed. This means that channel variables set by the executed applications won't be available to conditions at hunting time.

This is why you may find that your XML condition is failing even though the variable and its value are displayed with the <action application=«info»/>.

Workarounds

The workaround for this is to either implement the vast majority of your dialplan logic within Lua, JavaScript or one of the other Dialplan scripting languages, OR execute an extension which will make those variables you seek to do conditional evaluations on available for parsing within your XML Dialplan condition.

NOTE: Since f21b4a21374 it is possible for certain applications to be run  inline . This means that they are executed at hunting time which has the effect that channel variables set by these applications are available to the following conditions at hunting time.

 

Actions and Anti-Actions

So far, we've seen example dialplan entries that contain conditions along with the actions that run when the conditions match.

You can also specify 'anti-actions' that run if the conditions for the extension 'are not met'.

In this example, the value of ${my_var} is compared with 12, and a message is logged for either result.

<condition field="${cond(${my_var} > 12 ? YES : NO)}" expression="^YES$">
    <action application="log" data="INFO ${my_var} is indeed greater than 12"/>
    <anti-action application="log" data="INFO ${my_var} is not greater than 12"/>
</condition>

 

Available Actions

See Modulesand dialplan functions

Inline Actions

You may set an extra attribute inline=«true» on an action so that it will be executed during the hunting phase of the dialplan:

<action inline="true" application="set" data="some_var=some_val"/>

 

This makes it possible to have a condition in the following extension, that matches on the ${some_var} field.

Note that the only applications that may be run inline are the ones that quickly get- or set some variable(s) and that don't access or modify the state of the current session.

Applications that are allowed to be run inline are:

check_acl

eval

event

export

log

presence

set

set_global

set_profile_var

set_user

unset

verbose_events

cidlookup

curl

easyroute

enum

lcr

nibblebill

odbc_query

Also keep in mind that inline executed applications don't show up in your call detail records like normally run applications do.

Complete Syntax

<!-- For enumerated attributes the first value on the list is the default -->
 
<extension name="unique_extension_name" continue="[false|true]">
    <condition field="[field_name|${variable_name}|${api_func(api_args ${var_name})}]" expression="regular expression" break="[on-false|on-true|always|never]" require-nested="[true|false]">
        <condition ...><!-- Conditions can be nested --> ... </condition>
    <action application="app name" data="app arg"/>
    <anti-action application="app name" data="app arg"/>
    </condition>                                             <!-- Any number of condition tags may follow where the same rules apply -->
</extension>

 

Summary

Extensions hunting stops at the first extension where conditions evaluate to true and continue=«false» (the default).

Conditions evaluate to true if the last checked condition is true.

Conditions are checked depth-first until:

break=«on-false» and the condition is false

or break=«on-true» and the condition is true

or break=«always».

The condition is true if expression matches and either there are no nested conditions or require-nested=«false» or nested conditions evaluate to true.

If condition is true, its <action>s are collected for execution, otherwise its <anti-action>s are collected for execution.

If require-nested=«true» (the default) and nested conditions evalutate to false, no <anti-action>s are collected. (Is this intentional?)

FS XML dialplan examples

The dialplan is parsed once when the call hits the dialplan parser in the ROUTING state. With one pass across the XML the result will be a complete list of instructions installed into the channel based on parsed <action> or <anti-action> tags.

Those accustomed to Asterisk may expect the call to follow the dialplan by executing the applications as it parses them allowing data obtained from one action to influence the next action. This is not the case with the exception being the ${api func(api arg ${var_name})} field type where a pluggable api call from a module may be executed as the parsing occurs. This is meant to be used to draw real-time information such as date and time or other quickly accessible information and should not be abused.

Auto Hunt

You many turn on auto_hunt and then if the Extension name precisely equals the dialed number, FreeSWITCH will jump to this extension to begin the searching. It may or may not match the conditions, though.

Dialing through gateways

«gateway» is treated as a keyword by mod_sofia, it obviously means the call will be placed through a configured gateway. This is an exception for the pattern sofia/profilename/extension@ip-address.

If a gateway, for instance, is named «gw», the bridge string for sending a call to gw's extension 100 would be:

<extension name="testing">
    <condition field="destination_number" expression="^(100)$">
        <action application="bridge" data="sofia/gateway/gw/$1"/>
    </condition>
</extension>
destination_number is a FreeSWITCH variable; it shouldn't be changed.

NOTE: if you plan to include your extension in a separated .XML file:

please disable or change enum extension if you don't need it

add the tag <include> and close it with </include>

Example 1: Matching a condition

The incoming call will be bridged only if it comes from 192.168.1.1. If it does, the destination number will be captured in $1, and the call will be bridged to the same number, at 192.168.2.2.

This is a bizarre example. We can do better.
<extension name="Test1">
    <condition field="network_addr" expression="^192\.168\.1\.1$"/>
    <condition field="destination_number" expression="^(\d+)$">
        <action application="bridge" data="sofia/profilename/$1@192.168.2.2"/>
    </condition>
</extension>

Note that this example is not the same as doing this:

<extension name="Test1Wrong">
    <condition field="destination_number" expression="^(\d+)$"/>
    <condition field="network_addr" expression="^192\.168\.1\.1$">
        <action application="bridge" data="sofia/profilename/$1@192.168.2.2"/>
    </condition>
</extension>

The call will not be routed properly because the captured destination number in $1 is not available outside of the condition that created it.  This is a peculiarity of how captured values work.  You can work around this by storing the captured value in a standard variable, like this:

<extension name="Test1_2">
    <condition field="destination_number" expression="^(\d+)$">
        <action application="set" data="dialed_number=$1"/>
    </condition>
    <condition field="network_addr" expression="^192\.168\.1\.1$">
        <action application="bridge" data="sofia/profilename/${dialed_number}@192.168.2.2"/>
    </condition>
</extension>

Example 2: Matching multiple conditions (AND) 

In this example we need to match a called number beginning with the prefix 1 AND match the incoming IP address at the same time.

<extension name="Test2">
    <condition field="network_addr" expression="^192\.168\.1\.1$"/>
    <condition field="destination_number" expression="^1(\d+)$">
        <action application="bridge" data="sofia/profilename/$0@192.168.2.2"/>
    </condition>
</extension>

Notice that although we match with the rule 1(\d+)$ we don't use the variable $1 which would contain only the rest of the dialed number with the leading 1 stripped off, we use the variable $0 which contains the original destination number.

Example 3: Stripping leading digits

In this example we need to match a called number beginning with 00 but we also need to strip the leading digits. Assuming that FreeSWITCH™ receives the number 00123456789 and we need to strip the leading 00 digits, then we can use the following extension:

<extension name="Test3.1">
    <condition field="destination_number" expression="^00(\d+)$">
        <action application="bridge" data="sofia/profilename/$1@192.168.2.2"/>
    </condition>
</extension>

If you anticipate receiving non-digits, or you want to match on more than just digits, you can use «.+» instead of «\d+».

Exercise caution when using regular expressions containing (.*) or (.+). The more specific the regular expression, the less chance that your system can be exploited by an unauthorized user.

Example 4: Adding a prefix

In this example, numbers beginning with 00 are transformed into the same number, only beginning with 011 instead.  If macro receives 00123456789, we should dial 011123456789:

<extension name="Test4">
    <condition field="destination_number" expression="^00(\d+)$">
        <action application="bridge" data="sofia/profilename/011$1@x.x.x.x"/>
    </condition>
</extension>

Example 5: SIP Profiles (dialing with different configurations) 

In this example we will demonstrate the use of profiles when using a FreeSWITCH endpoint that supports profiles, like mod_sofia. Assuming that we want to use different call settings (codecs, DTMF modes, etc) for sending the calls to different IP addresses, we can create different profiles. For example, in the configuration of sofia.conf, we see an example profile named «test», which we rename to profile1 for this example, and add a profile2 for comparison:

<profile name="profile1">
    <param name="debug" value="1"/>
    <param name="rfc2833-pt" value="101"/>
    <param name="sip-port" value="5060"/>
    <param name="dialplan" value="XML"/>
    <param name="dtmf-duration" value="100"/>
    <param name="codec-prefs" value="PCMU@20i"/>
    <param name="codec-ms" value="20"/>
    <param name="use-rtp-timer" value="true"/>
</profile>
<profile name="profile2">
    <param name="debug" value="1"/>
    <param name="rfc2833-pt" value="101"/>
    <param name="sip-port" value="5070"/>
    <param name="dialplan" value="XML"/>
    <param name="dtmf-duration" value="100"/>
    <param name="codec-prefs" value="PCMA@20i"/>
    <param name="codec-ms" value="20"/>
    <param name="use-rtp-timer" value="true"/>
</profile> 

The difference between the two profiles are in the codecs. The first uses G.711 u-law and the second G.711 A-law.

Continuing the examples above, we have:

 <extension name="Test5ulaw">
    <condition field="network_addr" expression="^192\.168\.1\.1$"/>
    <condition field="destination_number" expression="^1(\d+)$">
        <action application="bridge" data="sofia/profile1/$0@192.168.2.2"/>
    </condition>
</extension>

to send the call in G.711 uLaw and

<extension name="Test5alaw">
    <condition field="network_addr" expression="^192\.168\.1\.1$"/>
    <condition field="destination_number" expression="^1(\d+)$">
        <action application="bridge" data="sofia/profile2/$0@192.168.2.2"/>
    </condition>
</extension>

 

Example 6: Calling registered user

This example shows how to bridge to devices that have registered with your FreeSWITCH box. In this example we assume that you have setup a sofia profile called 'local_profile' and your phones are registering with the domain example.com. Note the % instead of @ in the data string.

 <extension name="internal">
    <condition field="source" expression="mod_sofia" />
    <condition field="destination_number" expression="^(4\d+)">
        <action application="bridge" data="sofia/local_profile/$0%example.com" />
    </condition>
</extension>ondition>undefined</extension>undefined<extension name="internal">
<condition field="source" expression="mod_sofia" />
<condition field="destination_number" expression="^(4\d+)">
    <action application="bridge" data="sofia/local_profile/$0%example.com" />
</condition>undefined</extension>

 

Example 7: Action failover on failed action

The following example shows how it is possible to call another action if the first action fails.

If the first action is successful the call is bridged to 1111@example1.company.com and will exist until one of the parties hangs up. After this, no other processing will be done because the caller's channel is closed. (i.e. 1111@example2.company.com is not called)

If the initial call to 1111@example1.company.com was not successful the channel will not be closed and the second action will be called.

 <extension name="internal">
    <condition field="destination_number" expression="^1111">
        <action application="set" data="hangup_after_bridge=true"/>
        <action application="bridge" data="sofia/local_profile/1111@example1.company.com" />
        <action application="bridge" data="sofia/local_profile/1111@example2.company.com" />
    </condition>
</extension>

Note: If you have more than one action and the application of the first action 

DOES hangup the channel, the second action will NOT be called.

DOES NOT hangup the channel, the second action will be called.

Example 8: Check user is authenticated

The following example requires that a caller be authenticated before passing through. It was yanked from a mailing list post.

 <extension name="9191">
    <condition field="destination_number" expression="^9191$"/>
    <condition field="${sip_authorized}" expression="true">
        <anti-action application="respond" data="407"/>
    </condition>
    <condition>
        <action application="playback" data="/tmp/itworked.wav"/>
    </condition>
</extension>

 

Example 9: Routing DID to an extension

To route incoming calls which come in to a certain DID to a fixed extension 1001, do something LIKE the following (from a mailing list post) (where XXXxxxxxxx is the phone number of your incoming DID)

In public.xml:

 <extension name="test_did">
    <condition field="destination_number" expression="^(XXXxxxxxxx)$">
        <action application="transfer" data="$1 XML default"/>
    </condition>
</extension>

 

and then in default.xml have something like this in the default context:

 <extension name="Local_Extension">
    <condition field="destination_number" expression="^(XXXxxxxxxx)$">
        <action application="set" data="dialed_ext=$1"/>
    </condition>
    <condition field="destination_number" expression="^${caller_id_number}$">
        <action application="set" data="voicemail_authorized=${sip_authorized}"/>
        <action application="answer"/>
        <action application="sleep" data="1000"/>
        <action application="voicemail" data="check default $${domain} ${dialed_ext}"/>
        <anti-action application="ring_ready"/>
        <anti-action application="set" data="call_timeout=10"/>
        <anti-action application="set" data="hangup_after_bridge=true"/>
        <anti-action application="set" data="continue_on_fail=true"/>
        <anti-action application="bridge" data="USER/1001@$${domain}"/>
        <anti-action application="answer"/>
        <anti-action application="sleep" data="1000"/>
        <anti-action application="voicemail" data="default $${domain} ${dialed_ext}"/>
    </condition>
</extension>

 

(the 1001 in the «bridge» line is the extension we're ringing)

FYI, calls from the «public» go into the public context where they then need to be transferred to another more friendly context for processing, like default. That is why you add the entry to public and the 'data=«$1 XML PFC»' says to transfer called number $1 to the context PFC using XML dialplan. In the default context is where you actually ring the phone.

$${domain} a variable that it automatically fills in for you with your domain (most likely your IP) and the calling number. Just leave them as is.

Example 10: Route to a gateway extension with custom caller id

In this example we demonstrate an outgoing call with 10 digits from extension 1000 then route it to the asterlink.com gateway. This examples shows how to route for a specific extension and allows custom caller id for that extension.

<extension name="asterlink.com">
    <condition field="caller_id_number" expression="^1000$"/>
    <condition field="destination_number" expression="^(\d{10})$">
        <action application="set" data="effective_caller_id_number=8001231234"/>
        <action application="set" data="effective_caller_id_name=800 Number"/>
        <action application="bridge" data="sofia/gateway/asterlink.com/1208$1"/>
    </condition>
</extension>

 

Example 11: Route based on number prefix

In this example we demonstrate routing to different destination based on NPANXX. Also how to respond to the calling party with a different failure message than the destination sends to FreeSWITCH.

<extension>
    <condition field="network_addr" expression="^(66\.123\.321\.231|70\.221\.221\.221)$" break="on-false"/>
    <condition field="destination_number" expression="^\d+$" break="never">
        <action application="set" data="continue_on_fail=NORMAL_TEMPORARY_FAILURE,TIMEOUT,NO_ROUTE_DESTINATION"/>
        <action application="set" data="bypass_media=true"/>
        <action application="set" data="accountcode=myaccount"/>
    </condition>
    <condition field="destination_number" expression="^(1813\d+|1863\d+|1727\d+|1941\d+|404\d+)$" break="never">
        <action application="bridge" data="sofia/outbound_profile/${sip_to_user}@switch1.mydomain.com"/>
        <action application="info"/>
        <action application="respond" data="503"/>
        <action application="hangup"/>
    </condition>
    <condition field="destination_number" expression="^(1404\d+|1678\d+|1770\d+)$">
        <action application="bridge" data="sofia/outbound_profile/${sip_to_user}@switch2.mydomain.com"/>
        <action application="info"/>
        <action application="respond" data="503"/>
        <action application="hangup"/>
        <anti-action application="respond" data="503"/>
        <anti-action application="hangup"/>
    </condition>
</extension>

 

Example 12: Handle calls which match no extension

In this example we demonstrate how to catch invalid extensions/Destinations.

You need to add this extension at the bottom of your dialplan before ENUM can get included.

See mod_enum.

 <extension name="catchall">
    <condition field="destination_number" expression=".*" continue="true">
        <action application="playback" data="misc/invalid_extension.wav"/>
    </condition>
</extension>

 

Example 13: Call Screening

In this example, we ask the caller for a name, connect to the called party and announce that name. The called party may then press 1 to accept the call, or hang up. If the called party hangs up, the caller is connected with voicemail.

 <extension name="screen">
    <condition field="destination_number" expression="^(\d{4})$">
        <action application="set" data="call_screen_filename=/tmp/${caller_id_number}-name.wav"/>
        <action application="set" data="hangup_after_bridge=true" />
        <action application="answer"/>
        <action application="sleep" data="1000"/>
        <action application="phrase" data="voicemail_record_name"/>
        <action application="playback" data="tone_stream://%(500, 0, 640)"/>
        <action application="set" data="playback_terminators=#*0123456789"/>
        <action application="record" data="${call_screen_filename} 7 200 2"/>
        <action application="set" data="group_confirm_key=1"/>
        <action application="set" data="fail_on_single_reject=true"/>
        <action application="set" data="group_confirm_file=phrase:screen_confirm:${call_screen_filename}"/>
        <action application="set" data="continue_on_fail=true"/>
        <action application="bridge" data="user/$1"/>
        <action application="voicemail" data="default $${domain} $1"/>
        <action application="hangup"/>
    </condition>
</extension>

 

Example 14: Media recording

This extension is used to play/record media in audio (wav) format recording / playback extension

Thanks to rupa for the help.

 <extension name="recording">
    <condition field="destination_number" expression="^(2020)$">
        <action application="answer"/>
        <action application="set" data="playback_terminators=#"/>
        <action application="record" data="/tmp/recorded.wav 20 200"/>
    </condition>
</extension>
<extension name="playback">
    <condition field="destination_number" expression="^(2021)$">
        <action application="answer"/>
        <action application="set" data="playback_terminators=#"/>
        <action application="playback" data="/tmp/recorded.wav"/>
    </condition>
</extension>

 

Example 15: Speaking Clock

This example will speak time using the Flite text to speech engine.

See: mod_flite

<include>
    <extension name="SpeakTime">
        <condition field="destination_number" expression="^2910$">
            <action application="set" data="actime=${strftime(%H:%M)}"/>
            <action application="set" data="tts_engine=flite"/>
            <action application="set" data="tts_voice=slt"/>
            <action application="speak" data="It is +${actime}"/>
        </condition>
    </extension>
</include>

 

Example 16: Block certain codes

This extension example is to demonstrate how to block certain NPAs that you do not want to terminate based on caller id area codes and respond with SIP:503 to your origination so that they can route advance if they have other carrier to terminate to.

<extension name="blocked_cid_npa">
    <condition field="caller_id_number" expression="^(\+1|1)?((876|809)\d{7})$">
        <action application="respond" data="503"/>
        <action application="hangup"/>
    </condition>
</extension>

 

Example 17: Receive fax from inbound did

To use the predefined fax_receive extension in freeswitch/conf/dialplan/default.xml for inbound calls, put this in freeswitch/conf/dialplan/public/fax.xml:

<include>
    <extension name="incoming-fax">
        <condition field="destination_number" expression="^$${local_fax_number}$">
            <action application="set" data="domain_name=$${domain}"/>
            <action application="transfer" data="9178 XML default"/>
        </condition>
    </extension>
</include>

 

Then in freeswitch/conf/vars.xml you set your fax number to 1234 or whatever:

<X-PRE-PROCESS cmd="set" data="local_fax_number=1234"/>

 

Example 18: Add international call prefix to effective_caller_id_number on incoming BRI calls

When using FreeTDM with zaphfc on a BRI line, the incoming calls received will not contain the international call prefix in the caller_id_number. This extension adds it to the effective_caller_id_number.

The international call prefix is explained here: http://en.wikipedia.org/wiki/International_prefix.

In Germany, the international call prefix is called «Verkehrsausscheidungsziffer» (VAZ), see http://de.wikipedia.org/wiki/Verkehrsausscheidungsziffer.

The international call prefix is never transmitted. It can be predicted by looking at the ToN information.

<extension name="Add-VAZ" continue="true">
    <!-- On incoming BRI calls, the Verkehrsausscheidungsziffer (VAZ) is dropped. This extension adds it again to the caller_id_number. TODO: add support for international numbers -->
    <condition field="source" expression="^mod_freetdm$">
        <action application="set" data="effective_caller_id_number=0${caller_id_number}"/>
    </condition>
</extension>

Example 19: DISA 

Be able to dial into FS box and get a dialtone to dial again, just like in Asterisk's DISA()

In FS/conf/dialplan/public/*.xml

 <!-- -->
<!-- -->
<!-- -->
<!-- CAUTION!!! We TRANSFER here. Possible security breach. CAUTION!!! -->
<!-- -->
<!-- -->
<!-- -->
<extension name="incoming-bri-wor">
    <condition field="destination_number" expression="^(disa_target)$">
        <action application="answer"/>
        <action application="start_dtmf"/>
        <action application="play_and_get_digits" data="2 5 3 37000 # $${base_dir}/sounds/en/us/callie/ivr/8000/ivr-please_enter_pin_followed_by_pound.wav $${base_dir}/sounds/en/us/callie/ivr/8000/ivr-pin_or_extension_is-invalid.wav digits ^$${DISA_PASSWORD}$"/>
        <action application="transfer" data="$1 XML default"/>
    </condition>
</extension>
<!-- -->
<!-- -->
<!-- -->
<!-- CAUTION!!! We TRANSFER here. Possible security breach. CAUTION!!! -->
<!-- -->
<!-- -->
<!-- -->
<extension name="incoming-bri-wor">
    <condition field="destination_number" expression="^(disa_target)$">
        <action application="answer"/>
        <action application="start_dtmf"/>
        <action application="play_and_get_digits" data="2 5 3 37000 # $${base_dir}/sounds/en/us/callie/ivr/8000/ivr-please_enter_pin_followed_by_pound.wav $${base_dir}/sounds/en/us/callie/ivr/8000/ivr-pin_or_extension_is-invalid.wav digits ^$${DISA_PASSWORD}$"/>
        <action application="transfer" data="$1 XML default"/>
    </condition>
</extension>

In FS/conf/dialplan/default/03_DISA.xml

<!-- DISA - allow to dial into the box and get a dialtone like new trunk -->
<include>
    <extension name="DISA for FS">
        <condition field="destination_number" expression="^(disa_target)$">
            <action application="answer"/>
            <action application="read" data="2 15 'tone_stream://%(10000,0,350,440)' digits 30000 #"/>
            <action application="execute_extension" data="${digits}"/>
            <action application="transfer" data="disa_target XML default"/>
        </condition>
    </extension>
</include>

 

Please replace «disa_target» to you extension number.

You can use this technique to dial into your box from a pstn / mobile phone and get a dialtone to do anything with.

Example 20: Fix invalid caller ID 

If you run into a problem where your B-Leg do not like the invalid caller ID; for instance, you have an INVITE message with From: header as From: <sip:Unavailable@Unavailable.invalid:5060> You can force the invalid number to be replaced by a fixed caller ID number. The following example checks for a valid NANPA CLID:

<extension name="invalid_caller_id_fix" continue="true">
    <condition field="caller_id_number" expression="^1?([2-9]\d{2}[2-9]\d{6})$">
        <action application="set" data="effective_caller_id_number=$1"/>
        <anti-action application="set" data="effective_caller_id_number=2135551212"/>
    </condition>
</extension>

 

Example 21: Block outbound caller ID 

To have caller ID block for calling party by dialing *67 follows by the dial number, you can do the following:

<extension name="block_caller_id">
    <condition field="destination_number" expression="^\*67(\d+)$">
        <action application="privacy" data="full"/>
        <action application="set" data="sip_h_Privacy=id"/>
        <action application="set" data="privacy=yes"/>
        <action application="transfer" data="$1 XML default"/>
    </condition>
</extension>

 

Example 22: Play MOH while doing a database lookup 

If you want to play MOH while doing a data dip that takes a long time, the non-ESL way to do this by making the dialplan use the FSAPI via variable expansion to call luarun on the script. This way a new thread will be launched to execute the Lua script.

<extension name="Get_Data">
    <condition field="destination_number" expression="^(Get_Data)$">
        <action application="play_and_get_digits" data="4 16 3 7000 # phrase:Enter_Case_Number phrase:Invalid_entry case_number \d+" />
        <action application="set" data="x=${expand(luarun GetDataFromLDAP.lua ${case_number} ${uuid})}"/>
        <action application = "playback" data="/tmp/LongMusicFile.wav"/>
    </condition>
</extension>

 

In the Lua script you can use the «uuid» argument passed, to break the MOH or transfer to another extension

--GetDataFromLDAP.lua 
key = argv[1] sessionId = argv[2] api = freeswitch.API() --Do your data dips here --Once the database operations are done you can simply stop the MOH or transfer to another extension 
api:execute("uuid_break", sessionId) -- break the MOH

 

SIP-Specific Dialstrings

SIP dialing has several options. Here are some aspects of what you might call the anatomy of a SIP dialstring.

Dialing A SIP URI

Basic syntax is: sofia/my_profile/user@host Host can be a name or an IP address, for example:

sofia/my_profile/1234@192.168.0.1

 

This would dial 1234 at host 192.168.0.1 via the profile «my_profile». If you use a name instead of an IP address, Sofia will try to resolve the name as a NAPTR or SRV record before trying it as a standard A record.

Dialing A Registered User

There are two options depending upon whether or not there is an alias for the domain. Without an alias you can do this:

sofia/my_profile/1234%mydomain.com

 

If you have an alias for the domain then this syntax is valid:

sofia/mydomain.com/1234

 

Note how the profile does not need to be explicitly supplied in the dialstring.

Also you can do it this way for users defined in the directory:

user/1234@mydomain.com

Dialing Through A Gateway (SIP Provider)

A gateway is a means for making outbound calls through a SIP provider. For example:

sofia/gateway/mygateway.com/1234

 

This will dial through the gateway named mygateway.com to user 1234.

Note how there is no need to append anything after the user «1234» This is an example of how NOT to do it:

sofia/gateway/mygateway.com/1234@mygateway.com <==== WRONG WRONG WRONG

 

Dialing With A Specific Transport

Sometimes you will need to specify the transport, for example TCP, UDP, TLS, or SCTP. This can be done by appending a semicolon and the transport method. For example:

sofia/my_profile/1234@192.168.0.1;transport=tcp

 

Specifying The Codec

Occasionally you may want to force the system to use a specific codec. This syntax will accomplish that:

{absolute_codec_string=XXXX}sofia/my_profile/user@your.domain.com

 

In this example, XXXX represents the codec to be used. The possible codec values are listed here.  Additional dialstring examples from Absolute Codec String variable.

Getting Fancy With PortAudio

If you have PortAudio running and would like to specify the codec you need to originate first and bridge second:

originate {absolute_codec_string=XXXX}sofia/default/foo@bar.com bridge:portaudio/auto_answer inline

 

Changing the SIP Contact user

FreeSWITCH normally uses mod_sofia@ip:port for the internal SIP contact. To change this to foo@ip:port, there is a variable, sip_contact_user:

{sip_contact_user=foo}sofia/my_profile/1234@192.168.0.1;transport=tcp

 

Using a Custom SIP URI

FreeSWITCH allows you to specify custom URI's as needed. For example, you may need to interoperate with equipment that accepts a URI only if it is formatted in a particular way. The key is to prefix your SIP URI with «sip:» in the dialstring. For example:

sofia/my_profile/sip:xxxx;phone-context=cdp.udp@somedomain.com;user=phone

 

The above example will send the the URI exactly as specified after the «sip:» prefix.

Testing the dialplan with a command line

originate loopback/<destination number>/<mycontext> hangup inline

 

- Note: You can also set your variables to match your dialplan requirement. See below example:

originate {toll_allow=international}loopback/0116628888888/default hangup inline

 

Setting up SIP Diversion Header for call forward

<action application="export" data="sip_h_Diversion=<sip:2134445555@1.2.3.4>;reason=unavailable"/>
Только авторизованные участники могут оставлять комментарии.
  • freeswitch/dp/fs_xml_dialplan/examples.txt
  • Последние изменения: 2018/10/25