mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-01-06 11:43:50 +00:00
Voicemail Greetings: Better base64 support in gui (playback, download, etc) and lua scripts, some lua mods to allow re-recording without having to enter greeting # again, fixed choose greeting function, new greeting recordings now only save when told to (uses a temp file prior to), fix sorting on greetings list, app_defaults to move greetings from file system to base64 in db (and vice versa).
Recordings: Fix sorting and paging. IVRs: Code cleanup. (... and some other stuff I can't remember at this hour.)
This commit is contained in:
@@ -87,29 +87,27 @@
|
||||
|
||||
--get the greeting from the database
|
||||
if (storage_type == "base64") then
|
||||
if (string.len(ivr_menu_greet_long) > 1) then
|
||||
sql = [[SELECT * FROM v_voicemail_greetings
|
||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||
AND voicemail_id = ']].. voicemail_id.. [['
|
||||
AND greeting_id = ']].. greeting_id.. [[' ]];
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||
end
|
||||
status = dbh:query(sql, function(row)
|
||||
--add functions
|
||||
dofile(scripts_dir.."/resources/functions/base64.lua");
|
||||
|
||||
--set the voicemail message path
|
||||
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
||||
|
||||
--save the greeting to the file system
|
||||
if (string.len(row["greeting_base64"]) > 32) then
|
||||
local file = io.open(greeting_location, "w");
|
||||
file:write(base64.decode(row["greeting_base64"]));
|
||||
file:close();
|
||||
end
|
||||
end);
|
||||
sql = [[SELECT * FROM v_voicemail_greetings
|
||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||
AND voicemail_id = ']].. voicemail_id.. [['
|
||||
AND greeting_id = ']].. greeting_id.. [[' ]];
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||
end
|
||||
status = dbh:query(sql, function(row)
|
||||
--add functions
|
||||
dofile(scripts_dir.."/resources/functions/base64.lua");
|
||||
|
||||
--set the voicemail message path
|
||||
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
||||
|
||||
--save the greeting to the file system
|
||||
if (string.len(row["greeting_base64"]) > 32) then
|
||||
local file = io.open(greeting_location, "w");
|
||||
file:write(base64.decode(row["greeting_base64"]));
|
||||
file:close();
|
||||
end
|
||||
end);
|
||||
elseif (storage_type == "http_cache") then
|
||||
greeting_location = storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
||||
end
|
||||
|
||||
@@ -43,33 +43,35 @@
|
||||
|
||||
--get the greeting from the database
|
||||
if (storage_type == "base64") then
|
||||
sql = [[SELECT * FROM v_voicemail_greetings
|
||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||
AND voicemail_id = ']].. voicemail_id.. [['
|
||||
AND greeting_id = ']].. greeting_id.. [[' ]];
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||
end
|
||||
status = dbh:query(sql, function(row)
|
||||
--add functions
|
||||
dofile(scripts_dir.."/resources/functions/base64.lua");
|
||||
sql = [[SELECT * FROM v_voicemail_greetings
|
||||
WHERE domain_uuid = ']] .. domain_uuid ..[['
|
||||
AND voicemail_id = ']].. voicemail_id.. [['
|
||||
AND greeting_id = ']].. greeting_id.. [[' ]];
|
||||
if (debug["sql"]) then
|
||||
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
|
||||
end
|
||||
status = dbh:query(sql, function(row)
|
||||
--add functions
|
||||
dofile(scripts_dir.."/resources/functions/base64.lua");
|
||||
|
||||
--set the voicemail message path
|
||||
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
||||
--set the voicemail message path
|
||||
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
|
||||
|
||||
--save the greeting to the file system
|
||||
--if not found, save greeting to local file system
|
||||
--if (not file_exists(greeting_location)) then
|
||||
if (string.len(row["greeting_base64"]) > 32) then
|
||||
local file = io.open(greeting_location, "w");
|
||||
file:write(base64.decode(row["greeting_base64"]));
|
||||
file:close();
|
||||
end
|
||||
--end
|
||||
|
||||
--play the greeting
|
||||
session:streamFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||
--play the greeting
|
||||
session:streamFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||
|
||||
--delete the greeting
|
||||
os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||
end);
|
||||
--delete the greeting (retain local for better responsiveness)
|
||||
--os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||
end);
|
||||
elseif (storage_type == "http_cache") then
|
||||
session:streamFile(storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||
else
|
||||
|
||||
@@ -24,16 +24,18 @@
|
||||
-- POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
--define a function to record the greeting
|
||||
function record_greeting()
|
||||
function record_greeting(greeting_id)
|
||||
|
||||
--flush dtmf digits from the input buffer
|
||||
session:flushDigits();
|
||||
|
||||
--Choose a greeting between 1 and 9
|
||||
if (session:ready()) then
|
||||
dtmf_digits = '';
|
||||
greeting_id = macro(session, "choose_greeting_choose", 1, 5000, '');
|
||||
freeswitch.consoleLog("notice", "[voicemail] greeting_id: " .. greeting_id .. "\n");
|
||||
--choose a greeting between 1 and 9
|
||||
if (greeting_id == nil) then
|
||||
if (session:ready()) then
|
||||
dtmf_digits = '';
|
||||
greeting_id = macro(session, "choose_greeting_choose", 1, 5000, '');
|
||||
freeswitch.consoleLog("notice", "[voicemail] greeting_id: " .. greeting_id .. "\n");
|
||||
end
|
||||
end
|
||||
|
||||
--validate the greeting_id
|
||||
@@ -53,7 +55,11 @@
|
||||
end
|
||||
|
||||
--store the voicemail greeting
|
||||
if (storage_type == "base64") then
|
||||
if (storage_type == "http_cache") then
|
||||
freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. " ".. storage_path .."\n");
|
||||
storage_path = storage_path:gsub("${domain_name}", domain_name);
|
||||
session:execute("record", storage_path .."/"..recording_name);
|
||||
else
|
||||
--prepare to record the greeting
|
||||
if (session:ready()) then
|
||||
max_len_seconds = 30;
|
||||
@@ -61,97 +67,11 @@
|
||||
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);
|
||||
result = session:recordFile(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".tmp.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");
|
||||
storage_path = storage_path:gsub("${domain_name}", domain_name);
|
||||
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
|
||||
|
||||
--use the new greeting
|
||||
local array = {}
|
||||
table.insert(array, "update v_voicemails ");
|
||||
table.insert(array, "set greeting_id = '".. greeting_id .."' ");
|
||||
table.insert(array, "where domain_uuid = '".. domain_uuid .."' ");
|
||||
table.insert(array, "and voicemail_id = '".. voicemail_id .."' ");
|
||||
sql = table.concat(array, "\n");
|
||||
dbh:query(sql);
|
||||
|
||||
--play the greeting
|
||||
--if (session:ready()) then
|
||||
-- if (file_exists(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav")) then
|
||||
@@ -162,11 +82,7 @@
|
||||
--option to play, save, and re-record the greeting
|
||||
if (session:ready()) then
|
||||
timeouts = 0;
|
||||
record_menu("greeting", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||
if (storage_type == "base64") then
|
||||
--delete the greeting
|
||||
os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
|
||||
end
|
||||
record_menu("greeting", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".tmp.wav", greeting_id);
|
||||
end
|
||||
else
|
||||
--invalid greeting_id
|
||||
@@ -186,4 +102,12 @@
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--clean up any tmp greeting files
|
||||
for gid = 1, 9, 1 do
|
||||
if (file_exists(voicemail_dir.."/"..voicemail_id.."/greeting_"..gid..".tmp.wav")) then
|
||||
os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..gid..".tmp.wav");
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -24,7 +24,7 @@
|
||||
-- POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
--record message menu
|
||||
function record_menu(type, file)
|
||||
function record_menu(type, tmp_file, greeting_id)
|
||||
if (session:ready()) then
|
||||
--clear the dtmf digits variable
|
||||
dtmf_digits = '';
|
||||
@@ -52,10 +52,10 @@
|
||||
if (session:ready()) then
|
||||
if (dtmf_digits == "1") then
|
||||
--listen to the recording
|
||||
session:streamFile(file);
|
||||
session:streamFile(tmp_file);
|
||||
--session:streamFile(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext);
|
||||
--record menu 1 listen to the recording, 2 save the recording, 3 re-record
|
||||
record_menu(type, file);
|
||||
--record menu (1=listen, 2=save, 3=re-record)
|
||||
record_menu(type, tmp_file, greeting_id);
|
||||
elseif (dtmf_digits == "2") then
|
||||
--save the message
|
||||
dtmf_digits = '';
|
||||
@@ -67,6 +67,93 @@
|
||||
session:hangup();
|
||||
end
|
||||
if (type == "greeting") then
|
||||
--remove old greeting file, and rename tmp file
|
||||
local real_file = string.gsub(tmp_file, ".tmp", "");
|
||||
if (file_exists(real_file)) then
|
||||
os.remove(real_file);
|
||||
end
|
||||
if (file_exists(tmp_file)) then
|
||||
os.rename(tmp_file, real_file);
|
||||
end
|
||||
if (storage_type == "base64") then
|
||||
--delete the greeting (retain local for better responsiveness)
|
||||
--os.remove(real_file);
|
||||
end
|
||||
|
||||
--if base64, encode file
|
||||
if (storage_type == "base64") then
|
||||
--include the base64 function
|
||||
dofile(scripts_dir.."/resources/functions/base64.lua");
|
||||
--base64 encode the file
|
||||
local f = io.open(real_file, "rb");
|
||||
local file_content = f:read("*all");
|
||||
f:close();
|
||||
greeting_base64 = base64.encode(file_content);
|
||||
end
|
||||
|
||||
--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 .."' ";
|
||||
--freeswitch.consoleLog("notice", "[SQL] DELETING: " .. greeting_id .. "\n");
|
||||
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, "greeting_filename ");
|
||||
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.."', ");
|
||||
table.insert(array, "'greeting_"..greeting_id..".wav' ");
|
||||
table.insert(array, ") ");
|
||||
sql = table.concat(array, "\n");
|
||||
--freeswitch.consoleLog("notice", "[SQL] INSERTING: " .. greeting_id .. "\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
|
||||
|
||||
--use the new greeting
|
||||
local array = {}
|
||||
table.insert(array, "update v_voicemails ");
|
||||
table.insert(array, "set greeting_id = '".. greeting_id .."' ");
|
||||
table.insert(array, "where domain_uuid = '".. domain_uuid .."' ");
|
||||
table.insert(array, "and voicemail_id = '".. voicemail_id .."' ");
|
||||
sql = table.concat(array, "\n");
|
||||
dbh:query(sql);
|
||||
|
||||
advanced();
|
||||
end
|
||||
if (type == "name") then
|
||||
@@ -80,12 +167,22 @@
|
||||
record_message();
|
||||
end
|
||||
if (type == "greeting") then
|
||||
record_greeting();
|
||||
--remove temporary greeting file, if any
|
||||
if (file_exists(tmp_file)) then
|
||||
os.remove(tmp_file);
|
||||
end
|
||||
record_greeting(greeting_id);
|
||||
end
|
||||
if (type == "name") then
|
||||
record_name();
|
||||
end
|
||||
elseif (dtmf_digits == "*") then
|
||||
if (type == "greeting") then
|
||||
--remove temporary greeting file, if any
|
||||
if (file_exists(tmp_file)) then
|
||||
os.remove(tmp_file);
|
||||
end
|
||||
end
|
||||
--hangup
|
||||
if (session:ready()) then
|
||||
dtmf_digits = '';
|
||||
@@ -96,13 +193,19 @@
|
||||
if (session:ready()) then
|
||||
timeouts = timeouts + 1;
|
||||
if (timeouts < max_timeouts) then
|
||||
record_menu(type, file);
|
||||
record_menu(type, tmp_file, greeting_id);
|
||||
else
|
||||
if (type == "message") then
|
||||
dtmf_digits = '';
|
||||
macro(session, "message_saved", 1, 100, '');
|
||||
macro(session, "goodbye", 1, 1000, '');
|
||||
session:hangup();
|
||||
end
|
||||
if (type == "greeting") then
|
||||
--remove temporary greeting file, if any
|
||||
if (file_exists(tmp_file)) then
|
||||
os.remove(tmp_file);
|
||||
end
|
||||
advanced();
|
||||
end
|
||||
if (type == "name") then
|
||||
|
||||
@@ -185,7 +185,13 @@
|
||||
message_waiting(id, domain_uuid);
|
||||
--clear the variable
|
||||
db_voicemail_uuid = '';
|
||||
elseif (storage_type == "base64") then
|
||||
--delete voicemail recording file
|
||||
if (file_exists(file)) then
|
||||
os.remove(file);
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user