Ring Groups route_to_bridge was fixed re-add it to the code.

This commit is contained in:
FusionPBX
2018-02-11 10:22:25 -07:00
committed by GitHub
parent 10b3321042
commit b12a4ebae8
@@ -48,12 +48,9 @@
require "resources.functions.channel_utils" require "resources.functions.channel_utils"
require "resources.functions.format_ringback" require "resources.functions.format_ringback"
--additional includes --- include libs
file = require "resources.functions.file" local route_to_bridge = require "resources.functions.route_to_bridge"
require "resources.functions.basename" local play_file = require "resources.functions.play_file"
require "resources.functions.is_absolute_path"
require "resources.functions.find_file"
require "resources.functions.play_file"
--define the session hangup --define the session hangup
function session_hangup_hook() function session_hangup_hook()
@@ -496,33 +493,9 @@
--get the dialplan data and save it to a table --get the dialplan data and save it to a table
if (external) then if (external) then
sql = [[select * from v_dialplans as d, v_dialplan_details as s dialplans = route_to_bridge.preload_dialplan(
where (d.domain_uuid = :domain_uuid or d.domain_uuid is null) dbh, domain_uuid, {hostname = hostname, context = context}
and d.app_uuid = '8c914ec3-9fc0-8ab5-4cda-6c9288bdc9a3' )
and d.dialplan_enabled = 'true'
and d.dialplan_uuid = s.dialplan_uuid
order by
d.dialplan_order asc,
d.dialplan_name asc,
d.dialplan_uuid asc,
s.dialplan_detail_group asc,
CASE s.dialplan_detail_tag
WHEN 'condition' THEN 1
WHEN 'action' THEN 2
WHEN 'anti-action' THEN 3
ELSE 100 END,
s.dialplan_detail_order asc
]];
params = {domain_uuid = domain_uuid};
if debug["sql"] then
freeswitch.consoleLog("notice", "[ring group] SQL:" .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dialplans = {};
x = 1;
assert(dbh:query(sql, params, function(row)
dialplans[x] = row;
x = x + 1;
end));
end end
--process the destinations --process the destinations
@@ -660,68 +633,83 @@
--sip uri --sip uri
dial_string = "[sip_invite_domain="..domain_name..",call_direction="..call_direction..","..group_confirm.."leg_timeout="..destination_timeout..","..delay_name.."="..destination_delay.."]" .. row.destination_number; dial_string = "[sip_invite_domain="..domain_name..",call_direction="..call_direction..","..group_confirm.."leg_timeout="..destination_timeout..","..delay_name.."="..destination_delay.."]" .. row.destination_number;
else else
--external number --external number or direct dial
y = 0; dial_string = nil
dial_string = '';
previous_dialplan_uuid = ''; --prepare default actions
regex_match = false; local confirm = string.gsub(group_confirm, ',$', '') -- remove `,` from end of string
for k, r in pairs(dialplans) do local route = { -- predefined actions
if (y > 0) then "domain_name=${domain_name}",
if (previous_dialplan_uuid ~= r.dialplan_uuid) then "domain_uuid=${domain_uuid}",
regex_match = false; "sip_invite_domain=${domain_name}",
bridge_match = false; "call_direction=${call_direction}",
square = square .. "]"; "leg_timeout=${destination_timeout}",
y = 0; delay_name .. "=${destination_delay}",
end "ignore_early_media=true",
end confirm,
if (r.dialplan_detail_tag == "condition") then }
if (r.dialplan_detail_type == "destination_number") then
if (api:execute("regex", "m:~"..destination_number.."~"..r.dialplan_detail_data) == "true") then --prepare default variables
--get the regex result local session_mt = {__index = function(_, k) return session:getVariable(k) end}
destination_result = trim(api:execute("regex", "m:~"..destination_number.."~"..r.dialplan_detail_data.."~$1")); local params = setmetatable({
--set match equal to true __api__ = api,
regex_match = true destination_number = destination_number,
user_exists = 'false',
call_direction = 'outbound',
domain_name = domain_name,
domain_uuid = domain_uuid,
destination_timeout = destination_timeout,
destination_delay = destination_delay,
toll_allow = toll_allow,
}, session_mt)
--find destination route
if (tonumber(destination_number) == nil) then
--user define direct destination like `[key=value]sofia/gateway/carrier/123456`
local variables, destination = string.match(destination_number, "^%[(.-)%](.+)$")
if not variables then
destination = destination_number
else
for action in split_vars_pairs(variables) do
route[#route + 1] = action
end
end end
end route = route_to_bridge.apply_vars(route, params)
route.bridge = destination
else
--user define external number as destination
route = route_to_bridge.apply_vars(route, params)
route = route_to_bridge(dialplans, domain_uuid, params, route)
end end
if (r.dialplan_detail_tag == "action") then
if (regex_match) then --build dialstring
--replace $1 if route and route.bridge then
dialplan_detail_data = r.dialplan_detail_data:gsub("$1", destination_result); local remove_actions = {
--if the session is set then process the actions ["effective_caller_id_name="] = true;
if (y == 0) then ["effective_caller_id_number="] = true;
square = "[domain_name="..domain_name..",domain_uuid="..domain_uuid..",sip_invite_domain="..domain_name..",call_direction=outbound,"..group_confirm.."leg_timeout="..destination_timeout..","..delay_name.."="..destination_delay..",ignore_early_media=true,"; ['sip_h_X-accountcode='] = true;
end }
if (r.dialplan_detail_type == "set") then
--session:execute("eval", dialplan_detail_data); -- cleanup variables
if (dialplan_detail_data == "sip_h_X-accountcode=${accountcode}") then local i = 1 while i < #route do
if (session) then -- remove vars from prev variant
accountcode = session:getVariable("accountcode"); if remove_actions[ route[i] ] then
if (accountcode) then table.remove(route, i)
square = square .. "sip_h_X-accountcode="..accountcode..","; i = i - 1
end -- remove vars with unresolved vars
end elseif string.find(route[i], '%${.+}') then
elseif (dialplan_detail_data == "effective_caller_id_name=${outbound_caller_id_name}") then table.remove(route, i)
elseif (dialplan_detail_data == "effective_caller_id_number=${outbound_caller_id_number}") then i = i - 1
else -- remove vars with empty values
square = square .. dialplan_detail_data..","; elseif string.find(route[i], '=$') then
end table.remove(route, i)
elseif (r.dialplan_detail_type == "bridge") then i = i - 1
if (bridge_match) then end
dial_string = dial_string .. delimiter .. square .."]"..dialplan_detail_data; i = i + 1
square = "[";
else
dial_string = square .."]"..dialplan_detail_data;
end
bridge_match = true;
break;
end
--increment the value
y = y + 1;
end end
dial_string = '[' .. table.concat(route, ',') .. ']' .. route.bridge
end end
previous_dialplan_uuid = r.dialplan_uuid;
end
end end
--add a delimiter between destinations --add a delimiter between destinations