Feature code call forward *72 on, *73 off, *74 request id and password toggle on/off

This commit is contained in:
Mark Crane
2014-08-22 07:36:07 +00:00
parent 52907729d2
commit ca66aa8214
+119 -58
View File
@@ -56,10 +56,10 @@
dofile(config()); dofile(config());
--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
session:answer(); session:answer();
--get the variables --get the variables
enabled = session:getVariable("enabled"); enabled = session:getVariable("enabled");
pin_number = session:getVariable("pin_number"); pin_number = session:getVariable("pin_number");
@@ -69,7 +69,8 @@
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
request_id = session:getVariable("request_id");
--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");
default_dialect = session:getVariable("default_dialect"); default_dialect = session:getVariable("default_dialect");
@@ -77,37 +78,93 @@
if (not default_language) then default_language = 'en'; end if (not default_language) then default_language = 'en'; end
if (not default_dialect) then default_dialect = 'us'; end if (not default_dialect) then default_dialect = 'us'; end
if (not default_voice) then default_voice = 'callie'; end if (not default_voice) then default_voice = 'callie'; end
--a moment to sleep --a moment to sleep
session:sleep(1000); session:sleep(1000);
--connect to the database --connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua"); dofile(scripts_dir.."/resources/functions/database_handle.lua");
dbh = database_handle('system'); dbh = database_handle('system');
--determine whether to update the dial string --request id is true
sql = "select * from v_extensions "; if (request_id == "true") then
sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; --unset extension uuid
sql = sql .. "and extension_uuid = '"..extension_uuid.."' "; extension_uuid = nil;
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[call_forward] "..sql.."\n"); --get the id
if (session:ready()) then
min_digits = 2;
max_digits = 20;
id = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_id:#", "", "\\d+");
end
--get the pin number
if (session:ready()) then
min_digits = 3;
max_digits = 20;
caller_pin_number = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
end
--check to see if the pin number is correct
if (session:ready()) then
sql = "SELECT * FROM v_voicemails ";
sql = sql .. "WHERE domain_uuid = '" .. domain_uuid .."' ";
sql = sql .. "AND voicemail_id = '" .. id .."' ";
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[call_forward] "..sql .."\n");
end
dbh:query(sql, function(row)
voicemail_password = row.voicemail_password;
--freeswitch.consoleLog("notice", "[call_forward] "..voicemail_password .."\n");
end);
if (voicemail_password ~= caller_pin_number) then
--access denied
session:streamFile("phrase:voicemail_fail_auth:#");
session:hangup("NORMAL_CLEARING");
end
end
end end
status = dbh:query(sql, function(row)
extension = row.extension; --determine whether to update the dial string
number_alias = row.number_alias; if (session:ready()) then
accountcode = row.accountcode; sql = "select * from v_extensions ";
follow_me_uuid = row.follow_me_uuid; sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
--freeswitch.consoleLog("NOTICE", "[call forward] extension "..row.extension.."\n"); if (extension_uuid ~= nil) then
--freeswitch.consoleLog("NOTICE", "[call forward] accountcode "..row.accountcode.."\n"); sql = sql .. "and extension_uuid = '"..extension_uuid.."' ";
end); else
sql = sql .. "and (extension = '"..id.."' or number_alias = '"..id.."') ";
--set the variables end
if (enabled == "true") then if (debug["sql"]) then
freeswitch.consoleLog("notice", "[call_forward] "..sql.."\n");
end
status = dbh:query(sql, function(row)
extension_uuid = row.extension_uuid;
extension = row.extension;
number_alias = row.number_alias;
accountcode = row.accountcode;
forward_all_enabled = row.forward_all_enabled;
follow_me_uuid = row.follow_me_uuid;
--freeswitch.consoleLog("NOTICE", "[call forward] extension "..row.extension.."\n");
--freeswitch.consoleLog("NOTICE", "[call forward] accountcode "..row.accountcode.."\n");
end);
end
--toggle enabled
if (session:ready() and enabled == "toggle") then
if (forward_all_enabled == "true") then
enabled = "false";
else
enabled = "true";
end
end
--get the forward destination
if (session:ready() and enabled == "true" or enabled == "toggle") then
forward_all_destination = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-enter_destination_telephone_number.wav", "", "\\d+"); forward_all_destination = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-enter_destination_telephone_number.wav", "", "\\d+");
end end
--set the dial string --set the dial string
if (enabled == "true") then if (session:ready() and enabled == "true") then
dial_string = "{presence_id="..forward_all_destination.."@"..domain_name; dial_string = "{presence_id="..forward_all_destination.."@"..domain_name;
dial_string = dial_string .. ",instant_ringback=true"; dial_string = dial_string .. ",instant_ringback=true";
dial_string = dial_string .. ",domain_uuid="..domain_uuid; dial_string = dial_string .. ",domain_uuid="..domain_uuid;
@@ -118,7 +175,7 @@
dial_string = dial_string .. ",accountcode="..accountcode; dial_string = dial_string .. ",accountcode="..accountcode;
end end
dial_string = dial_string .. "}"; dial_string = dial_string .. "}";
cmd = "user_exists id ".. forward_all_destination .." "..domain_name; cmd = "user_exists id ".. forward_all_destination .." "..domain_name;
user_exists = trim(api:executeString(cmd)); user_exists = trim(api:executeString(cmd));
if (user_exists) then if (user_exists) then
@@ -127,25 +184,25 @@
dial_string = dial_string .. "loopback/"..forward_all_destination; dial_string = dial_string .. "loopback/"..forward_all_destination;
end end
end end
--set call forward --set call forward
if (enabled == "true") then if (session:ready() and enabled == "true") then
--set forward_all_enabled --set forward_all_enabled
forward_all_enabled = "true"; forward_all_enabled = "true";
--notify the caller --notify the caller
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_set.wav"); session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_set.wav");
end end
--unset call forward --unset call forward
if (enabled == "false") then if (session:ready() and enabled == "false") then
--set forward_all_enabled --set forward_all_enabled
forward_all_enabled = "false"; forward_all_enabled = "false";
--notify the caller --notify the caller
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_cancelled.wav"); session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-call_forwarding_has_been_cancelled.wav");
end end
--disable the follow me --disable the follow me
if (enabled == "true" and follow_me_uuid ~= nil) then if (session:ready() and enabled == "true" and follow_me_uuid ~= nil) then
sql = "update v_follow_me set "; sql = "update v_follow_me set ";
sql = sql .. "follow_me_enabled = 'false' "; sql = sql .. "follow_me_enabled = 'false' ";
sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
@@ -155,33 +212,37 @@
end end
dbh:query(sql); dbh:query(sql);
end end
--update the extension --update the extension
sql = "update v_extensions set "; if (session:ready()) then
if (enabled == "true") then sql = "update v_extensions set ";
sql = sql .. "forward_all_destination = '"..forward_all_destination.."', "; if (enabled == "true") then
sql = sql .. "dial_string = '"..dial_string.."', "; sql = sql .. "forward_all_destination = '"..forward_all_destination.."', ";
sql = sql .. "do_not_disturb = 'false', "; sql = sql .. "dial_string = '"..dial_string.."', ";
else sql = sql .. "do_not_disturb = 'false', ";
sql = sql .. "dial_string = null, "; else
sql = sql .. "dial_string = null, ";
end
sql = sql .. "forward_all_enabled = '"..forward_all_enabled.."' ";
sql = sql .. "where domain_uuid = '"..domain_uuid.."' ";
sql = sql .. "and extension_uuid = '"..extension_uuid.."' ";
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[call_forward] "..sql.."\n");
end
dbh:query(sql);
end end
sql = sql .. "forward_all_enabled = '"..forward_all_enabled.."' ";
sql = sql .. "where domain_uuid = '"..domain_uuid.."' "; --clear the cache and hangup
sql = sql .. "and extension_uuid = '"..extension_uuid.."' "; if (session:ready()) then
if (debug["sql"]) then --clear the cache
freeswitch.consoleLog("notice", "[call_forward] "..sql.."\n"); if (extension ~= nil) then
api:execute("memcache", "delete directory:"..extension.."@"..domain_name);
end
--wait for the file to be written before proceeding
session:sleep(100);
--end the call
session:hangup();
end end
dbh:query(sql);
--clear the cache
if (extension ~= nil) then
api:execute("memcache", "delete directory:"..extension.."@"..domain_name);
end
--wait for the file to be written before proceeding
session:sleep(1000);
--end the call
session:hangup();
end end