Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Freeswitch 1.6 Cookbook

You're reading from   Freeswitch 1.6 Cookbook Over 45 practical recipes to empower you with the latest FreeSWITCH 1.6 features

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher
ISBN-13 9781785280917
Length 190 pages
Edition 1st Edition
Concepts
Arrow right icon
Toc

Table of Contents (9) Chapters Close

Preface 1. Routing Calls FREE CHAPTER 2. Connecting Telephones and Service Providers 3. Processing Call Detail Records 4. External Control 5. PBX Functionality 6. WebRTC and Mod_Verto 7. Dialplan Scripting with Lua Index

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

  1. Create a new file in conf/dialplan/public/ named 01_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>
  2. Save the file and then execute reloadxml from fs_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
You have been reading a chapter from
Freeswitch 1.6 Cookbook
Published in: Jul 2015
Publisher:
ISBN-13: 9781785280917
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime