Book Image

FreeSWITCH Cookbook

Book Image

FreeSWITCH Cookbook

Overview of this book

FreeSWITCH is an open source telephony platform designed to facilitate the creation of voice, chat, and video applications. It can scale from a soft-phone to a PBX and even up to an enterprise-class softswitch.In the FreeSWITCH Cookbook, members of the FreeSWITCH development team share some of their hard-earned knowledge with you in the book's recipes. Use this knowledge to improve and expand your FreeSWITCH installations.The FreeSWITCH Cookbook is an essential addition to any VoIP administrator's library.The book starts with recipes on how to handle call routing and then discusses connecting your FreeSWITCH server to the outside world.It then teaches you more advanced topics like CDR handling, practical examples of controlling FreeSWITCH with the event socket, and configuring many features commonly associated with a PBX installation.
Table of Contents (12 chapters)
FreeSWITCH Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Incoming DID calls


Phone calls coming in from the Public Switched Telephone Network (PSTN) are often called DID calls. DID stands for Direct Inward Dialing. 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 like 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 of 8005551212. Our destination will be user 1000. Replace these sample numbers with the appropriate values for your setup.

How to do it...

Follow these steps:

  1. Create a new file in conf/dialplan/public/ named 01_DID.xml. Add this text:

    <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 the 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 dialplan context (dialplan contexts were discussed in more detail in this chapter's introduction). 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 below for some caveats). Once we match the incoming number, we then 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-mail.

Most systems have only a single domain, although FreeSWITCH supports multiple domains. See the FreeSWITCH wiki for explicit information on multiple domain configuration). The actual transfer happens with this dialplan entry:

<action application="transfer" data="1000 XML default"/>

In plain language, this tells FreeSWITCH to transfer the call to extension 1000 in the XML dialplan and the default context. The default context contains the Local_Extension, which handles calls to users' telephones.

There's more...

Keep in mind the match in destination_number must match what the provider sends to FreeSWITCH, not necessarily what the calling party actually dialed. In North America, there are providers that send DID information in various formats such as:

  • 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 listed above:

<condition field="destination_number" expression="^\+?1?(8005551212)$">

The value \+? means optionally match a literal + character and the value 1? means "optionally match a literal digit 1". Now our pattern will match all 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 he or she can use the pattern ^(\+1)?1?(8005551212)$ instead).

See also

  • The Configuring a SIP gateway section in Chapter 2, Connecting Telephones and Service Providers