Channel Variables

Each individual channel (call) in FreeSWITCH has a number of associated characteristics and values, known as "channel variables".

You use variables to get informations about the channel internals and to control the channel behavior.

Some of channel variables are assigned from the inception of the channel. Some of them change value during the life of the channel. Some variables are read-only. Some channel variables are writable, this means we can alter their value. You can (and often do) create variables in a channel, via dialplan or scripting. Specific channel variables modify the behavior of the channel, and you can take control of it by writing ("set") a variable value.

There are an incredible number of channels variables that are already set automatically when a call is processed.

For a first impact, connect via ssh to a FreeSWITCH server with demo configuration, execute /usr/local/freeswitch/bin/fs_cli, and then call 9192

    <extension name="show_info"> 
      <condition field="destination_number" expression="^9192$"> 
        <action application="answer"/> 
        <action application="info"/> 
        <action application="sleep" data="250"/> 
        <action application="hangup"/> 
      </condition> 
    </extension> 

This is a simple extension that checks destination_number, if it matches 9192 then it answers the call, execute the "info" application, then sleeps for a quarter of a second, and hangups.

As we'll see later in this chapter, the "info" application dumps on console every channel variable and its value. It's a precious debug tool!

This is an extract of what will be printed out in green characters on your terminal (actually this is a very small part. Try it for yourself!):

2017-05-25 17:34:15.625917 [INFO] mod_dptools.c:1743 CHANNEL_DATA: 
Channel-State: [CS_EXECUTE] 
Channel-Call-State: [ACTIVE] 
Channel-State-Number: [4] 
Channel-Name: [sofia/internal/[email protected]] 
... 
variable_direction: [inbound] 
variable_uuid: [12cd1ed7-d04a-40a8-b1b5-495af077c69c] 
variable_session_id: [2] 
variable_sip_from_user: [1011] 
variable_sip_from_uri: [[email protected]] 
... 
variable_accountcode: [1011] 
variable_user_context: [default] 
variable_effective_caller_id_name: [Extension 1011] 
variable_effective_caller_id_number: [1011] 
variable_outbound_caller_id_name: [FreeSWITCH] 
variable_outbound_caller_id_number: [0000000000] 
variable_callgroup: [techsupport] 
variable_user_name: [1011] 
variable_domain_name: [lab.opentelecomsolutions.com] 
... 
variable_endpoint_disposition: [ANSWER] 
variable_current_application: [info] 
 

All the output lines with "variable_" prefix can be accessed in dialplan using the ${} construct. For example, the last output line, "variable_current_application: [info]", means: the channel variable "${current_application}" has value "info". We can write a new dialplan extension to demonstrate it.

<extension name="giovanni_01"> 
   <condition field="destination_number" expression="^290864$"> 
         <action application="answer"/> 
         <action application="log" data="WARNING the value of current_application channel variable is: ${current_application}"/> 
         <action application="hangup"/> 
   </condition> 
</extension> 

We insert this new extension at the beginning of the /usr/local/freeswitch/conf/dialplan/default.xml file, just after

<include> 
  <context name="default"> 

Then from fs_cli, be sure to type: "fsctl loglevel 5", and then "reloadxml". Now, call 290864 (numerology: 29 August 1964 is my birthday).

Your terminal will show something similar to the following:

Now, let's set a variable and read it back. Add three lines:

<extension name="giovanni_02"> 
   <condition field="destination_number" expression="^290864$"> 
         <action application="answer"/> 
         <action application="log" data="WARNING the value of current_application channel variable is: ${current_application}"/> 
         <action application="log" data="WARNING the value of giovanni_nice_guy channel variable is: ||${giovanni_nice_guy}||"/> 
         <action application="set" data="giovanni_nice_guy=verymuch"/> 
         <action application="log" data="WARNING the value of giovanni_nice_guy channel variable is: ||${giovanni_nice_guy}||"/> 
         <action application="hangup"/> 
   </condition> 
</extension> 

From the console, reloadxml, and then call 290864 again.

As we can see from the output, the variable was not existing before we assigned ("set") her.

For more in deep coverage of channel variables, their characteristics, their usage to control FreeSWITCH, and much more, see the Chapter 9, Dialplan in Deep.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset