Page tree
Skip to end of metadata
Go to start of metadata


The XML dialplan is the default dialplan used by FreeSwitch. XML is easily edited by hand without requiring special tools, other than a text editor. 

In general, dialplans are used to route a dialed call to an endpoint, which can be a traditional extension, voicemail, interactive voice response (IVR) menu or other compatible application. Dialplans are extremely flexible.

Dialplans can be separated into "contexts" allowing calls to follow different pathways for different kinds of calls. Calls can be handed-off to other contexts as well. For example you might configure two dialplans; one that handles calls originating from the public phone network (PSTN) and one that handles calls originating from internal extensions. The FreeSwitch sample configuration files do this, forcing an incoming PSTN call through some additional scrutiny before being handed off to the internal dial plan.

Dialplan contexts also allow you to share a single PBX with multiple tenants in an office building. Since each tenant will likely have their own set of (and often conflicting) extensions, voice menus, etc., it makes sense to separate tenants into their own independent dialplans to ease configuration and maintenance.

Learning Prerequisites

Understanding this documentation requires an understanding of regular expressions. XML dialplans use the common Perl Compatible Regular Expression (PCRE) matching syntax on fields, which decreases the "learning curve" when creating and maintaining dialplans.

Simple dialplans can be created by anyone with a working knowledge of PCRE syntax.

Authors of moderately complex XML dialplans would benefit from in-depth PCRE experience along with a working knowledge of variables and flow-control used in scripting or programming languages.

Learning Goals 

After reading this document, you should be able to:

  • Add a configuration statement to the Sofia SIP profile to call an XML dialplan.
  • Create a moderately complex XML dialplan using regular expressions to reduce a 1000 extension dialplan to one extension definition.
  • Understand the flow-altering capabilities of conditions and nested conditions, and why they might be useful in a dialplan


 Click here to expand Table of Contents

The 10,000 Foot View

This overview uses the Sofia SIP driver as the source and destination for calls handled by a dialplan. Other drivers have similar mechanisms.

When a call arrives at the FreeSWITCH™ PBX, Sofia is the first responder. She gathers information about the call, and decides which dialplan to invoke.

Sofia passes information about the call to your dialplan inside "channel variables", which your dialplan accesses to make decisions about what to do with the call.  Channel variables contain a wealth of information about the call being processed.  For example, the "destination_number" variable contains the digits dialed by the caller.  Other variables contain the caller-ID information for the call, the source IP address of the caller, etc.

The XML dialplan is organized as a series of extension definitions (called "extensions").   FreeSWITCH™ steps through each extension definition until it finds one that matches.

Matching is performed by evaluating condition definitions (called "conditions") inside each extension.   FreeSWITCH™ steps through each condition inside the extension.

When condition(s) for an extension are met, the extension's action definitions (called "actions") are executed. In the simplest case, the action might be to connect the call to the physical extension.  Of course there are a wide range of actions you can perform in a dialplan.  For the purposes of this overview, we'll just use a few of them.

If the conditions for your extension are not met, there are optional action definitions (called "anti-actions") that can be executed.

Of course these are just the basic concepts needed to start working with the XML dialplan.  If you are familiar with other programming or scripting languages, XML dialplans offer logical operations and control-flow options allowing you to create amazingly complex dialplans.  But don't think the XML dialplan is the answer to all your problems.  Complex XML dialplans are sometimes difficult to read and understand, which is why other dialplan processors are available.  That said, the XML dialplan is a good place to start, and usually does the bulk of the work when  FreeSWITCH™ processes a call.

Introductory Example

This following example shows a dialplan that understands how to route calls to only two extensions, 500 and 501.  But before it can be used, you'll need to tell the SIP driver the name of the dialplan (called the "context") to use when a call needs processing. 

The sample dialplan is shown below. 


When a call needs processing,  FreeSWITCH™ evaluates each extension in the dialplan until it finds a match. 

The first line in our example defines the context block.  All items inside this block belong to the "example" dialplan context.  Nested inside the context block are extension blocks, containing matching "conditions" and their corresponding "action" rules. Extensions are processed in the order that they appear in the configuration file.

