Add voicemail skip_instructions, and skip_greetings they both work the same as FreeSWITCH's mod_voicemail. Fix a problem session:ready check was preventing the voicemail from being saved and emailed.

This commit is contained in:
Mark Crane
2013-01-08 03:34:51 +00:00
parent 98ae72f8cf
commit bbbfc2b0a5
+109 -96
View File
@@ -61,6 +61,8 @@
destination_number = session:getVariable("destination_number"); destination_number = session:getVariable("destination_number");
caller_id_name = session:getVariable("caller_id_name"); caller_id_name = session:getVariable("caller_id_name");
caller_id_number = session:getVariable("caller_id_number"); caller_id_number = session:getVariable("caller_id_number");
skip_instructions = session:getVariable("skip_instructions");
skip_greeting = session:getVariable("skip_greeting");
--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");
@@ -234,6 +236,11 @@
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
--beep
if (name == "record_beep") then
actions = {}
table.insert(actions, {app="tone_stream",data="L=1;%(1000, 0, 640)"});
end
--to listen to the recording press 1 --to listen to the recording press 1
if (name == "to_listen_to_recording") then if (name == "to_listen_to_recording") then
actions = {} actions = {}
@@ -582,55 +589,65 @@
--save the recording --save the recording
function record_message() function record_message()
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 if (skip_greeting == "true") then
result = macro(session, "record_beep", 1, 100);
else
result = macro(session, "record_message", 1, 100); result = macro(session, "record_message", 1, 100);
end
--start epoch --start epoch
start_epoch = os.time(); start_epoch = os.time();
if (debug["info"]) then if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. start_epoch .. "\n"); freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. start_epoch .. "\n");
end end
--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)
max_len_seconds = 30; max_len_seconds = 30;
silence_threshold = 30; silence_threshold = 30;
silence_seconds = 5; silence_seconds = 5;
os.execute("mkdir -p " .. voicemail_dir.."/"..voicemail_id); os.execute("mkdir -p " .. voicemail_dir.."/"..voicemail_id);
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");
--stop epoch --stop epoch
stop_epoch = os.time(); stop_epoch = os.time();
if (debug["info"]) then if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. stop_epoch .. "\n"); freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. stop_epoch .. "\n");
end end
--calculate the message length --calculate the message length
message_length = stop_epoch - start_epoch; message_length = stop_epoch - start_epoch;
message_length_formatted = format_seconds(message_length); message_length_formatted = format_seconds(message_length);
if (debug["info"]) then if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] message length: " .. message_length .. "\n"); freeswitch.consoleLog("notice", "[voicemail] message length: " .. message_length .. "\n");
end end
--if the recording is below the minmal length then re-record the message --if the recording is below the minmal length then re-record the message
if (message_length > 2) then if (message_length > 2) then
--continue --continue
else else
if (session:ready()) then
--your recording is below the minimal acceptable length, please try again
macro(session, "too_small", 1, 100);
--record your message at the tone
record_message();
end
end
--record menu 1 listen to the recording, 2 save the recording, 3 re-record
if (session:ready()) then if (session:ready()) then
--your recording is below the minimal acceptable length, please try again
macro(session, "too_small", 1, 100);
--record your message at the tone
record_message();
end
end
--instructions press 1 to listen to the recording, press 2 to save the recording, press 3 to re-record
if (session:ready()) then
if (skip_instructions == "true") then
--save the message
macro(session, "message_saved", 1, 100, '');
macro(session, "goodbye", 1, 100, '');
--hangup the call
session:hangup();
else
record_menu(); record_menu();
end end
end end
end end
--record message menu --record message menu
@@ -865,75 +882,71 @@
if (voicemail_action == "save") then if (voicemail_action == "save") then
--voicemail prompt --voicemail prompt
if (session:ready()) then if (skip_greeting == "true") then
if (string.len(greeting_id) > 0) then --skip the greeting
--play the greeting else
session:streamFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"); if (session:ready()) then
else if (string.len(greeting_id) > 0) then
--if there is no greeting then play digits of the voicemail_id --play the greeting
result = macro(session, "person_not_available_record_message", 1, 100); 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", 1, 100);
end
end 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 "); table.insert(sql, "(");
table.insert(sql, "("); table.insert(sql, "voicemail_message_uuid, ");
table.insert(sql, "voicemail_message_uuid, "); table.insert(sql, "domain_uuid, ");
table.insert(sql, "domain_uuid, "); table.insert(sql, "voicemail_uuid, ");
table.insert(sql, "voicemail_uuid, "); table.insert(sql, "created_epoch, ");
table.insert(sql, "created_epoch, "); table.insert(sql, "caller_id_name, ");
table.insert(sql, "caller_id_name, "); table.insert(sql, "caller_id_number, ");
table.insert(sql, "caller_id_number, "); table.insert(sql, "message_length ");
table.insert(sql, "message_length "); --table.insert(sql, "message_status, ");
--table.insert(sql, "message_status, "); --table.insert(sql, "message_priority, ");
--table.insert(sql, "message_priority, "); table.insert(sql, ") ");
table.insert(sql, ") "); table.insert(sql, "VALUES ");
table.insert(sql, "VALUES "); table.insert(sql, "( ");
table.insert(sql, "( "); table.insert(sql, "'".. uuid .."', ");
table.insert(sql, "'".. uuid .."', "); table.insert(sql, "'".. domain_uuid .."', ");
table.insert(sql, "'".. domain_uuid .."', "); table.insert(sql, "'".. voicemail_uuid .."', ");
table.insert(sql, "'".. voicemail_uuid .."', "); table.insert(sql, "'".. start_epoch .."', ");
table.insert(sql, "'".. start_epoch .."', "); table.insert(sql, "'".. caller_id_name .."', ");
table.insert(sql, "'".. caller_id_name .."', "); table.insert(sql, "'".. caller_id_number .."', ");
table.insert(sql, "'".. caller_id_number .."', "); table.insert(sql, "'".. message_length .."' ");
table.insert(sql, "'".. message_length .."' "); --table.insert(sql, "'".. message_status .."', ");
--table.insert(sql, "'".. message_status .."', "); --table.insert(sql, "'".. message_priority .."' ");
--table.insert(sql, "'".. message_priority .."' "); table.insert(sql, ") ");
table.insert(sql, ") "); if (voicemail_local_after_email == "true") then
if (voicemail_local_after_email == "true") then sql = table.concat(sql, "\n");
sql = table.concat(sql, "\n");
end
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
dbh:query(sql);
end end
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
dbh:query(sql);
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