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
|
||||
api = freeswitch.API();
|
||||
|
||||
--prepare the email to address
|
||||
to = {}
|
||||
|
||||
--get sessions info
|
||||
if (session and session:ready()) then
|
||||
domain_uuid = session:getVariable("domain_uuid");
|
||||
|
|
@ -71,21 +74,6 @@ else
|
|||
headers = {}
|
||||
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
|
||||
local dbh = Database.new('system');
|
||||
|
||||
|
|
@ -130,63 +118,47 @@ if (session and session:ready()) then
|
|||
sip_from_user = session:getVariable("sip_from_user");
|
||||
emergency_caller_id_name = session:getVariable("emergency_caller_id_name");
|
||||
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");
|
||||
end
|
||||
|
||||
--domain level check
|
||||
result = {}
|
||||
local sql = "SELECT count(domain_setting_value) ";
|
||||
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'}
|
||||
--set the defaults
|
||||
if (not emergency_caller_id_name) then emergency_caller_id_name = ''; end
|
||||
if (not emergency_caller_id_number) then emergency_caller_id_number = '' end
|
||||
|
||||
--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)
|
||||
total = result.total;
|
||||
--no emergency emails found under domain, using default
|
||||
if (total == 0 or total == nil) then
|
||||
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
|
||||
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
|
||||
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);
|
||||
|
||||
--set event
|
||||
|
|
|
|||
Loading…
Reference in New Issue