Problem Verifying an existing file with lua
Hi all, I like to export a vatiable to my dialplan. The variable file_name_ok should give back the value true if the file exists My fialplan: <action application="lua" data="file.lua ${call_screen_filename}"/> <action application="log" data="the value: ${file_name_ok}"/> My problem: i can.t export the variable from the luascript my scipt: -- function used to check for the existence of a file function file_exists(fname) local f = io.open(fname, "r") if (f and f:read()) then return true end end if ( session:ready() ) then session:answer( ); datei = session:getVariable("file_name_ok"); if (file_exists(datei..extension..".wav")) then session:setVariable("file_name_ok", "true"); else session:setVariable("file_name_ok", "true"); end end can your help me please? --------------- 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
Hey, What I understand you are trying to do is get a variable name from FS and check from LUA if the file exists ! file_name_ok is just a flag to return true or false depending upon existence of caal_screen_filename..if this is the case then datei = session:getVariable("file_**name_ok"); --You are getting the variable containing filename here. shouldn't it be ? datei = session:getVariable("call_screen_filename"); also, if (file_exists(datei..extension.**.".wav")) then
session:setVariable("file_**name_ok", "true"); else session:setVariable("file_**name_ok", "true"); end
returns true in any case file exists or not. Please see if this is right ! -- Regards, Sammy On Sun, Nov 6, 2011 at 4:55 PM, Thomas Hoellriegel <admin@blindi.net> wrote:
Hi all, I like to export a vatiable to my dialplan. The variable file_name_ok should give back the value true if the file exists My fialplan: <action application="lua" data="file.lua ${call_screen_filename}"/> <action application="log" data="the value: ${file_name_ok}"/>
My problem: i can.t export the variable from the luascript
my scipt: -- function used to check for the existence of a file function file_exists(fname) local f = io.open(fname, "r") if (f and f:read()) then return true end end if ( session:ready() ) then session:answer( );
datei = session:getVariable("file_**name_ok"); if (file_exists(datei..extension.**.".wav")) then session:setVariable("file_**name_ok", "true"); else session:setVariable("file_**name_ok", "true"); end end
can your help me please?
--------------- 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<http://www.blindi.net/mailman/listinfo/blinde-misc>
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
Hi Sammy, I become no output true or false. My Script is now: function file_exists(fname) local f = io.open(fname, "r") if (f and f:read()) then return true end end if ( session:ready() ) then session:answer( ); datei = session:getVariable("call_screen_filename"); if (file_exists(datei..extension.**.".wav")) then session:setVariable("fileex", "true"); session:setVariable(fileex, true) returns true; else session:setVariable("fileex", "false"); returns false; end end The variable fileex is emty. The variable: call_screen_filename will not be changed after to execute these script. I like to setup a callscreening. if the name exists, transfer to the given extension. If the name don.t exists, start the recording and transwer the call. Thanks. --------------- 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
Thomas, I suspect there is a problem elsewhere in your dialplan. Can you pastebin the whole extension and also a debug log of a call flowing through this extension? I have a feeling that will help us figure out what is going on. Please use pastebin.freeswitch.org and "FreeSWITCH Log" for syntax highlighting. -MC On Sun, Nov 6, 2011 at 3:51 PM, Thomas Hoellriegel <admin@blindi.net> wrote:
Hi Sammy, I become no output true or false. My Script is now:
function file_exists(fname) local f = io.open(fname, "r") if (f and f:read()) then return true end end if ( session:ready() ) then session:answer( ); datei = session:getVariable("call_**screen_filename"); if (file_exists(datei..extension.****.".wav")) then session:setVariable("fileex", "true"); session:setVariable(fileex, true) returns true; else session:setVariable("fileex", "false"); returns false; end end
The variable fileex is emty. The variable: call_screen_filename will not be changed after to execute these script.
I like to setup a callscreening. if the name exists, transfer to the given extension. If the name don.t exists, start the recording and transwer the call.
Thanks.
--------------- 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<http://www.blindi.net/mailman/listinfo/blinde-misc>
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
participants (3)
-
Michael Collins
-
Sammy Govind
-
Thomas Hoellriegel