From ddc3befd6053dbb751718fba6de0736d3d92db4d Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Mon, 4 Mar 2024 16:54:50 -0700 Subject: [PATCH] Add required diversion header --- app/ring_groups/app_config.php | 8 +++++ .../scripts/app/ring_groups/index.lua | 36 ++++++++++++++----- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/ring_groups/app_config.php b/app/ring_groups/app_config.php index 3f27e45f49..cadd14362c 100644 --- a/app/ring_groups/app_config.php +++ b/app/ring_groups/app_config.php @@ -223,6 +223,14 @@ $apps[$x]['default_settings'][$y]['default_setting_value'] = "true"; $apps[$x]['default_settings'][$y]['default_setting_enabled'] = "false"; $apps[$x]['default_settings'][$y]['default_setting_description'] = "Enable or disable the feature to add a range of extensions."; + $y++; + $apps[$x]['default_settings'][$y]['default_setting_uuid'] = "d25c1e2b-4098-408e-959b-c789ba4691e1"; + $apps[$x]['default_settings'][$y]['default_setting_category'] = "ring_group"; + $apps[$x]['default_settings'][$y]['default_setting_subcategory'] = "diversion_enabled"; + $apps[$x]['default_settings'][$y]['default_setting_name'] = "boolean"; + $apps[$x]['default_settings'][$y]['default_setting_value'] = "false"; + $apps[$x]['default_settings'][$y]['default_setting_enabled'] = "false"; + $apps[$x]['default_settings'][$y]['default_setting_description'] = "Enable or disable the adding diversion header for external destinations."; //schema details $y=0; diff --git a/app/switch/resources/scripts/app/ring_groups/index.lua b/app/switch/resources/scripts/app/ring_groups/index.lua index d33014de56..45404e5fae 100644 --- a/app/switch/resources/scripts/app/ring_groups/index.lua +++ b/app/switch/resources/scripts/app/ring_groups/index.lua @@ -28,7 +28,7 @@ -- Gill Abada --include the log - log = require "resources.functions.log".ring_group +log = require "resources.functions.log".ring_group --connect to the database local Database = require "resources.functions.database"; @@ -244,6 +244,10 @@ missed_call_data = row["ring_group_missed_call_data"]; end); +--create the settings object + local Settings = require "resources.functions.lazy_settings"; + local settings = Settings.new(dbh, domain_name, domain_uuid); + --prepare the recording path record_path = recordings_dir .. "/" .. domain_name .. "/archive/" .. os.date("%Y/%b/%d"); record_path = record_path:gsub("\\", "/"); @@ -355,7 +359,7 @@ caller_id_name = caller_id_name:gsub([["]], """); caller_id_number = caller_id_number:gsub("'", "'"); caller_id_number = caller_id_number:gsub([["]], """); - + --prepare the subject subject = subject:gsub("${caller_id_name}", caller_id_name); subject = subject:gsub("${caller_id_number}", caller_id_number); @@ -492,8 +496,8 @@ WHEN r.ring_group_strategy <> 'enterprise' THEN d.destination_delay END as destination_delay, - r.ring_group_caller_id_name, r.ring_group_caller_id_number, - r.ring_group_cid_name_prefix, r.ring_group_cid_number_prefix, + r.ring_group_caller_id_name, r.ring_group_caller_id_number, + r.ring_group_cid_name_prefix, r.ring_group_cid_number_prefix, r.ring_group_timeout_data, r.ring_group_ringback FROM v_ring_groups as r, v_ring_group_destinations as d @@ -848,7 +852,7 @@ dial_string_user = dial_string_user .. group_confirm..","..timeout_name.."="..destination_timeout..","; dial_string_user = dial_string_user .. delay_name.."="..destination_delay..","; dial_string_user = dial_string_user .. "dialed_extension=" .. row.destination_number .. ","; - if (hold_music ~= nil) and (string.len(hold_music) > 0) then +if (hold_music ~= nil) and (string.len(hold_music) > 0) then dial_string_user = dial_string_user .. "hold_music=" .. hold_music .. ","; end dial_string_user = dial_string_user .. "presence_id=" .. row.destination_number .. "@"..domain_name..","; @@ -865,7 +869,7 @@ dial_string = "[sip_invite_domain="..domain_name..",domain_name="..domain_name..",call_direction="..call_direction..","..group_confirm..""..timeout_name.."="..destination_timeout..","..delay_name.."="..destination_delay.."]" .. row.destination_number; else --external number - -- have to double destination_delay here due a FS bug requiring a 50% delay value for internal externsions, but not external calls. + -- have to double destination_delay here due a FS bug requiring a 50% delay value for internal externsions, but not external calls. --destination_delay = destination_delay * 2; route_bridge = 'loopback/'..destination_number; @@ -901,8 +905,22 @@ caller_id = caller_id .. ",origination_caller_id_number="..ring_group_caller_id_number..","; end + --set the diversion header + local diversion_enabled = settings:get('ring_group', 'diversion_enabled', 'boolean') or 'false'; + if (diversion_enabled == 'true') then + if (caller_is_local == 'true' and outbound_caller_id_number ~= nil) then + diversion_caller_id = outbound_caller_id_number; + end + if (ring_group_caller_id_number ~= nil and ring_group_caller_id_number ~= '') then + diversion_caller_id = ring_group_caller_id_number; + end + diversion_header = "sip_h_Diversion=;reason=unconditional,"; + else + diversion_header = ''; + end + --set the destination dial string - dial_string = "[toll_allow=".. toll_allow ..",".. caller_id ..",sip_invite_domain="..domain_name..",domain_name="..domain_name..",domain_uuid="..domain_uuid..",call_direction="..call_direction..","..group_confirm..""..timeout_name.."="..destination_timeout..","..delay_name.."="..destination_delay.."]"..route_bridge + dial_string = "["..diversion_header.."toll_allow=".. toll_allow ..",".. caller_id ..",sip_invite_domain="..domain_name..",domain_name="..domain_name..",domain_uuid="..domain_uuid..",call_direction="..call_direction..","..group_confirm..""..timeout_name.."="..destination_timeout..","..delay_name.."="..destination_delay.."]"..route_bridge end --add a delimiter between destinations @@ -1033,9 +1051,9 @@ session:setVariable("presence_id", ring_group_extension.."@"..domain_name); send_presence(uuid, ring_group_extension.."@"..domain_name, "early"); end - + session:execute("bridge", app_data); - + --set the presence to terminated and unset presence_id if (session:getVariable("ring_group_send_presence") == "true") then session:setVariable("presence_id", "");