In the example, Sofia would start the dialplan after she receives an incoming SIP call.  Here's what happens next:

  • The first extension is block is evaluated, and since the destination number does not exactly match "500", the rest of the block is skipped.
  • The second extension block is evaluated next.  The destination matches  "501" exactly, which causes the actions under that condition to be executed.  In this example, extension 501 rings. If the extension is not answered, the second action answers the call, and the following actions delay for 1000 milliseconds (1 second) and then connect the call to the voicemail system.

Things to Notice

  • Find the action in the example that bridges the call to voicemail.  Notice how the value of the channel variables domain_name and dialed_extension are passed along to the voicemail application.  You can refer to channel variables like this in your own dialplans.
  • The dialplan automatically stops processing additional actions and extensions when a call is bridged to another extension, or is handed-off to another dialplan.  This means that in our example, if extension 501 is answered, the rest of the actions will not be executed after the call ends.
  • Creating a dialplan like this for thousands of extensions would be tedious and not very efficient.  After reading this document, how would you construct a dialplan for 1000 extensions using only one extension definition?

Dialplan Configuration Directory Structure

The FreeSWITCH example configuration stores dialplans in the conf/dialplans directory, with each context stored in a subdirectory beneath it. This is the recommended configuration.

For example, this sample structure houses a dialplan for a simple PBX:


Things to Notice

  • This dialplan structure is similar to the example configuration that ships with  FreeSWITCH™. It is a good starting point to customize your own PBX, as we have done here.
  • Any .xml file placed in the dialplans directory will be loaded when FreeSWITCH starts.
  • public.xml contains all the common configuration information for the public context, then includes all the XML files in the public directory.
  • default.xml contains all the common configuration information for the default context, then includes all the XML files in the default directory.
  • Files are loaded in alphabetical order, so beginning file names with a number is a good practice to ensure the bits and pieces of your dialplan are loaded in the proper sequence, if needed.

Beginning Concepts


Contexts are a logical grouping of extensions.

The context tag has only one required parameter called name. This is the name that incoming call handlers (like the [Sofia] SIP driver) use when they need to route a call. There is often more than one context in a typical PBX dialplan. There is one reserved name, any which matches any context.


Inside each context are one or more extensions. Extensions are destinations for a call. In  FreeSWITCH™, extensions are the primary way calls are routed. Don't be fooled by the name, since an extension does not always have a real phone attached.  An extension can be used to process call routing logic, security restrictions, outgoing trunk selection and more.

The extension tag has one required parameter name, and it must be unique. Other dialplans can transfer control to your dialplan using this name.

Inside an extension are one or more conditions. If the conditions are met, the actions belonging to that condition are executed.  If the conditions are not met, optional anti-actions are executed. 

For example:

Typically when an extension is matched in your dialplan, the corresponding actions are performed and dialplan processing stops. An optional continue parameter allows your dialplan to continue evaluating the remaining extensions:


Conditions do the hard work in a dial-plan.  They are extremely flexible, and as such, are sometimes challenging to construct.  This document will start with simple examples and progress forward to more complex examples.

Conditions allow you to match regular expressions against channel variables associated with each call.  The first example in this document did just that, matching the destination number against "500", as shown below.

Each condition is parsed using the Perl Compatible Regular Expression library. (See the Perl Compatible Regular Expression documentation to learn more.)

Example 1: Capturing Digits

The next example will use a feature of PCRE to show how to route a local call to the local Telco/PTT. (Local providers often insist that local calls be stripped of their country/area/city code.)

In the USA, the last 7 digits of the full 11 digit phone number are the local part.  So, if our PBX is located in Los Angeles, the first four digits will always be 1213 for local calls, so we can check for that:

The condition will match any 11 digit number beginning with "1213".  To capture the final seven digits, we write it this way, enclosing the last seven digits in parentheses.

The condition will still match any 11 digit number beginning with 1213.  The added feature is that the final seven digits of the number are now available in the temporary variable $1.  Now we can make a complete dialplan extension that passes all local calls to the local phone company.

A destination number of 12135551212 would set $1 to 5551212 and then send the call out to the local phone company.

