[Freeswitch-users] Using Variables in Dialplans

Chris Fowler chris at fowler.cc
Wed Apr 22 17:20:44 PDT 2009


Brian, Michael,

Thanks for the help - I had read that but not fully comprehended it until you spun it the way you did.  

Here's what I ended up with - if there's optimization that could be done let me know.  Happy to update the wiki if this is a common request.

    <!-- Provide an internal ext # for Sales -->
    <extension name="RS-Sales-x2002">
      <condition field="destination_number" expression="^2002$">
        <action application="transfer" data="RS-Sales"/>
      </condition>
    </extension>

    <!-- Setup variables prior to transfering to call handler for sales -->
    <extension name="RS-Sales" continue="true">
      <!-- man strftime - M-F, 9AM to 5PM -->
      <condition field="destination_number" expression="^RS-Sales$"/>
      <condition field="${strftime(%w)}" expression="^([1-5])$"/>
      <condition field="${strftime(%H%M)}" expression="^((09|1[0-6])[0-5][0-9]|1700)$">
        <action application="set" data="RS-Sales_open=true"/>
        <action application="transfer" data="xfer-to-sales"/>
        <anti-action application="set" data="RS-Sales_open=false"/>
        <anti-action application="transfer" data="xfer-to-sales"/>
      </condition>
    </extension>

    <!-- Handle Sales Call -->
    <!-- If Sales is open then route to extension first then vMail; else direct to vMail -->
    <extension name="xfer-to-sales">
      <condition field="destination_number" expression="^xfer-to-sales$"/>
      <condition field="${RS-Sales_open}" expression="^true$">
        <action application="bridge" data="user/1001@${domain_name}"/>
        <action application="answer"/>
        <action application="sleep" data="2000"/>
        <action application="voicemail" data="default ${domain_name} 2001"/>
        <anti-action application="voicemail" data="default ${domain_name} 2001"/>
      </condition>
    </extension>

Thx, Chris.


From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Michael Collins
Sent: Wednesday, April 22, 2009 13:10
To: freeswitch-users at lists.freeswitch.org
Subject: Re: [Freeswitch-users] Using Variables in Dialplans


On Wed, Apr 22, 2009 at 12:19 PM, Chris Fowler <chris at fowler.cc> wrote:
I have the following defined:

   <!-- Billing Open? -->
   <extension name="billing_open" continue="true">
     <!-- man strftime - M-F, 9AM to 5PM -->
     <condition field="${strftime(%w)}" expression="^([1-5])$"/>
     <condition field="${strftime(%H%M)}" expression="^((09|1[0-6])[0-5][0-9]|1700)$">
       <action application="set" data="billingopen=true"/>
     </condition>
   </extension>


   <!-- billing line -->
   <extension name="billing">
     <condition field="destination_number" expression="^billing$|^2001$"/>
     <condition field="billingopen" expression="^true$">
     <...>


But despite the "Billing Open" ext firing correctly:
       Action set(billingopen=true)

The Billing extenstion fails to get the data:
       Regex (FAIL) [billing] billingopen() =~ /^true$/ break=on-false

Please could someone point me in the right direction for using variables correctly in a dialplan?  I must be missing something simple...

Thanks, Chris.

This is a classic case of "dialplan is parsed all at once." The reason that it is failing is because ${billingopen} is not defined when the extension named "billing" is parsed. You need another pass through the dialplan, for example by adding a transfer app to your "billing_open" extension:

<!-- Billing Open? -->
  <extension name="billing_open" continue="true">
  <!-- man strftime - M-F, 9AM to 5PM -->
     <condition field="${strftime(%w)}" expression="^([1-5])$"/>
     <condition field="${strftime(%H%M)}" expression="^((09|1[0-6])[0-5]
       <action application="set" data="billingopen=true"/>
       <action application="transfer" data="billing"/>
     </condition>
   </extension>

This will send the call back through the dialplan and into the "billing" extension, this time with the value of ${billing_open} == "true" so you can now work with it. The originally dialed number is now available in the ${rdnis} channel variable in case you need it.

Have fun and let us know how it goes.
-MC




More information about the FreeSWITCH-users mailing list