Add. Support variables in ring groups when use dierect dial (#2924)

Add. Support variables in ring groups when use direct dial
This commit is contained in:
Alexey Melnichuk 2017-11-29 10:20:45 +03:00 committed by FusionPBX
parent bbfbf4e065
commit 07a49f37bd
1 changed files with 104 additions and 53 deletions

View File

@ -95,6 +95,39 @@
end
--define iterator function to iterate over key/value pairs in string
local function split_vars_pairs(str)
local last_pos = 1
return function()
-- end of string
if not str then return end
-- handle case when there exists comma after kv pair
local action, next_pos = string.match(str, "([^=]+=%b''),()", last_pos)
if not action then
action, next_pos = string.match(str, "([^=]+=[^'][^,]-),()", last_pos)
if not action then
action, next_pos = string.match(str, "([^=]+=),()", last_pos)
end
end
if action then
last_pos = next_pos
return action
end
-- last kv pair may not have comma after it
if last_pos < #str then
action = string.match(str, "([^=]+=%b'')$", last_pos)
if not action then
action = string.match(str, "([^=]+=[^,]-)$", last_pos)
end
str = nil -- end of iteration
end
return action
end
end
--set the hangup hook function
if (session:ready()) then
session:setHangupHook("session_hangup_hook");
@ -564,13 +597,24 @@
--send to user
local dial_string_to_user = "[sip_invite_domain="..domain_name..",call_direction="..call_direction..","..group_confirm.."leg_timeout="..destination_timeout..","..delay_name.."="..destination_delay..",dialed_extension=" .. row.destination_number .. ",extension_uuid="..extension_uuid .. row.record_session .. "]user/" .. row.destination_number .. "@" .. domain_name;
dial_string = dial_string_to_user;
elseif (tonumber(destination_number) == nil) then
--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;
else
--external number
--external number or direct dial
dial_string = nil
--prepare default actions
local confirm = string.gsub(group_confirm, ',$', '') -- remove `,` from end of string
local route = { -- predefined actions
"domain_name=${domain_name}",
"domain_uuid=${domain_uuid}",
"sip_invite_domain=${domain_name}",
"call_direction=${call_direction}",
"leg_timeout=${destination_timeout}",
delay_name .. "=${destination_delay}",
"ignore_early_media=true",
confirm,
}
--prepare default variables
local session_mt = {__index = function(_, k) return session:getVariable(k) end}
local params = setmetatable({
__api__ = api,
@ -583,19 +627,26 @@
destination_delay = destination_delay,
}, session_mt)
local confirm = string.gsub(group_confirm, ',$', '') -- remove `,` from end of string
local route = route_to_bridge.apply_vars({ -- predefined actions
"domain_name=${domain_name}",
"domain_uuid=${domain_uuid}",
"sip_invite_domain=${domain_name}",
"leg_timeout=${destination_timeout}",
delay_name .. "=${destination_delay}",
"ignore_early_media=true",
confirm,
}, params)
--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
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
--build dialstring
if route and route.bridge then
local remove_actions = {
["effective_caller_id_name="] = true;