Add. Support DND feature via BLF key (#2606)
This commit is contained in:
parent
52642ea175
commit
64b1134482
|
|
@ -8,9 +8,13 @@
|
||||||
<action application="set" data="enabled=true"/>
|
<action application="set" data="enabled=true"/>
|
||||||
<action application="lua" data="do_not_disturb.lua"/>
|
<action application="lua" data="do_not_disturb.lua"/>
|
||||||
</condition>
|
</condition>
|
||||||
<condition field="destination_number" expression="^\*79$">
|
<condition field="destination_number" expression="^\*79$" break="on-true">
|
||||||
<action application="set" data="enabled=false"/>
|
<action application="set" data="enabled=false"/>
|
||||||
<action application="lua" data="do_not_disturb.lua"/>
|
<action application="lua" data="do_not_disturb.lua"/>
|
||||||
</condition>
|
</condition>
|
||||||
|
<condition field="destination_number" expression="^dnd\+${caller_id_number}$" break="on-true">
|
||||||
|
<action application="set" data="enabled=toggle"/>
|
||||||
|
<action application="lua" data="do_not_disturb.lua"/>
|
||||||
|
</condition>
|
||||||
</extension>
|
</extension>
|
||||||
</context>
|
</context>
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ local find_call_flow do
|
||||||
|
|
||||||
local find_call_flow_sql = [[select t1.call_flow_uuid, t1.call_flow_status
|
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
|
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)
|
function find_call_flow(user)
|
||||||
|
|
@ -18,8 +18,7 @@ function find_call_flow(user)
|
||||||
if not domain_name then return end
|
if not domain_name then return end
|
||||||
local dbh = Database.new('system')
|
local dbh = Database.new('system')
|
||||||
if not dbh then return end
|
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(find_call_flow_sql, {domain_name = domain_name, feature_code = ext})
|
||||||
local row = dbh:first_row(sql)
|
|
||||||
dbh:release()
|
dbh:release()
|
||||||
if not row then return end
|
if not row then return end
|
||||||
return row.call_flow_uuid, row.call_flow_status
|
return row.call_flow_uuid, row.call_flow_status
|
||||||
|
|
@ -27,6 +26,23 @@ end
|
||||||
|
|
||||||
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 service_name = "call_flow"
|
||||||
local pid_file = scripts_dir .. "/run/" .. service_name .. ".tmp"
|
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>')
|
log.warningf('Unknown service command: %s', command or '<NONE>')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- FS receive SUBSCRIBE to BLF from device
|
local protocols = {}
|
||||||
events:bind("PRESENCE_PROBE", function(self, name, event)
|
|
||||||
--handle only blf with `flow+` prefix
|
|
||||||
if event:getHeader('proto') ~= 'flow' then return end
|
|
||||||
|
|
||||||
|
protocols.flow = function(event)
|
||||||
local from, to = event:getHeader('from'), event:getHeader('to')
|
local from, to = event:getHeader('from'), event:getHeader('to')
|
||||||
local expires = tonumber(event:getHeader('expires'))
|
local expires = tonumber(event:getHeader('expires'))
|
||||||
if expires and expires > 0 then
|
if expires and expires > 0 then
|
||||||
|
|
@ -69,6 +83,32 @@ events:bind("PRESENCE_PROBE", function(self, name, event)
|
||||||
else
|
else
|
||||||
log.noticef("%s UNSUBSCRIBE from %s", from, to)
|
log.noticef("%s UNSUBSCRIBE from %s", from, to)
|
||||||
end
|
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)
|
end)
|
||||||
|
|
||||||
log.notice("start")
|
log.notice("start")
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@
|
||||||
--include config.lua
|
--include config.lua
|
||||||
require "resources.functions.config";
|
require "resources.functions.config";
|
||||||
|
|
||||||
|
local presence_in = require "resources.functions.presence_in"
|
||||||
|
|
||||||
--check if the session is ready
|
--check if the session is ready
|
||||||
if ( session:ready() ) then
|
if ( session:ready() ) then
|
||||||
--answer the call
|
--answer the call
|
||||||
|
|
@ -57,6 +59,7 @@
|
||||||
extension_uuid = session:getVariable("extension_uuid");
|
extension_uuid = session:getVariable("extension_uuid");
|
||||||
context = session:getVariable("context");
|
context = session:getVariable("context");
|
||||||
if (not context ) then context = 'default'; 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
|
||||||
default_language = session:getVariable("default_language");
|
default_language = session:getVariable("default_language");
|
||||||
|
|
@ -93,6 +96,9 @@
|
||||||
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;
|
||||||
|
if toggle then
|
||||||
|
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] extension "..row.extension.."\n");
|
||||||
--freeswitch.consoleLog("NOTICE", "[do_not_disturb] accountcode "..row.accountcode.."\n");
|
--freeswitch.consoleLog("NOTICE", "[do_not_disturb] accountcode "..row.accountcode.."\n");
|
||||||
end);
|
end);
|
||||||
|
|
@ -210,4 +216,14 @@
|
||||||
--end the call
|
--end the call
|
||||||
session:hangup();
|
session:hangup();
|
||||||
|
|
||||||
|
-- BLF for display DND status
|
||||||
|
local function dnd_blf(enabled, id, domain)
|
||||||
|
local user = string.format('dnd+%s@%s', id, domain)
|
||||||
|
presence_in.turn_lamp(enabled, user)
|
||||||
|
end
|
||||||
|
|
||||||
|
dnd_blf(enabled == "true", extension, domain_name)
|
||||||
|
if number_alias and #number_alias > 0 then
|
||||||
|
dnd_blf(enabled == "true", number_alias, domain_name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
require "resources.functions.split"
|
require "resources.functions.split"
|
||||||
|
local api = require "resources.functions.api"
|
||||||
|
local log = require "resources.functions.log".presence
|
||||||
|
|
||||||
local function turn_lamp(on, user, uuid)
|
local function turn_lamp(on, user, uuid)
|
||||||
|
log.debugf('turn_lamp: %s - %s(%s)', tostring(user), tostring(on), type(on))
|
||||||
|
|
||||||
local userid, domain, proto = split_first(user, "@", true)
|
local userid, domain, proto = split_first(user, "@", true)
|
||||||
proto, userid = split_first(userid, "+", true)
|
proto, userid = split_first(userid, "+", true)
|
||||||
if userid then
|
if userid then
|
||||||
|
|
@ -9,6 +13,7 @@ local function turn_lamp(on, user, uuid)
|
||||||
proto = "sip"
|
proto = "sip"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
uuid = uuid or api:execute('create_uuid')
|
||||||
|
|
||||||
local event = freeswitch.Event("PRESENCE_IN");
|
local event = freeswitch.Event("PRESENCE_IN");
|
||||||
event:addHeader("proto", proto);
|
event:addHeader("proto", proto);
|
||||||
|
|
@ -26,6 +31,9 @@ local function turn_lamp(on, user, uuid)
|
||||||
else
|
else
|
||||||
event:addHeader("answer-state", "terminated");
|
event:addHeader("answer-state", "terminated");
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- log.debug(event:serialize())
|
||||||
|
|
||||||
event:fire();
|
event:fire();
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue