Get emergency emails from both default and domain settings
This commit is contained in:
parent
81ab295059
commit
7a167f70af
|
|
@ -56,6 +56,9 @@ delete = argv[1];
|
||||||
--prepare the api object
|
--prepare the api object
|
||||||
api = freeswitch.API();
|
api = freeswitch.API();
|
||||||
|
|
||||||
|
--prepare the email to address
|
||||||
|
to = {}
|
||||||
|
|
||||||
--get sessions info
|
--get sessions info
|
||||||
if (session and session:ready()) then
|
if (session and session:ready()) then
|
||||||
domain_uuid = session:getVariable("domain_uuid");
|
domain_uuid = session:getVariable("domain_uuid");
|
||||||
|
|
@ -71,21 +74,6 @@ else
|
||||||
headers = {}
|
headers = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
function escape_csv(s)
|
|
||||||
if string.find(s, '[,"]') then
|
|
||||||
s = '"' .. string.gsub(s, '"', '""') .. '"'
|
|
||||||
end
|
|
||||||
return s
|
|
||||||
end
|
|
||||||
|
|
||||||
function to_csv(tt)
|
|
||||||
local s = ""
|
|
||||||
for _,p in ipairs(tt) do
|
|
||||||
s = s .. "," .. escape_csv(p)
|
|
||||||
end
|
|
||||||
return string.sub(s, 2)
|
|
||||||
end
|
|
||||||
|
|
||||||
--connect to the database
|
--connect to the database
|
||||||
local dbh = Database.new('system');
|
local dbh = Database.new('system');
|
||||||
|
|
||||||
|
|
@ -130,63 +118,47 @@ if (session and session:ready()) then
|
||||||
sip_from_user = session:getVariable("sip_from_user");
|
sip_from_user = session:getVariable("sip_from_user");
|
||||||
emergency_caller_id_name = session:getVariable("emergency_caller_id_name");
|
emergency_caller_id_name = session:getVariable("emergency_caller_id_name");
|
||||||
emergency_caller_id_number = session:getVariable("emergency_caller_id_number");
|
emergency_caller_id_number = session:getVariable("emergency_caller_id_number");
|
||||||
call_duration = session:getVariable("call_duration");
|
outbound_caller_id_number = session:getVariable("outbound_caller_id_number");
|
||||||
destination_number = session:getVariable("destination_number");
|
destination_number = session:getVariable("destination_number");
|
||||||
end
|
end
|
||||||
|
|
||||||
--domain level check
|
--set the defaults
|
||||||
result = {}
|
if (not emergency_caller_id_name) then emergency_caller_id_name = ''; end
|
||||||
local sql = "SELECT count(domain_setting_value) ";
|
if (not emergency_caller_id_number) then emergency_caller_id_number = '' end
|
||||||
sql = sql .. "AS total ";
|
|
||||||
sql = sql .. "FROM v_domain_settings ";
|
|
||||||
sql = sql .. "WHERE domain_uuid = :domain_uuid ";
|
|
||||||
sql = sql .. "AND domain_setting_category = :category ";
|
|
||||||
sql = sql .. "AND domain_setting_subcategory = :email_address ";
|
|
||||||
sql = sql .. "AND domain_setting_enabled = :status ";
|
|
||||||
|
|
||||||
local params = {domain_uuid = domain_uuid, category = 'emergency', email_address = 'email_address', status = 't'}
|
|
||||||
|
|
||||||
|
--no emergency emails found under domain, using default
|
||||||
|
local sql = "SELECT default_setting_value ";
|
||||||
|
sql = sql .. "FROM v_default_settings ";
|
||||||
|
sql = sql .. "WHERE default_setting_category = :category ";
|
||||||
|
sql = sql .. "AND default_setting_subcategory = :email_address ";
|
||||||
|
sql = sql .. "AND default_setting_enabled = :status ";
|
||||||
|
sql = sql .. "LIMIT 5 ";
|
||||||
|
local params = {category = 'emergency', email_address = 'email_address', status = 't'}
|
||||||
dbh:query(sql, params, function(result)
|
dbh:query(sql, params, function(result)
|
||||||
total = result.total;
|
for key,row in pairs(result) do
|
||||||
--no emergency emails found under domain, using default
|
table.insert(to, row);
|
||||||
if (total == 0 or total == nil) then
|
freeswitch.consoleLog("info", "[emergency] Inserted into table from default settings " .. row .. "\n");
|
||||||
to = {}
|
|
||||||
local sql = "SELECT default_setting_value ";
|
|
||||||
sql = sql .. "FROM v_default_settings ";
|
|
||||||
sql = sql .. "WHERE default_setting_category = :category ";
|
|
||||||
sql = sql .. "AND default_setting_subcategory = :email_address ";
|
|
||||||
sql = sql .. "AND default_setting_enabled = :status ";
|
|
||||||
sql = sql .. "LIMIT 5 ";
|
|
||||||
local params = {category = 'emergency', email_address = 'email_address', status = 't'}
|
|
||||||
dbh:query(sql, params, function(result)
|
|
||||||
for key,row in pairs(result) do
|
|
||||||
table.insert(to, row);
|
|
||||||
freeswitch.consoleLog("info", "[emergency] Inserted into table from default settings " .. row .. "\n");
|
|
||||||
end
|
|
||||||
--add some details
|
|
||||||
if (debug["sql"]) then
|
|
||||||
freeswitch.consoleLog("notice", "[emergency] SQL: " .. sql .. " result " .. result .. "\n");
|
|
||||||
end
|
|
||||||
end);
|
|
||||||
--domain level emails max 5
|
|
||||||
else if (tonumber(total) <= 5) then
|
|
||||||
to = {}
|
|
||||||
local sql = "SELECT domain_setting_value ";
|
|
||||||
sql = sql .. "FROM v_domain_settings ";
|
|
||||||
sql = sql .. "WHERE domain_uuid = :domain_uuid ";
|
|
||||||
sql = sql .. "AND domain_setting_category = :category ";
|
|
||||||
sql = sql .. "AND domain_setting_subcategory = :email_address ";
|
|
||||||
sql = sql .. "AND domain_setting_enabled = :status ";
|
|
||||||
local params = {domain_uuid = domain_uuid, category = 'emergency', email_address = 'email_address', status = 't'}
|
|
||||||
dbh:query(sql, params, function(result)
|
|
||||||
for key,row in pairs(result) do
|
|
||||||
table.insert(to, row);
|
|
||||||
freeswitch.consoleLog("info", "[template] Inserted into table " .. row .. "\n");
|
|
||||||
end
|
|
||||||
end);
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
--add some details
|
||||||
|
if (debug["sql"]) then
|
||||||
|
freeswitch.consoleLog("notice", "[emergency] SQL: " .. sql .. " result " .. result .. "\n");
|
||||||
|
end
|
||||||
|
end);
|
||||||
|
|
||||||
|
--domain level emails max 5
|
||||||
|
local sql = "SELECT domain_setting_value ";
|
||||||
|
sql = sql .. "FROM v_domain_settings ";
|
||||||
|
sql = sql .. "WHERE domain_uuid = :domain_uuid ";
|
||||||
|
sql = sql .. "AND domain_setting_category = :category ";
|
||||||
|
sql = sql .. "AND domain_setting_subcategory = :email_address ";
|
||||||
|
sql = sql .. "AND domain_setting_enabled = :status ";
|
||||||
|
sql = sql .. "LIMIT 5 ";
|
||||||
|
local params = {domain_uuid = domain_uuid, category = 'emergency', email_address = 'email_address', status = 't'}
|
||||||
|
dbh:query(sql, params, function(result)
|
||||||
|
for key,row in pairs(result) do
|
||||||
|
table.insert(to, row);
|
||||||
|
freeswitch.consoleLog("info", "[template] Inserted into table " .. row .. "\n");
|
||||||
|
end
|
||||||
end);
|
end);
|
||||||
|
|
||||||
--set event
|
--set event
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue