[Freeswitch-users] How do I originiate new session from within LUA script?

Peter Olsson peter.olsson at visionutveckling.se
Sun Mar 6 11:39:42 MSK 2011


It doesn't matter how you set the variables, getVariable() should always return then anyway, the "{var=val}" trick is just to make it possible to set vars when originating a new channel, since the actual channel will be created at the same time.

However, if you want to check variables on the originated leg, it would be something like this;

local s = freeswitch.Session();
s:originate(session, "{var1=val1,var2=val2}sofia/internal/1000 at x.x.x.x", 30);

-- Do whatever you want with this channel.

-- Get variables from the originated channel
local var1 = s:getVariable("whatever_variable");

That is, you must read the var from the correct object. In this case "s" is the new originated channel, and "session" is the channel that was created when dialing into the lua script.

PS! I've not written so much in Lua myself, so it's not really something I'm good at - but I guess it should be like this :)

/Peter
________________________________________
Från: freeswitch-users-bounces at lists.freeswitch.org [freeswitch-users-bounces at lists.freeswitch.org] för Dmitry Saratsky [simpot at simpot.com]
Skickat: den 6 mars 2011 02:03
Till: FreeSWITCH Users Help
Ämne: Re: [Freeswitch-users] How do I originiate new session from within LUA    script?

Hi Peter,

Thanks again for your help, this way works well for me.
I will update wiki, when I fix all puzzles of my script.

Now I have another problem... Sorry...

I actually hoped also to read session variables after my new originated sessions complete in same way, I set them.
However in way you have suggested me to set vars, I have no idea how to read those variables now...

I have tried to use the following after origination command:
   local fax_result_code = session:getVariable("fax_result_code"); local fax_result_text = session:getVariable("fax_result_text");
   freeswitch.consoleLog("info", "FAX - Error code: (" .. fax_result_code .. ") " .. fax_result_text .. "\n");

I got the following in console:
2011-03-06 02:54:23.311416 [ERR] mod_lua.cpp:182 /usr/local/freeswitch/scripts/faxoutservice.lua:53: attempt to concatenate global 'fax_success' (a nil value)
stack traceback:
        /usr/local/freeswitch/scripts/faxoutservice.lua:53: in function 'send_fax'
        /usr/local/freeswitch/scripts/faxoutservice.lua:74: in main chunk

According to docs (http://wiki.freeswitch.org/wiki/Mod_spandsp), those vars should be set on hangup both for tx and rx faxes...
Anyway, I have lua script I have wrote for receiving faxes - I can read those variables successfully in the way I wrote above.

So, any ideas how can I read session (that I start in that way - origination) variables after session hangup?

Thanks again,
Dmitry.

-----Original Message-----
From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Peter Olsson
Sent: 06 Mar 2011 00:29
To: FreeSWITCH Users Help
Subject: Re: [Freeswitch-users] How do I originiate new session from within LUA script?

10 is the origination timeout in seconds. This part is missing in the documentation right now, so I can't really tell you where to look - except in the source :)

To set variables you should be able to do it as you do in the dialplan, changing the dial string to something like "{var1=value,var2=value}sofia/internal/test at test.com". By the way - for originate variables origination_caller_id_xxxx must be used.

If you're successful with these commands, I would really appreciate if this could be updated in the Wiki as well.

/Peter

________________________________________
Från: freeswitch-users-bounces at lists.freeswitch.org [freeswitch-users-bounces at lists.freeswitch.org] för Dmitry Saratsky [simpot at simpot.com]
Skickat: den 5 mars 2011 22:51
Till: FreeSWITCH Users Help
Ämne: Re: [Freeswitch-users] How do I originiate new session from within LUA    script?

Hi Peter,

Thanks for your replay.
It works in this way, thanks.

Can you please also explain (or point me to right documentation) what does mean "10" as 3rd variable in your example?
Also I'm looking the way to set session variables before origination and I also failed with this...

For example I have tried this (the call itself was succeeded, but caller_id was not passed):
   s = freeswitch.Session();
   s:setVariable("effective_caller_id_number", "999");
   s:setVariable("effective_caller_id_name", "999");
   s:originate(session, "sofia/gateway/mygw/1000", 10);

and I got the following in console:

2011-03-05 23:43:05.754621 [ERR] switch_cpp.cpp:634 session is not initalized
2011-03-05 23:43:05.754621 [ERR] switch_cpp.cpp:634 session is not initialized

Thanks,
Dmitry.


-----Original Message-----
From: freeswitch-users-bounces at lists.freeswitch.org [mailto:freeswitch-users-bounces at lists.freeswitch.org] On Behalf Of Peter Olsson
Sent: 05 Mar 2011 22:48
To: FreeSWITCH Users Help
Subject: Re: [Freeswitch-users] How do I originiate new session from within LUA script?

This should work, last parameter is the originate timeout in seconds.

s = freeswitch.Session();
s:originate(session, "sofia/internal/1000 at 192.168.1.1", 10);

/Peter
________________________________________
Från: freeswitch-users-bounces at lists.freeswitch.org [freeswitch-users-bounces at lists.freeswitch.org] för Dmitry Saratsky [simpot at simpot.com]
Skickat: den 5 mars 2011 20:53
Till: freeswitch-users at lists.freeswitch.org
Ämne: [Freeswitch-users] How do I originiate new session from within LUA        script?

Hello all,

According to wiki:
http://wiki.freeswitch.org/wiki/Mod_lua#session:originate

I can use: "session:originate" command in LUA script to originate new session, but I can't understand how should I do it and can't find any example how I use this command.

Can you help, guys?

Thanks,
Dmitry.


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

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




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

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

!DSPAM:4d72dea332761110315127!




More information about the FreeSWITCH-users mailing list