Use caution when substituting captured text, especially when building numbers. Perhaps the local phone company requires that all local calls have the digit 5 added to the local number. We would be tempted to write "sofia/gateway/LocalTelco/$15", but that would be wrong. Surrounding the variable in brackets fixes the ambiguity: "sofia/gateway/LocalTelco/${1}5" This works for all FreeSWITCH™ variables, and often improves the readability of your dialplan.

Example 2: Logical AND

Suppose you wanted to redirect a call for extension 500 to extension 531, but only on Sunday.

In English you would say "if destination number is 500 and today is Sunday, send the call to ext. 531, otherwise send it to ext. 500"

In the XML dialplan, you can place more than one condition in an extension, and all conditions must match before the final condition's actions will be executed.

This does the trick:

Things to Notice
  • We use the "anti-action" here to ensure that if the final condition fails, the call will go to the proper place.
  • Don't be fooled:  FreeSWITCH™ does not evaluate all the conditions to make its decision. This design pattern only works because  FreeSWITCH™ stops processing an extension after the first condition failure.
  • Keep in mind that you must observe correct XML syntax when using this structure. Be sure to close all conditions except the last one with />. The last condition contains the final actions to be run, and is closed on the line following the last action.

Example 3: Logical OR

It is possible to emulate the logical OR operation available in many programming languages, using multiple conditions. In this situation, if one of the conditions matches, the actions are executed.

There are a few ways to do this.  Use the one that meets your needs.

The simplest version using a single regular expression that matches the destination number against 501 OR 502:

This method works well if your OR condition uses the same field. If you need to use two or more different fields then the extended regular expression syntax will help:

Notice the regex="any" in the condition.  This says that if any of the following regex statements match, then execute the actions.  Of course if none of the regular expressions match, the anti-actions (if any) will be executed instead. Here's an example that executes the extensions actions if the caller's name is "Some User" OR the extension being called is 1001.

The <condition regex=...> has two other options: all and xor.  So the full compliment of options looks like this:

  • regex="any" — We used this above.  Any of the regular expressions contained in the condition can match for the actions to be taken.
  • regex="all" — is equivalent to a logical AND operation.  All of the regular expressions contained in the condition must match for the actions to be taken.  This is another way to perform a logical AND, like we did in the previous section.  Use the syntax that makes your dialplan clearer and easier to read. 
  • regex="xor" — is the equivalent to a logical XOR operation.  XOR is commonly known as "eXclusive-OR", because exactly one of the regular expressions must match for the actions to be taken.

Actions and anti-actions are executed like they would be in a standard condition block.

This method makes it easier to match the caller's name OR caller ID number and execute actions when either is true.

A slightly more advanced use of this method is demonstrated below. If the caller's name is "Michael S Collins" OR the caller ID is 1002, 3757, or 2816, the variable calling_user is set to "mercutioviz". If neither is true, then the calling_user variable is set to "loser". After playing the welcome message, a custom message is played based on the calling_user variable. 

Notice the inline="true" option added to the actions that set the calling_user variable. Normally, when FreeSWITCH™ processes an extension, it collects all the actions together and executes them AFTER ALL the conditions in the extension are evaluated. Said another way: You cannot depend on an action being executed in an extension with more than one <condition... /> statement until all the conditions are evaluated.

The  inline="true" options causes the variable to be set immediately, when the first condition matches. With out it, our example would not work properly because all the condition blocks would be checked before the variable was actually set. This would make the third condition block useless.


Example 4: Logical XOR

We've seen how the regex= clause can be used to implement AND and OR.  For completeness, here is a final example showing how to use XOR.  The actions are executed if either the first or second regular expression matches, but not if both match.

Actions and Anti-Actions

The final parts of an extension definition are its actions.  These cause  FreeSWITCH™ to do things on your behalf, like connect a call or provide other functions.  The list of available actions is long and varied, and can be found here.  Some of the more useful actions are:

answerAnswer the call


Bridge the call to another session
logWrite a message in the log file
hangupDisconnect the call
playbackPay an audio file or tone stream
setSet a channel variable
transferTransfer the call the another extension

It bears repeating: Actions are not executed "in-line" with the conditions they are bundled with. FreeSWITCH™ first checks all the conditions in an extension before it executes any actions1. In most cases you cannot rely on an action being performed and having its result be available for checking (or using in) a <condition...> or <action...> that follows it.

