Add. Support DND feature via BLF key (#2606)

This commit is contained in:
Alexey Melnichuk
2017-05-29 18:50:20 +03:00
committed by FusionPBX
parent 71f681496b
commit a7d58e14c7
4 changed files with 76 additions and 8 deletions

View File

@@ -10,7 +10,7 @@ local find_call_flow do
local find_call_flow_sql = [[select t1.call_flow_uuid, t1.call_flow_status
from v_call_flows t1 inner join v_domains t2 on t1.domain_uuid = t2.domain_uuid
where t2.domain_name = '%s' and t1.call_flow_feature_code = '%s'
where t2.domain_name = :domain_name and t1.call_flow_feature_code = :feature_code
]]
function find_call_flow(user)
@@ -18,8 +18,7 @@ function find_call_flow(user)
if not domain_name then return end
local dbh = Database.new('system')
if not dbh then return end
local sql = string.format(find_call_flow_sql, dbh:escape(domain_name), dbh:escape(ext))
local row = dbh:first_row(sql)
local row = dbh:first_row(find_call_flow_sql, {domain_name = domain_name, feature_code = ext})
dbh:release()
if not row then return end
return row.call_flow_uuid, row.call_flow_status
@@ -27,6 +26,23 @@ end
end
local find_dnd do
local find_dnd_sql = [[select t1.do_not_disturb
from v_extensions t1 inner join v_domains t2 on t1.domain_uuid = t2.domain_uuid
where t2.domain_name = :domain_name and (t1.extension = :extension or t1.number_alias=:extension)]]
find_dnd = function(user)
local ext, domain_name = split_first(user, '@', true)
if not domain_name then return end
local dbh = Database.new('system')
if not dbh then return end
local dnd = dbh:first_value(find_dnd_sql, {domain_name = domain_name, extension = ext})
dbh:release()
return dnd
end
end
local service_name = "call_flow"
local pid_file = scripts_dir .. "/run/" .. service_name .. ".tmp"
@@ -51,11 +67,9 @@ events:bind("CUSTOM::fusion::service::control", function(self, name, event)
log.warningf('Unknown service command: %s', command or '<NONE>')
end)
-- FS receive SUBSCRIBE to BLF from device
events:bind("PRESENCE_PROBE", function(self, name, event)
--handle only blf with `flow+` prefix
if event:getHeader('proto') ~= 'flow' then return end
local protocols = {}
protocols.flow = function(event)
local from, to = event:getHeader('from'), event:getHeader('to')
local expires = tonumber(event:getHeader('expires'))
if expires and expires > 0 then
@@ -69,6 +83,32 @@ events:bind("PRESENCE_PROBE", function(self, name, event)
else
log.noticef("%s UNSUBSCRIBE from %s", from, to)
end
end
protocols.dnd = function(event)
local from, to = event:getHeader('from'), event:getHeader('to')
local expires = tonumber(event:getHeader('expires'))
if expires and expires > 0 then
local proto, user = split_first(to, '+', true)
user = user or proto
local dnd_status = find_dnd(user)
if dnd_status then
log.noticef("Find DND: %s staus: %s", to, tostring(dnd_status))
presence_in.turn_lamp(dnd_status == "true", to)
else
log.warningf("Can not find DND: %s", to)
end
else
log.noticef("%s UNSUBSCRIBE from %s", from, to)
end
end
-- FS receive SUBSCRIBE to BLF from device
events:bind("PRESENCE_PROBE", function(self, name, event)
local proto = event:getHeader('proto')
local handler = proto and protocols[proto]
if not handler then return end
return handler(event)
end)
log.notice("start")