Make pin_number.lua use phrases. White space cleanup on recordings.lua and wakeup.lua. Dial string add ability to change the dial string for a specific extension and add a pin number as an option.

This commit is contained in:
Mark Crane 2012-07-10 16:23:08 +00:00
parent 1bcfb8e938
commit 613c7ae678
4 changed files with 72 additions and 30 deletions

View File

@ -29,6 +29,8 @@
--set the debug level --set the debug level
debug["sql"] = false; debug["sql"] = false;
debug["var"] = false; debug["var"] = false;
db_dial_string = "";
db_extension_uuid = "";
--include the lua script --include the lua script
scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1)); scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1));
@ -52,6 +54,9 @@ if ( session:ready() ) then
sounds_dir = session:getVariable("sounds_dir"); sounds_dir = session:getVariable("sounds_dir");
sip_from_user = session:getVariable("sip_from_user"); sip_from_user = session:getVariable("sip_from_user");
direction = session:getVariable("direction"); --in, out, both direction = session:getVariable("direction"); --in, out, both
extension = tostring(session:getVariable("extension")); --true, false
dial_string = tostring(session:getVariable("dial_string"));
if (dial_string == "nil") then dial_string = ""; end
--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");
@ -66,39 +71,63 @@ if ( session:ready() ) then
max_digits = 15; max_digits = 15;
unique_id = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_id:#", "", "\\d+"); unique_id = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_id:#", "", "\\d+");
--get the vm_password --authenticate the user
min_digits = 1; if (pin_number) then
max_digits = 12; --get the pin number from the caller
vm_password = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+"); min_digits = string.len(pin_number);
if (debug["sql"]) then max_digits = string.len(pin_number)+1;
freeswitch.consoleLog("NOTICE", "unique_id ".. unique_id .. " vm_password " .. vm_password .. "\n"); caller_pin_number = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
else
--get the vm_password
min_digits = 1;
max_digits = 12;
vm_password = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "unique_id ".. unique_id .. " vm_password " .. vm_password .. "\n");
end
end end
--get the dial_string --get the dial_string, and extension_uuid
sql = "SELECT * FROM v_extensions as e, v_domains as d "; sql = "SELECT * FROM v_extensions as e, v_domains as d ";
sql = sql .. "WHERE e.domain_uuid = d.domain_uuid "; sql = sql .. "WHERE e.domain_uuid = d.domain_uuid ";
sql = sql .. "AND e.unique_id = '" .. unique_id .."' "; if (extension == "true") then
sql = sql .. "AND e.vm_password = '" .. vm_password .."' "; sql = sql .. "AND e.extension = '" .. unique_id .."' ";
--sql = sql .. "AND d.domain_name = '" .. domain_name .."' "; else
sql = sql .. "AND e.unique_id = '" .. unique_id .."' ";
end
if (pin_number) then
--do nothing
else
sql = sql .. "AND e.vm_password = '" .. vm_password .."' ";
end
if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "sql: ".. sql .. "\n"); freeswitch.consoleLog("NOTICE", "sql: ".. sql .. "\n");
end end
dbh:query(sql, function(row) dbh:query(sql, function(row)
domain_uuid = row.domain_uuid; --domain_uuid = row.domain_uuid;
--domain_name = row.domain_name; db_extension_uuid = row.extension_uuid;
--extension = row.extension; db_dial_string = row.dial_string;
extension_uuid = row.extension_uuid;
dial_string = row.dial_string;
end); end);
if (extension_uuid) then
--check to see if the pin number is correct
if (pin_number) then
if (pin_number ~= caller_pin_number) then
--access denied
db_extension_uuid = "";
end
end
if (string.len(db_extension_uuid) > 0) then
--add the dial string --add the dial string
if (direction == "in") then if (direction == "in") then
dial_string = [[{sip_invite_domain=]] .. domain_name .. [[,presence_id=]] .. sip_from_user .. [[@]] .. domain_name .. [[}${sofia_contact(]] .. sip_from_user .. [[@]] .. domain_name .. [[)}]]; if (string.len(dial_string) == 0) then
dial_string = [[{sip_invite_domain=]] .. domain_name .. [[,presence_id=]] .. sip_from_user .. [[@]] .. domain_name .. [[}${sofia_contact(]] .. sip_from_user .. [[@]] .. domain_name .. [[)}]];
end
sql = "UPDATE v_extensions SET "; sql = "UPDATE v_extensions SET ";
sql = sql .. "dial_string = '" .. dial_string .."', "; sql = sql .. "dial_string = '" .. dial_string .."', ";
sql = sql .. "dial_user = '" .. sip_from_user .."', "; sql = sql .. "dial_user = '" .. sip_from_user .."', ";
sql = sql .. "dial_domain = '" .. domain_name .."' "; sql = sql .. "dial_domain = '" .. domain_name .."' ";
sql = sql .. "WHERE extension_uuid = '" .. extension_uuid .."' "; sql = sql .. "WHERE extension_uuid = '" .. db_extension_uuid .."' ";
if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n"); freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n");
end end
@ -112,7 +141,7 @@ if ( session:ready() ) then
sql = sql .. "dial_string = null, "; sql = sql .. "dial_string = null, ";
sql = sql .. "dial_user = null, "; sql = sql .. "dial_user = null, ";
sql = sql .. "dial_domain = null "; sql = sql .. "dial_domain = null ";
sql = sql .. "WHERE extension_uuid = '" .. extension_uuid .."' "; sql = sql .. "WHERE extension_uuid = '" .. db_extension_uuid .."' ";
if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n"); freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n");
end end
@ -121,13 +150,13 @@ if ( session:ready() ) then
end end
--toggle the dial string --toggle the dial string
if (direction == "both") then if (direction == "both") then
if (string.len(dial_string) > 1) then if (string.len(db_dial_string) > 1) then
--if the the dial_string has a value then clear the dial string --if the the dial_string has a value then clear the dial string
sql = "UPDATE v_extensions SET "; sql = "UPDATE v_extensions SET ";
sql = sql .. "dial_string = null, "; sql = sql .. "dial_string = null, ";
sql = sql .. "dial_user = null, "; sql = sql .. "dial_user = null, ";
sql = sql .. "dial_domain = null "; sql = sql .. "dial_domain = null ";
sql = sql .. "WHERE extension_uuid = '" .. extension_uuid .."' "; sql = sql .. "WHERE extension_uuid = '" .. db_extension_uuid .."' ";
if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n"); freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n");
end end
@ -135,12 +164,14 @@ if ( session:ready() ) then
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-deleted.wav"); session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-deleted.wav");
else else
--if the dial string is empty then set the dial string --if the dial string is empty then set the dial string
dial_string = [[{sip_invite_domain=]] .. domain_name .. [[,presence_id=]] .. sip_from_user .. [[@]] .. domain_name .. [[}${sofia_contact(]] .. sip_from_user .. [[@]] .. domain_name .. [[)}]]; if (string.len(dial_string) == 0) then
dial_string = [[{sip_invite_domain=]] .. domain_name .. [[,presence_id=]] .. sip_from_user .. [[@]] .. domain_name .. [[}${sofia_contact(]] .. sip_from_user .. [[@]] .. domain_name .. [[)}]];
end
sql = "UPDATE v_extensions SET "; sql = "UPDATE v_extensions SET ";
sql = sql .. "dial_string = '" .. dial_string .."', "; sql = sql .. "dial_string = '" .. dial_string .."', ";
sql = sql .. "dial_user = '" .. sip_from_user .."', "; sql = sql .. "dial_user = '" .. sip_from_user .."', ";
sql = sql .. "dial_domain = '" .. domain_name .."' "; sql = sql .. "dial_domain = '" .. domain_name .."' ";
sql = sql .. "WHERE extension_uuid = '" .. extension_uuid .."' "; sql = sql .. "WHERE extension_uuid = '" .. db_extension_uuid .."' ";
if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n"); freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n");
end end
@ -149,9 +180,7 @@ if ( session:ready() ) then
end end
end end
else else
max_tries = 1; session:streamFile("phrase:voicemail_fail_auth:#");
digit_timeout = "1000";
result = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_fail_auth:#", "", "\\d+");
session:hangup("NORMAL_CLEARING"); session:hangup("NORMAL_CLEARING");
return; return;
end end

View File

@ -38,15 +38,28 @@ if ( session:ready() ) then
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
--set defaults
if (digit_min_length) then
--do nothing
else
digit_min_length = "2";
end
if (digit_max_length) then
--do nothing
else
digit_max_length = "11";
end
--if the pin number is provided then require it --if the pin number is provided then require it
if (pin_number) then if (pin_number) then
min_digits = string.len(pin_number); min_digits = string.len(pin_number);
max_digits = string.len(pin_number)+1; max_digits = string.len(pin_number)+1;
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/please_enter_the_pin_number.wav", "", "\\d+"); digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
if (digits == pin_number) then if (digits == pin_number) then
--pin is correct --pin is correct
else else
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/your_pin_number_is_incorect_goodbye.wav"); session:streamFile("phrase:voicemail_fail_auth:#");
session:hangup("NORMAL_CLEARING"); session:hangup("NORMAL_CLEARING");
return; return;
end end

View File

@ -68,7 +68,7 @@ recording_prefix = "";
--set a default recording_name --set a default recording_name
recording_name = "temp_"..session:get_uuid()..".wav"; recording_name = "temp_"..session:get_uuid()..".wav";
end end
--prompt for the recording --prompt for the recording
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/begin_recording.wav"); session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/begin_recording.wav");
session:execute("set", "playback_terminators=#"); session:execute("set", "playback_terminators=#");

View File

@ -170,7 +170,7 @@ else
end end
--freeswitch.consoleLog("NOTICE", "sched_api_time "..sched_api_time.."\n"); --freeswitch.consoleLog("NOTICE", "sched_api_time "..sched_api_time.."\n");
--wakeup call has been scheduled --wakeup call has been scheduled
session:streamFile("phrase:wakeup-scheduled"); session:streamFile("phrase:wakeup-scheduled");
session:say(wakeup_time, "en", "number", "ITERATED"); session:say(wakeup_time, "en", "number", "ITERATED");