1In some cases, the action may support the inline="true" option which causes the action to execute along with its matching condition. Not all dialplan applications support this. The set application is probably the most likely place you would use this feature, as we showed in this example. 


In a few of our introductory examples, we showed the use of the anti-action expression. As its name implies, anti-actions are executed when the condition they are contained in evaluate to false.

For every condition, if the condition's actions aren't executed, the anti-actions will be executed, and vice-versa.

Dialplan Variables

So far you've seen the basic pieces of the dialplan and its structure.  The examples have shown the basic use of:

  • Extensions
  • Conditions
  • Simple Regular Expressions
  • Actions and Anti-Actions

We have only touched upon dialplan variables.  They are essential to do anything useful inside a  FreeSWITCH™ dialplan.

Variables are named bits of information that are stored for later use.  When a dialplan starts, a wealth of information comes pre-loaded in the form of variables. You can use regular expressions to match against a variable and control your dialplan execution as a result.

We will touch on a few common variables here to solidify their proper use and demonstrate some features of variable substitution in  FreeSWITCH™.

Accessing Variables

There are three kinds of variables available for you to access in your XML dialplan:

    • Channel variables
    • Global variables
    • Built-in variables (time, date, etc.)
Channel Variables

Channel variables can be used to get information about a call and control its behavior as it progresses through your dialplan.  Channel variables contain a wealth of information about the call being processed and an amazing array of options that can be set.  You access the contents of a channel variable by surrounding its name with ${ }.  For example, to append the default SIP domain to the end of a dial string, you can just reference ${domain_name} in the dial string text, and its value will be substituted automatically:

You set the value of a channel variable like this:

For the complete list of Channel Variables and alternate ways to use them in dial strings, see: Channel Variables.  We'll present a short list here to give you a sense of what's possible.

Variable NameDescription

The name of the calling party.

destination_numberThe number that the calling party dialed.
directionWhether this call leg is inbound or outbound

The name of this call's inbound channel, for example:


call_timeoutSet to the number of seconds to wait for a call to be answered before giving up.
stateThe state of this channel, for example CS_EXECUTE or CS_HANGUP
bridge_hangup_causeThe reason a call ended, for example NO_ANSWER, NORMAL_CLEARING or USER_BUSY

Built-In Variables

Built-in variables are accessed by name, without using the customary $ prefix.

The built-in variables are:   (updated 29-July-2014, switch_xml.c, switch_xml_std_datetime_check())

Built-In NameDescription

Standard Date and Time


The current data and time: YYYY-MM-DD HH:MM:SS

For example: 2014-08-12 15:34:59


The current local time: HH:MM:SS

For example: 15:34:59

Data and Time Parts (all based on local timezone)
yearThe current year through. (1970 through 9999)
monThe current month. (1 through 12)
mdayThe day of the current month. (1 through 31)
hourThe hour of the current day. (0 through 23)
minuteThe minute of the current hour. (0 through 59)
Advanced Data and Time Parts
wdayThe day of the current week. (Sunday = 1 through 7)
weekThe current week since January 1st. (1 through 53)
mweekThe week of the current month. (1 through 6)
ydayThe day of the current year (1 through 366)
mindayThe current minute of the day starting at midnight. (0 through 1440)
tz-offsetTimezone offset in hours from GMT. (-11 to +11)
dstReturns 1 if daylight savings time is in effect, or 0 if not.

In condition statements, you can compare against more than one built-in variable.  All comparisons must match (logical AND) before its actions will be executed.

There are a number of ways match against a built-in variable.  You can:

Equality<condition wday="1">Is it Sunday?
Range<condition wday="2-4">

Is it Monday, Tuesday, or Wednesday?

List<condition wday="1,4">Is it Sunday or Wednesday?
Combination<condition wday="1-3,7">Is it Sunday, Monday, Tuesday, or Saturday?

The range operation can be used on times and dates as well.

The range operator for dates is "~", not "–"

Advanced Concepts

Nested Conditions

This section needs better examples and explanations. Feel free to contribute some.

As its name implies, you can nest an additional block of conditions inside a condition, allowing you to express more complex dialplan behavior.

