Use logger class.
This commit is contained in:
@@ -38,6 +38,9 @@
|
|||||||
require "resources.functions.database_handle";
|
require "resources.functions.database_handle";
|
||||||
dbh = database_handle('system');
|
dbh = database_handle('system');
|
||||||
|
|
||||||
|
--get logger
|
||||||
|
local log = require "resources.functions.log".ivr_menu
|
||||||
|
|
||||||
--include functions
|
--include functions
|
||||||
require "resources.functions.format_ringback"
|
require "resources.functions.format_ringback"
|
||||||
require "resources.functions.split"
|
require "resources.functions.split"
|
||||||
@@ -50,6 +53,8 @@
|
|||||||
caller_id_number = session:getVariable("caller_id_number");
|
caller_id_number = session:getVariable("caller_id_number");
|
||||||
domain_uuid = session:getVariable("domain_uuid");
|
domain_uuid = session:getVariable("domain_uuid");
|
||||||
|
|
||||||
|
local recordings_dir = recordings_dir .. "/" .. domain_name
|
||||||
|
|
||||||
--settings
|
--settings
|
||||||
require "resources.functions.settings";
|
require "resources.functions.settings";
|
||||||
settings = settings(domain_uuid);
|
settings = settings(domain_uuid);
|
||||||
@@ -94,9 +99,9 @@
|
|||||||
WHERE ivr_menu_uuid = ']] .. ivr_menu_uuid ..[['
|
WHERE ivr_menu_uuid = ']] .. ivr_menu_uuid ..[['
|
||||||
AND ivr_menu_enabled = 'true' ]];
|
AND ivr_menu_enabled = 'true' ]];
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
|
log.notice("SQL: " .. sql);
|
||||||
end
|
end
|
||||||
status = dbh:query(sql, function(row)
|
dbh:query(sql, function(row)
|
||||||
domain_uuid = row["domain_uuid"];
|
domain_uuid = row["domain_uuid"];
|
||||||
ivr_menu_name = row["ivr_menu_name"];
|
ivr_menu_name = row["ivr_menu_name"];
|
||||||
--ivr_menu_extension = row["ivr_menu_extension"];
|
--ivr_menu_extension = row["ivr_menu_extension"];
|
||||||
@@ -123,12 +128,10 @@
|
|||||||
end);
|
end);
|
||||||
|
|
||||||
--set the caller id name
|
--set the caller id name
|
||||||
if (caller_id_name) then
|
if caller_id_name and #caller_id_name >0 then
|
||||||
if (string.len(ivr_menu_cid_prefix) > 0) then
|
caller_id_name = ivr_menu_cid_prefix .. "#" .. caller_id_name;
|
||||||
caller_id_name = ivr_menu_cid_prefix .. "#" .. caller_id_name;
|
session:setVariable("caller_id_name", caller_id_name);
|
||||||
session:setVariable("caller_id_name", caller_id_name);
|
session:setVariable("effective_caller_id_name", caller_id_name);
|
||||||
session:setVariable("effective_caller_id_name", caller_id_name);
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--set ringback
|
--set ringback
|
||||||
@@ -167,11 +170,11 @@
|
|||||||
require "resources.functions.mkdir";
|
require "resources.functions.mkdir";
|
||||||
|
|
||||||
--make sure the recordings directory exists
|
--make sure the recordings directory exists
|
||||||
mkdir(recordings_dir.."/"..domain_name);
|
mkdir(recordings_dir);
|
||||||
|
|
||||||
--define function to load file from db
|
--define function to load file from db
|
||||||
local function load_file(recordings_dir, domain_name, file_name)
|
local function load_file(file_name)
|
||||||
local full_path = recordings_dir.."/"..domain_name .. "/" .. file_name
|
local full_path = recordings_dir .. "/" .. file_name
|
||||||
if file_exists(full_path) then
|
if file_exists(full_path) then
|
||||||
return full_path
|
return full_path
|
||||||
end
|
end
|
||||||
@@ -180,7 +183,7 @@
|
|||||||
[['AND recording_filename = ']]..file_name..[[' ]];
|
[['AND recording_filename = ']]..file_name..[[' ]];
|
||||||
|
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
|
log.notice("SQL: "..sql);
|
||||||
end
|
end
|
||||||
|
|
||||||
local is_base64
|
local is_base64
|
||||||
@@ -188,7 +191,8 @@
|
|||||||
if #row.recording_base64 > 32 then
|
if #row.recording_base64 > 32 then
|
||||||
local file, err = io.open(full_path, "w");
|
local file, err = io.open(full_path, "w");
|
||||||
if not file then
|
if not file then
|
||||||
freeswitch.consoleLog("err", "[ivr_menu] can not create file: "..full_path.."; Error - " .. tostring(err) .. "\n");
|
log.err("can not create file: "..full_path.."; Error - " .. tostring(err));
|
||||||
|
return
|
||||||
end
|
end
|
||||||
file:write(base64.decode(row.recording_base64));
|
file:write(base64.decode(row.recording_base64));
|
||||||
file:close();
|
file:close();
|
||||||
@@ -202,22 +206,22 @@
|
|||||||
|
|
||||||
--greet long
|
--greet long
|
||||||
if #ivr_menu_greet_long > 1 then
|
if #ivr_menu_greet_long > 1 then
|
||||||
ivr_menu_greet_long, ivr_menu_greet_long_is_base64 = load_file(recordings_dir, domain_name, greet_long_file_name)
|
ivr_menu_greet_long, ivr_menu_greet_long_is_base64 = load_file(greet_long_file_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
--greet short
|
--greet short
|
||||||
if #ivr_menu_greet_short > 1 then
|
if #ivr_menu_greet_short > 1 then
|
||||||
ivr_menu_greet_short, ivr_menu_greet_short_is_base64 = load_file(recordings_dir, domain_name, greet_short_file_name)
|
ivr_menu_greet_short, ivr_menu_greet_short_is_base64 = load_file(greet_short_file_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
--invalid sound
|
--invalid sound
|
||||||
if #ivr_menu_invalid_sound > 1 then
|
if #ivr_menu_invalid_sound > 1 then
|
||||||
ivr_menu_invalid_sound, ivr_menu_invalid_sound_is_base64 = load_file(recordings_dir, domain_name, invalid_sound_file_name)
|
ivr_menu_invalid_sound, ivr_menu_invalid_sound_is_base64 = load_file(invalid_sound_file_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
--exit sound
|
--exit sound
|
||||||
if #ivr_menu_exit_sound > 1 then
|
if #ivr_menu_exit_sound > 1 then
|
||||||
ivr_menu_exit_sound, ivr_menu_exit_sound_is_base64 = load_file(recordings_dir, domain_name, exit_sound_file_name)
|
ivr_menu_exit_sound, ivr_menu_exit_sound_is_base64 = load_file(exit_sound_file_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif (storage_type == "http_cache") then
|
elseif (storage_type == "http_cache") then
|
||||||
@@ -231,7 +235,7 @@
|
|||||||
--adjust file paths
|
--adjust file paths
|
||||||
local function adjust_file_path(full_path, file_name)
|
local function adjust_file_path(full_path, file_name)
|
||||||
return file_exists(full_path)
|
return file_exists(full_path)
|
||||||
or file_exists(recordings_dir.."/"..domain_name.."/"..file_name)
|
or file_exists(recordings_dir.."/"..file_name)
|
||||||
or file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name)
|
or file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name)
|
||||||
or full_path
|
or full_path
|
||||||
end
|
end
|
||||||
@@ -267,7 +271,7 @@
|
|||||||
end
|
end
|
||||||
|
|
||||||
if (debug["tries"]) then
|
if (debug["tries"]) then
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] greet " .. sound_type .. ": " .. sound .. "\n");
|
log.notice("greet " .. sound_type .. ": " .. sound);
|
||||||
end
|
end
|
||||||
|
|
||||||
-- read dtmf
|
-- read dtmf
|
||||||
@@ -281,7 +285,7 @@
|
|||||||
-- proceed dtmf
|
-- proceed dtmf
|
||||||
if dtmf_digits and #dtmf_digits > 0 then
|
if dtmf_digits and #dtmf_digits > 0 then
|
||||||
if (debug["tries"]) then
|
if (debug["tries"]) then
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] dtmf_digits: " .. dtmf_digits .. "\n");
|
log.notice("dtmf_digits: " .. dtmf_digits);
|
||||||
end
|
end
|
||||||
return menu_options(session, dtmf_digits);
|
return menu_options(session, dtmf_digits);
|
||||||
end
|
end
|
||||||
@@ -290,7 +294,7 @@
|
|||||||
if tries < tonumber(ivr_menu_max_failures) then
|
if tries < tonumber(ivr_menu_max_failures) then
|
||||||
--log the dtmf digits
|
--log the dtmf digits
|
||||||
if (debug["tries"]) then
|
if (debug["tries"]) then
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] tries: " .. tries .. "\n");
|
log.notice("tries: " .. tries);
|
||||||
end
|
end
|
||||||
--run the menu again
|
--run the menu again
|
||||||
return menu();
|
return menu();
|
||||||
@@ -301,13 +305,13 @@
|
|||||||
|
|
||||||
--log the dtmf digits
|
--log the dtmf digits
|
||||||
if (debug["dtmf"]) then
|
if (debug["dtmf"]) then
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] dtmf: " .. digits .. "\n");
|
log.notice("dtmf: " .. digits);
|
||||||
end
|
end
|
||||||
|
|
||||||
--get the ivr menu options
|
--get the ivr menu options
|
||||||
sql = [[SELECT * FROM v_ivr_menu_options WHERE ivr_menu_uuid = ']] .. ivr_menu_uuid ..[[' ORDER BY ivr_menu_option_order asc ]];
|
sql = [[SELECT * FROM v_ivr_menu_options WHERE ivr_menu_uuid = ']] .. ivr_menu_uuid ..[[' ORDER BY ivr_menu_option_order asc ]];
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
|
log.notice("SQL: " .. sql);
|
||||||
end
|
end
|
||||||
|
|
||||||
local action, script, data
|
local action, script, data
|
||||||
@@ -336,8 +340,8 @@
|
|||||||
regex = "m:~"..digits.."~"..row.ivr_menu_option_digits.."~$1"
|
regex = "m:~"..digits.."~"..row.ivr_menu_option_digits.."~$1"
|
||||||
local result = trim(api:execute("regex", regex));
|
local result = trim(api:execute("regex", regex));
|
||||||
if (debug["regex"]) then
|
if (debug["regex"]) then
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] regex "..regex.."\n");
|
log.notice("regex "..regex);
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] result: "..result.."\n");
|
log.notice("result: "..result);
|
||||||
end
|
end
|
||||||
|
|
||||||
--replace the $1 and the domain name
|
--replace the $1 and the domain name
|
||||||
@@ -361,14 +365,14 @@
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- we have unsupported IVR action
|
-- we have unsupported IVR action
|
||||||
freeswitch.consoleLog("warning", "[ivr_menu] invalid action in ivr: " .. row.ivr_menu_option_action .. "\n");
|
log.warning("invalid action in ivr: " .. row.ivr_menu_option_action);
|
||||||
end); --end results
|
end); --end results
|
||||||
|
|
||||||
--execute
|
--execute
|
||||||
if action and #action > 0 then
|
if action and #action > 0 then
|
||||||
-- send to the log
|
-- send to the log
|
||||||
if (debug["action"]) then
|
if (debug["action"]) then
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] action: " .. action .. " data: ".. data .. "\n");
|
log.notice("action: " .. action .. " data: ".. data);
|
||||||
end
|
end
|
||||||
|
|
||||||
-- run the action (with return to menu)
|
-- run the action (with return to menu)
|
||||||
@@ -392,10 +396,10 @@
|
|||||||
-- check to see if the user extension exists
|
-- check to see if the user extension exists
|
||||||
local cmd = "user_exists id ".. digits .." "..domain_name;
|
local cmd = "user_exists id ".. digits .." "..domain_name;
|
||||||
local result = api:executeString(cmd);
|
local result = api:executeString(cmd);
|
||||||
freeswitch.consoleLog("NOTICE", "[ivr_menu][direct dial] "..cmd.." "..result.."\n");
|
log.notice("[direct dial] "..cmd.." "..result);
|
||||||
if result == "true" then
|
if result == "true" then
|
||||||
--log the action
|
--log the action
|
||||||
freeswitch.consoleLog("NOTICE", "[ivr_menu][direct dial] "..digits.." XML "..context.."\n");
|
log.notice("[direct dial] "..digits.." XML "..context);
|
||||||
--run the action
|
--run the action
|
||||||
return session:execute("transfer", digits.." XML "..context);
|
return session:execute("transfer", digits.." XML "..context);
|
||||||
end
|
end
|
||||||
@@ -406,7 +410,7 @@
|
|||||||
|
|
||||||
--invalid input try again
|
--invalid input try again
|
||||||
if (debug["action"]) then
|
if (debug["action"]) then
|
||||||
freeswitch.consoleLog("notice", "[ivr_menu] unrecgnized action \n");
|
log.notice("unrecgnized action");
|
||||||
end
|
end
|
||||||
if ivr_menu_invalid_sound and #ivr_menu_invalid_sound then
|
if ivr_menu_invalid_sound and #ivr_menu_invalid_sound then
|
||||||
session:streamFile(ivr_menu_invalid_sound);
|
session:streamFile(ivr_menu_invalid_sound);
|
||||||
|
|||||||
Reference in New Issue
Block a user