mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-06 11:43:50 +00:00
Add max_digits to the macro function calls. Wrap 'if session:ready around most actions so that if the call ends that it doesn't throw unnecessary errors simply because the call ended.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
-- voicemail.lua
|
-- voicemail.lua
|
||||||
-- Part of FusionPBX
|
-- Part of FusionPBX
|
||||||
-- Copyright (C) 2012 Mark J Crane <markjcrane@fusionpbx.com>
|
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
|
||||||
-- All rights reserved.
|
-- All rights reserved.
|
||||||
--
|
--
|
||||||
-- Redistribution and use in source and binary forms, with or without
|
-- Redistribution and use in source and binary forms, with or without
|
||||||
@@ -114,7 +114,7 @@
|
|||||||
|
|
||||||
--get the voicemail id
|
--get the voicemail id
|
||||||
function get_voicemail_id()
|
function get_voicemail_id()
|
||||||
voicemail_id = macro(session, "voicemail_id", 5000, '');
|
voicemail_id = macro(session, "voicemail_id", 20, 5000, '');
|
||||||
if (string.len(voicemail_id) == 0) then
|
if (string.len(voicemail_id) == 0) then
|
||||||
if (session:ready()) then
|
if (session:ready()) then
|
||||||
voicemail_id = get_voicemail_id();
|
voicemail_id = get_voicemail_id();
|
||||||
@@ -155,11 +155,11 @@
|
|||||||
end);
|
end);
|
||||||
end
|
end
|
||||||
--please enter your password followed by pound
|
--please enter your password followed by pound
|
||||||
password = macro(session, "voicemail_password", 5000, '');
|
password = macro(session, "voicemail_password", 20, 5000, '');
|
||||||
--compare the password from the database with the password provided by the user
|
--compare the password from the database with the password provided by the user
|
||||||
if (voicemail_password ~= password) then
|
if (voicemail_password ~= password) then
|
||||||
--incorrect password
|
--incorrect password
|
||||||
macro(session, "password_not_valid", 1000, '');
|
macro(session, "password_not_valid", 1, 1000, '');
|
||||||
if (session:ready()) then
|
if (session:ready()) then
|
||||||
check_password(voicemail_id);
|
check_password(voicemail_id);
|
||||||
end
|
end
|
||||||
@@ -171,7 +171,7 @@
|
|||||||
function change_password(voicemail_id)
|
function change_password(voicemail_id)
|
||||||
if (session:ready()) then
|
if (session:ready()) then
|
||||||
--please enter your password followed by pound
|
--please enter your password followed by pound
|
||||||
password = macro(session, "password_new", 5000, '');
|
password = macro(session, "password_new", 20, 5000, '');
|
||||||
--update the voicemail password
|
--update the voicemail password
|
||||||
sql = [[UPDATE v_voicemails
|
sql = [[UPDATE v_voicemails
|
||||||
set voicemail_password = ']] .. password ..[['
|
set voicemail_password = ']] .. password ..[['
|
||||||
@@ -183,7 +183,7 @@
|
|||||||
end
|
end
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
--has been changed to
|
--has been changed to
|
||||||
macro(session, "password_changed", 3000, password);
|
macro(session, "password_changed", 20, 3000, password);
|
||||||
--advanced menu
|
--advanced menu
|
||||||
advanced();
|
advanced();
|
||||||
end
|
end
|
||||||
@@ -206,7 +206,7 @@
|
|||||||
--session:setInputCallback("on_dtmf", "");
|
--session:setInputCallback("on_dtmf", "");
|
||||||
|
|
||||||
--define the macro function
|
--define the macro function
|
||||||
function macro(session, name, max_timeout, param)
|
function macro(session, name, max_digits, max_timeout, param)
|
||||||
if (session:ready()) then
|
if (session:ready()) then
|
||||||
--Please enter your id followed by
|
--Please enter your id followed by
|
||||||
if (name == "voicemail_id") then
|
if (name == "voicemail_id") then
|
||||||
@@ -506,38 +506,44 @@
|
|||||||
dtmf_digits = '';
|
dtmf_digits = '';
|
||||||
tries = 1;
|
tries = 1;
|
||||||
timeout = 100;
|
timeout = 100;
|
||||||
max_digits = 10;
|
|
||||||
--loop through the action and data
|
--loop through the action and data
|
||||||
for key, row in pairs(actions) do
|
for key, row in pairs(actions) do
|
||||||
--freeswitch.consoleLog("notice", "[voicemail] app: " .. row.app .. " data: " .. row.data .. "\n");
|
--freeswitch.consoleLog("notice", "[voicemail] app: " .. row.app .. " data: " .. row.data .. "\n");
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (session:ready()) then
|
||||||
if (row.app == "playback") then
|
if (string.len(dtmf_digits) == 0) then
|
||||||
session:execute(row.app, sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data);
|
if (row.app == "playback") then
|
||||||
elseif (row.app == "tone_stream") then
|
session:execute(row.app, sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data);
|
||||||
session:execute("playback", "tone_stream://"..row.data);
|
elseif (row.app == "tone_stream") then
|
||||||
elseif (row.app == "playAndGetDigits") then
|
session:execute("playback", "tone_stream://"..row.data);
|
||||||
--playAndGetDigits <min> <max> <tries> <timeout> <terminators> <file> <invalid_file> <var_name> <regexp> <digit_timeout>
|
elseif (row.app == "playAndGetDigits") then
|
||||||
if (not file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data)) then
|
--playAndGetDigits <min> <max> <tries> <timeout> <terminators> <file> <invalid_file> <var_name> <regexp> <digit_timeout>
|
||||||
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data, "", "\\d+", max_timeout);
|
if (not file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data)) then
|
||||||
|
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data, "", "\\d+", max_timeout);
|
||||||
|
else
|
||||||
|
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", row.data, "", "\\d+", max_timeout);
|
||||||
|
end
|
||||||
|
elseif (row.app == "say.number.pronounced") then
|
||||||
|
session:say(row.data, default_language, "number", "pronounced");
|
||||||
|
elseif (row.app == "say.number.iterated") then
|
||||||
|
session:say(row.data, default_language, "number", "iterated");
|
||||||
|
else
|
||||||
|
session:execute(row.app, row.data);
|
||||||
|
end
|
||||||
|
end --if
|
||||||
|
end --session:ready
|
||||||
|
end --for
|
||||||
|
--get the remaining digits
|
||||||
|
if (session:ready()) then
|
||||||
|
if (string.len(dtmf_digits) < max_digits) then
|
||||||
|
if (string.len(dtmf_digits) == 0) then
|
||||||
|
dtmf_digits = session:getDigits(max_digits, "#", max_timeout);
|
||||||
else
|
else
|
||||||
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", row.data, "", "\\d+", max_timeout);
|
dtmf_digits = dtmf_digits .. session:getDigits(max_digits, "#", max_timeout);
|
||||||
end
|
end
|
||||||
elseif (row.app == "say.number.pronounced") then
|
|
||||||
session:say(row.data, default_language, "number", "pronounced");
|
|
||||||
elseif (row.app == "say.number.iterated") then
|
|
||||||
session:say(row.data, default_language, "number", "iterated");
|
|
||||||
else
|
|
||||||
session:execute(row.app, row.data);
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
--return dtmf the digits
|
||||||
if (string.len(dtmf_digits) == 0) then
|
return dtmf_digits;
|
||||||
dtmf_digits = session:getDigits(max_digits, "#", max_timeout);
|
|
||||||
else
|
|
||||||
dtmf_digits = dtmf_digits .. session:getDigits(max_digits, "#", max_timeout);
|
|
||||||
end
|
|
||||||
--return dtmf the digits
|
|
||||||
return dtmf_digits;
|
|
||||||
else
|
else
|
||||||
--no dtmf digits to return
|
--no dtmf digits to return
|
||||||
return '';
|
return '';
|
||||||
@@ -565,10 +571,10 @@
|
|||||||
voicemail_local_after_email = row["voicemail_local_after_email"];
|
voicemail_local_after_email = row["voicemail_local_after_email"];
|
||||||
end);
|
end);
|
||||||
--set default values
|
--set default values
|
||||||
if (string.len(voicemail_local_after_email) == 0) then
|
if (voicemail_local_after_email == nil) then
|
||||||
voicemail_local_after_email = "true";
|
voicemail_local_after_email = "true";
|
||||||
end
|
end
|
||||||
if (string.len(voicemail_attach_file) == 0) then
|
if (voicemail_attach_file == nil) then
|
||||||
voicemail_attach_file = "true";
|
voicemail_attach_file = "true";
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -578,7 +584,7 @@
|
|||||||
function record_message()
|
function record_message()
|
||||||
if (session:ready()) then
|
if (session:ready()) then
|
||||||
--record your message at the tone press any key or stop talking to end the recording
|
--record your message at the tone press any key or stop talking to end the recording
|
||||||
result = macro(session, "record_message", 100);
|
result = macro(session, "record_message", 1, 100);
|
||||||
|
|
||||||
--start epoch
|
--start epoch
|
||||||
start_epoch = os.time();
|
start_epoch = os.time();
|
||||||
@@ -614,14 +620,16 @@
|
|||||||
else
|
else
|
||||||
if (session:ready()) then
|
if (session:ready()) then
|
||||||
--your recording is below the minimal acceptable length, please try again
|
--your recording is below the minimal acceptable length, please try again
|
||||||
macro(session, "too_small", 100);
|
macro(session, "too_small", 1, 100);
|
||||||
--record your message at the tone
|
--record your message at the tone
|
||||||
record_message();
|
record_message();
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--record menu 1 listen to the recording, 2 save the recording, 3 re-record
|
--record menu 1 listen to the recording, 2 save the recording, 3 re-record
|
||||||
record_menu();
|
if (session:ready()) then
|
||||||
|
record_menu();
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -631,39 +639,47 @@
|
|||||||
--clear the dtmf digits variable
|
--clear the dtmf digits variable
|
||||||
dtmf_digits = '';
|
dtmf_digits = '';
|
||||||
--to listen to the recording press 1
|
--to listen to the recording press 1
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (session:ready()) then
|
||||||
dtmf_digits = macro(session, "to_listen_to_recording", 100, '');
|
if (string.len(dtmf_digits) == 0) then
|
||||||
|
dtmf_digits = macro(session, "to_listen_to_recording", 1, 100, '');
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--to save the recording press 2
|
--to save the recording press 2
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (session:ready()) then
|
||||||
dtmf_digits = macro(session, "to_save_recording", 100, '');
|
if (string.len(dtmf_digits) == 0) then
|
||||||
|
dtmf_digits = macro(session, "to_save_recording", 1, 100, '');
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--to re-record press 3
|
--to re-record press 3
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (session:ready()) then
|
||||||
dtmf_digits = macro(session, "to_rerecord", 3000, '');
|
if (string.len(dtmf_digits) == 0) then
|
||||||
|
dtmf_digits = macro(session, "to_rerecord", 1, 3000, '');
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--process the dtmf
|
--process the dtmf
|
||||||
if (dtmf_digits == "1") then
|
if (session:ready()) then
|
||||||
--listen to the recording
|
if (dtmf_digits == "1") then
|
||||||
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", "", "\\d+", 1000);
|
--listen to the recording
|
||||||
--record menu 1 listen to the recording, 2 save the recording, 3 re-record
|
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", "", "\\d+", 1000);
|
||||||
record_menu();
|
--record menu 1 listen to the recording, 2 save the recording, 3 re-record
|
||||||
elseif (dtmf_digits == "2") then
|
record_menu();
|
||||||
--save the message
|
elseif (dtmf_digits == "2") then
|
||||||
macro(session, "message_saved", 100, '');
|
--save the message
|
||||||
macro(session, "goodbye", 100, '');
|
macro(session, "message_saved", 1, 100, '');
|
||||||
--hangup the call
|
macro(session, "goodbye", 1, 100, '');
|
||||||
session:hangup();
|
--hangup the call
|
||||||
elseif (dtmf_digits == "3") then
|
session:hangup();
|
||||||
--rerecord the message
|
elseif (dtmf_digits == "3") then
|
||||||
record_message();
|
--rerecord the message
|
||||||
elseif (dtmf_digits == "*") then
|
record_message();
|
||||||
--hangup
|
elseif (dtmf_digits == "*") then
|
||||||
macro(session, "goodbye", 100, '');
|
--hangup
|
||||||
session:hangup();
|
macro(session, "goodbye", 1, 100, '');
|
||||||
else
|
session:hangup();
|
||||||
if (session:ready()) then
|
else
|
||||||
record_menu();
|
if (session:ready()) then
|
||||||
|
record_menu();
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -721,8 +737,9 @@
|
|||||||
|
|
||||||
--define a function to forward a message to an extension
|
--define a function to forward a message to an extension
|
||||||
function forward_to_extension(uuid)
|
function forward_to_extension(uuid)
|
||||||
if (session:ready()) then
|
|
||||||
--get voicemail message details
|
--get voicemail message details
|
||||||
|
if (session:ready()) then
|
||||||
sql = [[SELECT * FROM v_voicemail_messages
|
sql = [[SELECT * FROM v_voicemail_messages
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
AND voicemail_message_uuid = ']] .. uuid ..[[']]
|
AND voicemail_message_uuid = ']] .. uuid ..[[']]
|
||||||
@@ -738,17 +755,25 @@
|
|||||||
message_status = row["message_status"];
|
message_status = row["message_status"];
|
||||||
message_priority = row["message_priority"];
|
message_priority = row["message_priority"];
|
||||||
end);
|
end);
|
||||||
|
end
|
||||||
|
|
||||||
--request the forward_voicemail_id
|
--request the forward_voicemail_id
|
||||||
forward_voicemail_id = macro(session, "forward_enter_extension", 7000, '');
|
if (session:ready()) then
|
||||||
if (string.len(forward_voicemail_id) == 0) then
|
forward_voicemail_id = macro(session, "forward_enter_extension", 20, 5000, '');
|
||||||
forward_voicemail_id = macro(session, "forward_enter_extension", 7000, '');
|
if (session:ready()) then
|
||||||
|
if (string.len(forward_voicemail_id) == 0) then
|
||||||
|
forward_voicemail_id = macro(session, "forward_enter_extension", 20, 5000, '');
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(forward_voicemail_id) == 0) then
|
if (string.len(forward_voicemail_id) == 0) then
|
||||||
forward_voicemail_id = macro(session, "forward_enter_extension", 7000, '');
|
forward_voicemail_id = macro(session, "forward_enter_extension", 20, 5000, '');
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--get the voicemail settings using the voicemail_uuid
|
--get the voicemail settings using the voicemail_uuid
|
||||||
|
if (session:ready()) then
|
||||||
sql = [[SELECT * FROM v_voicemails
|
sql = [[SELECT * FROM v_voicemails
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
AND voicemail_id = ']] .. forward_voicemail_id ..[['
|
AND voicemail_id = ']] .. forward_voicemail_id ..[['
|
||||||
@@ -762,16 +787,22 @@
|
|||||||
forward_voicemail_attach_file = row["voicemail_attach_file"];
|
forward_voicemail_attach_file = row["voicemail_attach_file"];
|
||||||
forward_voicemail_local_after_email = row["voicemail_local_after_email"];
|
forward_voicemail_local_after_email = row["voicemail_local_after_email"];
|
||||||
end);
|
end);
|
||||||
|
end
|
||||||
|
|
||||||
--set default values
|
--set default values
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(forward_voicemail_attach_file) == 0) then
|
if (string.len(forward_voicemail_attach_file) == 0) then
|
||||||
forward_voicemail_attach_file = "true";
|
forward_voicemail_attach_file = "true";
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(forward_voicemail_local_after_email) == 0) then
|
if (string.len(forward_voicemail_local_after_email) == 0) then
|
||||||
forward_voicemail_local_after_email = "true";
|
forward_voicemail_local_after_email = "true";
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--save the message to the voicemail messages
|
--save the message to the voicemail messages
|
||||||
|
if (session:ready()) then
|
||||||
local sql = {}
|
local sql = {}
|
||||||
table.insert(sql, "INSERT INTO v_voicemail_messages ");
|
table.insert(sql, "INSERT INTO v_voicemail_messages ");
|
||||||
table.insert(sql, "(");
|
table.insert(sql, "(");
|
||||||
@@ -804,42 +835,53 @@
|
|||||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
|
end
|
||||||
|
|
||||||
--set the message waiting event
|
--set the message waiting event
|
||||||
|
if (session:ready()) then
|
||||||
local event = freeswitch.Event("message_waiting");
|
local event = freeswitch.Event("message_waiting");
|
||||||
event:addHeader("MWI-Messages-Waiting", "yes");
|
event:addHeader("MWI-Messages-Waiting", "yes");
|
||||||
event:addHeader("MWI-Message-Account", "sip:"..forward_voicemail_id.."@"..domain_name);
|
event:addHeader("MWI-Message-Account", "sip:"..forward_voicemail_id.."@"..domain_name);
|
||||||
event:fire();
|
event:fire();
|
||||||
|
end
|
||||||
|
|
||||||
--local after email is true so copy the recording file
|
--local after email is true so copy the recording file
|
||||||
|
if (session:ready()) then
|
||||||
if (voicemail_local_after_email == "true") then
|
if (voicemail_local_after_email == "true") then
|
||||||
os.execute("mkdir -p " .. voicemail_dir.."/"..forward_voicemail_id);
|
os.execute("mkdir -p " .. voicemail_dir.."/"..forward_voicemail_id);
|
||||||
os.execute("cp "..voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav "..voicemail_dir.."/"..forward_voicemail_id.."/msg_"..uuid..".wav");
|
os.execute("cp "..voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav "..voicemail_dir.."/"..forward_voicemail_id.."/msg_"..uuid..".wav");
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--send the email with the voicemail recording attached
|
--send the email with the voicemail recording attached
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(forward_voicemail_mail_to) > 2) then
|
if (string.len(forward_voicemail_mail_to) > 2) then
|
||||||
send_email(uuid);
|
send_email(uuid);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--leave a voicemail
|
--leave a voicemail
|
||||||
if (voicemail_action == "save") then
|
if (voicemail_action == "save") then
|
||||||
if (session:ready()) then
|
|
||||||
--voicemail prompt
|
--voicemail prompt
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(greeting_id) > 0) then
|
if (string.len(greeting_id) > 0) then
|
||||||
--play the greeting
|
--play the greeting
|
||||||
session:streamFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
session:streamFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||||
else
|
else
|
||||||
--if there is no greeting then play digits of the voicemail_id
|
--if there is no greeting then play digits of the voicemail_id
|
||||||
result = macro(session, "person_not_available_record_message", 100);
|
result = macro(session, "person_not_available_record_message", 1, 100);
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--save the recording
|
--save the recording
|
||||||
|
if (session:ready()) then
|
||||||
record_message();
|
record_message();
|
||||||
|
end
|
||||||
|
|
||||||
--save the message to the voicemail messages
|
--save the message to the voicemail messages
|
||||||
|
if (session:ready()) then
|
||||||
if (message_length > 2) then
|
if (message_length > 2) then
|
||||||
local sql = {}
|
local sql = {}
|
||||||
table.insert(sql, "INSERT INTO v_voicemail_messages ");
|
table.insert(sql, "INSERT INTO v_voicemail_messages ");
|
||||||
@@ -874,27 +916,31 @@
|
|||||||
end
|
end
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--set the message waiting event
|
--set the message waiting event
|
||||||
|
if (session:ready()) then
|
||||||
if (message_length > 2) then
|
if (message_length > 2) then
|
||||||
local event = freeswitch.Event("message_waiting");
|
local event = freeswitch.Event("message_waiting");
|
||||||
event:addHeader("MWI-Messages-Waiting", "yes");
|
event:addHeader("MWI-Messages-Waiting", "yes");
|
||||||
event:addHeader("MWI-Message-Account", "sip:"..voicemail_id.."@"..domain_name);
|
event:addHeader("MWI-Message-Account", "sip:"..voicemail_id.."@"..domain_name);
|
||||||
event:fire();
|
event:fire();
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--send the email with the voicemail recording attached
|
--send the email with the voicemail recording attached
|
||||||
|
if (session:ready()) then
|
||||||
if (message_length > 2) then
|
if (message_length > 2) then
|
||||||
if (string.len(voicemail_mail_to) > 3) then
|
if (string.len(voicemail_mail_to) > 3) then
|
||||||
send_email(uuid);
|
send_email(uuid);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--local after email is false so delete the recording file
|
--local after email is false so delete the recording file
|
||||||
if (voicemail_local_after_email == "false") then
|
if (voicemail_local_after_email == "false") then
|
||||||
os.remove(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav");
|
os.remove(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav");
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function main_menu ()
|
function main_menu ()
|
||||||
@@ -902,137 +948,176 @@ function main_menu ()
|
|||||||
--clear the value
|
--clear the value
|
||||||
dtmf_digits = '';
|
dtmf_digits = '';
|
||||||
--new voicemail count
|
--new voicemail count
|
||||||
sql = [[SELECT count(*) as new_messages FROM v_voicemail_messages
|
if (session:ready()) then
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
sql = [[SELECT count(*) as new_messages FROM v_voicemail_messages
|
||||||
AND voicemail_uuid = ']] .. voicemail_uuid ..[['
|
|
||||||
AND (message_status is null or message_status = '') ]];
|
|
||||||
if (debug["sql"]) then
|
|
||||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
|
||||||
end
|
|
||||||
status = dbh:query(sql, function(row)
|
|
||||||
new_messages = row["new_messages"];
|
|
||||||
end);
|
|
||||||
dtmf_digits = macro(session, "new_messages", 100, new_messages);
|
|
||||||
--saved voicemail count
|
|
||||||
if (string.len(dtmf_digits) == 0) then
|
|
||||||
sql = [[SELECT count(*) as saved_messages FROM v_voicemail_messages
|
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
AND voicemail_uuid = ']] .. voicemail_uuid ..[['
|
AND voicemail_uuid = ']] .. voicemail_uuid ..[['
|
||||||
AND message_status = 'saved' ]];
|
AND (message_status is null or message_status = '') ]];
|
||||||
if (debug["sql"]) then
|
if (debug["sql"]) then
|
||||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
status = dbh:query(sql, function(row)
|
status = dbh:query(sql, function(row)
|
||||||
saved_messages = row["saved_messages"];
|
new_messages = row["new_messages"];
|
||||||
end);
|
end);
|
||||||
dtmf_digits = macro(session, "saved_messages", 100, saved_messages);
|
dtmf_digits = macro(session, "new_messages", 1, 100, new_messages);
|
||||||
|
end
|
||||||
|
--saved voicemail count
|
||||||
|
if (session:ready()) then
|
||||||
|
if (string.len(dtmf_digits) == 0) then
|
||||||
|
sql = [[SELECT count(*) as saved_messages FROM v_voicemail_messages
|
||||||
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
|
AND voicemail_uuid = ']] .. voicemail_uuid ..[['
|
||||||
|
AND message_status = 'saved' ]];
|
||||||
|
if (debug["sql"]) then
|
||||||
|
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||||
|
end
|
||||||
|
status = dbh:query(sql, function(row)
|
||||||
|
saved_messages = row["saved_messages"];
|
||||||
|
end);
|
||||||
|
dtmf_digits = macro(session, "saved_messages", 1, 100, saved_messages);
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--to listen to new message
|
--to listen to new message
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (session:ready()) then
|
||||||
dtmf_digits = macro(session, "listen_to_new_messages", 100, '');
|
if (string.len(dtmf_digits) == 0) then
|
||||||
|
dtmf_digits = macro(session, "listen_to_new_messages", 1, 100, '');
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--to listen to saved message
|
--to listen to saved message
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (session:ready()) then
|
||||||
dtmf_digits = macro(session, "listen_to_saved_messages", 100, '');
|
if (string.len(dtmf_digits) == 0) then
|
||||||
|
dtmf_digits = macro(session, "listen_to_saved_messages", 1, 100, '');
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--for advanced options
|
--for advanced options
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (session:ready()) then
|
||||||
dtmf_digits = macro(session, "advanced", 100, '');
|
if (string.len(dtmf_digits) == 0) then
|
||||||
|
dtmf_digits = macro(session, "advanced", 1, 100, '');
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--to exit press #
|
--to exit press #
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (session:ready()) then
|
||||||
dtmf_digits = macro(session, "to_exit_press", 3000, '');
|
if (string.len(dtmf_digits) == 0) then
|
||||||
|
dtmf_digits = macro(session, "to_exit_press", 1, 3000, '');
|
||||||
|
end
|
||||||
end
|
end
|
||||||
--process the dtmf
|
--process the dtmf
|
||||||
if (dtmf_digits == "1") then
|
if (session:ready()) then
|
||||||
menu_messages("new");
|
if (dtmf_digits == "1") then
|
||||||
elseif (dtmf_digits == "2") then
|
menu_messages("new");
|
||||||
menu_messages("saved");
|
elseif (dtmf_digits == "2") then
|
||||||
elseif (dtmf_digits == "5") then
|
menu_messages("saved");
|
||||||
advanced();
|
elseif (dtmf_digits == "5") then
|
||||||
elseif (dtmf_digits == "0") then
|
advanced();
|
||||||
session:transfer("0", "XML", context);
|
elseif (dtmf_digits == "0") then
|
||||||
elseif (dtmf_digits == "*") then
|
session:transfer("0", "XML", context);
|
||||||
macro(session, "goodbye", 100, '');
|
elseif (dtmf_digits == "*") then
|
||||||
session:hangup();
|
macro(session, "goodbye", 1, 100, '');
|
||||||
else
|
session:hangup();
|
||||||
if (session:ready()) then
|
else
|
||||||
main_menu();
|
if (session:ready()) then
|
||||||
|
main_menu();
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function listen_to_recording (message_number, uuid, created_epoch, caller_id_name, caller_id_number)
|
function listen_to_recording (message_number, uuid, created_epoch, caller_id_name, caller_id_number)
|
||||||
if (session:ready()) then
|
|
||||||
--clear the value
|
--clear the value
|
||||||
dtmf_digits = '';
|
dtmf_digits = '';
|
||||||
--set the display
|
--set the display
|
||||||
|
if (session:ready()) then
|
||||||
api = freeswitch.API();
|
api = freeswitch.API();
|
||||||
reply = api:executeString("uuid_display "..session:get_uuid().." "..caller_id_number);
|
reply = api:executeString("uuid_display "..session:get_uuid().." "..caller_id_number);
|
||||||
--say the message number
|
end
|
||||||
dtmf_digits = macro(session, "message_number", 100, '');
|
--say the message number
|
||||||
--say the number
|
if (session:ready()) then
|
||||||
|
dtmf_digits = macro(session, "message_number", 1, 100, '');
|
||||||
|
end
|
||||||
|
--say the number
|
||||||
|
if (session:ready()) then
|
||||||
session:say(message_number, default_language, "NUMBER", "pronounced");
|
session:say(message_number, default_language, "NUMBER", "pronounced");
|
||||||
--say the message date
|
end
|
||||||
|
--say the message date
|
||||||
|
if (session:ready()) then
|
||||||
session:say(created_epoch, default_language, "CURRENT_DATE_TIME", "pronounced");
|
session:say(created_epoch, default_language, "CURRENT_DATE_TIME", "pronounced");
|
||||||
--play the message
|
end
|
||||||
|
--play the message
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (string.len(dtmf_digits) == 0) then
|
||||||
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", "", "\\d+", max_timeout);
|
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", "", "\\d+", max_timeout);
|
||||||
end
|
end
|
||||||
--to listen to the recording press 1
|
end
|
||||||
|
--to listen to the recording press 1
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (string.len(dtmf_digits) == 0) then
|
||||||
dtmf_digits = macro(session, "listen_to_recording", 100, '');
|
dtmf_digits = macro(session, "listen_to_recording", 1, 100, '');
|
||||||
end
|
end
|
||||||
--to save the recording press 2
|
end
|
||||||
|
--to save the recording press 2
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (string.len(dtmf_digits) == 0) then
|
||||||
dtmf_digits = macro(session, "save_recording", 100, '');
|
dtmf_digits = macro(session, "save_recording", 1, 100, '');
|
||||||
end
|
end
|
||||||
--to return the call now press 5
|
end
|
||||||
|
--to return the call now press 5
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (string.len(dtmf_digits) == 0) then
|
||||||
dtmf_digits = macro(session, "return_call", 100, '');
|
dtmf_digits = macro(session, "return_call", 1, 100, '');
|
||||||
end
|
end
|
||||||
--to delete the recording press 7
|
end
|
||||||
|
--to delete the recording press 7
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (string.len(dtmf_digits) == 0) then
|
||||||
dtmf_digits = macro(session, "delete_recording", 100, '');
|
dtmf_digits = macro(session, "delete_recording", 1, 100, '');
|
||||||
end
|
end
|
||||||
--to forward this message press 8
|
end
|
||||||
|
--to forward this message press 8
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (string.len(dtmf_digits) == 0) then
|
||||||
dtmf_digits = macro(session, "to_forward_message", 100, '');
|
dtmf_digits = macro(session, "to_forward_message", 1, 100, '');
|
||||||
end
|
end
|
||||||
--to forward this recording to your email press 9
|
end
|
||||||
|
--to forward this recording to your email press 9
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (string.len(dtmf_digits) == 0) then
|
||||||
dtmf_digits = macro(session, "forward_to_email", 100, '');
|
dtmf_digits = macro(session, "forward_to_email", 1, 3000, '');
|
||||||
end
|
end
|
||||||
--wait for more digits
|
end
|
||||||
if (string.len(dtmf_digits) == 0) then
|
--wait for more digits
|
||||||
dtmf_digits = session:getDigits(max_digits, "#", 3000);
|
--if (session:ready()) then
|
||||||
end
|
-- if (string.len(dtmf_digits) == 0) then
|
||||||
--process the dtmf
|
-- dtmf_digits = session:getDigits(max_digits, "#", 1, 3000);
|
||||||
|
-- end
|
||||||
|
--end
|
||||||
|
--process the dtmf
|
||||||
|
if (session:ready()) then
|
||||||
if (dtmf_digits == "1") then
|
if (dtmf_digits == "1") then
|
||||||
listen_to_recording(message_number, uuid, created_epoch, caller_id_name, caller_id_number);
|
listen_to_recording(message_number, uuid, created_epoch, caller_id_name, caller_id_number);
|
||||||
elseif (dtmf_digits == "2") then
|
elseif (dtmf_digits == "2") then
|
||||||
message_saved(uuid);
|
message_saved(uuid);
|
||||||
macro(session, "message_saved", 100, '');
|
macro(session, "message_saved", 1, 100, '');
|
||||||
elseif (dtmf_digits == "5") then
|
elseif (dtmf_digits == "5") then
|
||||||
return_call(caller_id_number);
|
return_call(caller_id_number);
|
||||||
elseif (dtmf_digits == "7") then
|
elseif (dtmf_digits == "7") then
|
||||||
delete_recording(uuid);
|
delete_recording(uuid);
|
||||||
elseif (dtmf_digits == "8") then
|
elseif (dtmf_digits == "8") then
|
||||||
forward_to_extension(uuid);
|
forward_to_extension(uuid);
|
||||||
macro(session, "message_saved", 100, '');
|
macro(session, "message_saved", 1, 100, '');
|
||||||
elseif (dtmf_digits == "9") then
|
elseif (dtmf_digits == "9") then
|
||||||
send_email(uuid);
|
send_email(uuid);
|
||||||
macro(session, "emailed", 100);
|
macro(session, "emailed", 1, 100);
|
||||||
elseif (dtmf_digits == "*") then
|
elseif (dtmf_digits == "*") then
|
||||||
main_menu();
|
main_menu();
|
||||||
elseif (dtmf_digits == "0") then
|
elseif (dtmf_digits == "0") then
|
||||||
session:transfer("0", "XML", context);
|
session:transfer("0", "XML", context);
|
||||||
else
|
else
|
||||||
message_saved(uuid);
|
message_saved(uuid);
|
||||||
macro(session, "message_saved", 100, '');
|
macro(session, "message_saved", 1, 100, '');
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--voicemail count if zero new messages set the mwi to no
|
--voicemail count if zero new messages set the mwi to no
|
||||||
@@ -1079,7 +1164,7 @@ end
|
|||||||
end
|
end
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
--message deleted
|
--message deleted
|
||||||
macro(session, "message_deleted", 100, '');
|
macro(session, "message_deleted", 1, 100, '');
|
||||||
--check the message waiting status
|
--check the message waiting status
|
||||||
message_waiting();
|
message_waiting();
|
||||||
end
|
end
|
||||||
@@ -1112,16 +1197,17 @@ end
|
|||||||
end
|
end
|
||||||
|
|
||||||
function menu_messages (message_status)
|
function menu_messages (message_status)
|
||||||
if (session:ready()) then
|
|
||||||
--set default values
|
--set default values
|
||||||
max_timeout = 2000;
|
max_timeout = 2000;
|
||||||
min_digits = 1;
|
min_digits = 1;
|
||||||
max_digits = 1;
|
max_digits = 1;
|
||||||
tries = 1;
|
tries = 1;
|
||||||
timeout = 2000;
|
timeout = 2000;
|
||||||
--set the message number
|
--set the message number
|
||||||
message_number = 0;
|
message_number = 0;
|
||||||
--message_status new,saved
|
--message_status new,saved
|
||||||
|
if (session:ready()) then
|
||||||
if (voicemail_id ~= nil) then
|
if (voicemail_id ~= nil) then
|
||||||
sql = [[SELECT * FROM v_voicemail_messages
|
sql = [[SELECT * FROM v_voicemail_messages
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
@@ -1154,8 +1240,10 @@ function menu_messages (message_status)
|
|||||||
end
|
end
|
||||||
end);
|
end);
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--voicemail count if zero new messages set the mwi to no
|
--voicemail count if zero new messages set the mwi to no
|
||||||
|
if (session:ready()) then
|
||||||
if (voicemail_id ~= nil) then
|
if (voicemail_id ~= nil) then
|
||||||
sql = [[SELECT count(*) as new_messages FROM v_voicemail_messages
|
sql = [[SELECT count(*) as new_messages FROM v_voicemail_messages
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
@@ -1174,37 +1262,52 @@ function menu_messages (message_status)
|
|||||||
end
|
end
|
||||||
end);
|
end);
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--set the display
|
--set the display
|
||||||
|
if (session:ready()) then
|
||||||
api = freeswitch.API();
|
api = freeswitch.API();
|
||||||
reply = api:executeString("uuid_display "..session:get_uuid().." "..destination_number);
|
reply = api:executeString("uuid_display "..session:get_uuid().." "..destination_number);
|
||||||
|
end
|
||||||
|
|
||||||
--send back to the main menu
|
--send back to the main menu
|
||||||
|
if (session:ready()) then
|
||||||
main_menu();
|
main_menu();
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function advanced ()
|
function advanced ()
|
||||||
if (session:ready()) then
|
|
||||||
--To record a greeting press 1
|
--To record a greeting press 1
|
||||||
dtmf_digits = macro(session, "to_record_greeting", 100, '');
|
if (session:ready()) then
|
||||||
--To choose greeting press 2
|
dtmf_digits = macro(session, "to_record_greeting", 1, 100, '');
|
||||||
|
end
|
||||||
|
--To choose greeting press 2
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (string.len(dtmf_digits) == 0) then
|
||||||
dtmf_digits = macro(session, "choose_greeting", 100, '');
|
dtmf_digits = macro(session, "choose_greeting", 1, 100, '');
|
||||||
end
|
end
|
||||||
--To record your name 3
|
end
|
||||||
|
--To record your name 3
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (string.len(dtmf_digits) == 0) then
|
||||||
dtmf_digits = macro(session, "to_record_name", 100, '');
|
dtmf_digits = macro(session, "to_record_name", 1, 100, '');
|
||||||
end
|
end
|
||||||
--To change your password press 6
|
end
|
||||||
|
--To change your password press 6
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (string.len(dtmf_digits) == 0) then
|
||||||
dtmf_digits = macro(session, "change_password", 100, '');
|
dtmf_digits = macro(session, "change_password", 1, 100, '');
|
||||||
end
|
end
|
||||||
--For the main menu press 0
|
end
|
||||||
|
--For the main menu press 0
|
||||||
|
if (session:ready()) then
|
||||||
if (string.len(dtmf_digits) == 0) then
|
if (string.len(dtmf_digits) == 0) then
|
||||||
dtmf_digits = macro(session, "main_menu", 5000, '');
|
dtmf_digits = macro(session, "main_menu", 1, 5000, '');
|
||||||
end
|
end
|
||||||
--process the dtmf
|
end
|
||||||
|
--process the dtmf
|
||||||
|
if (session:ready()) then
|
||||||
if (dtmf_digits == "1") then
|
if (dtmf_digits == "1") then
|
||||||
--To record a greeting press 1
|
--To record a greeting press 1
|
||||||
record_greeting();
|
record_greeting();
|
||||||
@@ -1221,33 +1324,36 @@ function advanced ()
|
|||||||
--For the main menu press 0
|
--For the main menu press 0
|
||||||
main_menu();
|
main_menu();
|
||||||
else
|
else
|
||||||
if (session:ready()) then
|
advanced();
|
||||||
advanced();
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function record_greeting()
|
function record_greeting()
|
||||||
if (session:ready()) then
|
|
||||||
--Choose a greeting between 1 and 9
|
|
||||||
greeting_id = macro(session, "choose_greeting_choose", 5000, '');
|
|
||||||
|
|
||||||
--validate the greeting_id
|
--Choose a greeting between 1 and 9
|
||||||
if (greeting_id == "1"
|
if (session:ready()) then
|
||||||
or greeting_id == "2"
|
greeting_id = macro(session, "choose_greeting_choose", 1, 5000, '');
|
||||||
or greeting_id == "3"
|
end
|
||||||
or greeting_id == "4"
|
|
||||||
or greeting_id == "5"
|
|
||||||
or greeting_id == "6"
|
|
||||||
or greeting_id == "7"
|
|
||||||
or greeting_id == "8"
|
|
||||||
or greeting_id == "9") then
|
|
||||||
|
|
||||||
--record your greeting at the tone press any key or stop talking to end the recording
|
--validate the greeting_id
|
||||||
macro(session, "record_greeting", 100, '');
|
if (greeting_id == "1"
|
||||||
|
or greeting_id == "2"
|
||||||
|
or greeting_id == "3"
|
||||||
|
or greeting_id == "4"
|
||||||
|
or greeting_id == "5"
|
||||||
|
or greeting_id == "6"
|
||||||
|
or greeting_id == "7"
|
||||||
|
or greeting_id == "8"
|
||||||
|
or greeting_id == "9") then
|
||||||
|
|
||||||
--record the greeting
|
--record your greeting at the tone press any key or stop talking to end the recording
|
||||||
|
if (session:ready()) then
|
||||||
|
macro(session, "record_greeting", 1, 100, '');
|
||||||
|
end
|
||||||
|
|
||||||
|
--record the greeting
|
||||||
|
if (session:ready()) then
|
||||||
max_len_seconds = 30;
|
max_len_seconds = 30;
|
||||||
silence_threshold = 30;
|
silence_threshold = 30;
|
||||||
silence_seconds = 5;
|
silence_seconds = 5;
|
||||||
@@ -1255,45 +1361,52 @@ function record_greeting()
|
|||||||
-- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs)
|
-- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs)
|
||||||
result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", max_len_seconds, silence_threshold, silence_seconds);
|
result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", max_len_seconds, silence_threshold, silence_seconds);
|
||||||
--session:execute("record", voicemail_dir.."/"..uuid.." 180 200");
|
--session:execute("record", voicemail_dir.."/"..uuid.." 180 200");
|
||||||
|
end
|
||||||
|
|
||||||
--advanced menu
|
--advanced menu
|
||||||
|
if (session:ready()) then
|
||||||
advanced();
|
advanced();
|
||||||
else
|
end
|
||||||
--invalid greeting_id
|
else
|
||||||
greeting_id = macro(session, "choose_greeting_fail", 100, '');
|
--invalid greeting_id
|
||||||
|
if (session:ready()) then
|
||||||
|
greeting_id = macro(session, "choose_greeting_fail", 1, 100, '');
|
||||||
|
end
|
||||||
|
|
||||||
--send back to choose the greeting
|
--send back to choose the greeting
|
||||||
if (session:ready()) then
|
if (session:ready()) then
|
||||||
record_greeting();
|
record_greeting();
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function choose_greeting()
|
function choose_greeting()
|
||||||
if (session:ready()) then
|
|
||||||
--select the greeting
|
|
||||||
greeting_id = macro(session, "choose_greeting_choose", 5000, '');
|
|
||||||
|
|
||||||
--check to see if the greeting file exists
|
--select the greeting
|
||||||
if (not file_exists(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav")) then
|
if (session:ready()) then
|
||||||
--invalid greeting_id file does not exist
|
greeting_id = macro(session, "choose_greeting_choose", 1, 5000, '');
|
||||||
greeting_id = "invalid";
|
end
|
||||||
end
|
|
||||||
|
|
||||||
--validate the greeting_id
|
--check to see if the greeting file exists
|
||||||
if (greeting_id == "0"
|
if (not file_exists(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav")) then
|
||||||
or greeting_id == "1"
|
--invalid greeting_id file does not exist
|
||||||
or greeting_id == "2"
|
greeting_id = "invalid";
|
||||||
or greeting_id == "3"
|
end
|
||||||
or greeting_id == "4"
|
|
||||||
or greeting_id == "5"
|
|
||||||
or greeting_id == "6"
|
|
||||||
or greeting_id == "7"
|
|
||||||
or greeting_id == "8"
|
|
||||||
or greeting_id == "9") then
|
|
||||||
|
|
||||||
--valid greeting_id update the database
|
--validate the greeting_id
|
||||||
|
if (greeting_id == "0"
|
||||||
|
or greeting_id == "1"
|
||||||
|
or greeting_id == "2"
|
||||||
|
or greeting_id == "3"
|
||||||
|
or greeting_id == "4"
|
||||||
|
or greeting_id == "5"
|
||||||
|
or greeting_id == "6"
|
||||||
|
or greeting_id == "7"
|
||||||
|
or greeting_id == "8"
|
||||||
|
or greeting_id == "9") then
|
||||||
|
|
||||||
|
--valid greeting_id update the database
|
||||||
|
if (session:ready()) then
|
||||||
if (greeting_id == "0") then
|
if (greeting_id == "0") then
|
||||||
sql = [[UPDATE v_voicemails SET greeting_id = null ]];
|
sql = [[UPDATE v_voicemails SET greeting_id = null ]];
|
||||||
else
|
else
|
||||||
@@ -1305,34 +1418,44 @@ function choose_greeting()
|
|||||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||||
end
|
end
|
||||||
dbh:query(sql);
|
dbh:query(sql);
|
||||||
|
end
|
||||||
|
|
||||||
--play the greeting
|
--play the greeting
|
||||||
|
if (session:ready()) then
|
||||||
session:streamFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
session:streamFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||||
|
end
|
||||||
|
|
||||||
--greeting selected
|
--greeting selected
|
||||||
macro(session, "greeting_selected", 100, greeting_id);
|
if (session:ready()) then
|
||||||
|
macro(session, "greeting_selected", 1, 100, greeting_id);
|
||||||
|
end
|
||||||
|
|
||||||
--advanced menu
|
--advanced menu
|
||||||
|
if (session:ready()) then
|
||||||
advanced();
|
advanced();
|
||||||
else
|
end
|
||||||
--invalid greeting_id
|
else
|
||||||
greeting_id = macro(session, "choose_greeting_fail", 100, '');
|
--invalid greeting_id
|
||||||
|
if (session:ready()) then
|
||||||
|
greeting_id = macro(session, "choose_greeting_fail", 1, 100, '');
|
||||||
|
end
|
||||||
|
|
||||||
--send back to choose the greeting
|
--send back to choose the greeting
|
||||||
if (session:ready()) then
|
if (session:ready()) then
|
||||||
choose_greeting();
|
choose_greeting();
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--advanced menu
|
--advanced menu
|
||||||
|
if (session:ready()) then
|
||||||
advanced();
|
advanced();
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function record_name()
|
function record_name()
|
||||||
if (session:ready()) then
|
if (session:ready()) then
|
||||||
--play the name record
|
--play the name record
|
||||||
macro(session, "record_name", 100, '');
|
macro(session, "record_name", 1, 100, '');
|
||||||
|
|
||||||
--save the recording
|
--save the recording
|
||||||
-- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs)
|
-- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs)
|
||||||
@@ -1347,7 +1470,7 @@ function record_name()
|
|||||||
session:streamFile(voicemail_dir.."/"..voicemail_id.."/recorded_name.wav");
|
session:streamFile(voicemail_dir.."/"..voicemail_id.."/recorded_name.wav");
|
||||||
|
|
||||||
--message saved
|
--message saved
|
||||||
macro(session, "message_saved", 100, '');
|
macro(session, "message_saved", 1, 100, '');
|
||||||
|
|
||||||
--advanced menu
|
--advanced menu
|
||||||
advanced();
|
advanced();
|
||||||
|
|||||||
Reference in New Issue
Block a user