Many improvements to voicemail when exiting the voicemail ivr say good bye, notify when the message is below the minimum length, record message menu 1 to listen to the recording, 2 to save the recording and 3 to re-record, and other enhancements.
This commit is contained in:
parent
5bd0875b25
commit
914e1504ac
|
|
@ -216,10 +216,8 @@
|
||||||
actions = {}
|
actions = {}
|
||||||
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-person.wav"});
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-person.wav"});
|
||||||
--pronounce the voicemail_id
|
--pronounce the voicemail_id
|
||||||
table.insert(actions, {app="say.number.pronounced",data=voicemail_id});
|
table.insert(actions, {app="say.number.iterated",data=voicemail_id});
|
||||||
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-not_available.wav"});
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-not_available.wav"});
|
||||||
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-record_message.wav"});
|
|
||||||
table.insert(actions, {app="tone_stream",data="L=1;%(1000, 0, 640)"});
|
|
||||||
end
|
end
|
||||||
--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
|
||||||
if (name == "record_message") then
|
if (name == "record_message") then
|
||||||
|
|
@ -227,6 +225,27 @@
|
||||||
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-record_message.wav"});
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-record_message.wav"});
|
||||||
table.insert(actions, {app="tone_stream",data="L=1;%(1000, 0, 640)"});
|
table.insert(actions, {app="tone_stream",data="L=1;%(1000, 0, 640)"});
|
||||||
end
|
end
|
||||||
|
--to listen to the recording press 1
|
||||||
|
if (name == "to_listen_to_recording") then
|
||||||
|
actions = {}
|
||||||
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-listen_to_recording.wav"});
|
||||||
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-press.wav"});
|
||||||
|
table.insert(actions, {app="playAndGetDigits",data="digits/1.wav"});
|
||||||
|
end
|
||||||
|
--to save the recording press 2
|
||||||
|
if (name == "to_save_recording") then
|
||||||
|
actions = {}
|
||||||
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-save_recording.wav"});
|
||||||
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-press.wav"});
|
||||||
|
table.insert(actions, {app="playAndGetDigits",data="digits/2.wav"});
|
||||||
|
end
|
||||||
|
--to rerecord press 3
|
||||||
|
if (name == "to_rerecord") then
|
||||||
|
actions = {}
|
||||||
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-rerecord.wav"});
|
||||||
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-press.wav"});
|
||||||
|
table.insert(actions, {app="playAndGetDigits",data="digits/3.wav"});
|
||||||
|
end
|
||||||
--You have zero new messages
|
--You have zero new messages
|
||||||
if (name == "new_messages") then
|
if (name == "new_messages") then
|
||||||
actions = {}
|
actions = {}
|
||||||
|
|
@ -412,6 +431,11 @@
|
||||||
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-press.wav"});
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-press.wav"});
|
||||||
table.insert(actions, {app="playAndGetDigits",data="digits/7.wav"});
|
table.insert(actions, {app="playAndGetDigits",data="digits/7.wav"});
|
||||||
end
|
end
|
||||||
|
--Message deleted
|
||||||
|
if (name == "message_deleted") then
|
||||||
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-message.wav"});
|
||||||
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-deleted.wav"});
|
||||||
|
end
|
||||||
--To return the call now press 5
|
--To return the call now press 5
|
||||||
if (name == "return_call") then
|
if (name == "return_call") then
|
||||||
actions = {}
|
actions = {}
|
||||||
|
|
@ -448,9 +472,20 @@
|
||||||
--Message saved
|
--Message saved
|
||||||
if (name == "message_saved") then
|
if (name == "message_saved") then
|
||||||
actions = {}
|
actions = {}
|
||||||
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-message.wav"})
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-message.wav"});
|
||||||
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-saved.wav"})
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-saved.wav"});
|
||||||
end
|
end
|
||||||
|
--Your recording is below the minimal acceptable length, please try again.
|
||||||
|
if (name == "too_small") then
|
||||||
|
actions = {}
|
||||||
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-too-small.wav"});
|
||||||
|
end
|
||||||
|
--Goodbye
|
||||||
|
if (name == "goodbye") then
|
||||||
|
actions = {}
|
||||||
|
table.insert(actions, {app="playAndGetDigits",data="voicemail/vm-goodbye.wav"});
|
||||||
|
end
|
||||||
|
|
||||||
--if actions table exists then process it
|
--if actions table exists then process it
|
||||||
if (actions) then
|
if (actions) then
|
||||||
--set default values
|
--set default values
|
||||||
|
|
@ -475,6 +510,8 @@
|
||||||
end
|
end
|
||||||
elseif (row.app == "say.number.pronounced") then
|
elseif (row.app == "say.number.pronounced") then
|
||||||
session:say(row.data, "en", "number", "pronounced");
|
session:say(row.data, "en", "number", "pronounced");
|
||||||
|
elseif (row.app == "say.number.iterated") then
|
||||||
|
session:say(row.data, "en", "number", "iterated");
|
||||||
else
|
else
|
||||||
session:execute(row.app, row.data);
|
session:execute(row.app, row.data);
|
||||||
end
|
end
|
||||||
|
|
@ -493,40 +530,39 @@
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--get the voicemail settings from the database
|
--get the voicemail settings
|
||||||
if (voicemail_id ~= nil) then
|
if (voicemail_id ~= nil) then
|
||||||
sql = [[SELECT * FROM v_voicemails
|
--get the information from the database
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
sql = [[SELECT * FROM v_voicemails
|
||||||
AND voicemail_id = ']] .. voicemail_id ..[['
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
AND voicemail_enabled = 'true' ]];
|
AND voicemail_id = ']] .. voicemail_id ..[['
|
||||||
if (debug["sql"]) then
|
AND voicemail_enabled = 'true' ]];
|
||||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
if (debug["sql"]) then
|
||||||
end
|
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||||
status = dbh:query(sql, function(row)
|
end
|
||||||
voicemail_uuid = string.lower(row["voicemail_uuid"]);
|
status = dbh:query(sql, function(row)
|
||||||
voicemail_password = row["voicemail_password"];
|
voicemail_uuid = string.lower(row["voicemail_uuid"]);
|
||||||
greeting_id = row["greeting_id"];
|
voicemail_password = row["voicemail_password"];
|
||||||
voicemail_mail_to = row["voicemail_mail_to"];
|
greeting_id = row["greeting_id"];
|
||||||
voicemail_attach_file = row["voicemail_attach_file"];
|
voicemail_mail_to = row["voicemail_mail_to"];
|
||||||
voicemail_local_after_email = row["voicemail_local_after_email"];
|
voicemail_attach_file = row["voicemail_attach_file"];
|
||||||
end);
|
voicemail_local_after_email = row["voicemail_local_after_email"];
|
||||||
|
end);
|
||||||
|
--set default values
|
||||||
|
if (string.len(voicemail_local_after_email) == 0) then
|
||||||
|
voicemail_local_after_email = "true";
|
||||||
|
end
|
||||||
|
if (string.len(voicemail_attach_file) == 0) then
|
||||||
|
voicemail_attach_file = "true";
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--leave a voicemail
|
--save the recording
|
||||||
if (voicemail_action == "save") then
|
function record_message()
|
||||||
|
--record your message at the tone press any key or stop talking to end the recording
|
||||||
|
result = macro(session, "record_message", 200);
|
||||||
|
|
||||||
--voicemail prompt
|
--start epoch
|
||||||
if (string.len(greeting_id) > 0) then
|
|
||||||
--play the greeting
|
|
||||||
session:streamFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
|
||||||
--record your message at the tone press any key or stop talking to end the recording
|
|
||||||
result = macro(session, "record_message", 200);
|
|
||||||
else
|
|
||||||
--if there is no greeting then play digits of the voicemail_id
|
|
||||||
result = macro(session, "person_not_available_record_message", 200);
|
|
||||||
end
|
|
||||||
|
|
||||||
--set the epoch
|
|
||||||
start_epoch = os.time();
|
start_epoch = os.time();
|
||||||
freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. start_epoch .. "\n");
|
freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. start_epoch .. "\n");
|
||||||
|
|
||||||
|
|
@ -539,13 +575,7 @@
|
||||||
result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", max_len_seconds, silence_threshold, silence_seconds);
|
result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", max_len_seconds, silence_threshold, silence_seconds);
|
||||||
--session:execute("record", voicemail_dir.."/"..uuid.." 180 200");
|
--session:execute("record", voicemail_dir.."/"..uuid.." 180 200");
|
||||||
|
|
||||||
--set the message waiting event
|
--stop epoch
|
||||||
local event = freeswitch.Event("message_waiting");
|
|
||||||
event:addHeader("MWI-Messages-Waiting", "yes");
|
|
||||||
event:addHeader("MWI-Message-Account", "sip:"..voicemail_id.."@"..domain_name);
|
|
||||||
event:fire();
|
|
||||||
|
|
||||||
--set the epoch
|
|
||||||
stop_epoch = os.time();
|
stop_epoch = os.time();
|
||||||
freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. stop_epoch .. "\n");
|
freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. stop_epoch .. "\n");
|
||||||
|
|
||||||
|
|
@ -554,6 +584,83 @@
|
||||||
message_length_formatted = format_seconds(message_length);
|
message_length_formatted = format_seconds(message_length);
|
||||||
freeswitch.consoleLog("notice", "[voicemail] message length: " .. message_length .. "\n");
|
freeswitch.consoleLog("notice", "[voicemail] message length: " .. message_length .. "\n");
|
||||||
|
|
||||||
|
--if the recording is below the minmal length then re-record the message
|
||||||
|
if (message_length < 4) then
|
||||||
|
if (session:ready()) then
|
||||||
|
--your recording is below the minimal acceptable length, please try again
|
||||||
|
macro(session, "too_small", 200);
|
||||||
|
--record your message at the tone
|
||||||
|
record_message();
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--record menu 1 listen to the recording, 2 save the recording, 3 re-record
|
||||||
|
record_menu();
|
||||||
|
end
|
||||||
|
|
||||||
|
--record message menu
|
||||||
|
function record_menu()
|
||||||
|
--clear the dtmf digits variable
|
||||||
|
dtmf_digits = '';
|
||||||
|
--to listen to the recording press 1
|
||||||
|
if (string.len(dtmf_digits) == 0) then
|
||||||
|
dtmf_digits = macro(session, "to_listen_to_recording", 200, '');
|
||||||
|
end
|
||||||
|
--to save the recording press 2
|
||||||
|
if (string.len(dtmf_digits) == 0) then
|
||||||
|
dtmf_digits = macro(session, "to_save_recording", 200, '');
|
||||||
|
end
|
||||||
|
--to re-record press 3
|
||||||
|
if (string.len(dtmf_digits) == 0) then
|
||||||
|
dtmf_digits = macro(session, "to_rerecord", 3000, '');
|
||||||
|
end
|
||||||
|
--process the dtmf
|
||||||
|
if (dtmf_digits == "1") then
|
||||||
|
--listen to the recording
|
||||||
|
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav", "", "\\d+", 1000);
|
||||||
|
--record menu 1 listen to the recording, 2 save the recording, 3 re-record
|
||||||
|
record_menu();
|
||||||
|
elseif (dtmf_digits == "2") then
|
||||||
|
--save the message
|
||||||
|
macro(session, "message_saved", 200, '');
|
||||||
|
macro(session, "goodbye", 200, '');
|
||||||
|
--hangup the call
|
||||||
|
session:hangup();
|
||||||
|
elseif (dtmf_digits == "3") then
|
||||||
|
--rerecord the message
|
||||||
|
record_message();
|
||||||
|
elseif (dtmf_digits == "*") then
|
||||||
|
--hangup
|
||||||
|
macro(session, "goodbye", 200, '');
|
||||||
|
session:hangup();
|
||||||
|
else
|
||||||
|
if (session:ready()) then
|
||||||
|
record_menu();
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--leave a voicemail
|
||||||
|
if (voicemail_action == "save") then
|
||||||
|
|
||||||
|
--voicemail prompt
|
||||||
|
if (string.len(greeting_id) > 0) then
|
||||||
|
--play the greeting
|
||||||
|
session:streamFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||||
|
else
|
||||||
|
--if there is no greeting then play digits of the voicemail_id
|
||||||
|
result = macro(session, "person_not_available_record_message", 200);
|
||||||
|
end
|
||||||
|
|
||||||
|
--save the recording
|
||||||
|
record_message();
|
||||||
|
|
||||||
|
--set the message waiting event
|
||||||
|
local event = freeswitch.Event("message_waiting");
|
||||||
|
event:addHeader("MWI-Messages-Waiting", "yes");
|
||||||
|
event:addHeader("MWI-Message-Account", "sip:"..voicemail_id.."@"..domain_name);
|
||||||
|
event:fire();
|
||||||
|
|
||||||
--send the email with the voicemail recording attached
|
--send the email with the voicemail recording attached
|
||||||
if (string.len(voicemail_mail_to) > 3) then
|
if (string.len(voicemail_mail_to) > 3) then
|
||||||
message = [[<font face=arial>
|
message = [[<font face=arial>
|
||||||
|
|
@ -672,6 +779,7 @@ function main_menu ()
|
||||||
elseif (dtmf_digits == "0") then
|
elseif (dtmf_digits == "0") then
|
||||||
session:transfer("0", "XML", context);
|
session:transfer("0", "XML", context);
|
||||||
elseif (dtmf_digits == "*") then
|
elseif (dtmf_digits == "*") then
|
||||||
|
macro(session, "goodbye", 200, '');
|
||||||
session:hangup();
|
session:hangup();
|
||||||
else
|
else
|
||||||
if (session:ready()) then
|
if (session:ready()) then
|
||||||
|
|
@ -739,33 +847,73 @@ function listen_to_recording (message_number, uuid, created_epoch, caller_id_nam
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function message_saved(uuid)
|
--voicemail count if zero new messages set the mwi to no
|
||||||
--delete from the database
|
function message_waiting()
|
||||||
sql = [[UPDATE v_voicemail_messages SET message_status = 'saved'
|
if (voicemail_id ~= nil) then
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
sql = [[SELECT count(*) as new_messages FROM v_voicemail_messages
|
||||||
AND voicemail_message_uuid = ']] .. uuid ..[[']];
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
if (debug["sql"]) then
|
AND voicemail_uuid = ']] .. voicemail_uuid ..[['
|
||||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
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)
|
||||||
|
if (row["new_messages"] == "0") then
|
||||||
|
--send the message waiting event
|
||||||
|
local event = freeswitch.Event("message_waiting");
|
||||||
|
event:addHeader("MWI-Messages-Waiting", "no");
|
||||||
|
event:addHeader("MWI-Message-Account", "sip:"..voicemail_id.."@"..domain_name);
|
||||||
|
event:fire();
|
||||||
|
else
|
||||||
|
--set the message waiting event
|
||||||
|
local event = freeswitch.Event("message_waiting");
|
||||||
|
event:addHeader("MWI-Messages-Waiting", "yes");
|
||||||
|
event:addHeader("MWI-Message-Account", "sip:"..voicemail_id.."@"..domain_name);
|
||||||
|
event:fire();
|
||||||
|
end
|
||||||
|
end);
|
||||||
end
|
end
|
||||||
dbh:query(sql);
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function delete_recording(uuid)
|
--delete the recording
|
||||||
--delete the file
|
function delete_recording(uuid)
|
||||||
os.remove(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav");
|
--delete the file
|
||||||
--delete from the database
|
os.remove(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav");
|
||||||
sql = [[DELETE FROM v_voicemail_messages
|
--delete from the database
|
||||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
sql = [[DELETE FROM v_voicemail_messages
|
||||||
AND voicemail_message_uuid = ']] .. uuid ..[[']];
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
if (debug["sql"]) then
|
AND voicemail_message_uuid = ']] .. uuid ..[[']];
|
||||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
if (debug["sql"]) then
|
||||||
end
|
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||||
dbh:query(sql);
|
end
|
||||||
end
|
dbh:query(sql);
|
||||||
|
--message deleted
|
||||||
|
macro(session, "message_deleted", 200, '');
|
||||||
|
--check the message waiting status
|
||||||
|
message_waiting();
|
||||||
|
end
|
||||||
|
|
||||||
function return_call(destination)
|
--save the message
|
||||||
session:transfer(destination, "XML", context);
|
function message_saved(uuid)
|
||||||
end
|
--delete from the database
|
||||||
|
sql = [[UPDATE v_voicemail_messages SET message_status = 'saved'
|
||||||
|
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||||
|
AND voicemail_message_uuid = ']] .. uuid ..[[']];
|
||||||
|
if (debug["sql"]) then
|
||||||
|
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||||
|
end
|
||||||
|
dbh:query(sql);
|
||||||
|
--check the message waiting status
|
||||||
|
message_waiting();
|
||||||
|
end
|
||||||
|
|
||||||
|
--return the call
|
||||||
|
function return_call(destination)
|
||||||
|
--check the message waiting status
|
||||||
|
message_waiting();
|
||||||
|
--transfer the call
|
||||||
|
session:transfer(destination, "XML", context);
|
||||||
|
end
|
||||||
|
|
||||||
function menu_messages (message_status)
|
function menu_messages (message_status)
|
||||||
--set default values
|
--set default values
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue