Discussion:
[Freeswitch-users] Mod perl using $session->setVariable inline
Liam Farr
2014-12-10 09:20:29 UTC
Permalink
Hi,

I need to set a variable using a perl script inline.

Normally I would use $session->setVariable('some_var',$my_value);

However I cant find any options to execute this inline / as an inline
action. (I need to evaluate the variable later in the hunting phase of the
dialplan hence need it to be an inline action).

Is there a way to do this?

Or is there another way to achieve the same result, e.g. hacking
$session->execute("set","some_var=$my_value") to run as an inline action?

Any help would be much appreciated, I've scoured the wiki, confluence and
git repo and come up empty.
--
Kind Regards


Liam Farr
Michael Jerris
2014-12-10 17:28:07 UTC
Permalink
If you are in a perl script using session->setVariable, how are you still in the dialplan? This doesn't make sense to me. There should be no need for an inline if you are already in the script.
Post by Liam Farr
Hi,
I need to set a variable using a perl script inline.
Normally I would use $session->setVariable('some_var',$my_value);
However I cant find any options to execute this inline / as an inline action. (I need to evaluate the variable later in the hunting phase of the dialplan hence need it to be an inline action).
Is there a way to do this?
Or is there another way to achieve the same result, e.g. hacking $session->execute("set","some_var=$my_value") to run as an inline action?
Any help would be much appreciated, I've scoured the wiki, confluence and git repo and come up empty.
--
Kind Regards
Liam Farr
_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
***@freeswitch.org
http://www.freeswitchsolutions.com

Official FreeSWITCH Sites
http://www.freeswitch.org
http://confluence.freeswitch.org
http://www.cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-***@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
Liam Farr
2014-12-10 17:56:33 UTC
Permalink
Heres an expanded example;



Extension runs the perl script as part of the public dialplan first;


<extension name="run-script" continue="true">

<condition>

<action application="perl" data="/etc/freeswitch/scripts/my-script.pl"/>

</condition>

</extension>



Script sets some variables;


$my_value = "123";

$session->setVariable('some_var',$my_value);



Use that variable later in another extension in the public dialplan as a
condition selector;



<extension name="bridge-call" >

<condition field="context" expression="public" />

<condition field="${some_var}" expression="123" >

<action application="set" data="call_direction=inbound"/>

<action application="bridge" data="sofia/internal/${
destination_number}@1.2.3.4:5060" />

</condition>

</extension>



However this will fail, because the perl script "$session->setVariable" run
earlier is not inline, so you cant make use of it in the condition
(<condition field="${some_var}" expression="123" >) in the second extension
that exists in a later part of the public dialplan. Hence I need a way to
set inline variables from my perl script.



Cheers


Liam Farr
Post by Michael Jerris
If you are in a perl script using session->setVariable, how are you still
in the dialplan? This doesn't make sense to me. There should be no need
for an inline if you are already in the script.
Post by Liam Farr
Hi,
I need to set a variable using a perl script inline.
Normally I would use $session->setVariable('some_var',$my_value);
However I cant find any options to execute this inline / as an inline
action. (I need to evaluate the variable later in the hunting phase of the
dialplan hence need it to be an inline action).
Post by Liam Farr
Is there a way to do this?
Or is there another way to achieve the same result, e.g. hacking
$session->execute("set","some_var=$my_value") to run as an inline action?
Post by Liam Farr
Any help would be much appreciated, I've scoured the wiki, confluence
and git repo and come up empty.
Post by Liam Farr
--
Kind Regards
Liam Farr
_________________________________________________________________________
http://www.freeswitchsolutions.com
Official FreeSWITCH Sites
http://www.freeswitch.org
http://confluence.freeswitch.org
http://www.cluecon.com
FreeSWITCH-users mailing list
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
Michael Jerris
2014-12-10 18:01:55 UTC
Permalink
That perl script will not run at all until the dialplan parsing is complete. You would need to run the perl script inline (which I am not sure we allow) or run the perl script, then transfer to re-enter the dialplan after it is run.
Post by Liam Farr
Heres an expanded example;
Extension runs the perl script as part of the public dialplan first;
<extension name="run-script" continue="true">
<condition>
<action application="perl" data="/etc/freeswitch/scripts/my-script.pl <http://my-script.pl/>"/>
</condition>
</extension>
Script sets some variables;
$my_value = "123";
$session->setVariable('some_var',$my_value);
Use that variable later in another extension in the public dialplan as a condition selector;
<extension name="bridge-call" >
<condition field="context" expression="public" />
<condition field="${some_var}" expression="123" >
<action application="set" data="call_direction=inbound"/>
</condition>
</extension>
However this will fail, because the perl script "$session->setVariable" run earlier is not inline, so you cant make use of it in the condition (<condition field="${some_var}" expression="123" >) in the second extension that exists in a later part of the public dialplan. Hence I need a way to set inline variables from my perl script.
Cheers
Liam Farr
If you are in a perl script using session->setVariable, how are you still in the dialplan? This doesn't make sense to me. There should be no need for an inline if you are already in the script.
Post by Liam Farr
Hi,
I need to set a variable using a perl script inline.
Normally I would use $session->setVariable('some_var',$my_value);
However I cant find any options to execute this inline / as an inline action. (I need to evaluate the variable later in the hunting phase of the dialplan hence need it to be an inline action).
Is there a way to do this?
Or is there another way to achieve the same result, e.g. hacking $session->execute("set","some_var=$my_value") to run as an inline action?
Any help would be much appreciated, I've scoured the wiki, confluence and git repo and come up empty.
--
Kind Regards
Liam Farr
Stanislav Sinyagin
2014-12-11 00:47:10 UTC
Permalink
I'm using mod_perl quite intensively, and I do all the logic and
bridging from within the Perl script. It works fine, and you don't
really need to return the control back to the dialplan.

