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

Outgoing calls


In order to make your system useful, you need a way to dial out to the "real world". This section will cover dialing out to the PSTN and allow you to connect to land lines, 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.

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.

How to do it...

Routing outbound calls is simply a matter of creating a dialplan entry. Follow these steps:

  1. Create a new file in conf/dialplan/default/ named outbound_calls.xml. 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 press F6 or issue the reloadxml command at the fs_cli.

How it works...

Assuming you have a phone set up on the default context, our 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.

There's more...

The regular expression matching in FreeSWITCH allows the possibility of having very powerful conditions. You can also match caller_id_number to route calls from a user at extension 1011 out to the second gateway called our_sip_provider2 and everyone else at the 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_sip_provider2/$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 out to the our_sip_provider2 gateway, otherwise the second extension is matched and the call goes out 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 (NANPA) numbers. The regular expression used to capture dialed digits will 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://wiki.freeswitch.org/wiki/Regular_Expression for further details.

See also

  • The Configuring a SIP phone to register with FreeSWITCH and Configuring a SIP gateway sections in Chapter 2, Connecting Telephones and Service Providers