Update do_not_disturb.lua
This commit is contained in:
parent
36ae092c13
commit
b2245fbe64
|
|
@ -28,9 +28,6 @@
|
||||||
max_tries = "3";
|
max_tries = "3";
|
||||||
digit_timeout = "3000";
|
digit_timeout = "3000";
|
||||||
|
|
||||||
--debug
|
|
||||||
debug["sql"] = false;
|
|
||||||
|
|
||||||
--define the trim function
|
--define the trim function
|
||||||
require "resources.functions.trim";
|
require "resources.functions.trim";
|
||||||
|
|
||||||
|
|
@ -48,46 +45,50 @@
|
||||||
local Settings = require "resources.functions.lazy_settings"
|
local Settings = require "resources.functions.lazy_settings"
|
||||||
local notify = require "app.feature_event.resources.functions.feature_event_notify"
|
local notify = require "app.feature_event.resources.functions.feature_event_notify"
|
||||||
|
|
||||||
--check if the session is ready
|
--answer the call
|
||||||
if ( session:ready() ) then
|
if (session:ready()) then
|
||||||
--answer the call
|
|
||||||
session:answer();
|
session:answer();
|
||||||
|
end
|
||||||
|
|
||||||
--get the variables
|
--get the variables
|
||||||
|
if (session:ready()) then
|
||||||
enabled = session:getVariable("enabled");
|
enabled = session:getVariable("enabled");
|
||||||
pin_number = session:getVariable("pin_number");
|
pin_number = session:getVariable("pin_number");
|
||||||
sounds_dir = session:getVariable("sounds_dir");
|
sounds_dir = session:getVariable("sounds_dir");
|
||||||
domain_uuid = session:getVariable("domain_uuid");
|
domain_uuid = session:getVariable("domain_uuid");
|
||||||
domain_name = session:getVariable("domain_name");
|
domain_name = session:getVariable("domain_name");
|
||||||
extension_uuid = session:getVariable("extension_uuid");
|
extension_uuid = session:getVariable("extension_uuid");
|
||||||
context = session:getVariable("context");
|
end
|
||||||
if (not context ) then context = 'default'; end
|
|
||||||
toggle = (enabled == "toggle")
|
|
||||||
|
|
||||||
--set the sounds path for the language, dialect and voice
|
--set the sounds path for the language, dialect and voice
|
||||||
|
if (session:ready()) then
|
||||||
default_language = session:getVariable("default_language");
|
default_language = session:getVariable("default_language");
|
||||||
default_dialect = session:getVariable("default_dialect");
|
default_dialect = session:getVariable("default_dialect");
|
||||||
default_voice = session:getVariable("default_voice");
|
default_voice = session:getVariable("default_voice");
|
||||||
if (not default_language) then default_language = 'en'; end
|
if (not default_language) then default_language = 'en'; end
|
||||||
if (not default_dialect) then default_dialect = 'us'; end
|
if (not default_dialect) then default_dialect = 'us'; end
|
||||||
if (not default_voice) then default_voice = 'callie'; end
|
if (not default_voice) then default_voice = 'callie'; end
|
||||||
|
end
|
||||||
|
|
||||||
--a moment to sleep
|
--wait a moment to sleep
|
||||||
|
if (session:ready()) then
|
||||||
session:sleep(1000);
|
session:sleep(1000);
|
||||||
|
end
|
||||||
|
|
||||||
--connect to the database
|
--connect to the database
|
||||||
local Database = require "resources.functions.database";
|
local Database = require "resources.functions.database";
|
||||||
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);
|
||||||
|
|
||||||
--include json library
|
--include json library
|
||||||
|
debug["sql"] = true;
|
||||||
local json
|
local json
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
json = require "resources.functions.lunajson"
|
json = require "resources.functions.lunajson"
|
||||||
end
|
end
|
||||||
|
|
||||||
--determine whether to update the dial string
|
--determine whether to update the dial string
|
||||||
local sql = "select * from v_extensions ";
|
local sql = "select * from v_extensions ";
|
||||||
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 ";
|
||||||
|
|
@ -101,16 +102,21 @@
|
||||||
accountcode = row.accountcode;
|
accountcode = row.accountcode;
|
||||||
follow_me_uuid = row.follow_me_uuid;
|
follow_me_uuid = row.follow_me_uuid;
|
||||||
do_not_disturb = row.do_not_disturb;
|
do_not_disturb = row.do_not_disturb;
|
||||||
forward_all_destination = row.forward_all_destination
|
forward_all_destination = row.forward_all_destination;
|
||||||
forward_all_enabled = row.forward_all_enabled
|
forward_all_enabled = row.forward_all_enabled;
|
||||||
if toggle then
|
context = row.user_context;
|
||||||
enabled = (do_not_disturb == 'true') and 'false' or 'true'
|
|
||||||
end
|
|
||||||
--freeswitch.consoleLog("NOTICE", "[do_not_disturb] extension "..row.extension.."\n");
|
|
||||||
--freeswitch.consoleLog("NOTICE", "[do_not_disturb] accountcode "..row.accountcode.."\n");
|
|
||||||
end);
|
end);
|
||||||
|
|
||||||
--toggle do not disturb
|
--send information to the console
|
||||||
|
if (session:ready()) then
|
||||||
|
freeswitch.consoleLog("NOTICE", "[do_not_disturb] do_not_disturb "..do_not_disturb.."\n");
|
||||||
|
freeswitch.consoleLog("NOTICE", "[do_not_disturb] extension "..extension.."\n");
|
||||||
|
freeswitch.consoleLog("NOTICE", "[do_not_disturb] follow_me_uuid "..follow_me_uuid.."\n");
|
||||||
|
freeswitch.consoleLog("NOTICE", "[do_not_disturb] accountcode "..accountcode.."\n");
|
||||||
|
--freeswitch.consoleLog("NOTICE", "[do_not_disturb] enabled before "..enabled.."\n");
|
||||||
|
end
|
||||||
|
|
||||||
|
--toggle do not disturb
|
||||||
if (enabled == "toggle") then
|
if (enabled == "toggle") then
|
||||||
if (do_not_disturb == "true") then
|
if (do_not_disturb == "true") then
|
||||||
enabled = "false";
|
enabled = "false";
|
||||||
|
|
@ -119,47 +125,55 @@
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--set the dial string
|
--send information to the console
|
||||||
|
if (session:ready()) then
|
||||||
|
freeswitch.consoleLog("NOTICE", "[do_not_disturb] enabled "..enabled.."\n");
|
||||||
|
end
|
||||||
|
|
||||||
|
--set the dial string
|
||||||
if (enabled == "true") then
|
if (enabled == "true") then
|
||||||
local user = (number_alias and #number_alias > 0) and number_alias or extension;
|
local user = (number_alias and #number_alias > 0) and number_alias or extension;
|
||||||
dial_string = "error/user_busy";
|
dial_string = "error/user_busy";
|
||||||
end
|
end
|
||||||
|
|
||||||
--set do not disturb
|
--set do not disturb
|
||||||
if (enabled == "true") then
|
if (enabled == "true") then
|
||||||
--set do_not_disturb_enabled
|
--set do_not_disturb_enabled
|
||||||
do_not_disturb_enabled = "true";
|
do_not_disturb_enabled = "true";
|
||||||
--notify the caller
|
--notify the caller
|
||||||
|
if (session:ready()) then
|
||||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-dnd_activated.wav");
|
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-dnd_activated.wav");
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--unset do not disturb
|
--unset do not disturb
|
||||||
if (enabled == "false") then
|
if (enabled == "false") then
|
||||||
--set fdo_not_disturb_enabled
|
--set fdo_not_disturb_enabled
|
||||||
do_not_disturb_enabled = "false";
|
do_not_disturb_enabled = "false";
|
||||||
--notify the caller
|
--notify the caller
|
||||||
|
if (session:ready()) then
|
||||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-dnd_cancelled.wav");
|
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-dnd_cancelled.wav");
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--disable follow me
|
--update follow me
|
||||||
if (follow_me_uuid ~= nil) then
|
if (follow_me_uuid ~= nil and enabled == 'true') then
|
||||||
if (string.len(follow_me_uuid) > 0 and enabled == "true") then
|
local sql = "update v_follow_me ";
|
||||||
local sql = "update v_follow_me set ";
|
sql = sql .. "set follow_me_enabled = 'false' ";
|
||||||
sql = sql .. "follow_me_enabled = 'false' ";
|
|
||||||
sql = sql .. "where domain_uuid = :domain_uuid ";
|
sql = sql .. "where domain_uuid = :domain_uuid ";
|
||||||
sql = sql .. "and follow_me_uuid = :follow_me_uuid ";
|
sql = sql .. "and follow_me_uuid = :follow_me_uuid ";
|
||||||
local params = {domain_uuid = domain_uuid, follow_me_uuid = follow_me_uuid};
|
local params = {domain_uuid = domain_uuid, follow_me_uuid = follow_me_uuid};
|
||||||
if (debug["sql"]) then
|
-- if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[do_not_disturb] "..sql.."; params:" .. json.encode(params) .. "\n");
|
freeswitch.consoleLog("notice", "[do_not_disturb] "..sql.."; params:" .. json.encode(params) .. "\n");
|
||||||
end
|
-- end
|
||||||
dbh:query(sql, params);
|
dbh:query(sql, params);
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
--update the extension
|
--update the extension
|
||||||
sql = "update v_extensions set ";
|
sql = "update v_extensions set ";
|
||||||
if (enabled == "true") then
|
if (enabled == "true") then
|
||||||
sql = sql .. "dial_string = :dial_string, ";
|
sql = sql .. "follow_me_enabled = 'false', ";
|
||||||
|
sql = sql .. "dial_string = null, ";
|
||||||
sql = sql .. "do_not_disturb = 'true', ";
|
sql = sql .. "do_not_disturb = 'true', ";
|
||||||
sql = sql .. "forward_all_enabled = 'false' ";
|
sql = sql .. "forward_all_enabled = 'false' ";
|
||||||
else
|
else
|
||||||
|
|
@ -174,7 +188,7 @@
|
||||||
end
|
end
|
||||||
dbh:query(sql, params);
|
dbh:query(sql, params);
|
||||||
|
|
||||||
--determine whether to update the dial string
|
--determine whether to update the dial string
|
||||||
sql = "select * from v_extension_users as e, v_users as u ";
|
sql = "select * from v_extension_users as e, v_users as u ";
|
||||||
sql = sql .. "where e.extension_uuid = :extension_uuid ";
|
sql = sql .. "where e.extension_uuid = :extension_uuid ";
|
||||||
sql = sql .. "and e.user_uuid = u.user_uuid ";
|
sql = sql .. "and e.user_uuid = u.user_uuid ";
|
||||||
|
|
@ -217,6 +231,7 @@
|
||||||
sip_profile = notify.get_profile(extension, domain_name);
|
sip_profile = notify.get_profile(extension, domain_name);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- check if not nil
|
||||||
if (sip_profile ~= nil) then
|
if (sip_profile ~= nil) then
|
||||||
freeswitch.consoleLog("NOTICE", "[feature_event] SIP NOTIFY: CFWD set to "..forward_all_enabled.."\n");
|
freeswitch.consoleLog("NOTICE", "[feature_event] SIP NOTIFY: CFWD set to "..forward_all_enabled.."\n");
|
||||||
|
|
||||||
|
|
@ -253,31 +268,33 @@
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--clear the cache
|
--clear the cache
|
||||||
if extension and #extension > 0 and cache.support() then
|
if extension and #extension > 0 and cache.support() then
|
||||||
cache.del("directory:"..extension.."@"..domain_name);
|
cache.del("directory:"..extension.."@"..context);
|
||||||
if #number_alias > 0 then
|
if #number_alias > 0 then
|
||||||
cache.del("directory:"..number_alias.."@"..domain_name);
|
cache.del("directory:"..number_alias.."@"..context);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--wait for the file to be written before proceeding
|
--wait for the file to be written before proceeding
|
||||||
|
if (session:ready()) then
|
||||||
session:sleep(1000);
|
session:sleep(1000);
|
||||||
|
end
|
||||||
|
|
||||||
--end the call
|
--end the call
|
||||||
|
if (session:ready()) then
|
||||||
session:hangup();
|
session:hangup();
|
||||||
|
end
|
||||||
|
|
||||||
-- BLF for display DND status
|
-- BLF for display DND status
|
||||||
blf.dnd(enabled == "true", extension, number_alias, domain_name)
|
blf.dnd(enabled == "true", extension, number_alias, domain_name)
|
||||||
|
|
||||||
-- Turn off BLF for call forward
|
-- Turn off BLF for call forward
|
||||||
if forward_all_enabled == 'true' and enabled == 'true' then
|
if forward_all_enabled == 'true' and enabled == 'true' then
|
||||||
blf.forward(false, extension, number_alias,
|
blf.forward(false, extension, number_alias,
|
||||||
forward_all_destination, nil, domain_name
|
forward_all_destination, nil, domain_name
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
--disconnect from database
|
--disconnect from database
|
||||||
dbh:release()
|
dbh:release()
|
||||||
|
|
||||||
end
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue