Sponsor: VoiceMeUp - Corporate & Wholesale VoIP Services

VoIP Mailing List Archives
Mailing list archives for the VoIP community
 SearchSearch 

[Freeswitch-users] Using Variables in Dialplans


 
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users
View previous topic :: View next topic  
Author Message
chris at fowler.cc
Guest





PostPosted: Wed Apr 22, 2009 2:29 pm    Post subject: [Freeswitch-users] Using Variables in Dialplans Reply with quote

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.

_______________________________________________
Freeswitch-users mailing list
Freeswitch-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
Back to top
brian at freeswitch.org
Guest





PostPosted: Wed Apr 22, 2009 2:39 pm    Post subject: [Freeswitch-users] Using Variables in Dialplans Reply with quote

This again? Wink Lets see if this helps!

http://wiki.freeswitch.org/wiki/Dialplan_XML#Anatomy_of_the_XML_Dialplan


The dialplan is not processed and executed line by line... its compiled and installed into the session before it goes into execute state.
So you can't use set on one line then use that var in a condition on the next line because the SET hasn't happened yet. Once the session
leaves the routing state it enters execute state. This is when the compiled list of things to do gets ran.


If you wish to re-enter the dialplan and re-eval some condition you use execute_extension or "transfer" the session back to the dialplan.


/b



On Apr 22, 2009, at 2:19 PM, Chris Fowler wrote:
Quote:
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


Brian West
brian@freeswitch.org (brian@freeswitch.org)



-- Meet us at ClueCon! http://www.cluecon.com
Back to top
msc at freeswitch.org
Guest





PostPosted: Wed Apr 22, 2009 3:10 pm    Post subject: [Freeswitch-users] Using Variables in Dialplans Reply with quote

On Wed, Apr 22, 2009 at 12:19 PM, Chris Fowler <chris@fowler.cc> wrote:
Quote:
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
Back to top
chris at fowler.cc
Guest





PostPosted: Wed Apr 22, 2009 7:31 pm    Post subject: [Freeswitch-users] Using Variables in Dialplans Reply with quote

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@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Michael Collins
Sent: Wednesday, April 22, 2009 13:10
To: freeswitch-users@lists.freeswitch.org
Subject: Re: [Freeswitch-users] Using Variables in Dialplans


On Wed, Apr 22, 2009 at 12:19 PM, Chris Fowler <chris@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

_______________________________________________
Freeswitch-users mailing list
Freeswitch-users@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
Back to top
msc at freeswitch.org
Guest





PostPosted: Thu Apr 23, 2009 10:34 am    Post subject: [Freeswitch-users] Using Variables in Dialplans Reply with quote

On Wed, Apr 22, 2009 at 5:20 PM, Chris Fowler <chris@fowler.cc> wrote:
Quote:
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.

That looks pretty good. It is clean and readable and most importantly it sounds like it does what you need! Smile
-MC
 
Quote:


   <!-- 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.

Back to top
chris at fowler.cc
Guest





PostPosted: Thu Apr 23, 2009 3:24 pm    Post subject: [Freeswitch-users] Using Variables in Dialplans Reply with quote

I added a Wiki example on this. Hopefully it will help the next FreeSWITCHer…

http://wiki.freeswitch.org/wiki/Time_of_Day_Routing


From: freeswitch-users-bounces@lists.freeswitch.org [mailto:freeswitch-users-bounces@lists.freeswitch.org] On Behalf Of Michael Collins
Sent: Thursday, April 23, 2009 08:29
To: freeswitch-users@lists.freeswitch.org
Subject: Re: [Freeswitch-users] Using Variables in Dialplans



On Wed, Apr 22, 2009 at 5:20 PM, Chris Fowler <chris@fowler.cc> wrote:
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.

That looks pretty good. It is clean and readable and most importantly it sounds like it does what you need! Smile
-MC
Back to top
msc at freeswitch.org
Guest





PostPosted: Thu Apr 23, 2009 4:12 pm    Post subject: [Freeswitch-users] Using Variables in Dialplans Reply with quote

On Thu, Apr 23, 2009 at 1:07 PM, Chris Fowler <chris@fowler.cc> wrote:
Quote:

I added a Wiki example on this.  Hopefully it will help the next FreeSWITCHer…
 
http://wiki.freeswitch.org/wiki/Time_of_Day_Routing
 

Thanks - it definitely will help. Having the perspective of newer users seeking help from the docs is valuable. Keep up the good work.

-MC
Back to top
Display posts from previous:   
Post new topic   Reply to topic    VoIP Mailing List Archives Forum Index -> freeSWITCH Users All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

VoiceMeUp - Corporate & Wholesale VoIP Services