[Freeswitch-users] lua error in session:transfer

Adam Kelloway adam.kelloway at newpace.ca
Tue Dec 6 16:03:05 MSK 2011


Just a hunch, but I would guess command line input is being treated as 
ints. Note that, in lua, 1 == 1 evaluates to true, while "1" == 1 
evaluates to false. I believe session:read returns a string.

http://www.lua.org/manual/5.1/manual.html#2.5.2

Also, the last two elseif statements could also potentially set 
target_number to nil, as you are only passing the script 4 arguments. 
Likewise for the empty else at the end.

Your transfer will work once this is fixed, assuming your have an 
extension called "target_number". Something tells me you actually want 
the extension number you are setting the variable to though, so you 
might want to remove the quotes around target_number when calling transfer.

Add some print statements in you if/elseif clauses to see which one 
resolve to true.

Hope those ideas help,

Adam

On 3:59 PM, Thomas Hoellriegel wrote:
> Hi all,
> i have a luascript. I hear the prompt, but the transfer fails.
> My script is:
>
> session:answer();
> freeswitch.console_log("info", "Announce\n");
> announce='/usr/local/freeswitch/sounds/callscreen/callscrrenopts.wav';
> number = session:read(1, 1, announce, 5000, "#");
> freeswitch.consoleLog("info", "Got number: ".. number .. "\n");
> if number == argv[1] then
>    target_number=argv[2];
> elseif number == argv[3] then
>    target_number=argv[4];
> elseif number == argv[5] then
>    target_number=argv[6];
> elseif number == argv[7] then
>    target_number=argv[8];
> else
> end
> freeswitch.consoleLog("info", "Transfer to target number: ".. 
> target_number .. " XML default\n");
> session:transfer("target_number", "XML", "default");
>
> in my dialplan reads:
> <action application="set" data="group_confirm_file=lua thomas.lua 1 
> 7676 2   4000"/>
>
> Then i press 1 for example, i become on the cli:
> [ERR] mod_lua.cpp:196 /usr/local/freeswitch/scripts/thomas.lua:16:
> attempt to concatenate global 'target_number' (a nil value)M
>
> What is wrong please?
> Thanks for your help.
>
> ---------------
> Du kannst mich jederzeit kostenlos per Festnetz erreichen unter:
> http://www.blindi.net/callback
> homepage: http://www.blindi.net
> blinde-misc mailingliste für blinde. anmeldung unter:
> http://www.blindi.net/mailman/listinfo/blinde-misc 



Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list