[feature event] Don't update extension dial string (#6166)

* [feature event] Don't update extension dial string

* remove comma

* [feature_event] dnd don't update follow me and forward all

* cleaned up some code
This commit is contained in:
agree 2021-12-02 19:45:01 -05:00 committed by GitHub
parent c94a7f5081
commit 5e760a363f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 96 deletions

View File

@ -51,51 +51,43 @@
--connect to the database --connect to the database
local Database = require "resources.functions.database"; local Database = require "resources.functions.database";
local Settings = require "resources.functions.lazy_settings" local Settings = require "resources.functions.lazy_settings"
local route_to_bridge = require "resources.functions.route_to_bridge"
local blf = require "resources.functions.blf"
local cache = require "resources.functions.cache" local cache = require "resources.functions.cache"
local notify = require "app.feature_event.resources.functions.feature_event_notify" local notify = require "app.feature_event.resources.functions.feature_event_notify"
dbh = Database.new('system'); dbh = Database.new('system');
local settings = Settings.new(dbh, domain_name, domain_uuid); local settings = Settings.new(dbh, domain_name, domain_uuid);
--set debug --set debug
debug["sql"] = true; debug["sql"] = false;
--include json library --include json library
local json local json
if (debug["sql"]) then if (debug["sql"]) then
json = require "resources.functions.lunajson" json = require "resources.functions.lunajson"
end end
local function empty(t)
return (not t) or (#t == 0)
end
--get the events --get the events
--if (user == nil) then --serialize the data for the console
--serialize the data for the console --freeswitch.consoleLog("notice","[events] " .. event:serialize("xml") .. "\n");
--freeswitch.consoleLog("notice","[events] " .. event:serialize("xml") .. "\n"); --freeswitch.consoleLog("notice","[evnts] " .. event:serialize("json") .. "\n");
--freeswitch.consoleLog("notice","[evnts] " .. event:serialize("json") .. "\n");
--get the event variables --get the event variables
user = event:getHeader("user"); user = event:getHeader("user");
host = event:getHeader("host"); host = event:getHeader("host");
domain_name = event:getHeader("host"); domain_name = event:getHeader("host");
contact = event:getHeader("contact"); contact = event:getHeader("contact");
feature_action = event:getHeader("Feature-Action"); feature_action = event:getHeader("Feature-Action");
feature_enabled = event:getHeader("Feature-Enabled"); feature_enabled = event:getHeader("Feature-Enabled");
action_name = event:getHeader("Action-Name"); action_name = event:getHeader("Action-Name");
action_value = event:getHeader("Action-Value") action_value = event:getHeader("Action-Value")
ring_count = event:getHeader("ringCount") ring_count = event:getHeader("ringCount")
--send to the log --send to the log
--freeswitch.consoleLog("notice","[events] user: " .. user .. "\n"); -- freeswitch.consoleLog("notice","[events] user: " .. user .. "\n");
--freeswitch.consoleLog("notice","[events] host: " .. host .. "\n"); -- freeswitch.consoleLog("notice","[events] host: " .. host .. "\n");
--if (feature_action ~= nil) then freeswitch.consoleLog("notice","[events] feature_action: " .. feature_action .. "\n"); end -- if (feature_action ~= nil) then freeswitch.consoleLog("notice","[events] feature_action: " .. feature_action .. "\n"); end
--if (feature_enabled ~= nil) then freeswitch.consoleLog("notice","[events] feature_enabled: " .. feature_enabled .. "\n"); end -- if (feature_enabled ~= nil) then freeswitch.consoleLog("notice","[events] feature_enabled: " .. feature_enabled .. "\n"); end
--if (action_name ~= nil) then freeswitch.consoleLog("notice","[events] action_name: " .. action_name .. "\n"); end -- if (action_name ~= nil) then freeswitch.consoleLog("notice","[events] action_name: " .. action_name .. "\n"); end
--if (action_value ~= nil) then freeswitch.consoleLog("notice","[events] action_value: " .. action_value .. "\n"); end -- if (action_value ~= nil) then freeswitch.consoleLog("notice","[events] action_value: " .. action_value .. "\n"); end
--end
--get the domain uuid from the host --get the domain uuid from the host
local sql = "select * from v_domains "; local sql = "select * from v_domains ";
@ -121,66 +113,29 @@
--DND --DND
if (sip_profiles ~= nil) then if (sip_profiles ~= nil) then
--DND enabled --DND enabled
if (feature_action == "SetDoNotDisturb" and feature_enabled == "true") then if (feature_action == "SetDoNotDisturb") then
--set a variable --set dnd
dial_string = "!USER_BUSY"; if(feature_enabled == "true") then
do_not_disturb = "true"; do_not_disturb = "true";
else
do_not_disturb = "false";
end
--update the extension --update the extension
sql = "update v_extensions set "; sql = "update v_extensions set ";
sql = sql .. "do_not_disturb = :do_not_disturb, "; sql = sql .. "do_not_disturb = :do_not_disturb ";
sql = sql .. "forward_all_enabled = 'false', ";
sql = sql .. "dial_string = :dial_string ";
sql = sql .. "where domain_uuid = :domain_uuid "; sql = sql .. "where domain_uuid = :domain_uuid ";
sql = sql .. "and extension_uuid = :extension_uuid "; sql = sql .. "and extension_uuid = :extension_uuid ";
local params = {domain_uuid = domain_uuid, extension_uuid = extension_uuid, do_not_disturb = do_not_disturb, dial_string = dial_string}; local params = {domain_uuid = domain_uuid, extension_uuid = extension_uuid, do_not_disturb = do_not_disturb};
if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("notice", "[feature_event] "..sql.."; params:" .. json.encode(params) .. "\n"); freeswitch.consoleLog("notice", "[feature_event] "..sql.."; params:" .. json.encode(params) .. "\n");
end end
dbh:query(sql, params); dbh:query(sql, params);
--update follow me
if (follow_me_uuid ~= nil) then
if (string.len(follow_me_uuid) > 0) then
local sql = "update v_follow_me set ";
sql = sql .. "follow_me_enabled = 'false' ";
sql = sql .. "where domain_uuid = :domain_uuid ";
sql = sql .. "and follow_me_uuid = :follow_me_uuid ";
local params = {domain_uuid = domain_uuid, follow_me_uuid = follow_me_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[feature_event] "..sql.."; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params);
end
end
--send notify to the phone --send notify to the phone
notify.dnd(user, host, sip_profiles, do_not_disturb); notify.dnd(user, host, sip_profiles, do_not_disturb);
end end
--DND disabled
if (feature_action == "SetDoNotDisturb" and feature_enabled == "false") then
--set a variable
do_not_disturb = "false";
--update the extension
sql = "update v_extensions set ";
sql = sql .. "do_not_disturb = :do_not_disturb, ";
sql = sql .. "forward_all_enabled = 'false', ";
sql = sql .. "dial_string = null ";
sql = sql .. "where domain_uuid = :domain_uuid ";
sql = sql .. "and extension_uuid = :extension_uuid ";
local params = {domain_uuid = domain_uuid, extension_uuid = extension_uuid, do_not_disturb = do_not_disturb};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[feature_event] "..sql.."; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params);
--send notify to the phone
notify.dnd(user, host, sip_profiles, do_not_disturb);
end
--Call Forward --Call Forward
--Call Formward All enabled --Call Formward All enabled
@ -191,7 +146,6 @@
forward_immediate_destination = action_value; forward_immediate_destination = action_value;
forward_immediate_enabled = "true"; forward_immediate_enabled = "true";
--set the dial string
if feature_enabled == "true" then if feature_enabled == "true" then
local destination_extension, destination_number_alias local destination_extension, destination_number_alias
@ -221,8 +175,7 @@
sql = "update v_extensions set "; sql = "update v_extensions set ";
sql = sql .. "do_not_disturb = 'false', "; sql = sql .. "do_not_disturb = 'false', ";
sql = sql .. "forward_all_enabled = 'true', "; sql = sql .. "forward_all_enabled = 'true', ";
sql = sql .. "forward_all_destination = :forward_all_destination, "; sql = sql .. "forward_all_destination = :forward_all_destination ";
sql = sql .. "dial_string = null ";
sql = sql .. "where domain_uuid = :domain_uuid "; sql = sql .. "where domain_uuid = :domain_uuid ";
sql = sql .. "and extension_uuid = :extension_uuid "; sql = sql .. "and extension_uuid = :extension_uuid ";
local params = {domain_uuid = domain_uuid, extension_uuid = extension_uuid, forward_all_destination = forward_all_destination}; local params = {domain_uuid = domain_uuid, extension_uuid = extension_uuid, forward_all_destination = forward_all_destination};
@ -231,21 +184,6 @@
end end
dbh:query(sql, params); dbh:query(sql, params);
--update follow me
if (follow_me_uuid ~= nil) then
if (string.len(follow_me_uuid) > 0) then
local sql = "update v_follow_me set ";
sql = sql .. "follow_me_enabled = 'false' ";
sql = sql .. "where domain_uuid = :domain_uuid ";
sql = sql .. "and follow_me_uuid = :follow_me_uuid ";
local params = {domain_uuid = domain_uuid, follow_me_uuid = follow_me_uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[feature_event] "..sql.."; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params);
end
end
--send notify to the phone --send notify to the phone
notify.forward_immediate(user, host, sip_profiles, forward_immediate_enabled, forward_immediate_destination); notify.forward_immediate(user, host, sip_profiles, forward_immediate_enabled, forward_immediate_destination);
end end
@ -263,11 +201,10 @@
sql = sql .. "do_not_disturb = 'false', "; sql = sql .. "do_not_disturb = 'false', ";
sql = sql .. "forward_all_enabled = 'false', "; sql = sql .. "forward_all_enabled = 'false', ";
if (forward_all_destination ~= nil) then if (forward_all_destination ~= nil) then
sql = sql .. "forward_all_destination = :forward_all_destination, "; sql = sql .. "forward_all_destination = :forward_all_destination ";
else else
sql = sql .. "forward_all_destination = null, "; sql = sql .. "forward_all_destination = null ";
end end
sql = sql .. "dial_string = null ";
sql = sql .. "where domain_uuid = :domain_uuid "; sql = sql .. "where domain_uuid = :domain_uuid ";
sql = sql .. "and extension_uuid = :extension_uuid "; sql = sql .. "and extension_uuid = :extension_uuid ";
local params = {domain_uuid = domain_uuid, extension_uuid = extension_uuid, forward_all_destination = forward_all_destination}; local params = {domain_uuid = domain_uuid, extension_uuid = extension_uuid, forward_all_destination = forward_all_destination};