Add support for voicemail forward destinations.

This commit is contained in:
Mark Crane
2014-12-04 13:43:09 +00:00
parent 6395455576
commit c618f852b5
@@ -271,80 +271,109 @@
--valid voicemail --valid voicemail
if (voicemail_uuid ~= nil) then if (voicemail_uuid ~= nil) then
--save the recording --play the greeting
timeouts = 0; timeouts = 0;
play_greeting(); play_greeting();
--save the message
record_message(); record_message();
--save the message to the voicemail messages --get the voicemail destinations
if (message_length > 2) then sql = [[select * from v_voicemail_destinations
local sql = {} where voicemail_uuid = ']]..voicemail_uuid..[[']]
table.insert(sql, "INSERT INTO v_voicemail_messages "); --freeswitch.consoleLog("notice", "[voicemail][destinations] SQL:" .. sql .. "\n");
table.insert(sql, "("); destinations = {};
table.insert(sql, "voicemail_message_uuid, "); x = 1;
table.insert(sql, "domain_uuid, "); table.insert(destinations, {domain_uuid=domain_uuid,voicemail_destination_uuid=voicemail_uuid,voicemail_uuid=voicemail_uuid,voicemail_uuid_copy=voicemail_uuid});
table.insert(sql, "voicemail_uuid, "); x = x + 1;
table.insert(sql, "created_epoch, "); assert(dbh:query(sql, function(row)
table.insert(sql, "caller_id_name, "); destinations[x] = row;
table.insert(sql, "caller_id_number, "); x = x + 1;
table.insert(sql, "message_length "); end));
--table.insert(sql, "message_status, ");
--table.insert(sql, "message_priority, "); --loop through the voicemail destinations
table.insert(sql, ") "); for key,row in pairs(destinations) do
table.insert(sql, "VALUES "); --save the message to the voicemail messages
table.insert(sql, "( "); if (tonumber(message_length) > 2) then
table.insert(sql, "'".. uuid .."', "); local sql = {}
table.insert(sql, "'".. domain_uuid .."', "); table.insert(sql, "INSERT INTO v_voicemail_messages ");
table.insert(sql, "'".. voicemail_uuid .."', "); table.insert(sql, "(");
table.insert(sql, "'".. start_epoch .."', "); table.insert(sql, "voicemail_message_uuid, ");
table.insert(sql, "'".. caller_id_name .."', "); table.insert(sql, "domain_uuid, ");
table.insert(sql, "'".. caller_id_number .."', "); table.insert(sql, "voicemail_uuid, ");
table.insert(sql, "'".. message_length .."' "); table.insert(sql, "created_epoch, ");
--table.insert(sql, "'".. message_status .."', "); table.insert(sql, "caller_id_name, ");
--table.insert(sql, "'".. message_priority .."' "); table.insert(sql, "caller_id_number, ");
table.insert(sql, ") "); table.insert(sql, "message_length ");
sql = table.concat(sql, "\n"); --table.insert(sql, "message_status, ");
if (debug["sql"]) then --table.insert(sql, "message_priority, ");
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n"); table.insert(sql, ") ");
end table.insert(sql, "VALUES ");
dbh:query(sql); table.insert(sql, "( ");
table.insert(sql, "'".. uuid .."', ");
table.insert(sql, "'".. domain_uuid .."', ");
table.insert(sql, "'".. row.voicemail_uuid_copy .."', ");
table.insert(sql, "'".. start_epoch .."', ");
table.insert(sql, "'".. caller_id_name .."', ");
table.insert(sql, "'".. caller_id_number .."', ");
table.insert(sql, "'".. message_length .."' ");
--table.insert(sql, "'".. message_status .."', ");
--table.insert(sql, "'".. message_priority .."' ");
table.insert(sql, ") ");
sql = table.concat(sql, "\n");
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
dbh:query(sql);
end
--get saved and new message counts
sql = [[SELECT count(*) as new_messages FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_uuid = ']] .. row.voicemail_uuid_copy ..[['
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(result)
new_messages = result["new_messages"];
end);
sql = [[SELECT count(*) as saved_messages FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_uuid = ']] .. row.voicemail_uuid_copy ..[['
AND message_status = 'saved' ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(result)
saved_messages = result["saved_messages"];
end);
--get the voicemail_id
sql = [[SELECT voicemail_id FROM v_voicemails
WHERE voicemail_uuid = ']] .. row.voicemail_uuid_copy ..[[']];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(result)
voicemail_id_copy = result["voicemail_id"];
end);
--set the message waiting event
if (tonumber(message_length) > 2) then
local event = freeswitch.Event("message_waiting");
event:addHeader("MWI-Messages-Waiting", "yes");
event:addHeader("MWI-Message-Account", "sip:"..voicemail_id_copy.."@"..domain_name);
event:addHeader("MWI-Voice-Message", new_messages.."/"..saved_messages.." (0/0)");
event:fire();
end
--send the email with the voicemail recording attached
if (tonumber(message_length) > 2) then
send_email(voicemail_id_copy, uuid);
end
end end
--get saved and new message counts
sql = [[SELECT count(*) as new_messages FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
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);
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);
--set the message waiting event
if (message_length > 2) then
local event = freeswitch.Event("message_waiting");
event:addHeader("MWI-Messages-Waiting", "yes");
event:addHeader("MWI-Message-Account", "sip:"..voicemail_id.."@"..domain_name);
event:addHeader("MWI-Voice-Message", new_messages.."/"..saved_messages.." (0/0)");
event:fire();
end
--send the email with the voicemail recording attached
if (message_length > 2) then
send_email(voicemail_id, uuid);
end
else else
--voicemail not enabled or does not exist --voicemail not enabled or does not exist
referred_by = session:getVariable("sip_h_Referred-By"); referred_by = session:getVariable("sip_h_Referred-By");