From 9ff799cfe4143ea8a096dfeb082ff589220ce93a Mon Sep 17 00:00:00 2001 From: konradSC Date: Mon, 19 Nov 2018 17:39:54 -0500 Subject: [PATCH] BLF of agent status "agent+username@domain.com (#3860) * BLF of agent status "agent+username@domain.com Add the ability to monitor the availability status of a call center agent with "agent+agentname@domain.com". * Update index.lua Send notify to blf with "agent+agentname@domain.com" --- .../scripts/app/agent_status/index.lua | 11 +++++ resources/install/scripts/blf_subscribe.lua | 47 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/resources/install/scripts/app/agent_status/index.lua b/resources/install/scripts/app/agent_status/index.lua index 893aa9c7b9..45b0d02b4c 100644 --- a/resources/install/scripts/app/agent_status/index.lua +++ b/resources/install/scripts/app/agent_status/index.lua @@ -18,6 +18,8 @@ json = require "resources.functions.lunajson" end + local presence_in = require "resources.functions.presence_in" + --set the api api = freeswitch.API(); @@ -181,6 +183,15 @@ event:addHeader("answer-state", "confirmed"); event:fire(); end + + if (action == "login") then + blf_status = "false" + end + if string.find(agent_name, 'agent+', nil, true) ~= 1 then + presence_in.turn_lamp( blf_status, + 'agent+'..agent_name.."@"..domain_name + ); + end end --unauthorized diff --git a/resources/install/scripts/blf_subscribe.lua b/resources/install/scripts/blf_subscribe.lua index a5050cca70..4be98621bb 100644 --- a/resources/install/scripts/blf_subscribe.lua +++ b/resources/install/scripts/blf_subscribe.lua @@ -9,6 +9,7 @@ end require "resources.functions.config" require "resources.functions.split" +require "resources.functions.trim"; local log = require "resources.functions.log"[service_name] local presence_in = require "resources.functions.presence_in" @@ -82,6 +83,34 @@ end end +local find_agent_status do + +local find_agent_uuid_sql = [[select t1.call_center_agent_uuid +from v_call_center_agents t1 inner join v_domains t2 on t1.domain_uuid = t2.domain_uuid +where t2.domain_name = :domain_name and t1.agent_name = :agent_name +]] + +function find_agent_status(user) + local agent_name, domain_name = split_first(user, '@', true) + local _, short = split_first(agent_name, '+', true) + if not domain_name then return end + local dbh = Database.new('system') + if not dbh then return end + local row = dbh:first_row(find_agent_uuid_sql, { + domain_name = domain_name, agent_name = agent_name + }) + dbh:release() + if not row then return end + if row.call_center_agent_uuid then + local cmd = "callcenter_config agent get status "..row.call_center_agent_uuid..""; + freeswitch.consoleLog("notice", "[user status][login] "..cmd.."\n"); + user_status = trim(api:executeString(cmd)); + end + return row.call_center_agent_uuid, user_status +end + +end + local protocols = {} protocols.flow = function(event) @@ -140,6 +169,24 @@ protocols.forward = function(event) end end +protocols.agent = 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 call_center_agent_uuid, agent_status = find_agent_status(user) + if agent_status then + log.noticef("Find agent: %s status: %s", user, tostring(agent_status)) + presence_in.turn_lamp(agent_status == "Available", to) + else + log.warningf("Can not find agent status: %s", to) + end + else + log.noticef("%s UNSUBSCRIBE from %s", from, to) + end +end + if proto ~= 'all' then for name in pairs(protocols) do if proto ~= name then