Update index.lua
This commit is contained in:
parent
093f9d3f0a
commit
e4ec48eb48
|
|
@ -5,6 +5,9 @@
|
||||||
digit_timeout = 5000;
|
digit_timeout = 5000;
|
||||||
debug["sql"] = true;
|
debug["sql"] = true;
|
||||||
|
|
||||||
|
--general functions
|
||||||
|
require "resources.functions.trim";
|
||||||
|
|
||||||
--connect to the database
|
--connect to the database
|
||||||
local Database = require "resources.functions.database";
|
local Database = require "resources.functions.database";
|
||||||
dbh = Database.new('system');
|
dbh = Database.new('system');
|
||||||
|
|
@ -104,74 +107,80 @@
|
||||||
|
|
||||||
--get the user_uuid
|
--get the user_uuid
|
||||||
if (agent_authorized == 'true') then
|
if (agent_authorized == 'true') then
|
||||||
local sql = "SELECT user_status FROM v_users ";
|
|
||||||
sql = sql .. "WHERE user_uuid = :user_uuid ";
|
|
||||||
sql = sql .. "AND domain_uuid = :domain_uuid ";
|
|
||||||
local params = {user_uuid = user_uuid, domain_uuid = domain_uuid};
|
|
||||||
if (debug["sql"]) then
|
|
||||||
freeswitch.consoleLog("notice", "[call_center] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
|
|
||||||
end
|
|
||||||
dbh:query(sql, params, function(row)
|
|
||||||
--get the user info
|
|
||||||
user_status = row.user_status;
|
|
||||||
if (user_status == "Available") then
|
|
||||||
action = "logout";
|
|
||||||
status = 'Logged Out';
|
|
||||||
else
|
|
||||||
action = "login";
|
|
||||||
status = 'Available';
|
|
||||||
end
|
|
||||||
|
|
||||||
--show the status in the log
|
--get the agent status from mod_callcenter
|
||||||
freeswitch.consoleLog("NOTICE", "[call_center] user_status: ".. status .. "\n");
|
cmd = "callcenter_config agent get status "..agent_uuid.."";
|
||||||
|
freeswitch.consoleLog("notice", "[user status][login] "..cmd.."\n");
|
||||||
|
user_status = trim(api:executeString(cmd));
|
||||||
|
|
||||||
--set the user_status in the users table
|
--get the user info
|
||||||
local sql = "UPDATE v_users SET ";
|
if (user_status == "Available") then
|
||||||
sql = sql .. "user_status = :status ";
|
action = "logout";
|
||||||
|
status = 'Logged Out';
|
||||||
|
else
|
||||||
|
action = "login";
|
||||||
|
status = 'Available';
|
||||||
|
end
|
||||||
|
|
||||||
|
--send a login or logout to mod_callcenter
|
||||||
|
cmd = "callcenter_config agent set status "..agent_uuid.." '"..status.."'";
|
||||||
|
freeswitch.consoleLog("notice", "[user status][login] "..cmd.."\n");
|
||||||
|
result = api:executeString(cmd);
|
||||||
|
|
||||||
|
--update the user status
|
||||||
|
if (user_uuid ~= nil and user_uuid ~= '') then
|
||||||
|
local sql = "SELECT user_status FROM v_users ";
|
||||||
sql = sql .. "WHERE user_uuid = :user_uuid ";
|
sql = sql .. "WHERE user_uuid = :user_uuid ";
|
||||||
local params = {status = status, user_uuid = user_uuid};
|
sql = sql .. "AND domain_uuid = :domain_uuid ";
|
||||||
|
local params = {user_uuid = user_uuid, domain_uuid = domain_uuid};
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[call_center] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
|
freeswitch.consoleLog("notice", "[call_center] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
|
||||||
end
|
end
|
||||||
dbh:query(sql, params);
|
dbh:query(sql, params, function(row)
|
||||||
|
|
||||||
--send a login or logout to mod_callcenter
|
--set the user_status in the users table
|
||||||
cmd = "callcenter_config agent set status "..agent_uuid.." '"..status.."'";
|
local sql = "UPDATE v_users SET ";
|
||||||
freeswitch.consoleLog("notice", "[user status][login] "..cmd.."\n");
|
sql = sql .. "user_status = :status ";
|
||||||
result = api:executeString(cmd);
|
sql = sql .. "WHERE user_uuid = :user_uuid ";
|
||||||
|
local params = {status = status, user_uuid = user_uuid};
|
||||||
|
if (debug["sql"]) then
|
||||||
|
freeswitch.consoleLog("notice", "[call_center] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
|
||||||
|
end
|
||||||
|
dbh:query(sql, params);
|
||||||
|
end);
|
||||||
|
end
|
||||||
|
|
||||||
--set the presence to terminated - turn the lamp off:
|
--set the presence to terminated - turn the lamp off:
|
||||||
if (action == "logout") then
|
if (action == "logout") then
|
||||||
event = freeswitch.Event("PRESENCE_IN");
|
event = freeswitch.Event("PRESENCE_IN");
|
||||||
event:addHeader("proto", "sip");
|
event:addHeader("proto", "sip");
|
||||||
event:addHeader("event_type", "presence");
|
event:addHeader("event_type", "presence");
|
||||||
event:addHeader("alt_event_type", "dialog");
|
event:addHeader("alt_event_type", "dialog");
|
||||||
event:addHeader("Presence-Call-Direction", "outbound");
|
event:addHeader("Presence-Call-Direction", "outbound");
|
||||||
event:addHeader("state", "Active (1 waiting)");
|
event:addHeader("state", "Active (1 waiting)");
|
||||||
event:addHeader("from", agent_name.."@"..domain_name);
|
event:addHeader("from", agent_name.."@"..domain_name);
|
||||||
event:addHeader("login", agent_name.."@"..domain_name);
|
event:addHeader("login", agent_name.."@"..domain_name);
|
||||||
event:addHeader("unique-id", user_uuid);
|
event:addHeader("unique-id", agent_uuid);
|
||||||
event:addHeader("answer-state", "terminated");
|
event:addHeader("answer-state", "terminated");
|
||||||
event:fire();
|
event:fire();
|
||||||
end
|
end
|
||||||
|
|
||||||
--set presence in - turn lamp on
|
--set presence in - turn lamp on
|
||||||
if (action == "login") then
|
if (action == "login") then
|
||||||
event = freeswitch.Event("PRESENCE_IN");
|
event = freeswitch.Event("PRESENCE_IN");
|
||||||
event:addHeader("proto", "sip");
|
event:addHeader("proto", "sip");
|
||||||
event:addHeader("login", agent_name.."@"..domain_name);
|
event:addHeader("login", agent_name.."@"..domain_name);
|
||||||
event:addHeader("from", agent_name.."@"..domain_name);
|
event:addHeader("from", agent_name.."@"..domain_name);
|
||||||
event:addHeader("status", "Active (1 waiting)");
|
event:addHeader("status", "Active (1 waiting)");
|
||||||
event:addHeader("rpid", "unknown");
|
event:addHeader("rpid", "unknown");
|
||||||
event:addHeader("event_type", "presence");
|
event:addHeader("event_type", "presence");
|
||||||
event:addHeader("alt_event_type", "dialog");
|
event:addHeader("alt_event_type", "dialog");
|
||||||
event:addHeader("event_count", "1");
|
event:addHeader("event_count", "1");
|
||||||
event:addHeader("unique-id", user_uuid);
|
event:addHeader("unique-id", agent_uuid);
|
||||||
event:addHeader("Presence-Call-Direction", "outbound");
|
event:addHeader("Presence-Call-Direction", "outbound");
|
||||||
event:addHeader("answer-state", "confirmed");
|
event:addHeader("answer-state", "confirmed");
|
||||||
event:fire();
|
event:fire();
|
||||||
end
|
end
|
||||||
end);
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--unauthorized
|
--unauthorized
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue