2015-01-04 10:29:02 +01:00
|
|
|
--get the argv values
|
|
|
|
|
script_name = argv[0];
|
|
|
|
|
file_name = argv[1];
|
|
|
|
|
|
2015-04-24 04:47:10 +02:00
|
|
|
--include config.lua
|
2015-08-10 19:50:29 +02:00
|
|
|
scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1));
|
|
|
|
|
dofile(scripts_dir.."/resources/functions/config.lua");
|
|
|
|
|
dofile(config());
|
2015-04-24 04:47:10 +02:00
|
|
|
|
|
|
|
|
--connect to the database
|
2015-08-10 19:50:29 +02:00
|
|
|
dofile(scripts_dir.."/resources/functions/database_handle.lua");
|
2015-04-24 04:47:10 +02:00
|
|
|
dbh = database_handle('system');
|
|
|
|
|
|
|
|
|
|
--get the variables
|
|
|
|
|
domain_name = session:getVariable("domain_name");
|
|
|
|
|
domain_uuid = session:getVariable("domain_uuid");
|
|
|
|
|
|
|
|
|
|
--get the sounds dir, language, dialect and voice
|
|
|
|
|
sounds_dir = session:getVariable("sounds_dir");
|
|
|
|
|
default_language = session:getVariable("default_language");
|
|
|
|
|
default_dialect = session:getVariable("default_dialect");
|
|
|
|
|
default_voice = session:getVariable("default_voice");
|
|
|
|
|
if (not default_language) then default_language = 'en'; end
|
|
|
|
|
if (not default_dialect) then default_dialect = 'us'; end
|
|
|
|
|
if (not default_voice) then default_voice = 'callie'; end
|
|
|
|
|
|
|
|
|
|
--settings
|
2015-08-10 19:50:29 +02:00
|
|
|
dofile(scripts_dir.."/resources/functions/settings.lua");
|
2015-04-24 04:47:10 +02:00
|
|
|
settings = settings(domain_uuid);
|
|
|
|
|
storage_type = "";
|
|
|
|
|
storage_path = "";
|
|
|
|
|
if (settings['recordings'] ~= nil) then
|
|
|
|
|
if (settings['recordings']['storage_type'] ~= nil) then
|
|
|
|
|
if (settings['recordings']['storage_type']['text'] ~= nil) then
|
|
|
|
|
storage_type = settings['recordings']['storage_type']['text'];
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if (settings['recordings']['storage_path'] ~= nil) then
|
|
|
|
|
if (settings['recordings']['storage_path']['text'] ~= nil) then
|
|
|
|
|
storage_path = settings['recordings']['storage_path']['text'];
|
|
|
|
|
storage_path = storage_path:gsub("${domain_name}", domain_name);
|
|
|
|
|
storage_path = storage_path:gsub("${voicemail_id}", voicemail_id);
|
|
|
|
|
storage_path = storage_path:gsub("${voicemail_dir}", voicemail_dir);
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-08-07 10:11:27 +02:00
|
|
|
|
|
|
|
|
if (not temp_dir) or (#temp_dir == 0) then
|
|
|
|
|
if (settings['server'] ~= nil) then
|
|
|
|
|
if (settings['server']['temp'] ~= nil) then
|
|
|
|
|
if (settings['server']['temp']['dir'] ~= nil) then
|
|
|
|
|
temp_dir = settings['server']['temp']['dir'];
|
|
|
|
|
end
|
2015-04-24 04:47:10 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--set the recordings directory
|
|
|
|
|
if (domain_count > 1) then
|
|
|
|
|
recordings_dir = recordings_dir .. "/"..domain_name;
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--check if a file exists
|
2015-08-10 19:50:29 +02:00
|
|
|
function file_exists(name)
|
|
|
|
|
local f=io.open(name,"r")
|
|
|
|
|
if f~=nil then io.close(f) return true else return false end
|
|
|
|
|
end
|
2015-04-24 04:47:10 +02:00
|
|
|
|
2015-01-04 10:29:02 +01:00
|
|
|
--define the on_dtmf call back function
|
|
|
|
|
function on_dtmf(s, type, obj, arg)
|
|
|
|
|
if (type == "dtmf") then
|
2015-04-28 19:24:32 +02:00
|
|
|
session:setVariable("dtmf_digits", obj['digit']);
|
2015-01-04 10:29:02 +01:00
|
|
|
freeswitch.console_log("info", "[streamfile] dtmf digit: " .. obj['digit'] .. ", duration: " .. obj['duration'] .. "\n");
|
|
|
|
|
if (obj['digit'] == "*") then
|
2015-01-23 19:10:48 +01:00
|
|
|
return("false"); --return to previous
|
2015-01-04 10:29:02 +01:00
|
|
|
elseif (obj['digit'] == "0") then
|
|
|
|
|
return("restart"); --start over
|
|
|
|
|
elseif (obj['digit'] == "1") then
|
|
|
|
|
return("volume:-1"); --volume down
|
|
|
|
|
elseif (obj['digit'] == "3") then
|
|
|
|
|
return("volume:+1"); -- volume up
|
|
|
|
|
elseif (obj['digit'] == "4") then
|
|
|
|
|
return("seek:-5000"); -- back
|
|
|
|
|
elseif (obj['digit'] == "5") then
|
|
|
|
|
return("pause"); -- pause toggle
|
|
|
|
|
elseif (obj['digit'] == "6") then
|
|
|
|
|
return("seek:+5000"); -- forward
|
|
|
|
|
elseif (obj['digit'] == "7") then
|
|
|
|
|
return("speed:-1"); -- increase playback
|
|
|
|
|
elseif (obj['digit'] == "9") then
|
|
|
|
|
return("speed:+1"); -- decrease playback
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-04-24 04:47:10 +02:00
|
|
|
--parse file name
|
|
|
|
|
file_name_only = file_name:match("([^/]+)$");
|
|
|
|
|
|
|
|
|
|
--if base64, get from db, create temp file
|
|
|
|
|
if (storage_type == "base64") then
|
|
|
|
|
if (not file_exists(recordings_dir.."/"..file_name_only)) then
|
|
|
|
|
sql = [[SELECT * FROM v_recordings
|
|
|
|
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
|
|
|
|
AND recording_filename = ']].. file_name_only.. [[' ]];
|
|
|
|
|
if (debug["sql"]) then
|
|
|
|
|
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
|
|
|
|
|
end
|
|
|
|
|
status = dbh:query(sql, function(row)
|
|
|
|
|
--add functions
|
2015-08-10 19:50:29 +02:00
|
|
|
dofile(scripts_dir.."/resources/functions/base64.lua");
|
2015-04-24 04:47:10 +02:00
|
|
|
--add the path to filename
|
|
|
|
|
file_name = recordings_dir.."/"..file_name_only;
|
|
|
|
|
--save the recording to the file system
|
|
|
|
|
if (string.len(row["recording_base64"]) > 32) then
|
|
|
|
|
local file = io.open(file_name, "w");
|
|
|
|
|
file:write(base64.decode(row["recording_base64"]));
|
|
|
|
|
file:close();
|
|
|
|
|
end
|
|
|
|
|
end);
|
|
|
|
|
else
|
|
|
|
|
file_name = recordings_dir.."/"..file_name_only;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--adjust file path
|
|
|
|
|
if (not file_exists(file_name)) then
|
|
|
|
|
if (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name_only)) then
|
|
|
|
|
file_name = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name_only;
|
|
|
|
|
elseif (file_exists(recordings_dir.."/"..file_name_only)) then
|
|
|
|
|
file_name = recordings_dir.."/"..file_name_only;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--stream file if exists
|
2015-01-04 10:29:02 +01:00
|
|
|
if (session:ready()) then
|
2015-04-24 04:47:10 +02:00
|
|
|
session:answer();
|
2015-04-28 19:24:32 +02:00
|
|
|
slept = session:getVariable("slept");
|
|
|
|
|
if (slept == nil or slept == "false") then
|
2015-04-28 21:06:27 +02:00
|
|
|
freeswitch.consoleLog("notice", "[ivr_menu] sleeping (1s)\n");
|
2015-04-28 19:24:32 +02:00
|
|
|
session:sleep(1000);
|
|
|
|
|
if (slept == "false") then
|
|
|
|
|
session:setVariable("slept", "true");
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-01-04 10:29:02 +01:00
|
|
|
session:setInputCallback("on_dtmf", "");
|
|
|
|
|
session:streamFile(file_name);
|
|
|
|
|
end
|
2015-04-24 04:47:10 +02:00
|
|
|
|
|
|
|
|
--if base64, remove temp file (increases responsiveness when files remain local)
|
|
|
|
|
if (storage_type == "base64") then
|
|
|
|
|
if (file_exists(file_name)) then
|
|
|
|
|
--os.remove(file_name);
|
|
|
|
|
end
|
|
|
|
|
end
|