Lua script app/user_status updated to use agent_id and agent_password.
This commit is contained in:
parent
e5421c26c0
commit
cbd41428c8
|
|
@ -27,8 +27,8 @@
|
|||
domain_name = session:getVariable("domain_name");
|
||||
context = session:getVariable("context");
|
||||
uuid = session:get_uuid();
|
||||
sip_from_user = session:getVariable("sip_from_user");
|
||||
sip_from_host = session:getVariable("sip_from_host");
|
||||
agent_id = session:getVariable("agent_id");
|
||||
agent_password = session:getVariable("agent_password");
|
||||
|
||||
--set the sounds path for the language, dialect and voice
|
||||
default_language = session:getVariable("default_language");
|
||||
|
|
@ -43,105 +43,58 @@
|
|||
sounds_dir = session:getVariable("sounds_dir");
|
||||
sounds_dir = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice;
|
||||
|
||||
--set the user_id from the user if its a local call
|
||||
require_user_id = true;
|
||||
require_pin_number = true;
|
||||
if (sip_from_host == domain_name) then
|
||||
user_id = sip_from_user;
|
||||
require_user_id = false;
|
||||
require_pin_number = false;
|
||||
end
|
||||
|
||||
--get the user_id from the caller
|
||||
if (require_user_id) then
|
||||
--get the agent_id from the caller
|
||||
if (agent_id == nil) then
|
||||
min_digits = 2;
|
||||
max_digits = 20;
|
||||
max_tries = 3;
|
||||
user_id = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_id:#", "", "\\d+");
|
||||
agent_id = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_id:#", "", "\\d+");
|
||||
end
|
||||
|
||||
--get the pin number from the caller
|
||||
if (require_pin_number) then
|
||||
if (agent_password == nil) then
|
||||
min_digits = 3;
|
||||
max_digits = 12;
|
||||
pin_number = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
|
||||
max_digits = 20;
|
||||
max_tries = 3;
|
||||
agent_password = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
|
||||
end
|
||||
|
||||
--get the voicemail password
|
||||
if (require_pin_number) then
|
||||
sql = "SELECT * FROM v_voicemails ";
|
||||
--set default as access denied
|
||||
authorized = 'false';
|
||||
|
||||
--get the agent password
|
||||
sql = "SELECT * FROM v_call_center_agents ";
|
||||
sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .."' ";
|
||||
sql = sql .. "AND voicemail_id = '" .. user_id .."' ";
|
||||
sql = sql .. "AND agent_id = '" .. agent_id .."' ";
|
||||
sql = sql .. "AND agent_password = '" .. agent_password .."' ";
|
||||
freeswitch.consoleLog("notice", "[user status] sql: " .. sql .. "\n");
|
||||
dbh:query(sql, function(row)
|
||||
voicemail_password = row.voicemail_password;
|
||||
end);
|
||||
end
|
||||
|
||||
--show the results
|
||||
if (context) then
|
||||
freeswitch.consoleLog("notice", "[call center][login] context: " .. context .. "\n");
|
||||
end
|
||||
freeswitch.consoleLog("notice", "[call center][login] voicemail_id: " .. user_id .. "\n");
|
||||
if (pin_number) then
|
||||
freeswitch.consoleLog("notice", "[call center][login] pin_number: " .. pin_number .. "\n");
|
||||
end
|
||||
if (voicemail_password) then
|
||||
freeswitch.consoleLog("notice", "[call center][login] voicemail_password: " .. voicemail_password .. "\n");
|
||||
end
|
||||
|
||||
--check to see if the pin number is correct
|
||||
if (require_pin_number) then
|
||||
if (pin_number) then
|
||||
if (voicemail_password == pin_number) then
|
||||
--access granted
|
||||
access = 1;
|
||||
else
|
||||
--access denied
|
||||
access = 0;
|
||||
end
|
||||
else
|
||||
--access denied
|
||||
access = 0;
|
||||
end
|
||||
else
|
||||
access = 1;
|
||||
end
|
||||
|
||||
--show the results
|
||||
if (access == 0) then
|
||||
freeswitch.consoleLog("notice", "[call center][login] access denied\n");
|
||||
end
|
||||
if (access == 1) then
|
||||
freeswitch.consoleLog("notice", "[call center][login] access granted\n");
|
||||
end
|
||||
|
||||
--use the voicemail_id to get the list of users assigned to an extension
|
||||
sql = "SELECT extension_uuid FROM v_extensions ";
|
||||
sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .."' ";
|
||||
sql = sql .. "AND (extension = '" .. user_id .."' ";
|
||||
sql = sql .. "or number_alias = '" .. user_id .."') ";
|
||||
dbh:query(sql, function(row)
|
||||
extension_uuid = row.extension_uuid;
|
||||
--set the variables
|
||||
agent_name = row.agent_name;
|
||||
agent_id = row.agent_id;
|
||||
--authorize the user
|
||||
authorized = 'true';
|
||||
end);
|
||||
|
||||
--set the status
|
||||
if (action == "login") then
|
||||
status = 'Available';
|
||||
--show the results
|
||||
if (agent_id) then
|
||||
freeswitch.consoleLog("notice", "[user status][login] agent_id: " .. agent_id .. " authorized " .. authorized .. "\n");
|
||||
end
|
||||
if (action == "logout") then
|
||||
status = 'Logged Out';
|
||||
if (agent_password and debug["password"]) then
|
||||
freeswitch.consoleLog("notice", "[user status][login] agent_password: " .. agent_password .. "\n");
|
||||
end
|
||||
|
||||
--get the dial_string, and extension_uuid
|
||||
sql = "SELECT u.user_uuid, u.username, u.user_status FROM v_extension_users as e, v_users as u ";
|
||||
sql = sql .. "WHERE e.extension_uuid = '" .. extension_uuid .."' ";
|
||||
sql = sql .. "AND e.user_uuid = u.user_uuid ";
|
||||
--get the user_uuid
|
||||
if (authorized == 'true') then
|
||||
sql = "SELECT user_uuid, user_status FROM v_users ";
|
||||
sql = sql .. "WHERE username = '".. agent_name .."' ";
|
||||
sql = sql .. "AND domain_uuid = '" .. domain_uuid .."' ";
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("NOTICE", "[call_center] sql: ".. sql .. "\n");
|
||||
end
|
||||
dbh:query(sql, function(row)
|
||||
--get the user info
|
||||
user_uuid = row.user_uuid;
|
||||
username = row.username;
|
||||
user_status = row.user_status;
|
||||
if (user_status == "Available") then
|
||||
action = "logout";
|
||||
|
|
@ -150,6 +103,8 @@
|
|||
action = "login";
|
||||
status = 'Available';
|
||||
end
|
||||
|
||||
--show the status in the log
|
||||
freeswitch.consoleLog("NOTICE", "[call_center] user_status: ".. status .. "\n");
|
||||
|
||||
--set the user_status in the users table
|
||||
|
|
@ -162,8 +117,8 @@
|
|||
dbh:query(sql);
|
||||
|
||||
--send a login or logout to mod_callcenter
|
||||
cmd = "callcenter_config agent set status "..username.."@"..domain_name.." '"..status.."'";
|
||||
freeswitch.consoleLog("notice", "[call center][login] "..cmd.."\n");
|
||||
cmd = "callcenter_config agent set status "..agent_name.."@"..domain_name.." '"..status.."'";
|
||||
freeswitch.consoleLog("notice", "[user status][login] "..cmd.."\n");
|
||||
result = api:executeString(cmd);
|
||||
|
||||
--set the presence to terminated - turn the lamp off:
|
||||
|
|
@ -174,18 +129,19 @@
|
|||
event:addHeader("alt_event_type", "dialog");
|
||||
event:addHeader("Presence-Call-Direction", "outbound");
|
||||
event:addHeader("state", "Active (1 waiting)");
|
||||
event:addHeader("from", username.."@"..domain_name);
|
||||
event:addHeader("login", username.."@"..domain_name);
|
||||
event:addHeader("from", agent_name.."@"..domain_name);
|
||||
event:addHeader("login", agent_name.."@"..domain_name);
|
||||
event:addHeader("unique-id", user_uuid);
|
||||
event:addHeader("answer-state", "terminated");
|
||||
event:fire();
|
||||
end
|
||||
|
||||
--set presence in - turn lamp on
|
||||
if (action == "login") then
|
||||
event = freeswitch.Event("PRESENCE_IN");
|
||||
event:addHeader("proto", "sip");
|
||||
event:addHeader("login", username.."@"..domain_name);
|
||||
event:addHeader("from", username.."@"..domain_name);
|
||||
event:addHeader("login", agent_name.."@"..domain_name);
|
||||
event:addHeader("from", agent_name.."@"..domain_name);
|
||||
event:addHeader("status", "Active (1 waiting)");
|
||||
event:addHeader("rpid", "unknown");
|
||||
event:addHeader("event_type", "presence");
|
||||
|
|
@ -197,6 +153,13 @@
|
|||
event:fire();
|
||||
end
|
||||
end);
|
||||
end
|
||||
|
||||
--unauthorized
|
||||
if (authorized == 'false') then
|
||||
result = session:streamFile(sounds_dir.."/voicemail/vm-fail_auth.wav");
|
||||
status = "Invalid ID or Password";
|
||||
end
|
||||
|
||||
--send the status to the display
|
||||
if (status ~= nil) then
|
||||
|
|
|
|||
Loading…
Reference in New Issue