A public tutorial on freeswitch - dial plan

Posted by bouton on Sat, 22 Jan 2022 22:18:00 +0100

This is what we often call call routing. Through the dial plan, freeswitch turns the corresponding channel to fixed processing.

Dial plan is not a scripting language. Its goal is to simply help you find the application you need. We can simply call it call routing rule.

freeswitch is a multi environment dial plan by default, which is public and default by default.

public context is mainly open to all non authentication requests, and default must be an extension user who needs to be registered by default.

You can map it to a profile, but not exactly one-to-one. For example, the default internal and external profile s.

For example, you create a sip_profile file

<profile name="your_sip_profile">    
        <param name="context" value="your_sip_profile_context"/>    
         
    </profile>

The corresponding routing rule xml file can be distinguished by context

<context name="your_sip_profile_context">
    <extension name="yourextension1">
        <condition field="destination_number" expression="^1001$">
            <action application="bridge" data="user/1001"/> 
        </condition>
    </extension>
</context>

Multiple < extension > routes representing different rules can be created under each context.

Condition represents a condition, and expression can be combined with regular expressions to create many interesting telephone routes.

<1> Line sip docking operator gateway:

a: Create a gateway in the profile to describe the sip address, ip port and authentication information of the specified operator

 </profile>
       <settings>
       ........................
       </settings>
    <gateways>
            <gateway name="outbound">
              <param name="realm" value="ip:port"/>
              <param name="register" value="false"/>
            </gateway>
    </gateways>
</profile>

b: Simple diallan for outgoing calls

    <extension name="call_out">
                <condition field="destination_number" expression="(^[0-1][0-9]{10,11}$)">
                <action application="log" data="22~~~~~~~~~~~~${caller_id_number}"/>

                <action application="set" data="call_timeout=20"/>
                <action application="set" data="hangup_after_bridge=true"/>
                        <action application="bridge" data="{origination_caller_id_number=yournumber**,hangup_after_bridge=true}sofia/gateway/outbound/$1"/>
                        <action application="set" data="test=${hangup_cause}"/>
                        <action application="log" data="1 A-leg hangup cause: ${hangup_cause}"/>
                </condition>
        </extension>

Regular expression: (^ [0-1] [0-9] {10,11} $) represents the beginning of 0 or 1, and then the number between 0-9 can appear 10-11 times.

The following $1 represents the number in parentheses of the whole regular expression, that is, the number you call.

<2> : telephone recording

<extension name="test-route1">             
         <condition field="destination_number" expression="(^99030135$)">                  
            <action application="set" data="RECORD_COPYRIGHT=(c) 2011"/>                              
            <action application="set" data="RECORD_SOFTWARE=FreeSWITCH"/>                                          <action application="set" data="RECORD_ARTIST=FreeSWITCH"/>                               <action application="set" data="RECORD_COMMENT=FreeSWITCH"/>                            <action application="set" data="RECORD_DATE=${strftime(%Y-%m-%d %H:%M)}"/>                            
            <action application="record_session" data="/data/recordings/archive/${call_uuid}.wav"/>                   <action application="bridge" data="user/99030135"/>                   </condition>        
            </extension>

Telephone recording application, using record_session application, and use ${} to express the channel variable of freeswitch.

<3> : dialplan transfer ivr

For example, after you define your ivr.

<menu name="welcome"         greet-long="shout://xeducationfile-stg.oss-cn-hangzhou.aliyuncs.com/smartcall/dialogue/audio/mp3/101.mp3"         greet-short="shout://xeducationfile-stg.oss-cn-hangzhou.aliyuncs.com/smartcall/dialogue/audio/mp3/101.mp3"          invalid-sound="shout://xeducationfile-stg.oss-cn-hangzhou.aliyuncs.com/smartcall/dialogue/audio/mp3/101.mp3"         exit-sound="shout://xeducationfile-stg.oss-cn-hangzhou.aliyuncs.com/smartcall/dialogue/audio/mp3/101.mp3"         timeout="15000"         max-failures="3"         max-timeouts="3"         inter-digit-timeout="2000"         digit-len="4">         <entry action="menu-exec-app" digits="0" param="transfer 1000 XML default"/>         <entry action="menu-exec-app" digits="/^(10[01][0-9])$/" param="transfer $1 XML default"/>         </menu>

How should our diaplan be written?

<extension name="incoming_call">          
   <condition field="destination_number" expression="^1234$">                <action application="answer" data=""/>              
   <action application="sleep" data="1000"/>             
    <action application="ivr" data="welcome"/>         </condition>     
    </extension>

<4> : dia lua, python and other scripts

        <extension name="your-dialplan">
            <condition field="destination_number" expression="^(.*)$">
                <action application="set" data="ringback=${cn-ring}"/>
                <action application="lua" data="dialplan.lua"/>
            </condition>
        </extension>

Note the corresponding dialplan Lua scripts should be placed in the script directory

<5> application such as curl:

freeswitch's diplan has many complex functions, such as the cooperation of anti action and action, condition nested condition, which can be described in detail in Mr. Du's authoritative guide.

But I still hope to hand over the complex logic to the code implementation, so I can use curl to implement a lot of fun dailplan.

To use curl, you must first load mod_curl, then we write

We can send the corresponding data to the back-end service through http request, and then command through esl to achieve our desired purpose.

Therefore, curl is a very good choice for complex diplan. Of course, you can try lua, python and other script reality.

<6> : using lua and python scripting languages

It is a very good choice to use the scripting languages Lua and python to make complex dialplan. Of course, it needs to master the scripting syntax of lua and python.

We will not introduce the syntax basis of lua and python here. By default, you have mastered the corresponding basis.

If you want freeswitch to support lua and python languages, you need to compile mod at compile time_ lua and mod_python. Then configure the startup and loading module in the module of freeswitch_ lua and mod_python.

Topics: Java PostMan p2p