From 87a79a92113931ea44e0612ce62f08cb5ac33cab Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Sat, 22 Feb 2014 18:06:30 +0000 Subject: [PATCH] Fix a problem with inbound calls and improve the dialplan lua script. --- .../install/scripts/app/dialplan/index.lua | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/resources/install/scripts/app/dialplan/index.lua b/resources/install/scripts/app/dialplan/index.lua index a6388b3f89..7fa5350d01 100644 --- a/resources/install/scripts/app/dialplan/index.lua +++ b/resources/install/scripts/app/dialplan/index.lua @@ -37,35 +37,48 @@ local domain_name = session:getVariable("domain_name"); --determine the call direction - if (context == "public") then - call_direction = "inbound"; - else - if (call_direction == nil) then - if (context == "outbound@"..domain_name) then - call_direction = "outbound"; + if (call_direction == nil) then + --get the call directory + if (context == "public") then + call_direction = "inbound"; else - if (string.len(destination_number) > 6) then + if (context == "outbound@"..domain_name) then call_direction = "outbound"; else - call_direction = "local"; + if (string.len(destination_number) > 6) then + call_direction = "outbound"; + else + call_direction = "local"; + end end end - end + --set the call direction as a session variable + session:setVariable("call_direction", call_direction); + --freeswitch.consoleLog("notice", "[app:dialplan] set call_direction " .. call_direction .. "\n"); end ---set the call direction as a session variable - session:setVariable("call_direction", call_direction); - --freeswitch.consoleLog("notice", "[app:dialplan] set call_direction " .. call_direction .. "\n"); +--determine the directory to include + if (context == "public") then + dialplan_dir = "inbound"; + else + if (context == "outbound@"..domain_name) then + dialplan_dir = "outbound"; + else + if (string.len(destination_number) > 6) then + dialplan_dir = "outbound"; + else + dialplan_dir = "local"; + end + end + end --include the dialplans - result = assert (io.popen ("dir " ..scripts_dir.."/app/dialplan/resources/"..call_direction.." /b -1")); + result = assert (io.popen ("dir " ..scripts_dir.."/app/dialplan/resources/"..dialplan_dir.." /b -1")); for file in result:lines() do if (string.sub(file, -4) == ".lua") then - --order = string.match(file, "%d+"); - --if (order == nil) then order = file; end - if file_exists(scripts_dir.."/app/dialplan/resources/"..call_direction.."/"..file) then - dofile(scripts_dir.."/app/dialplan/resources/"..call_direction.."/"..file); + if file_exists(scripts_dir.."/app/dialplan/resources/"..dialplan_dir.."/"..file) then + dofile(scripts_dir.."/app/dialplan/resources/"..dialplan_dir.."/"..file); end - freeswitch.consoleLog("notice", "[app:dialplan] lua: " .. file .. "\n"); + freeswitch.consoleLog("notice", "[app:dialplan] lua: "..dialplan_dir.."/" .. file .. "\n"); end end