Update the failure handler to work with the new call forward no answer feature. Optimize it using the variables instead of the database. Change the indentation.

This commit is contained in:
Mark Crane
2014-12-03 11:57:34 +00:00
parent 4f4237bb7e
commit 0dbe87a1cc
@@ -32,9 +32,10 @@
dofile(scripts_dir .. "/resources/functions/explode.lua"); dofile(scripts_dir .. "/resources/functions/explode.lua");
--handle originate_disposition --handle originate_disposition
if (session ~= nil and if (session ~= nil and session:ready()) then
session:ready()) then context = session:getVariable("context");
domain_name = session:getVariable("domain_name");
uuid = session:getVariable("uuid");
originate_disposition = session:getVariable("originate_disposition"); originate_disposition = session:getVariable("originate_disposition");
originate_causes = session:getVariable("originate_causes"); originate_causes = session:getVariable("originate_causes");
hangup_on_subscriber_absent = session:getVariable("hangup_on_subscriber_absent"); hangup_on_subscriber_absent = session:getVariable("hangup_on_subscriber_absent");
@@ -58,106 +59,73 @@
if (originate_disposition ~= nil) then if (originate_disposition ~= nil) then
if (originate_disposition == 'USER_BUSY') then if (originate_disposition == 'USER_BUSY') then
--handle USER_BUSY --handle USER_BUSY
dialed_extension = session:getVariable("dialed_extension");
dialed_extension = session:getVariable("dialed_extension"); last_busy_dialed_extension = session:getVariable("last_busy_dialed_extension");
context = session:getVariable("context"); if (debug["info"] ) then
domain_name = session:getVariable("domain_name"); freeswitch.consoleLog("INFO", "[failure_handler] last_busy_dialed_extension: " .. tostring(last_busy_dialed_extension) .. "\n");
uuid = session:getVariable("uuid");
last_busy_dialed_extension = session:getVariable("last_busy_dialed_extension");
if (debug["info"] ) then
freeswitch.consoleLog("INFO", "[failure_handler] last_busy_dialed_extension: " .. tostring(last_busy_dialed_extension) .. "\n");
end
--connect to the database
dofile(scripts_dir .. "/resources/functions/database_handle.lua");
dbh = database_handle('system');
--get the domain_uuid
domain_uuid = session:getVariable("domain_uuid");
if (domain_uuid == nil) then
--get the domain_uuid using the domain name required for multi-tenant
if (domain_name ~= nil) then
sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = '" .. domain_name .. "' ";
if (debug["sql"]) then
freeswitch.consoleLog("INFO", "[failure_handler] SQL: " .. sql .. "\n");
end
dbh:query(sql, function(rows)
domain_uuid = rows["domain_uuid"];
end);
end
end
domain_uuid = string.lower(domain_uuid);
if (dialed_extension ~= nil and
dialed_extension ~= last_busy_dialed_extension) then
--get the information from the database
sql = [[SELECT * FROM v_extensions
WHERE domain_uuid = ']] .. domain_uuid .. [['
AND extension = ']] .. dialed_extension .. [['
AND forward_busy_enabled = 'true' ]];
if (debug["sql"]) then
freeswitch.consoleLog("INFO", "[failure_handler] SQL: " .. sql .. "\n");
end end
dbh:query(sql, function(row) --transfer to the forward busy destination
forward_busy_destination = string.lower(row["forward_busy_destination"]); if (dialed_extension ~= nil and dialed_extension ~= last_busy_dialed_extension) then
forward_busy_enabled = session:getVariable("forward_busy_enabled");
if (forward_busy_destination ~= nil and if (forward_busy_enabled == "true") then
string.len(forward_busy_destination) > 0 ) then forward_busy_destination = string.lower(row["forward_busy_destination"]);
if (forward_busy_destination ~= nil and string.len(forward_busy_destination) > 0) then
--handle USER_BUSY - forwarding to number --handle USER_BUSY - forwarding to number
session:setVariable("last_busy_dialed_extension", dialed_extension);
freeswitch.consoleLog("NOTICE", "[failure_handler] forwarding on busy to: " .. forward_busy_destination .. "\n"); if (forward_busy_destination == nil) then
session:setVariable("last_busy_dialed_extension", dialed_extension); freeswitch.consoleLog("NOTICE", "[failure_handler] forwarding on busy to hangup\n");
session:transfer(forward_busy_destination, "XML", context); session:hangup("USER_BUSY");
else else
freeswitch.consoleLog("NOTICE", "[failure_handler] forwarding on busy to: " .. forward_busy_destination .. "\n");
--handle USER_BUSY - hangup session:transfer(forward_busy_destination, "XML", context);
end
freeswitch.consoleLog("NOTICE", "[failure_handler] forward on busy with empty destination: hangup(USER_BUSY)\n"); else
session:hangup("USER_BUSY"); --handle USER_BUSY - hangup
freeswitch.consoleLog("NOTICE", "[failure_handler] forward on busy with empty destination: hangup(USER_BUSY)\n");
session:hangup("USER_BUSY");
end
end end
end); end
end
--close the database connection
dbh:release();
elseif (originate_disposition == "ALLOTTED_TIMEOUT") then elseif (originate_disposition == "ALLOTTED_TIMEOUT") then
--handle ALLOTTED_TIMEOUT ( NO ANSWER ) --handle ALLOTTED_TIMEOUT ( NO ANSWER )
forward_no_answer_enabled = session:getVariable("forward_no_answer_enabled");
if (debug["info"] ) then if (forward_no_answer_enabled == "true") then
freeswitch.consoleLog("NOTICE", "[failure_handler] - ALLOTTED_TIMEOUT - Doing nothing\n"); forward_no_answer_destination = session:getVariable("forward_no_answer_destination");
if (forward_no_answer_destination == nil) then
freeswitch.consoleLog("NOTICE", "[failure_handler] forwarding no answer to hangup\n");
session:hangup("ALLOTTED_TIMEOUT");
else
freeswitch.consoleLog("NOTICE", "[failure_handler] forwarding no answer to: " .. forward_no_answer_destination .. "\n");
session:transfer(forward_no_answer_destination, "XML", context);
end
end end
if (debug["info"] ) then
freeswitch.consoleLog("NOTICE", "[failure_handler] - ALLOTTED_TIMEOUT\n");
end
elseif (originate_disposition == "USER_NOT_REGISTERED") then elseif (originate_disposition == "USER_NOT_REGISTERED") then
--handle USER_NOT_REGISTERED --handle USER_NOT_REGISTERED
if (debug["info"] ) then if (debug["info"] ) then
freeswitch.consoleLog("NOTICE", "[failure_handler] - USER_NOT_REGISTERED - Doing nothing\n"); freeswitch.consoleLog("NOTICE", "[failure_handler] - USER_NOT_REGISTERED - Doing nothing\n");
end end
elseif (originate_disposition == "SUBSCRIBER_ABSENT" and
hangup_on_subscriber_absent == "true") then
--handle SUBSCRIBER_ABSENT elseif (originate_disposition == "SUBSCRIBER_ABSENT" and hangup_on_subscriber_absent == "true") then
--handle SUBSCRIBER_ABSENT
freeswitch.consoleLog("NOTICE", "[failure_handler] - SUBSCRIBER_ABSENT - hangup(UNALLOCATED_NUMBER)\n"); freeswitch.consoleLog("NOTICE", "[failure_handler] - SUBSCRIBER_ABSENT - hangup(UNALLOCATED_NUMBER)\n");
session:hangup("UNALLOCATED_NUMBER"); session:hangup("UNALLOCATED_NUMBER");
elseif (originate_disposition == "CALL_REJECTED" and
hangup_on_call_reject =="true") then
--handle CALL_REJECT elseif (originate_disposition == "CALL_REJECTED" and hangup_on_call_reject =="true") then
--handle CALL_REJECT
freeswitch.consoleLog("NOTICE", "[failure_handler] - CALL_REJECT - hangup()\n"); freeswitch.consoleLog("NOTICE", "[failure_handler] - CALL_REJECT - hangup()\n");
session:hangup(); session:hangup();
end end
end end
end end