[Freeswitch-users] System global mode variable

Pete Ashdown pashdown at xmission.com
Thu Jun 9 19:54:29 MSD 2016


Answered my own question:

In your dialplan:
<action application="lua" data="script.lua"/>

In script.lua:
mode = freeswitch.getGlobalVariable("mode")
if (mode == "open") then
  session:speak("open")
end
if (mode == "techonly") then
  session:speak("teck only")
end
if (mode == "event") then
  session:speak("event")
else
  session:speak("i dont know")
end

Make sure the global is created somewhere, like vars.xml:
<X-PRE-PROCESS cmd="set" data="mode=open"/>


On 06/07/2016 08:50 AM, Pete Ashdown wrote:
> What is the simplest way to have a conditional branch based on a global
> variable in a dialplan?  Actually using a global variable and xml is
> giving me mixed results.  Do I need to use Lua or another scripting
> language?
>
> This is what I have, which doesn't give the results desired.   The
> "speak" actions are merely debug placeholders.  I know there are better
> ways to do conditional voice to text.
>
>       <condition regex="any" field="${cond(${mode} == 'open' ? YES :
> NO)}" expression="^YES$">
>             <action application="speak" data="open"/>
>       </condition>
>
>       <condition regex="any" field="${cond(${mode} == 'tech only' ? YES
> : NO)}" expression="^YES$">
>             <action application="speak" data="teck only"/>
>       </condition>
>
>       <condition regex="any" field="${cond(${mode} == 'event' ? YES :
> NO)}" expression="^YES$">
>             <action application="speak" data="event"/>
>       </condition>
>



Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users mailing list