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();
freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. start_epoch .. "\n"); if (debug["info"]) then
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();
freeswitch.consoleLog("notice", "[voicemail] start epoch: " .. stop_epoch .. "\n"); if (debug["info"]) then
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);
freeswitch.consoleLog("notice", "[voicemail] message length: " .. message_length .. "\n"); if (debug["info"]) then
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,52 +671,52 @@
--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 ..[[' AND voicemail_message_uuid = ']] .. uuid ..[[']]
AND voicemail_message_uuid = ']] .. uuid ..[[']] 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) --get the values from the database
--get the values from the database --uuid = row["voicemail_message_uuid"];
--uuid = row["voicemail_message_uuid"]; --created_epoch = row["created_epoch"];
--created_epoch = row["created_epoch"]; caller_id_name = row["caller_id_name"];
caller_id_name = row["caller_id_name"]; caller_id_number = row["caller_id_number"];
caller_id_number = row["caller_id_number"]; message_length = row["message_length"];
message_length = row["message_length"]; --message_status = row["message_status"];
--message_status = row["message_status"]; --message_priority = row["message_priority"];
--message_priority = row["message_priority"]; end);
end);
--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>
<b>Message From "]]..caller_id_name..[[" <A HREF="tel:]]..caller_id_number..[[">]]..caller_id_number..[[</A></b><br> <b>Message From "]]..caller_id_name..[[" <A HREF="tel:]]..caller_id_number..[[">]]..caller_id_number..[[</A></b><br>
<hr noshade size=1> <hr noshade size=1>
Created: ]]..os.date("%A, %d %b %Y %I:%M %p", start_epoch)..[[<br> Created: ]]..os.date("%A, %d %b %Y %I:%M %p", start_epoch)..[[<br>
Duration: ]]..message_length_formatted..[[<br> Duration: ]]..message_length_formatted..[[<br>
Account: ]]..voicemail_id..[[@]]..domain_name..[[<br> Account: ]]..voicemail_id..[[@]]..domain_name..[[<br>
</font>]]; </font>]];
if (voicemail_attach_file == "true") then if (voicemail_attach_file == "true") then
freeswitch.email("", freeswitch.email("",
"",
"To: "..voicemail_mail_to.."\nFrom: "..voicemail_mail_to.."\nSubject: Voicemail from "..caller_id_name.." <"..caller_id_number.."> "..message_length_formatted,
message,
voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav"
);
else
freeswitch.email("",
"", "",
"To: "..voicemail_mail_to.."\nFrom: "..voicemail_mail_to.."\nSubject: Voicemail from "..caller_id_name.." <"..caller_id_number.."> "..message_length_formatted, "To: "..voicemail_mail_to.."\nFrom: "..voicemail_mail_to.."\nSubject: Voicemail from "..caller_id_name.." <"..caller_id_number.."> "..message_length_formatted,
message, message
voicemail_dir.."/"..voicemail_id.."/msg_"..uuid..".wav" );
); end
else
freeswitch.email("",
"",
"To: "..voicemail_mail_to.."\nFrom: "..voicemail_mail_to.."\nSubject: Voicemail from "..caller_id_name.." <"..caller_id_number.."> "..message_length_formatted,
message
);
end
end
end end
--define a function to forward a message to an extension --define a function to forward a message to an extension
@ -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,48 +840,54 @@
record_message(); record_message();
--save the message to the voicemail messages --save the message to the voicemail messages
local sql = {} if (message_length > 2) then
table.insert(sql, "INSERT INTO v_voicemail_messages "); local sql = {}
table.insert(sql, "("); table.insert(sql, "INSERT INTO v_voicemail_messages ");
table.insert(sql, "voicemail_message_uuid, "); table.insert(sql, "(");
table.insert(sql, "domain_uuid, "); table.insert(sql, "voicemail_message_uuid, ");
table.insert(sql, "voicemail_uuid, "); table.insert(sql, "domain_uuid, ");
table.insert(sql, "created_epoch, "); table.insert(sql, "voicemail_uuid, ");
table.insert(sql, "caller_id_name, "); table.insert(sql, "created_epoch, ");
table.insert(sql, "caller_id_number, "); table.insert(sql, "caller_id_name, ");
table.insert(sql, "message_length "); table.insert(sql, "caller_id_number, ");
--table.insert(sql, "message_status, "); table.insert(sql, "message_length ");
--table.insert(sql, "message_priority, "); --table.insert(sql, "message_status, ");
table.insert(sql, ") "); --table.insert(sql, "message_priority, ");
table.insert(sql, "VALUES "); table.insert(sql, ") ");
table.insert(sql, "( "); table.insert(sql, "VALUES ");
table.insert(sql, "'".. uuid .."', "); table.insert(sql, "( ");
table.insert(sql, "'".. domain_uuid .."', "); table.insert(sql, "'".. uuid .."', ");
table.insert(sql, "'".. voicemail_uuid .."', "); table.insert(sql, "'".. domain_uuid .."', ");
table.insert(sql, "'".. start_epoch .."', "); table.insert(sql, "'".. voicemail_uuid .."', ");
table.insert(sql, "'".. caller_id_name .."', "); table.insert(sql, "'".. start_epoch .."', ");
table.insert(sql, "'".. caller_id_number .."', "); table.insert(sql, "'".. caller_id_name .."', ");
table.insert(sql, "'".. message_length .."' "); table.insert(sql, "'".. caller_id_number .."', ");
--table.insert(sql, "'".. message_status .."', "); table.insert(sql, "'".. message_length .."' ");
--table.insert(sql, "'".. message_priority .."' "); --table.insert(sql, "'".. message_status .."', ");
table.insert(sql, ") "); --table.insert(sql, "'".. message_priority .."' ");
if (voicemail_local_after_email == "true") then table.insert(sql, ") ");
sql = table.concat(sql, "\n"); if (voicemail_local_after_email == "true") then
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);
--set the message waiting event --set the message waiting event
local event = freeswitch.Event("message_waiting"); if (message_length > 2) then
event:addHeader("MWI-Messages-Waiting", "yes"); local event = freeswitch.Event("message_waiting");
event:addHeader("MWI-Message-Account", "sip:"..voicemail_id.."@"..domain_name); event:addHeader("MWI-Messages-Waiting", "yes");
event:fire(); event:addHeader("MWI-Message-Account", "sip:"..voicemail_id.."@"..domain_name);
event:fire();
end
--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 (message_length > 2) then
send_email(uuid); if (string.len(voicemail_mail_to) > 3) then
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
@ -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
freeswitch.consoleLog("notice", message_number.." "..string.lower(row["voicemail_message_uuid"]).." "..row["created_epoch"]); if (debug["info"]) then
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);