Add an option to save the greeting to the database.
This commit is contained in:
parent
7f8e7d98ca
commit
3c36351762
|
|
@ -52,15 +52,96 @@
|
|||
macro(session, "record_greeting", 1, 100, '');
|
||||
end
|
||||
|
||||
--record the greeting
|
||||
if (session:ready()) then
|
||||
max_len_seconds = 30;
|
||||
silence_threshold = 30;
|
||||
silence_seconds = 5;
|
||||
mkdir(voicemail_dir.."/"..voicemail_id);
|
||||
-- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs)
|
||||
result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", max_len_seconds, silence_threshold, silence_seconds);
|
||||
--session:execute("record", voicemail_dir.."/"..uuid.." 180 200");
|
||||
|
||||
--store the voicemail greeting
|
||||
if (storage_type == "base64") then
|
||||
--prepare to record the greeting
|
||||
if (session:ready()) then
|
||||
max_len_seconds = 30;
|
||||
silence_threshold = 30;
|
||||
silence_seconds = 5;
|
||||
mkdir(voicemail_dir.."/"..voicemail_id);
|
||||
-- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs)
|
||||
result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", max_len_seconds, silence_threshold, silence_seconds);
|
||||
--session:execute("record", voicemail_dir.."/"..uuid.." 180 200");
|
||||
end
|
||||
|
||||
--include the base64 function
|
||||
dofile(scripts_dir.."/resources/functions/base64.lua");
|
||||
|
||||
--show the storage type
|
||||
freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n");
|
||||
|
||||
--base64 encode the file
|
||||
local f = io.open(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "rb");
|
||||
local file_content = f:read("*all");
|
||||
f:close();
|
||||
greeting_base64 = base64.encode(file_content);
|
||||
|
||||
--delete the previous recording
|
||||
sql = "delete from v_voicemail_greetings ";
|
||||
sql = sql .. "where domain_uuid = '".. domain_uuid .. "' ";
|
||||
sql = sql .. "and voicemail_id = '".. voicemail_id .."'";
|
||||
sql = sql .. "and greeting_id = '".. greeting_id .."'";
|
||||
dbh:query(sql);
|
||||
|
||||
--get a new uuid
|
||||
voicemail_greeting_uuid = api:execute("create_uuid");
|
||||
|
||||
--save the message to the voicemail messages
|
||||
local array = {}
|
||||
table.insert(array, "INSERT INTO v_voicemail_greetings ");
|
||||
table.insert(array, "(");
|
||||
table.insert(array, "voicemail_greeting_uuid, ");
|
||||
table.insert(array, "domain_uuid, ");
|
||||
table.insert(array, "voicemail_id, ");
|
||||
table.insert(array, "greeting_id, ");
|
||||
if (storage_type == "base64") then
|
||||
table.insert(array, "greeting_base64, ");
|
||||
end
|
||||
table.insert(array, "greeting_name ");
|
||||
table.insert(array, ") ");
|
||||
table.insert(array, "VALUES ");
|
||||
table.insert(array, "( ");
|
||||
table.insert(array, "'"..voicemail_greeting_uuid.."', ");
|
||||
table.insert(array, "'"..domain_uuid.."', ");
|
||||
table.insert(array, "'"..voicemail_id.."', ");
|
||||
table.insert(array, "'"..greeting_id.."', ");
|
||||
if (storage_type == "base64") then
|
||||
table.insert(array, "'"..greeting_base64.."', ");
|
||||
end
|
||||
table.insert(array, "'greeting_"..greeting_id..".wav' ");
|
||||
table.insert(array, ") ");
|
||||
sql = table.concat(array, "\n");
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||
end
|
||||
if (storage_type == "base64") then
|
||||
array = explode("://", database["system"]);
|
||||
local luasql = require "luasql.postgres";
|
||||
local env = assert (luasql.postgres());
|
||||
local db = env:connect(array[2]);
|
||||
res, serr = db:execute(sql);
|
||||
db:close();
|
||||
env:close();
|
||||
else
|
||||
dbh:query(sql);
|
||||
end
|
||||
elseif (storage_type == "http_cache") then
|
||||
freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. " ".. storage_path .."\n");
|
||||
session:execute("record", storage_path .."/"..recording_name);
|
||||
else
|
||||
--prepare to record the greeting
|
||||
if (session:ready()) then
|
||||
max_len_seconds = 30;
|
||||
silence_threshold = 30;
|
||||
silence_seconds = 5;
|
||||
mkdir(voicemail_dir.."/"..voicemail_id);
|
||||
-- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs)
|
||||
result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", max_len_seconds, silence_threshold, silence_seconds);
|
||||
--session:execute("record", voicemail_dir.."/"..uuid.." 180 200");
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--play the greeting
|
||||
|
|
@ -93,4 +174,4 @@
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue