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:
parent
1bcfb8e938
commit
613c7ae678
|
|
@ -29,6 +29,8 @@
|
|||
--set the debug level
|
||||
debug["sql"] = false;
|
||||
debug["var"] = false;
|
||||
db_dial_string = "";
|
||||
db_extension_uuid = "";
|
||||
|
||||
--include the lua script
|
||||
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");
|
||||
sip_from_user = session:getVariable("sip_from_user");
|
||||
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
|
||||
default_language = session:getVariable("default_language");
|
||||
|
|
@ -66,39 +71,63 @@ if ( session:ready() ) then
|
|||
max_digits = 15;
|
||||
unique_id = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_id:#", "", "\\d+");
|
||||
|
||||
--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");
|
||||
--authenticate the user
|
||||
if (pin_number) then
|
||||
--get the pin number from the caller
|
||||
min_digits = string.len(pin_number);
|
||||
max_digits = string.len(pin_number)+1;
|
||||
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
|
||||
|
||||
--get the dial_string
|
||||
--get the dial_string, and extension_uuid
|
||||
sql = "SELECT * FROM v_extensions as e, v_domains as d ";
|
||||
sql = sql .. "WHERE e.domain_uuid = d.domain_uuid ";
|
||||
sql = sql .. "AND e.unique_id = '" .. unique_id .."' ";
|
||||
sql = sql .. "AND e.vm_password = '" .. vm_password .."' ";
|
||||
--sql = sql .. "AND d.domain_name = '" .. domain_name .."' ";
|
||||
if (extension == "true") then
|
||||
sql = sql .. "AND e.extension = '" .. unique_id .."' ";
|
||||
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
|
||||
freeswitch.consoleLog("NOTICE", "sql: ".. sql .. "\n");
|
||||
end
|
||||
dbh:query(sql, function(row)
|
||||
domain_uuid = row.domain_uuid;
|
||||
--domain_name = row.domain_name;
|
||||
--extension = row.extension;
|
||||
extension_uuid = row.extension_uuid;
|
||||
dial_string = row.dial_string;
|
||||
--domain_uuid = row.domain_uuid;
|
||||
db_extension_uuid = row.extension_uuid;
|
||||
db_dial_string = row.dial_string;
|
||||
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
|
||||
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 = sql .. "dial_string = '" .. dial_string .."', ";
|
||||
sql = sql .. "dial_user = '" .. sip_from_user .."', ";
|
||||
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
|
||||
freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n");
|
||||
end
|
||||
|
|
@ -112,7 +141,7 @@ if ( session:ready() ) then
|
|||
sql = sql .. "dial_string = null, ";
|
||||
sql = sql .. "dial_user = 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
|
||||
freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n");
|
||||
end
|
||||
|
|
@ -121,13 +150,13 @@ if ( session:ready() ) then
|
|||
end
|
||||
--toggle the dial string
|
||||
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
|
||||
sql = "UPDATE v_extensions SET ";
|
||||
sql = sql .. "dial_string = null, ";
|
||||
sql = sql .. "dial_user = 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
|
||||
freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n");
|
||||
end
|
||||
|
|
@ -135,12 +164,14 @@ if ( session:ready() ) then
|
|||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-deleted.wav");
|
||||
else
|
||||
--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 = sql .. "dial_string = '" .. dial_string .."', ";
|
||||
sql = sql .. "dial_user = '" .. sip_from_user .."', ";
|
||||
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
|
||||
freeswitch.consoleLog("NOTICE", "[dial_string] sql: ".. sql .. "\n");
|
||||
end
|
||||
|
|
@ -149,9 +180,7 @@ if ( session:ready() ) then
|
|||
end
|
||||
end
|
||||
else
|
||||
max_tries = 1;
|
||||
digit_timeout = "1000";
|
||||
result = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_fail_auth:#", "", "\\d+");
|
||||
session:streamFile("phrase:voicemail_fail_auth:#");
|
||||
session:hangup("NORMAL_CLEARING");
|
||||
return;
|
||||
end
|
||||
|
|
|
|||
|
|
@ -38,15 +38,28 @@ if ( session:ready() ) then
|
|||
if (not default_dialect) then default_dialect = 'us'; 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 (pin_number) then
|
||||
min_digits = string.len(pin_number);
|
||||
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
|
||||
--pin is correct
|
||||
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");
|
||||
return;
|
||||
end
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ recording_prefix = "";
|
|||
--set a default recording_name
|
||||
recording_name = "temp_"..session:get_uuid()..".wav";
|
||||
end
|
||||
|
||||
|
||||
--prompt for the recording
|
||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/begin_recording.wav");
|
||||
session:execute("set", "playback_terminators=#");
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ else
|
|||
end
|
||||
--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:say(wakeup_time, "en", "number", "ITERATED");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue