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

Outgoing calls

In order to make your system useful, you need a way to dial out to the "real world". This recipe will cover dialing out to the PSTN and allow you to connect to landlines, cellular phones, and so on. In this recipe, we'll make an extension that will allow an outbound call to any valid US number. We'll attempt to complete the call using the gateway named our_sip_provider (see the Configuring an SIP Gateway section in Chapter 2, Connecting Telephones and Service Providers).

Getting ready

Making outbound calls requires you to know the numbering format that your provider requires. For example, do they require all 11 digits for US dialing? Or will they accept 10? In our example, we're going to assume that our provider will accept a 10-digit format for US dialing (for example, without the international prefix "1").

How to do it...

Routing outbound calls is simply a matter of creating a dialplan entry:

  1. Create a new file in conf/dialplan/default/ named outbound_calls.xml. then add the following text:
    <include>
    <extension name="outbound_calls">
    <condition field="destination_number" expression="^1?([2-9]\d{2}[2-9]\d{6})$">
    <action application="bridge" data="sofia/gateway/our_sip_provider/$1"/>
    </condition>
    </extension>
    </include>
  2. Save your XML file and issue the reloadxml command at fs_cli.

How it works...

Assuming you have a phone set up on the default context, your regular expression will match any destination_number that follows the US dialing format (10 or 11 digits), and send the call to our_sip_provider in a 10-digit format. The format in regexp is as follows: optional "1", then one digit between 2 and 9, then two digits, then one digit between 2 and 9, and finally six digits. Only the part after the optional digit "1" is captured by the parentheses and passed down in the $1 variable.

There's more...

The regular expression matching in FreeSWITCH allows the privilege of having very powerful conditions. You can also match caller_id_number to route calls from a user calling from extension 1011 out to the second gateway called our_second_sip_provider, while everyone else will be sent through our_sip_provider. Consider the following alternative outbound_calls.xml file:

<include>
<extension name="outbound_calls_from_1011">
<condition field="caller_id_number" expression="^1011$"/>
<condition field="destination_number"
   expression="^1?([2-9]\d{2}[2-9]\d{6})$">
<action application="bridge" data="sofia/gateway/our_second_sip_provider/$1"/>
</condition>
</extension>
<extension name="outbound_calls">
<condition field="destination_number"
    expression="^1?([2-9]\d{2}[2-9]\d{6})$">
<action application="bridge" data="sofia/gateway/our_sip_provider/$1"/>
</condition>
</extension>
</include>

Note that we have two extensions. The first one tries to match the caller_id_number field to the value 1011. If it matches 1011, then the call gets sent to the our_second_sip_provider gateway. Otherwise, the next extension is matched and the call goes to the our_sip_provider gateway. Note that we use $1 to capture the matching value in the conditions' expressions. In each case, we capture exactly 10 digits, which correspond to the area code (three digits), exchange (three digits), and phone number (four digits). These are North American Numbering Plan (NANP) numbers. The regular expressions used to capture the format of dialed digits vary, depending upon the country.

Note

Regular expressions can be a challenge. There are a number of examples with explanations on the FreeSWITCH wiki. See http://freeswitch.org/confluence/display/FREESWITCH/Regular+Expression for further details.

See also

  • The Configuring an SIP phone to register with FreeSWITCH and Configuring an SIP gateway sections 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 $19.99/month. Cancel anytime