2012-06-04 16:58:40 +02:00
|
|
|
--
|
|
|
|
|
-- FusionPBX
|
|
|
|
|
-- Version: MPL 1.1
|
|
|
|
|
--
|
|
|
|
|
-- The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
|
-- 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
|
-- the License. You may obtain a copy of the License at
|
|
|
|
|
-- http://www.mozilla.org/MPL/
|
|
|
|
|
--
|
|
|
|
|
-- Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
|
-- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
|
-- for the specific language governing rights and limitations under the
|
|
|
|
|
-- License.
|
|
|
|
|
--
|
|
|
|
|
-- The Original Code is FusionPBX
|
|
|
|
|
--
|
|
|
|
|
-- The Initial Developer of the Original Code is
|
|
|
|
|
-- Mark J Crane <markjcrane@fusionpbx.com>
|
2019-03-15 06:41:06 +01:00
|
|
|
-- Copyright (C) 2010 - 2019
|
2012-06-04 16:58:40 +02:00
|
|
|
-- the Initial Developer. All Rights Reserved.
|
|
|
|
|
--
|
|
|
|
|
-- Contributor(s):
|
|
|
|
|
-- Mark J Crane <markjcrane@fusionpbx.com>
|
|
|
|
|
|
2013-05-27 20:55:59 +02:00
|
|
|
--set the variables
|
|
|
|
|
pin_number = "";
|
2015-04-21 18:56:58 +02:00
|
|
|
max_tries = 3;
|
|
|
|
|
digit_timeout = 3000;
|
2013-05-27 20:55:59 +02:00
|
|
|
sounds_dir = "";
|
|
|
|
|
recordings_dir = "";
|
|
|
|
|
file_name = "";
|
|
|
|
|
recording_number = "";
|
2019-03-15 06:41:06 +01:00
|
|
|
recording_id = "";
|
2013-05-27 20:55:59 +02:00
|
|
|
recording_prefix = "";
|
|
|
|
|
|
|
|
|
|
--include config.lua
|
2015-08-11 04:06:33 +02:00
|
|
|
require "resources.functions.config";
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2019-08-17 23:49:15 +02:00
|
|
|
--add functions
|
|
|
|
|
require "resources.functions.mkdir";
|
|
|
|
|
require "resources.functions.explode";
|
|
|
|
|
|
|
|
|
|
--setup the database connection
|
2019-09-26 00:46:52 +02:00
|
|
|
local Database = require "resources.functions.database";
|
2019-08-17 23:49:15 +02:00
|
|
|
local db = dbh or Database.new('system');
|
2015-04-16 21:13:05 +02:00
|
|
|
|
2016-11-21 21:50:38 +01:00
|
|
|
--include json library
|
|
|
|
|
local json
|
|
|
|
|
if (debug["sql"]) then
|
|
|
|
|
json = require "resources.functions.lunajson"
|
|
|
|
|
end
|
|
|
|
|
|
2015-03-31 01:08:21 +02:00
|
|
|
--get the domain_uuid
|
2019-09-26 00:46:52 +02:00
|
|
|
if (session:ready()) then
|
|
|
|
|
domain_uuid = session:getVariable("domain_uuid");
|
|
|
|
|
end
|
2015-03-31 01:08:21 +02:00
|
|
|
|
|
|
|
|
--initialize the recordings
|
|
|
|
|
api = freeswitch.API();
|
|
|
|
|
|
2019-09-26 00:46:52 +02:00
|
|
|
--load lazy settings library
|
2019-08-17 23:49:15 +02:00
|
|
|
local Settings = require "resources.functions.lazy_settings";
|
|
|
|
|
|
|
|
|
|
--get the recordings settings
|
|
|
|
|
local settings = Settings.new(db, domain_name, domain_uuid);
|
|
|
|
|
|
|
|
|
|
--set the storage type and path
|
|
|
|
|
storage_type = settings:get('recordings', 'storage_type', 'text') or '';
|
|
|
|
|
storage_path = settings:get('recordings', 'storage_path', 'text') or '';
|
|
|
|
|
if (storage_path ~= '') then
|
|
|
|
|
storage_path = storage_path:gsub("${domain_name}", session:getVariable("domain_name"));
|
|
|
|
|
storage_path = storage_path:gsub("${domain_uuid}", domain_uuid);
|
2015-03-31 01:08:21 +02:00
|
|
|
end
|
|
|
|
|
|
2019-08-17 23:49:15 +02:00
|
|
|
--set the recordings variables
|
|
|
|
|
local recording_max_length = settings:get('recordings', 'recording_max_length', 'numeric') or 90;
|
|
|
|
|
local recording_silence_threshold = settings:get('recordings', 'recording_silence_threshold', 'numeric') or 200;
|
|
|
|
|
local recording_silence_seconds = settings:get('recordings', 'recording_silence_seconds', 'numeric') or 3;
|
|
|
|
|
|
|
|
|
|
--set the temp directory
|
|
|
|
|
temp_dir = settings:get('server', 'temp', 'dir') or nil;
|
|
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
--dtmf call back function detects the "#" and ends the call
|
|
|
|
|
function onInput(s, type, obj)
|
|
|
|
|
if (type == "dtmf" and obj['digit'] == '#') then
|
|
|
|
|
return "break";
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--start the recording
|
|
|
|
|
function begin_record(session, sounds_dir, recordings_dir)
|
|
|
|
|
|
|
|
|
|
--set the sounds path for the language, dialect and voice
|
|
|
|
|
default_language = session:getVariable("default_language");
|
|
|
|
|
default_dialect = session:getVariable("default_dialect");
|
|
|
|
|
default_voice = session:getVariable("default_voice");
|
|
|
|
|
if (not default_language) then default_language = 'en'; end
|
|
|
|
|
if (not default_dialect) then default_dialect = 'us'; end
|
|
|
|
|
if (not default_voice) then default_voice = 'callie'; end
|
2019-03-15 06:41:06 +01:00
|
|
|
recording_id = session:getVariable("recording_id");
|
2012-06-04 16:58:40 +02:00
|
|
|
recording_prefix = session:getVariable("recording_prefix");
|
|
|
|
|
recording_name = session:getVariable("recording_name");
|
2015-12-23 20:02:14 +01:00
|
|
|
record_ext = session:getVariable("record_ext");
|
2015-12-06 21:37:35 +01:00
|
|
|
domain_name = session:getVariable("domain_name");
|
2019-08-17 22:18:25 +02:00
|
|
|
time_limit_secs = session:getVariable("time_limit_secs");
|
|
|
|
|
silence_thresh = session:getVariable("silence_thresh");
|
|
|
|
|
silence_hits = session:getVariable("silence_hits");
|
|
|
|
|
if (not time_limit_secs) then time_limit_secs = '10800'; end
|
2019-08-17 22:37:08 +02:00
|
|
|
if (not silence_thresh) then silence_thresh = '200'; end
|
|
|
|
|
if (not silence_hits) then silence_hits = '10'; end
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2019-03-20 00:31:53 +01:00
|
|
|
--select the recording number and set the recording name
|
|
|
|
|
if (recording_id == nil) then
|
2012-06-04 16:58:40 +02:00
|
|
|
min_digits = 1;
|
|
|
|
|
max_digits = 20;
|
2015-04-29 23:05:19 +02:00
|
|
|
session:sleep(1000);
|
2019-03-20 00:31:53 +01:00
|
|
|
recording_id = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-id_number.wav", "", "\\d+");
|
|
|
|
|
recording_name = recording_prefix..recording_id.."."..record_ext;
|
|
|
|
|
elseif (tonumber(recording_id) ~= nil) then
|
|
|
|
|
recording_name = recording_prefix..recording_id.."."..record_ext;
|
|
|
|
|
else
|
|
|
|
|
recording_name = recording_prefix.."."..record_ext;
|
2012-06-04 16:58:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--set the default recording name if one was not provided
|
|
|
|
|
if (recording_name) then
|
|
|
|
|
--recording name is provided do nothing
|
|
|
|
|
else
|
|
|
|
|
--set a default recording_name
|
2015-12-23 20:02:14 +01:00
|
|
|
recording_name = "temp_"..session:get_uuid().."."..record_ext;
|
2012-06-04 16:58:40 +02:00
|
|
|
end
|
2012-07-10 18:23:08 +02:00
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
--prompt for the recording
|
2014-07-31 00:35:46 +02:00
|
|
|
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-recording_started.wav");
|
2012-06-04 16:58:40 +02:00
|
|
|
session:execute("set", "playback_terminators=#");
|
|
|
|
|
|
2018-12-04 04:25:04 +01:00
|
|
|
--make the directory
|
|
|
|
|
mkdir(recordings_dir);
|
|
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
--begin recording
|
2015-03-31 01:08:21 +02:00
|
|
|
if (storage_type == "base64") then
|
2016-09-04 21:05:47 +02:00
|
|
|
--include the file io
|
|
|
|
|
local file = require "resources.functions.file"
|
2015-04-01 07:44:07 +02:00
|
|
|
|
2015-03-31 01:08:21 +02:00
|
|
|
--record the file to the file system
|
|
|
|
|
-- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs);
|
|
|
|
|
session:execute("record", recordings_dir .."/".. recording_name);
|
|
|
|
|
|
|
|
|
|
--show the storage type
|
|
|
|
|
freeswitch.consoleLog("notice", "[recordings] ".. storage_type .. "\n");
|
|
|
|
|
|
2016-09-04 21:05:47 +02:00
|
|
|
--read file content as base64 string
|
|
|
|
|
recording_base64 = assert(file.read_base64(recordings_dir .. "/" .. recording_name));
|
2015-03-31 01:08:21 +02:00
|
|
|
|
|
|
|
|
elseif (storage_type == "http_cache") then
|
2015-04-15 23:16:11 +02:00
|
|
|
freeswitch.consoleLog("notice", "[recordings] ".. storage_type .. " ".. storage_path .."\n");
|
2015-04-01 10:14:03 +02:00
|
|
|
session:execute("record", storage_path .."/"..recording_name);
|
2015-03-31 01:08:21 +02:00
|
|
|
else
|
2018-12-04 04:25:04 +01:00
|
|
|
freeswitch.consoleLog("notice", "[recordings] ".. storage_type .. " ".. recordings_dir .."\n");
|
2019-08-17 22:18:25 +02:00
|
|
|
-- record,Record File,<path> [<time_limit_secs>] [<silence_thresh>] [<silence_hits>]
|
2019-08-17 22:28:26 +02:00
|
|
|
session:execute("record", "'"..recordings_dir.."/"..recording_name.."' "..time_limit_secs.." "..silence_thresh.." "..silence_hits);
|
2015-03-31 01:08:21 +02:00
|
|
|
end
|
2012-06-04 16:58:40 +02:00
|
|
|
|
2019-09-26 00:46:52 +02:00
|
|
|
--setup the database connection
|
|
|
|
|
local Database = require "resources.functions.database";
|
|
|
|
|
local db = dbh or Database.new('system');
|
|
|
|
|
|
2018-12-10 17:30:02 +01:00
|
|
|
--get the description of the previous recording
|
|
|
|
|
sql = "SELECT recording_description FROM v_recordings ";
|
|
|
|
|
sql = sql .. "where domain_uuid = :domain_uuid ";
|
|
|
|
|
sql = sql .. "and recording_filename = :recording_name ";
|
|
|
|
|
sql = sql .. "limit 1";
|
|
|
|
|
local params = {domain_uuid = domain_uuid, recording_name = recording_name};
|
2019-09-26 00:46:52 +02:00
|
|
|
local recording_description = db:first_value(sql, params) or ''
|
2019-08-17 22:18:25 +02:00
|
|
|
|
2015-04-16 16:47:21 +02:00
|
|
|
--delete the previous recording
|
|
|
|
|
sql = "delete from v_recordings ";
|
2016-11-21 21:50:38 +01:00
|
|
|
sql = sql .. "where domain_uuid = :domain_uuid ";
|
|
|
|
|
sql = sql .. "and recording_filename = :recording_name";
|
2019-09-26 00:46:52 +02:00
|
|
|
db:query(sql, {domain_uuid = domain_uuid, recording_name = recording_name});
|
2015-04-16 16:47:21 +02:00
|
|
|
|
|
|
|
|
--get a new uuid
|
|
|
|
|
recording_uuid = api:execute("create_uuid");
|
|
|
|
|
|
|
|
|
|
--save the message to the voicemail messages
|
|
|
|
|
local array = {}
|
|
|
|
|
table.insert(array, "INSERT INTO v_recordings ");
|
|
|
|
|
table.insert(array, "(");
|
|
|
|
|
table.insert(array, "recording_uuid, ");
|
|
|
|
|
table.insert(array, "domain_uuid, ");
|
|
|
|
|
table.insert(array, "recording_filename, ");
|
2019-08-17 22:18:25 +02:00
|
|
|
table.insert(array, "recording_description, ");
|
2015-04-16 16:47:21 +02:00
|
|
|
if (storage_type == "base64") then
|
|
|
|
|
table.insert(array, "recording_base64, ");
|
|
|
|
|
end
|
|
|
|
|
table.insert(array, "recording_name ");
|
|
|
|
|
table.insert(array, ") ");
|
|
|
|
|
table.insert(array, "VALUES ");
|
|
|
|
|
table.insert(array, "( ");
|
2016-11-21 21:50:38 +01:00
|
|
|
table.insert(array, ":recording_uuid, ");
|
|
|
|
|
table.insert(array, ":domain_uuid, ");
|
|
|
|
|
table.insert(array, ":recording_name, ");
|
2019-08-17 22:18:25 +02:00
|
|
|
table.insert(array, ":recording_description, ");
|
2015-04-16 16:47:21 +02:00
|
|
|
if (storage_type == "base64") then
|
2016-11-21 21:50:38 +01:00
|
|
|
table.insert(array, ":recording_base64, ");
|
2015-04-16 16:47:21 +02:00
|
|
|
end
|
2016-11-21 21:50:38 +01:00
|
|
|
table.insert(array, ":recording_name ");
|
2015-04-16 16:47:21 +02:00
|
|
|
table.insert(array, ") ");
|
|
|
|
|
sql = table.concat(array, "\n");
|
2016-11-21 21:50:38 +01:00
|
|
|
|
|
|
|
|
local params = {
|
|
|
|
|
recording_uuid = recording_uuid;
|
|
|
|
|
domain_uuid = domain_uuid;
|
|
|
|
|
recording_name = recording_name;
|
2018-12-10 17:30:02 +01:00
|
|
|
recording_description = recording_description;
|
2016-11-21 21:50:38 +01:00
|
|
|
recording_base64 = recording_base64;
|
|
|
|
|
};
|
|
|
|
|
|
2015-04-16 16:47:21 +02:00
|
|
|
if (debug["sql"]) then
|
2016-11-21 21:50:38 +01:00
|
|
|
freeswitch.consoleLog("notice", "[recording] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n");
|
2015-04-16 16:47:21 +02:00
|
|
|
end
|
2016-11-21 21:50:38 +01:00
|
|
|
|
2015-04-16 16:47:21 +02:00
|
|
|
if (storage_type == "base64") then
|
2016-09-04 21:05:47 +02:00
|
|
|
local Database = require "resources.functions.database"
|
|
|
|
|
local dbh = Database.new('system', 'base64');
|
2016-11-21 21:50:38 +01:00
|
|
|
dbh:query(sql, params);
|
2016-09-04 21:05:47 +02:00
|
|
|
dbh:release();
|
2015-04-16 16:47:21 +02:00
|
|
|
else
|
2019-09-26 00:46:52 +02:00
|
|
|
--setup the database connection
|
|
|
|
|
local Database = require "resources.functions.database";
|
|
|
|
|
local db = dbh or Database.new('system');
|
|
|
|
|
db:query(sql, params);
|
2015-04-16 16:47:21 +02:00
|
|
|
end
|
|
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
--preview the recording
|
|
|
|
|
session:streamFile(recordings_dir.."/"..recording_name);
|
|
|
|
|
|
|
|
|
|
--approve the recording, to save the recording press 1 to re-record press 2
|
|
|
|
|
min_digits="0" max_digits="1" max_tries = "1"; digit_timeout = "100";
|
|
|
|
|
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "voicemail/vm-save_recording.wav", "", "\\d+");
|
|
|
|
|
|
|
|
|
|
if (string.len(digits) == 0) then
|
|
|
|
|
min_digits="0" max_digits="1" max_tries = "1"; digit_timeout = "100";
|
|
|
|
|
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "voicemail/vm-press.wav", "", "\\d+");
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if (string.len(digits) == 0) then
|
|
|
|
|
min_digits="0" max_digits="1" max_tries = "1"; digit_timeout = "100";
|
|
|
|
|
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "digits/1.wav", "", "\\d+");
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if (string.len(digits) == 0) then
|
|
|
|
|
min_digits="0" max_digits="1" max_tries = "1"; digit_timeout = "100";
|
|
|
|
|
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "voicemail/vm-rerecord.wav", "", "\\d+");
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if (string.len(digits) == 0) then
|
|
|
|
|
min_digits="0" max_digits="1" max_tries = "1"; digit_timeout = "100";
|
|
|
|
|
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "voicemail/vm-press.wav", "", "\\d+");
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if (string.len(digits) == 0) then
|
|
|
|
|
min_digits="1" max_digits="1" max_tries = "1"; digit_timeout = "5000";
|
|
|
|
|
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "digits/2.wav", "", "\\d+");
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if (digits == "1") then
|
|
|
|
|
--recording saved, hangup
|
|
|
|
|
session:streamFile("voicemail/vm-saved.wav");
|
|
|
|
|
return;
|
|
|
|
|
elseif (digits == "2") then
|
|
|
|
|
--delete the old recording
|
|
|
|
|
os.remove (recordings_dir.."/"..recording_name);
|
|
|
|
|
--session:execute("system", "rm "..);
|
|
|
|
|
--make a new recording
|
|
|
|
|
begin_record(session, sounds_dir, recordings_dir);
|
|
|
|
|
else
|
|
|
|
|
--recording saved, hangup
|
|
|
|
|
session:streamFile("voicemail/vm-saved.wav");
|
|
|
|
|
return;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-09-26 00:46:52 +02:00
|
|
|
if (session:ready()) then
|
2012-06-04 16:58:40 +02:00
|
|
|
session:answer();
|
|
|
|
|
|
|
|
|
|
--get the dialplan variables and set them as local variables
|
|
|
|
|
pin_number = session:getVariable("pin_number");
|
|
|
|
|
sounds_dir = session:getVariable("sounds_dir");
|
2013-05-27 20:55:59 +02:00
|
|
|
domain_name = session:getVariable("domain_name");
|
2015-03-31 01:08:21 +02:00
|
|
|
domain_uuid = session:getVariable("domain_uuid");
|
|
|
|
|
|
2015-12-06 21:37:35 +01:00
|
|
|
--add the domain name to the recordings directory
|
|
|
|
|
recordings_dir = recordings_dir .. "/"..domain_name;
|
2013-05-27 20:55:59 +02:00
|
|
|
|
2018-12-04 04:25:04 +01:00
|
|
|
--if a recording directory is specified, use that instead
|
2018-12-07 20:13:05 +01:00
|
|
|
if (storage_path ~= nil and string.len(storage_path) > 0) then recordings_dir = storage_path; end
|
2019-08-17 22:18:25 +02:00
|
|
|
|
2012-06-04 16:58:40 +02:00
|
|
|
--set the sounds path for the language, dialect and voice
|
|
|
|
|
default_language = session:getVariable("default_language");
|
|
|
|
|
default_dialect = session:getVariable("default_dialect");
|
|
|
|
|
default_voice = session:getVariable("default_voice");
|
|
|
|
|
if (not default_language) then default_language = 'en'; end
|
|
|
|
|
if (not default_dialect) then default_dialect = 'us'; end
|
|
|
|
|
if (not default_voice) then default_voice = 'callie'; end
|
|
|
|
|
|
|
|
|
|
--if the pin number is provided then require it
|
|
|
|
|
if (pin_number) then
|
2015-04-21 18:56:58 +02:00
|
|
|
freeswitch.consoleLog("notice", "[recordings] pin_number: ".. pin_number .. "\n");
|
2012-06-04 16:58:40 +02:00
|
|
|
min_digits = string.len(pin_number);
|
|
|
|
|
max_digits = string.len(pin_number)+1;
|
2014-03-22 00:47:40 +01:00
|
|
|
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
|
2012-06-04 16:58:40 +02:00
|
|
|
if (digits == pin_number) then
|
|
|
|
|
--pin is correct
|
2015-04-21 18:56:58 +02:00
|
|
|
freeswitch.consoleLog("notice", "[recordings] pin_number: correct \n");
|
2012-06-04 16:58:40 +02:00
|
|
|
else
|
2015-04-21 18:56:58 +02:00
|
|
|
freeswitch.consoleLog("notice", "[recordings] pin_number: incorrect \n");
|
2014-03-22 00:47:40 +01:00
|
|
|
session:streamFile("phrase:voicemail_fail_auth:#");
|
2012-06-04 16:58:40 +02:00
|
|
|
session:hangup("NORMAL_CLEARING");
|
|
|
|
|
return;
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--start recording
|
|
|
|
|
begin_record(session, sounds_dir, recordings_dir);
|
|
|
|
|
|
2015-03-31 01:08:21 +02:00
|
|
|
--hangup the call
|
|
|
|
|
session:hangup();
|
2015-04-01 07:44:07 +02:00
|
|
|
|
2015-04-21 18:56:58 +02:00
|
|
|
end
|