Require the message to be 3 seconds or longer to save the recording. Remove a session:ready from the send_email function to fix voicemail to email.

This commit is contained in:
Mark Crane 2013-01-04 06:14:52 +00:00
parent fb59acd07b
commit daffa7d856
1 changed files with 106 additions and 86 deletions

View File

@ -89,7 +89,9 @@
--set the voicemail_dir --set the voicemail_dir
voicemail_dir = base_dir.."/storage/voicemail/default/"..domain_name; voicemail_dir = base_dir.."/storage/voicemail/default/"..domain_name;
--freeswitch.consoleLog("notice", "[voicemail] voicemail_dir: " .. voicemail_dir .. "\n"); if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] voicemail_dir: " .. voicemail_dir .. "\n");
end
--check if a file exists --check if a file exists
function file_exists(name) function file_exists(name)
@ -129,7 +131,9 @@
--do nothing --do nothing
else else
voicemail_id = get_voicemail_id(); voicemail_id = get_voicemail_id();
--freeswitch.consoleLog("notice", "[voicemail] voicemail id: " .. voicemail_id .. "\n"); if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] voicemail id: " .. voicemail_id .. "\n");
end
end end
--get the voicemail settings from the database --get the voicemail settings from the database
@ -578,7 +582,9 @@
--start epoch --start epoch
start_epoch = os.time(); start_epoch = os.time();
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. start_epoch .. "\n"); freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. start_epoch .. "\n");
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)
@ -591,15 +597,21 @@
--stop epoch --stop epoch
stop_epoch = os.time(); stop_epoch = os.time();
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. stop_epoch .. "\n"); freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. stop_epoch .. "\n");
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
freeswitch.consoleLog("notice", "[voicemail] message length: " .. message_length .. "\n"); freeswitch.consoleLog("notice", "[voicemail] message length: " .. message_length .. "\n");
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 < 4) then if (message_length > 2) then
--continue
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", 100);
@ -659,7 +671,6 @@
--define a function to send email --define a function to send email
function send_email(uuid) function send_email(uuid)
if (session:ready()) then
--get voicemail message details --get voicemail message details
sql = [[SELECT * FROM v_voicemail_messages sql = [[SELECT * FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[[' WHERE domain_uuid = ']] .. domain_uuid ..[['
@ -680,7 +691,9 @@
--calculate the message length --calculate the message length
message_length_formatted = format_seconds(message_length); message_length_formatted = format_seconds(message_length);
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] message length: " .. message_length .. "\n"); freeswitch.consoleLog("notice", "[voicemail] message length: " .. message_length .. "\n");
end
--send the email --send the email
message = [[<font face=arial> message = [[<font face=arial>
@ -705,7 +718,6 @@
); );
end end
end end
end
--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)
@ -806,7 +818,7 @@
end end
--send the email with the voicemail recording attached --send the email with the voicemail recording attached
if (string.len(forward_voicemail_mail_to) > 3) then if (string.len(forward_voicemail_mail_to) > 2) then
send_email(uuid); send_email(uuid);
end end
end end
@ -828,6 +840,7 @@
record_message(); record_message();
--save the message to the voicemail messages --save the message to the voicemail messages
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, "(");
@ -860,17 +873,22 @@
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 (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
--send the email with the voicemail recording attached --send the email with the voicemail recording attached
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
--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
@ -1129,7 +1147,9 @@ function menu_messages (message_status)
message_number = message_number + 1; message_number = message_number + 1;
--listen to the message --listen to the message
if (session:ready()) then if (session:ready()) then
if (debug["info"]) then
freeswitch.consoleLog("notice", message_number.." "..string.lower(row["voicemail_message_uuid"]).." "..row["created_epoch"]); freeswitch.consoleLog("notice", message_number.." "..string.lower(row["voicemail_message_uuid"]).." "..row["created_epoch"]);
end
listen_to_recording(message_number, string.lower(row["voicemail_message_uuid"]), row["created_epoch"], row["caller_id_name"], row["caller_id_number"]); listen_to_recording(message_number, string.lower(row["voicemail_message_uuid"]), row["created_epoch"], row["caller_id_name"], row["caller_id_number"]);
end end
end); end);