The only concern is, that if you do "bridge" from the script, your
perl script stays in memory and finishes only when the call ends. It
should be harmless for a modestly loaded server, and for a massive
service you would anyway do much better with an external script
talking via ESL.
Post by Liam Farr
Heres an expanded example;
Extension runs the perl script as part of the public dialplan first;
<extension name="run-script" continue="true">
<condition>
<action application="perl" data="/etc/freeswitch/scripts/my-script.pl"/>
</condition>
</extension>
Script sets some variables;
$my_value = "123";
$session->setVariable('some_var',$my_value);
Use that variable later in another extension in the public dialplan as a
condition selector;
<extension name="bridge-call" >
<condition field="context" expression="public" />
<condition field="${some_var}" expression="123" >
<action application="set" data="call_direction=inbound"/>
<action application="bridge"
</condition>
</extension>
However this will fail, because the perl script "$session->setVariable" run
earlier is not inline, so you cant make use of it in the condition
(<condition field="${some_var}" expression="123" >) in the second extension
that exists in a later part of the public dialplan. Hence I need a way to
set inline variables from my perl script.
Cheers
Liam Farr
Post by Michael Jerris
If you are in a perl script using session->setVariable, how are you still
in the dialplan? This doesn't make sense to me. There should be no need
for an inline if you are already in the script.
Post by Liam Farr
Hi,
I need to set a variable using a perl script inline.
Normally I would use $session->setVariable('some_var',$my_value);
However I cant find any options to execute this inline / as an inline
action. (I need to evaluate the variable later in the hunting phase of the
dialplan hence need it to be an inline action).
Is there a way to do this?
Or is there another way to achieve the same result, e.g. hacking
$session->execute("set","some_var=$my_value") to run as an inline action?
Any help would be much appreciated, I've scoured the wiki, confluence
and git repo and come up empty.
--
Kind Regards
Liam Farr
_________________________________________________________________________
http://www.freeswitchsolutions.com
Official FreeSWITCH Sites
http://www.freeswitch.org
http://confluence.freeswitch.org
http://www.cluecon.com
FreeSWITCH-users mailing list
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
_________________________________________________________________________
http://www.freeswitchsolutions.com
Official FreeSWITCH Sites
http://www.freeswitch.org
http://confluence.freeswitch.org
http://www.cluecon.com
FreeSWITCH-users mailing list
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
***@freeswitch.org
http://www.freeswitchsolutions.com

Official FreeSWITCH Sites
http://www.freeswitch.org
http://confluence.freeswitch.org
http://www.cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-***@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
Michael Jerris
2014-12-11 01:27:57 UTC
Permalink
The issue here is he is expecting the value to be set later in the dialplan. That won't work as he's doing. Another option for both of you is to handle the logic in perl, then set vars from perl for what to bridge to, then have a bridge line in the dp fter perl that uses those vars (not a condition).
Post by Stanislav Sinyagin
I'm using mod_perl quite intensively, and I do all the logic and
bridging from within the Perl script. It works fine, and you don't
really need to return the control back to the dialplan.
The only concern is, that if you do "bridge" from the script, your
perl script stays in memory and finishes only when the call ends. It
should be harmless for a modestly loaded server, and for a massive
service you would anyway do much better with an external script
talking via ESL.
Post by Liam Farr
Heres an expanded example;
Extension runs the perl script as part of the public dialplan first;
<extension name="run-script" continue="true">
<condition>
<action application="perl" data="/etc/freeswitch/scripts/my-script.pl"/>
</condition>
</extension>
Script sets some variables;
$my_value = "123";
$session->setVariable('some_var',$my_value);
Use that variable later in another extension in the public dialplan as a
condition selector;
<extension name="bridge-call" >
<condition field="context" expression="public" />
<condition field="${some_var}" expression="123" >
<action application="set" data="call_direction=inbound"/>
<action application="bridge"
</condition>
</extension>
However this will fail, because the perl script "$session->setVariable" run
earlier is not inline, so you cant make use of it in the condition
(<condition field="${some_var}" expression="123" >) in the second extension
that exists in a later part of the public dialplan. Hence I need a way to
set inline variables from my perl script.
Cheers
Liam Farr
Post by Michael Jerris
If you are in a perl script using session->setVariable, how are you still
in the dialplan? This doesn't make sense to me. There should be no need
for an inline if you are already in the script.
Post by Liam Farr
Hi,
I need to set a variable using a perl script inline.
Normally I would use $session->setVariable('some_var',$my_value);
However I cant find any options to execute this inline / as an inline
action. (I need to evaluate the variable later in the hunting phase of the
dialplan hence need it to be an inline action).
Is there a way to do this?
Or is there another way to achieve the same result, e.g. hacking
$session->execute("set","some_var=$my_value") to run as an inline action?
Any help would be much appreciated, I've scoured the wiki, confluence
and git repo and come up empty.
--
Kind Regards
Liam Farr
_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
***@freeswitch.org
http://www.freeswitchsolutions.com

Official FreeSWITCH Sites
http://www.freeswitch.org
http://confluence.freeswitch.org
http://www.cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-***@lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org

Loading...