Additional work on voicemail with base64.

This commit is contained in:
Mark Crane
2015-04-17 20:10:36 +00:00
parent 949b2ec3fe
commit 93dffec059
2 changed files with 48 additions and 26 deletions

View File

@@ -122,6 +122,28 @@
domain_uuid = string.lower(domain_uuid);
end
--settings
dofile(scripts_dir.."/resources/functions/settings.lua");
settings = settings(domain_uuid);
storage_type = "";
if (settings['voicemail']['storage_type'] ~= nil) then
if (settings['voicemail']['storage_type']['text'] ~= nil) then
storage_type = settings['voicemail']['storage_type']['text'];
end
end
storage_path = "";
if (settings['voicemail']['storage_path'] ~= nil) then
if (settings['voicemail']['storage_path']['text'] ~= nil) then
storage_path = settings['voicemail']['storage_path']['text'];
end
end
temp_dir = "";
if (settings['server']['temp'] ~= nil) then
if (settings['server']['temp']['dir'] ~= nil) then
temp_dir = settings['server']['temp']['dir'];
end
end
--if voicemail_id is non numeric then get the number-alias
if (voicemail_id ~= nil) then
if tonumber(voicemail_id) == nil then
@@ -322,11 +344,13 @@
dofile(scripts_dir.."/resources/functions/base64.lua");
--base64 encode the file
local f = io.open(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, "rb");
local file_content = f:read("*all");
f:close();
message_base64 = base64.encode(file_content);
--freeswitch.consoleLog("notice", "[voicemail] ".. message_base64 .. "\n");
if (file_exists(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext)) then
local f = io.open(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, "rb");
local file_content = f:read("*all");
f:close();
message_base64 = base64.encode(file_content);
--freeswitch.consoleLog("notice", "[voicemail] ".. message_base64 .. "\n");
end
end
--get the voicemail destinations

View File

@@ -59,28 +59,26 @@
--get the recordings from the database
if (storage_type == "base64") then
if (string.len(ivr_menu_greet_long) > 1) then
sql = [[SELECT * FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_message_uuid = ']].. uuid.. [[' ]];
--if (debug["sql"]) then
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
--end
status = dbh:query(sql, function(row)
--add functions
dofile(scripts_dir.."/resources/functions/base64.lua");
--set the voicemail message path
message_location = voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext;
--save the recording to the file system
if (string.len(row["message_base64"]) > 32) then
local file = io.open(message_location, "w");
file:write(base64.decode(row["message_base64"]));
file:close();
end
end);
sql = [[SELECT * FROM v_voicemail_messages
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_message_uuid = ']].. uuid.. [[' ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(row)
--add functions
dofile(scripts_dir.."/resources/functions/base64.lua");
--set the voicemail message path
message_location = voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext;
--save the recording to the file system
if (string.len(row["message_base64"]) > 32) then
local file = io.open(message_location, "w");
file:write(base64.decode(row["message_base64"]));
file:close();
end
end);
elseif (storage_type == "http_cache") then
message_location = storage_path.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext;
end