Merge pull request #1164 from moteus/intercept_enterprise_group

Fix. Intercept enterprise ring group.
This commit is contained in:
FusionPBX 2015-09-24 15:45:08 -06:00
commit d4e8be5b75
4 changed files with 63 additions and 7 deletions

View File

@ -27,6 +27,8 @@
-- Mark J Crane <markjcrane@fusionpbx.com>
-- Luis Daniel Lucio Qurioz <dlucio@okay.com.mx>
local log = require "resources.functions.log".ring_group
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
@ -618,10 +620,23 @@
end
freeswitch.consoleLog("NOTICE", "[ring group] app_data: "..app_data.."\n");
session:execute("bridge", app_data);
-- log.noticef("bridge done: originate_disposition:%s answered:%s ready:%s bridged:%s", session:getVariable("originate_disposition"), session:answered() and "true" or "false", session:ready() and "true" or "false", session:bridged() and "true" or "false")
end
--timeout destination
if (app_data ~= nil) then
if ring_group_strategy == "enterprise"
and ( true
--- I see 2 errors here `failure` and `PICKED_OFF`
--- but they be more. I think check `answered` is enough.
-- or session:getVariable("originate_disposition") == "failure"
-- or session:getVariable("originate_disposition") == "PICKED_OFF"
)
and session:answered() then
-- for enterprise calls when intercept we get "failure" but session answered
return
end
if (session:getVariable("originate_disposition") == "ALLOTTED_TIMEOUT"
or session:getVariable("originate_disposition") == "NO_ANSWER"
or session:getVariable("originate_disposition") == "NO_USER_RESPONSE"

View File

@ -48,6 +48,7 @@
--add the function
require "resources.functions.trim";
require "resources.functions.channel_utils";
--exits the script if we didn't connect properly
assert(dbh:connected());
@ -119,7 +120,7 @@ if ( session:ready() ) then
callee_num = '';
--check the database to get the uuid of a ringing call
sql = "select call_uuid as uuid, hostname, callee_num, ip_addr from channels ";
sql = "select uuid, call_uuid, hostname, callee_num, ip_addr from channels ";
sql = sql .. "where callstate in ('RINGING', 'EARLY') ";
--sql = sql .. "AND direction = 'outbound' ";
if (extension) then
@ -132,11 +133,18 @@ if ( session:ready() ) then
if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "sql "..sql.."\n");
end
dbh:query(sql, function(result)
dbh:query(sql, function(result)
--for key, val in pairs(result) do
-- freeswitch.consoleLog("NOTICE", "result "..key.." "..val.."\n");
--end
uuid = result.uuid;
if result.uuid == result.call_uuid then
uuid = channel_variable(result.uuid, 'ent_originate_aleg_uuid') or
channel_variable(result.uuid, 'cc_member_session_uuid') or
channel_variable(result.uuid, 'fifo_bridge_uuid') or
result.uuid
else
uuid = result.call_uuid;
end
call_hostname = result.hostname;
callee_num = result.callee_num;
end);

View File

@ -35,11 +35,19 @@
--add the function
require "resources.functions.explode";
require "resources.functions.trim";
require "resources.functions.channel_utils";
--prepare the api object
api = freeswitch.API();
--connect to the database
require "resources.functions.database_handle";
dbh = database_handle('system');
--get the hostname
hostname = trim(api:execute("switchname", ""));
--check if the session is ready
if ( session:ready() ) then
--answer the session
@ -163,7 +171,7 @@
--check the database to get the uuid of a ringing call
call_hostname = "";
sql = "SELECT call_uuid AS uuid, hostname, ip_addr FROM channels ";
sql = "SELECT uuid, call_uuid, hostname, ip_addr FROM channels ";
sql = sql .. "WHERE callstate in ('RINGING', 'EARLY') ";
--sql = sql .. "AND direction = 'outbound' ";
sql = sql .. "AND (";
@ -189,14 +197,19 @@
--for key, val in pairs(row) do
-- freeswitch.consoleLog("NOTICE", "row "..key.." "..val.."\n");
--end
uuid = row.uuid;
if row.uuid == row.call_uuid then
uuid = channel_variable(row.uuid, 'ent_originate_aleg_uuid') or
channel_variable(row.uuid, 'cc_member_session_uuid') or
channel_variable(row.uuid, 'fifo_bridge_uuid') or
row.uuid
else
uuid = row.call_uuid;
end
call_hostname = row.hostname;
ip_addr = row.ip_addr;
end);
end
--get the hostname
hostname = freeswitch.getGlobalVariable("hostname");
freeswitch.consoleLog("NOTICE", "Hostname:"..hostname.." Call Hostname:"..call_hostname.."\n");
--intercept a call that is ringing

View File

@ -0,0 +1,20 @@
local api = api or freeswitch.API()
function channel_variable(uuid, name)
local result = api:executeString("uuid_getvar " .. uuid .. " " .. name)
if result:sub(1, 4) == '-ERR' then return nil, result end
if result == '_undef_' then return false end
return result
end
function channel_evalute(uuid, cmd)
local result = api:executeString("eval uuid:" .. uuid .. " " .. cmd)
if result:sub(1, 4) == '-ERR' then return nil, result end
if result == '_undef_' then return false end
return result
end