By default, all of the nested conditions must be true  

The new attribute in the condition statement is require-nested, it is true (the default) or false and indicates if the nested conditions are required to be true in order to evaluate any actions contained in its parent. 

Said another way, if required-nested is true, the nested conditions are required to all be true before the actions of its parent will be executed.

If required-nested is false, no matter what happens in the nested condition, even if it fails completely, the parent's actions will be executed.

In the following example, if the destination number is 123, the file foo.wav is played, followed by the file bar.wav.   If the destination number is 122, no sound is played– even though the first condition is met.  The require-nested="true" statement alters its behavior.

So below if "require-nested" is true which is the default even when not specified, the sub-condition must either be true or have break=never set in the same fashion as top-level extensions. Basically each level of nested conditions are parsed with the identical method that an extension is parsed only instead of continue you use the "require-nested" logic described above.

Basically with this combination of logic you should be able to do one main condition with "require-nested=false" then a series of nested conditions each implementing the logical AND.

Nested Condition Caveats and Notes

Keep in mind that while evaluating dialplan conditions, nested child conditions are always parsed first.  Think of it this way: The parent condition cannot know what to do until it evaluates all the nested child conditions.

This example shows that actions for this extension are not executed in the order that they appear in the file.

Which results in:

Also note that captured values from regular expressions ($1, $2, etc.) work as expected.  A captured value in a parent will not be overwritten by a captured value in a nested child.  Think of captured values as "local" variables.


Advanced Condition/Action Rules


Here is a more complex example, using the break="on-true" and break="on-false" statements to perform time-based routing for a support organization. The user dials extension 1100. The actual support extension is 1105 and is staffed every day from 8am to 10pm, except Friday, when it is staffed between 8am and 1pm. At all other times, calls to 1100 are sent to the support "after-hours" mailbox.

Thing to Notice

The break="on-true" statement causes the extension to halt processing when the condition its used in matches.  In the example above, if the call arrives in the designated support hours, the call is transferred and the rest of the conditions are not processed.

By default, break="on-false" behavior is assumed if it is not specified.


In this example, we use the break="never" statement to cause the first condition to always "fall through" to the next condition even if the first condition is false. This is useful to set various flags as part of extension processing. This example sets the variable begins_with_one if the destination number begins with 1.  

Asterisk Pattern Matching

In addition to PCRE FreeSWITCH also supports Asterisk patterns. Any expression starting with an underscore (_) will be processed using asterisk pattern matching.  See Mod_dialplan_asterisk.

Since * is normally reserved in regular expressions, its use in Asterisk patterns must be escaped with \, as shown in the second part of the example below.

Example Library

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:


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:


While channel variables are accessed like this:


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:


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


Informational Tip

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).


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"/>.


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 svn rev 14906 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.


Available Actions

See API Reference and 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:


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:




















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

Complete Syntax



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?)


Other Dialplan Pearls of Wisdom

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:



Informational Tip

"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 If it does, the destination number will be captured in $1, and the call will be bridged to the same number, at

This is a bizarre example. We can do better.

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

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:

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.

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:

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 FreeSWITCH™ receives 00123456789, we should dial 011123456789:

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:

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:

to send the call in G.711 uLaw and


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 Note the '%' instead of '@' in the data string.


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 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.: is not called)

If the initial call to was not successful the channel will not be closed and the second action will be called.

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.


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:


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


(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 gateway. This examples shows how to route for a specific extension and allows custom caller id for that 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.


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.


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.


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.


Example 15: Speaking Clock

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

See: mod_flite


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.


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:


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


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:

In Germany, the international call prefix is called "Verkehrsausscheidungsziffer" (VAZ), see

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

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

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


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:


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:


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.


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


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:


This would dial 1234 at host 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:


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


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:

Dialing Through A Gateway (SIP Provider)

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


This will dial through the gateway named "" 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:


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:


Specifying The Codec

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


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:


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:


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:


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

Testing the dialplan with a command line


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


Setting up SIP Diversion Header for call forward



  • No labels

1 Comment

  1. Don't forget in the regex examples that we might want to use the \d{4} format or atleast explain it as \d{4} is the same as \d\d\d\d and can allow for variable length