Incoming DID (also known as DDI) calls
Phone calls coming in from the Public Switched Telephone Network (PSTN) are often called DID or DDI calls. DID stands for Direct Inward Dialing, while DDI means Direct Dial In; both acronyms refer to the same thing. DID numbers are delivered by your telephone service provider. They can be delivered over VoIP connections (such as a SIP trunk) or via traditional telephone circuits, such as PRI lines. These phone numbers are sometimes called DID numbers or external phone numbers.
Getting ready
Routing a call requires two pieces of information: the phone number being routed and a destination for that phone number. In our example, we will use a DID number 8005551212
. Our destination will be user 1000
. Replace these sample numbers with the appropriate values for your setup.
How to do it...
- Create a new file in
conf/dialplan/public/
named01_DID.xml
. Add this text to it:<include> <extension name="public_did"> <condition field="destination_number"expression="^(8005551212)$"> <action application="set" data="domain_name=$${domain}"/> <action application="transfer" data="1000 XML default"/> </condition> </extension> </include>
- Save the file and then execute
reloadxml
fromfs_cli
.
How it works...
All calls that come in to the FreeSWITCH server from outside (as well as internal calls that are not authenticated) are initially handled in the public
context (dialplan contexts were discussed in more detail in this chapter's introduction) of the XML dialplan. Once the call hits the public
context, we try to match the destination_number
field. The destination_number
is generally the DID number (see the There's more… section for some caveats). Once we match the incoming number, we set the domain_name
channel variable to the default domain value, and then transfer the call to user 1000. (FreeSWITCH is domain-based in a way similar to e-mails. Most systems have only a single domain, though FreeSWITCH supports multiple domains.) The actual transfer happens with this dialplan entry:
<action application="transfer" data="1000 XML default"/>
In plain words, this tells FreeSWITCH to transfer the call to extension 1000 in the default context of the XML dialplan. The default
context contains the Local_Extension
that matches "1000" as destination_number
and handles the calls to users' telephones.
There's more...
Keep in mind that the expression for destination_number
must match what the provider sends to FreeSWITCH, not necessarily what the calling party actually dialed. There are providers that send DID information in various formats, such as these:
8005551212
18005551212
+18005551212
The expression must match what the provider sends. One way to accomplish this is to have a few optional characters in the pattern. This pattern matches all three formats you just saw:
<condition field="destination_number" expression="^\+?1?(8005551212)$">
The \+?
value means "optionally match the literal + character," and the 1
? value means "optionally match the literal digit 1." Now our pattern will match all of the three formats that are commonly used in North America. (Technically, our pattern will also match +8005551212
, but we are not concerned about that. However, the pedantic admin might be, so they can use the ^(\+1)?1?(8005551212)$
pattern instead.)
See also
- The Configuring a SIP gateway section in Chapter 2, Connecting Telephones and Service Providers