Voicemail: Use phrases instead of direct sounds.

This commit is contained in:
Nate
2020-09-25 16:58:44 -06:00
parent 02d71cc0ef
commit 46adde4a22
63 changed files with 6266 additions and 1197 deletions

View File

@@ -29,34 +29,12 @@
dtmf_digits = '';
--flush dtmf digits from the input buffer
session:flushDigits();
--To record a greeting press 1
--play entire menu using phrases
if (session:ready()) then
dtmf_digits = macro(session, "to_record_greeting", 1, 100, '');
end
--To choose greeting press 2
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "choose_greeting", 1, 100, '');
end
end
--To record your name 3
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "to_record_name", 1, 100, '');
end
end
--To change your password press 6
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "change_password", 1, 100, '');
end
end
--For the main menu press 0
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "main_menu", 1, 5000, '');
end
dtmf_digits = session:playAndGetDigits(1, 1, max_tries, digit_timeout, "#", "phrase:voicemail_config_menu:1:2:3:6:0", "", "\\d+");
end
--process the dtmf
if (session:ready()) then
if (dtmf_digits == "1") then
@@ -82,7 +60,7 @@
if (timeouts <= max_timeouts) then
advanced();
else
macro(session, "goodbye", 1, 1000, '');
session:execute("playback", "phrase:voicemail_goodbye");
session:hangup();
end
end

View File

@@ -1,123 +1,123 @@
-- Part of FusionPBX
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--check the voicemail password
function change_password(voicemail_id, menu)
if (session:ready()) then
--flush dtmf digits from the input buffer
session:flushDigits();
--set password valitity in case of hangup
valid_password = "false";
--please enter your password followed by pound
dtmf_digits = '';
password = macro(session, "password_new", 20, 5000, '');
if (password_complexity ~= "true") then
valid_password = "true";
end
--check password comlexity
if (password_complexity == "true") then
--check for length
if (string.len(password) < tonumber(password_min_length)) then
password_error_flag = "1";
dtmf_digits = '';
--freeswitch.consoleLog("notice", "[voicemail] Not long enough \n");
macro(session, "password_below_minimum", 20, 3000, password_min_length);
timeouts = 0;
if (menu == "tutorial") then
change_password(voicemail_id, "tutorial");
end
if (menu == "advanced") then
change_password(voicemail_id, "advanced");
end
end
--check for repeating digits
local repeating = {"000", "111", "222", "333", "444", "555", "666", "777", "888", "999"};
for i = 1, 10 do
if (string.match(password, repeating[i])) then
password_error_flag = "1";
dtmf_digits = '';
--freeswitch.consoleLog("notice", "[voicemail] You can't use repeating digits like ".. repeating[i] .." \n");
macro(session, "password_not_secure", 20, 3000);
timeouts = 0;
if (menu == "tutorial") then
change_password(voicemail_id, "tutorial");
end
if (menu == "advanced") then
change_password(voicemail_id, "advanced");
end
end
end
--check for squential digits
local sequential = {"012", "123", "345", "456", "567", "678", "789", "987"};
for i = 1, 8 do
if (string.match(password, sequential[i])) then
password_error_flag = "1";
dtmf_digits = '';
--freeswitch.consoleLog("notice", "[voicemail] You can't use sequential digits like ".. sequential[i] .." \n");
macro(session, "password_not_secure", 20, 3000);
timeouts = 0;
if (menu == "tutorial") then
change_password(voicemail_id, "tutorial");
end
if (menu == "advanced") then
change_password(voicemail_id, "advanced");
end
end
end
--password is valid
if (password_error_flag ~= "1") then
freeswitch.consoleLog("notice", "[voicemail] Password is valid! \n");
valid_password = "true";
end
end
--update the voicemail password
if (valid_password == "true") then
local sql = [[UPDATE v_voicemails
set voicemail_password = :password
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND voicemail_enabled = 'true' ]];
local params = {password = password, domain_uuid = domain_uuid,
voicemail_id = voicemail_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params);
end
--has been changed to
dtmf_digits = '';
macro(session, "password_changed", 20, 3000, password);
--advanced menu
timeouts = 0;
if (menu == "advanced") then
advanced();
end
if (menu == "tutorial") then
tutorial("record_greeting");
end
end
end
-- Part of FusionPBX
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--check the voicemail password
function change_password(voicemail_id, menu)
if (session:ready()) then
--flush dtmf digits from the input buffer
session:flushDigits();
--set password valitity in case of hangup
valid_password = "false";
--please enter your password followed by pound
dtmf_digits = '';
password = session:playAndGetDigits(1, 20, max_tries, 5000, "#", "phrase:voicemail_enter_new_pass", "", "\\d+");
if (password_complexity ~= "true") then
valid_password = "true";
end
--check password comlexity
if (password_complexity == "true") then
--check for length
if (string.len(password) < tonumber(password_min_length)) then
password_error_flag = "1";
dtmf_digits = '';
--freeswitch.consoleLog("notice", "[voicemail] Not long enough \n");
session:execute("playback", "phrase:voicemail_password_below_minimum:" .. password_min_length);
timeouts = 0;
if (menu == "tutorial") then
change_password(voicemail_id, "tutorial");
end
if (menu == "advanced") then
change_password(voicemail_id, "advanced");
end
end
--check for repeating digits
local repeating = {"000", "111", "222", "333", "444", "555", "666", "777", "888", "999"};
for i = 1, 10 do
if (string.match(password, repeating[i])) then
password_error_flag = "1";
dtmf_digits = '';
--freeswitch.consoleLog("notice", "[voicemail] You can't use repeating digits like ".. repeating[i] .." \n");
session:execute("playback", "phrase:voicemail_password_not_secure");
timeouts = 0;
if (menu == "tutorial") then
change_password(voicemail_id, "tutorial");
end
if (menu == "advanced") then
change_password(voicemail_id, "advanced");
end
end
end
--check for squential digits
local sequential = {"012", "123", "234", "345", "456", "567", "678", "789", "987", "876", "765", "654", "543", "432", "321", "210"};
for i = 1, 8 do
if (string.match(password, sequential[i])) then
password_error_flag = "1";
dtmf_digits = '';
--freeswitch.consoleLog("notice", "[voicemail] You can't use sequential digits like ".. sequential[i] .." \n");
session:execute("playback", "phrase:voicemail_password_not_secure");
timeouts = 0;
if (menu == "tutorial") then
change_password(voicemail_id, "tutorial");
end
if (menu == "advanced") then
change_password(voicemail_id, "advanced");
end
end
end
--password is valid
if (password_error_flag ~= "1") then
freeswitch.consoleLog("notice", "[voicemail] Password is valid! \n");
valid_password = "true";
end
end
--update the voicemail password
if (valid_password == "true") then
local sql = [[UPDATE v_voicemails
set voicemail_password = :password
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND voicemail_enabled = 'true' ]];
local params = {password = password, domain_uuid = domain_uuid,
voicemail_id = voicemail_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params);
end
--has been changed to
dtmf_digits = '';
session:execute("playback", "phrase:voicemail_change_pass_repeat_success:" .. password);
--advanced menu
timeouts = 0;
if (menu == "advanced") then
advanced();
end
if (menu == "tutorial") then
tutorial("record_greeting");
end
end
end

View File

@@ -1,95 +1,95 @@
-- Part of FusionPBX
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--check the voicemail password
function check_password(voicemail_id, password_tries)
if (session:ready()) then
--flush dtmf digits from the input buffer
session:flushDigits();
--please enter your id followed by pound
if (voicemail_id) then
--do nothing
else
timeouts = 0;
voicemail_id = get_voicemail_id();
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] voicemail id: " .. voicemail_id .. "\n");
end
end
--get the voicemail settings from the database
if (voicemail_id) then
if (session:ready()) then
local sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND voicemail_enabled = 'true' ]];
local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(row)
voicemail_uuid = string.lower(row["voicemail_uuid"]);
voicemail_password = row["voicemail_password"];
greeting_id = row["greeting_id"];
voicemail_mail_to = row["voicemail_mail_to"];
voicemail_attach_file = row["voicemail_attach_file"];
voicemail_local_after_email = row["voicemail_local_after_email"];
end);
end
end
--end the session if this is an invalid voicemail box
if (not voicemail_uuid) or (#voicemail_uuid == 0) then
return session:hangup();
end
--please enter your password followed by pound
min_digits = 2;
max_digits = 20;
digit_timeout = 5000;
max_tries = 3;
password = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
--freeswitch.consoleLog("notice", "[voicemail] password: " .. password .. "\n");
--compare the password from the database with the password provided by the user
if (voicemail_password ~= password) then
--incorrect password
dtmf_digits = '';
macro(session, "password_not_valid", 1, 1000, '');
if (session:ready()) then
password_tries = password_tries + 1;
if (password_tries < max_tries) then
check_password(voicemail_id, password_tries);
else
macro(session, "goodbye", 1, 1000, '');
session:hangup();
end
end
end
end
end
-- Part of FusionPBX
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--check the voicemail password
function check_password(voicemail_id, password_tries)
if (session:ready()) then
--flush dtmf digits from the input buffer
session:flushDigits();
--please enter your id followed by pound
if (voicemail_id) then
--do nothing
else
timeouts = 0;
voicemail_id = get_voicemail_id();
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] voicemail id: " .. voicemail_id .. "\n");
end
end
--get the voicemail settings from the database
if (voicemail_id) then
if (session:ready()) then
local sql = [[SELECT * FROM v_voicemails
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND voicemail_enabled = 'true' ]];
local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params, function(row)
voicemail_uuid = string.lower(row["voicemail_uuid"]);
voicemail_password = row["voicemail_password"];
greeting_id = row["greeting_id"];
voicemail_mail_to = row["voicemail_mail_to"];
voicemail_attach_file = row["voicemail_attach_file"];
voicemail_local_after_email = row["voicemail_local_after_email"];
end);
end
end
--end the session if this is an invalid voicemail box
if (not voicemail_uuid) or (#voicemail_uuid == 0) then
return session:hangup();
end
--please enter your password followed by pound
min_digits = 2;
max_digits = 20;
digit_timeout = 5000;
max_tries = 3;
password = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
--freeswitch.consoleLog("notice", "[voicemail] password: " .. password .. "\n");
--compare the password from the database with the password provided by the user
if (voicemail_password ~= password) then
--incorrect password
dtmf_digits = '';
session:execute("playback", "phrase:voicemail_fail_auth");
if (session:ready()) then
password_tries = password_tries + 1;
if (password_tries < max_tries) then
check_password(voicemail_id, password_tries);
else
session:execute("playback", "phrase:voicemail_goodbye");
session:hangup();
end
end
end
end
end

View File

@@ -34,7 +34,7 @@
--select the greeting
if (session:ready()) then
dtmf_digits = '';
greeting_id = macro(session, "choose_greeting_choose", 1, 5000, '');
greeting_id = session:playAndGetDigits(1, 1, max_tries, 5000, "#", "phrase:voicemail_choose_greeting", "", "\\d+");
end
--check to see if the greeting file exists
@@ -137,7 +137,7 @@
--greeting selected
if (session:ready()) then
dtmf_digits = '';
macro(session, "greeting_selected", 1, 100, greeting_id);
session:execute("playback", "phrase:voicemail_greeting_selected:" .. greeting_id);
end
--advanced menu
@@ -149,7 +149,7 @@
--invalid greeting_id
if (session:ready()) then
dtmf_digits = '';
greeting_id = macro(session, "choose_greeting_fail", 1, 100, '');
session:execute("playback", "phrase:voicemail_choose_greeting_fail");
end
--send back to choose the greeting

View File

@@ -29,7 +29,7 @@
if (session ~= nil) then
if (session:ready()) then
dtmf_digits = '';
macro(session, "message_deleted", 1, 100, '');
session:execute("playback", "phrase:voicemail_ack:deleted");
end
end

View File

@@ -1,120 +1,121 @@
-- Part of FusionPBX
-- Copyright (C) 2016 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--define a function to forward a message to an extension
function forward_add_intro(voicemail_id, uuid)
--flush dtmf digits from the input buffer
session:flushDigits();
--request whether to add the intro
--To add an introduction to this message press 1
add_intro_id = session:playAndGetDigits(1, 1, 3, 5000, "#*", "phrase:voicemail_forward_prepend:1:2", "phrase:invalid_entry", "\\d+");
freeswitch.consoleLog("notice", "[voicemail][forward add intro] "..add_intro_id.."\n");
if (add_intro_id == '1') then
--load libraries
local Database = require "resources.functions.database";
local Settings = require "resources.functions.lazy_settings";
--connect to the database
local db = dbh or Database.new('system');
--get the settings.
local settings = Settings.new(db, domain_name, domain_uuid);
local max_len_seconds = settings:get('voicemail', 'max_len_seconds', 'boolean') or 300;
--record your message at the tone press any key or stop talking to end the recording
if (session:ready()) then
session:sayPhrase("voicemail_record_greeting", "", "en")
end
--set the file full path
message_location = voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext;
message_intro_location = voicemail_dir.."/"..voicemail_id.."/intro_"..uuid.."."..vm_message_ext;
--record the message introduction
-- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs)
silence_seconds = 5;
if (storage_path == "http_cache") then
result = session:recordFile(message_intro_location, max_len_seconds, record_silence_threshold, silence_seconds);
else
mkdir(voicemail_dir.."/"..voicemail_id);
if (vm_message_ext == "mp3") then
shout_exists = trim(api:execute("module_exists", "mod_shout"));
if (shout_exists == "true") then
freeswitch.consoleLog("notice", "using mod_shout for mp3 encoding\n");
--record in mp3 directly
result = session:recordFile(message_intro_location, max_len_seconds, record_silence_threshold, silence_seconds);
else
--create initial wav recording
result = session:recordFile(message_intro_location, max_len_seconds, record_silence_threshold, silence_seconds);
--use lame to encode, if available
if (file_exists("/usr/bin/lame")) then
freeswitch.consoleLog("notice", "using lame for mp3 encoding\n");
--convert the wav to an mp3 (lame required)
resample = "/usr/bin/lame -b 32 --resample 8 -m s "..voicemail_dir.."/"..voicemail_id.."/intro_"..uuid..".wav "..message_intro_location;
session:execute("system", resample);
--delete the wav file, if mp3 exists
if (file_exists(message_intro_location)) then
os.remove(voicemail_dir.."/"..voicemail_id.."/intro_"..uuid..".wav");
else
vm_message_ext = "wav";
end
else
freeswitch.consoleLog("notice", "neither mod_shout or lame found, defaulting to wav\n");
vm_message_ext = "wav";
end
end
else
result = session:recordFile(message_intro_location, max_len_seconds, record_silence_threshold, silence_seconds);
end
end
--save the merged file into the database as base64
if (storage_type == "base64") then
local file = require "resources.functions.file"
--get the content of the file
local file_content = assert(file.read_base64(message_intro_location));
--save the merged file as base64
local sql = [[UPDATE SET v_voicemail_messages
SET message_intro_base64 = :file_content
WHERE domain_uuid = :domain_uuid
AND voicemail_message_uuid = :uuid]];
local params = {file_content = file_content, domain_uuid = domain_uuid, uuid = uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n");
end
local dbh = Database.new('system', 'base64')
dbh:query(sql, params)
dbh:release()
end
end
end
-- Part of FusionPBX
-- Copyright (C) 2016 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--define a function to forward a message to an extension
function forward_add_intro(voicemail_id, uuid)
--flush dtmf digits from the input buffer
session:flushDigits();
--request whether to add the intro
--To add an introduction to this message press 1
add_intro_id = session:playAndGetDigits(1, 1, 3, 5000, "#*", "phrase:voicemail_forward_prepend:1:2", "phrase:invalid_entry", "\\d+");
freeswitch.consoleLog("notice", "[voicemail][forward add intro] "..add_intro_id.."\n");
if (add_intro_id == '1') then
--load libraries
local Database = require "resources.functions.database";
local Settings = require "resources.functions.lazy_settings";
--connect to the database
local db = dbh or Database.new('system');
--get the settings.
local settings = Settings.new(db, domain_name, domain_uuid);
local max_len_seconds = settings:get('voicemail', 'max_len_seconds', 'boolean') or 300;
--record your message at the tone press any key or stop talking to end the recording
if (session:ready()) then
--session:sayPhrase("voicemail_record_greeting", "", "en")
session:execute("playback", "phrase:voicemail_record_greeting");
end
--set the file full path
message_location = voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext;
message_intro_location = voicemail_dir.."/"..voicemail_id.."/intro_"..uuid.."."..vm_message_ext;
--record the message introduction
-- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs)
silence_seconds = 5;
if (storage_path == "http_cache") then
result = session:recordFile(message_intro_location, max_len_seconds, record_silence_threshold, silence_seconds);
else
mkdir(voicemail_dir.."/"..voicemail_id);
if (vm_message_ext == "mp3") then
shout_exists = trim(api:execute("module_exists", "mod_shout"));
if (shout_exists == "true") then
freeswitch.consoleLog("notice", "using mod_shout for mp3 encoding\n");
--record in mp3 directly
result = session:recordFile(message_intro_location, max_len_seconds, record_silence_threshold, silence_seconds);
else
--create initial wav recording
result = session:recordFile(message_intro_location, max_len_seconds, record_silence_threshold, silence_seconds);
--use lame to encode, if available
if (file_exists("/usr/bin/lame")) then
freeswitch.consoleLog("notice", "using lame for mp3 encoding\n");
--convert the wav to an mp3 (lame required)
resample = "/usr/bin/lame -b 32 --resample 8 -m s "..voicemail_dir.."/"..voicemail_id.."/intro_"..uuid..".wav "..message_intro_location;
session:execute("system", resample);
--delete the wav file, if mp3 exists
if (file_exists(message_intro_location)) then
os.remove(voicemail_dir.."/"..voicemail_id.."/intro_"..uuid..".wav");
else
vm_message_ext = "wav";
end
else
freeswitch.consoleLog("notice", "neither mod_shout or lame found, defaulting to wav\n");
vm_message_ext = "wav";
end
end
else
result = session:recordFile(message_intro_location, max_len_seconds, record_silence_threshold, silence_seconds);
end
end
--save the merged file into the database as base64
if (storage_type == "base64") then
local file = require "resources.functions.file"
--get the content of the file
local file_content = assert(file.read_base64(message_intro_location));
--save the merged file as base64
local sql = [[UPDATE SET v_voicemail_messages
SET message_intro_base64 = :file_content
WHERE domain_uuid = :domain_uuid
AND voicemail_message_uuid = :uuid]];
local params = {file_content = file_content, domain_uuid = domain_uuid, uuid = uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params: " .. json.encode(params) .. "\n");
end
local dbh = Database.new('system', 'base64')
dbh:query(sql, params)
dbh:release()
end
end
end

View File

@@ -35,18 +35,18 @@
--request the forward_voicemail_id
if (session:ready()) then
dtmf_digits = '';
forward_voicemail_id = macro(session, "forward_enter_extension", 20, 5000, '');
forward_voicemail_id = session:playAndGetDigits(1, 20, max_tries, digit_timeout, "#", "phrase:voicemail_forward_message_enter_extension:#", "", "\\d+");
if (session:ready()) then
if (string.len(forward_voicemail_id) == 0) then
dtmf_digits = '';
forward_voicemail_id = macro(session, "forward_enter_extension", 20, 5000, '');
forward_voicemail_id = session:playAndGetDigits(1, 20, max_tries, digit_timeout, "#", "phrase:voicemail_forward_message_enter_extension:#", "", "\\d+");
end
end
end
if (session:ready()) then
if (string.len(forward_voicemail_id) == 0) then
dtmf_digits = '';
forward_voicemail_id = macro(session, "forward_enter_extension", 20, 5000, '');
forward_voicemail_id = session:playAndGetDigits(1, 20, max_tries, digit_timeout, "#", "phrase:voicemail_forward_message_enter_extension:#", "", "\\d+");
end
end

View File

@@ -1,43 +1,43 @@
-- Part of FusionPBX
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--get the voicemail id
function get_voicemail_id()
session:flushDigits();
dtmf_digits = '';
voicemail_id = macro(session, "voicemail_id", 20, 5000, '');
if (string.len(voicemail_id) == 0) then
if (session:ready()) then
timeouts = timeouts + 1;
if (timeouts < max_timeouts) then
voicemail_id = get_voicemail_id();
else
macro(session, "goodbye", 1, 1000, '');
session:hangup();
end
end
end
return voicemail_id;
-- Part of FusionPBX
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--get the voicemail id
function get_voicemail_id()
session:flushDigits();
dtmf_digits = '';
voicemail_id = session:playAndGetDigits(1, 20, max_tries, digit_timeout, "#", "phrase:voicemail_enter_id:#", "", "\\d+");
if (string.len(voicemail_id) == 0) then
if (session:ready()) then
timeouts = timeouts + 1;
if (timeouts < max_timeouts) then
voicemail_id = get_voicemail_id();
else
session:execute("playback", "phrase:voicemail_goodbye");
session:hangup();
end
end
end
return voicemail_id;
end

View File

@@ -24,7 +24,7 @@
-- POSSIBILITY OF SUCH DAMAGE.
--define function to listen to the recording
function listen_to_recording (message_number, uuid, created_epoch, caller_id_name, caller_id_number)
function listen_to_recording (message_number, uuid, created_epoch, caller_id_name, caller_id_number, message_status)
--set default values
dtmf_digits = '';
@@ -43,20 +43,14 @@
--say the message number
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "message_number", 1, 100, '');
end
end
--say the number
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
session:say(message_number, default_language, "number", "pronounced");
session:execute("playback", "phrase:voicemail_say_message_number:" .. message_status .. ":" .. message_number);
end
end
--say the caller id number
if (session:ready() and caller_id_number ~= nil) then
if (vm_say_caller_id_number ~= nil) then
if (vm_say_caller_id_number == "true") then
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-message_from.wav");
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-from.wav");
session:say(caller_id_number, default_language, "name_spelled", "iterated");
end
end
@@ -162,40 +156,11 @@
os.remove(voicemail_dir.."/"..voicemail_id.."/intro_"..uuid.."."..vm_message_ext);
os.remove(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext);
end
--to listen to the recording press 1
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "listen_to_recording", 1, 100, '');
end
end
--to save the recording press 2
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "save_recording", 1, 100, '');
end
end
--to return the call now press 5
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "return_call", 1, 100, '');
end
end
--to delete the recording press 7
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "delete_recording", 1, 100, '');
end
end
--to forward this message press 8
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "to_forward_message", 1, 100, '');
end
end
--to forward this recording to your email press 9
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "forward_to_email", 1, 3000, '');
--post listen options
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = session:playAndGetDigits(1, 1, max_tries, digit_timeout, "#", "phrase:voicemail_listen_file_options:1:2:5:7:8:9:0", "", "\\d+");
end
end
--wait for more digits
@@ -210,7 +175,7 @@
listen_to_recording(message_number, uuid, created_epoch, caller_id_name, caller_id_number);
elseif (dtmf_digits == "2") then
message_saved(voicemail_id, uuid);
macro(session, "message_saved", 1, 100, '');
session:execute("playback", "phrase:voicemail_ack:saved");
elseif (dtmf_digits == "5") then
message_saved(voicemail_id, uuid);
return_call(caller_id_number);
@@ -224,11 +189,11 @@
elseif (dtmf_digits == "8") then
forward_to_extension(voicemail_id, uuid);
dtmf_digits = '';
macro(session, "message_saved", 1, 100, '');
session:execute("playback", "phrase:voicemail_ack:saved");
elseif (dtmf_digits == "9") then
send_email(voicemail_id, uuid);
dtmf_digits = '';
macro(session, "emailed", 1, 100, '');
session:execute("playback", "phrase:voicemail_ack:emailed");
elseif (dtmf_digits == "*") then
timeouts = 0;
main_menu();
@@ -237,7 +202,8 @@
session:transfer("0", "XML", context);
else
message_saved(voicemail_id, uuid);
macro(session, "message_saved", 1, 100, '');
session:execute("playback", "phrase:voicemail_ack:saved");
end
session:execute("sleep", "400");
end
end

View File

@@ -1,365 +1,365 @@
-- Part of FusionPBX
-- Copyright (C) 2013 - 2016 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--define the macro function
function macro(session, name, max_digits, max_timeout, param)
if (session:ready()) then
--create an empty table
actions = {}
--Please enter your id followed by
if (name == "voicemail_id") then
table.insert(actions, {app="streamFile",data="phrase:voicemail_enter_id:#"});
end
--Please enter your id followed by
if (name == "voicemail_password") then
table.insert(actions, {app="streamFile",data="phrase:voicemail_enter_pass:#"});
end
--the person at extension 101 is not available record your message at the tone press any key or stop talking to end the recording
if (name == "person_not_available_record_message") then
table.insert(actions, {app="streamFile",data="voicemail/vm-person.wav"});
--pronounce the voicemail_id
if (voicemail_alternate_greet_id and string.len(voicemail_alternate_greet_id) > 0) then
table.insert(actions, {app="say.number.iterated",data=voicemail_alternate_greet_id});
elseif (voicemail_greet_id and string.len(voicemail_greet_id) > 0) then
table.insert(actions, {app="say.number.iterated",data=voicemail_greet_id});
else
table.insert(actions, {app="say.number.iterated",data=voicemail_id});
end
table.insert(actions, {app="streamFile",data="voicemail/vm-not_available.wav"});
end
--record your message at the tone press any key or stop talking to end the recording
if (name == "record_message") then
table.insert(actions, {app="streamFile",data="voicemail/vm-record_message.wav"});
end
--beep
if (name == "record_beep") then
table.insert(actions, {app="tone_stream",data="L=1;%(1000, 0, 640)"});
end
--to listen to the recording press 1
if (name == "to_listen_to_recording") then
table.insert(actions, {app="streamFile",data="voicemail/vm-listen_to_recording.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--to save the recording press 2
if (name == "to_save_recording") then
table.insert(actions, {app="streamFile",data="voicemail/vm-save_recording.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/2.wav"});
end
--to rerecord press 3
if (name == "to_rerecord") then
table.insert(actions, {app="streamFile",data="voicemail/vm-rerecord.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/3.wav"});
end
--You have zero new messages
if (name == "new_messages") then
table.insert(actions, {app="streamFile",data="phrase:voicemail_message_count:" .. param .. ":new"})
end
--You have zero saved messages
if (name == "saved_messages") then
table.insert(actions, {app="streamFile",data="phrase:voicemail_message_count:" .. param .. ":saved"})
end
--To listen to new messages press 1
if (name == "listen_to_new_messages") then
table.insert(actions, {app="streamFile",data="voicemail/vm-listen_new.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--To listen to saved messages press 2
if (name == "listen_to_saved_messages") then
table.insert(actions, {app="streamFile",data="voicemail/vm-listen_saved.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/2.wav"});
end
--For advanced options press 5
if (name == "advanced") then
table.insert(actions, {app="streamFile",data="voicemail/vm-advanced.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/5.wav"});
end
--Advanced Options Menu
--To record a greeting press 1
if (name == "to_record_greeting") then
table.insert(actions, {app="streamFile",data="voicemail/vm-to_record_greeting.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--Choose a greeting between 1 and 9
if (name == "choose_greeting_choose") then
table.insert(actions, {app="streamFile",data="voicemail/vm-choose_greeting_choose.wav"});
end
--Greeting invalid value
if (name == "choose_greeting_fail") then
table.insert(actions, {app="streamFile",data="voicemail/vm-choose_greeting_fail.wav"});
end
--Record your greeting at the tone press any key or stop talking to end the recording
if (name == "record_greeting") then
table.insert(actions, {app="streamFile",data="voicemail/vm-record_greeting.wav"});
table.insert(actions, {app="tone_stream",data="L=1;%(1000, 0, 640)"});
end
--To choose greeting press 2
if (name == "choose_greeting") then
table.insert(actions, {app="streamFile",data="voicemail/vm-choose_greeting.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/2.wav"});
end
--Greeting 1 selected
if (name == "greeting_selected") then
table.insert(actions, {app="streamFile",data="voicemail/vm-greeting.wav"});
table.insert(actions, {app="streamFile",data="digits/"..param..".wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-selected.wav"});
end
--To record your name 3
if (name == "to_record_name") then
table.insert(actions, {app="streamFile",data="voicemail/vm-record_name2.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/3.wav"});
end
--At the tone please record your name press any key or stop talking to end the recording
if (name == "record_name") then
table.insert(actions, {app="streamFile",data="voicemail/vm-record_name1.wav"});
table.insert(actions, {app="tone_stream",data="L=1;%(2000, 0, 640)"});
end
--To change your password press 6
if (name == "change_password") then
table.insert(actions, {app="streamFile",data="voicemail/vm-change_password.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/6.wav"});
end
--For the main menu press 0
if (name == "main_menu") then
table.insert(actions, {app="streamFile",data="voicemail/vm-main_menu.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/0.wav"});
end
--To exit press *
if (name == "to_exit_press") then
table.insert(actions, {app="streamFile",data="voicemail/vm-to_exit.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/star.wav"});
end
--Additional Macros
--Please enter your new password then press the # key #
if (name == "password_new") then
table.insert(actions, {app="streamFile",data="voicemail/vm-enter_new_pin.wav"});
end
--Has been changed to
if (name == "password_changed") then
table.insert(actions, {app="streamFile",data="voicemail/vm-has_been_changed_to.wav"});
table.insert(actions, {app="say.number.iterated",data=param});
end
--Login Incorrect
--if (name == "password_not_valid") then
-- table.insert(actions, {app="streamFile",data="voicemail/vm-password_not_valid.wav"});
--end
--Login Incorrect
if (name == "password_not_valid") then
table.insert(actions, {app="streamFile",data="voicemail/vm-fail_auth.wav"});
end
--Too many failed attempts
if (name == "too_many_failed_attempts") then
table.insert(actions, {app="streamFile",data="voicemail/vm-abort.wav"});
end
--Message number
if (name == "message_number") then
table.insert(actions, {app="streamFile",data="voicemail/vm-message_number.wav"});
end
--To listen to the recording press 1
if (name == "listen_to_recording") then
table.insert(actions, {app="streamFile",data="voicemail/vm-listen_to_recording.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--To save the recording press 2
if (name == "save_recording") then
table.insert(actions, {app="streamFile",data="voicemail/vm-save_recording.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/2.wav"});
end
--To delete the recording press 7
if (name == "delete_recording") then
table.insert(actions, {app="streamFile",data="voicemail/vm-delete_recording.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/7.wav"});
end
--Message deleted
if (name == "message_deleted") then
table.insert(actions, {app="streamFile",data="voicemail/vm-message.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-deleted.wav"});
end
--To return the call now press 5
if (name == "return_call") then
table.insert(actions, {app="streamFile",data="voicemail/vm-return_call.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/5.wav"});
end
--To add an introduction to this message press 1
if (name == "forward_add_intro") then
table.insert(actions, {app="streamFile",data="voicemail/vm-forward_add_intro.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--To forward this message press 8
if (name == "to_forward_message") then
table.insert(actions, {app="streamFile",data="voicemail/vm-to_forward.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/8.wav"});
end
--Please enter the extension to forward this message to followed by #
if (name == "forward_enter_extension") then
table.insert(actions, {app="streamFile",data="voicemail/vm-forward_enter_ext.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-followed_by.wav"});
table.insert(actions, {app="streamFile",data="ascii/35.wav"});
end
--To forward this recording to your email press 9
if (name == "forward_to_email") then
table.insert(actions, {app="streamFile",data="voicemail/vm-forward_to_email.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/9.wav"});
end
--Emailed
if (name == "emailed") then
table.insert(actions, {app="streamFile",data="voicemail/vm-emailed.wav"});
end
--Please enter the extension to send this message to followed by #
--if (name == "send_message_to_extension") then
-- table.insert(actions, {app="streamFile",data="voicemail/vm-zzz.wav"});
--end
--Message saved
if (name == "message_saved") then
table.insert(actions, {app="streamFile",data="voicemail/vm-message.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-saved.wav"});
end
--Your recording is below the minimal acceptable length, please try again.
if (name == "too_small") then
table.insert(actions, {app="streamFile",data="voicemail/vm-too-small.wav"});
end
--Goodbye
if (name == "goodbye") then
table.insert(actions, {app="streamFile",data="voicemail/vm-goodbye.wav"});
end
--Password is not secure
if (name == "password_not_secure") then
table.insert(actions, {app="streamFile",data="voicemail/vm-password_is_not_secure.wav"});
end
--Password is below minimum length
if (name == "password_below_minimum") then
table.insert(actions, {app="streamFile",data="voicemail/vm-pin_below_minimum_length.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-minimum_pin_length_is.wav"});
table.insert(actions, {app="streamFile",data="digits/"..param..".wav"});
end
--Tutorial
--Tutorial intro
if (name == "tutorial_intro") then
table.insert(actions, {app="streamFile",data="voicemail/vm-tutorial_yes_no.wav"});
end
--Tutorial to record your name 1
if (name == "tutorial_to_record_name") then
table.insert(actions, {app="streamFile",data="voicemail/vm-tutorial_record_name.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-record_name2.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--Tutorial to change your password press 1
if (name == "tutorial_change_password") then
table.insert(actions, {app="streamFile",data="voicemail/vm-tutorial_change_pin.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-change_password.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--Tutorial to record your greeting press 1
if (name == "tutorial_record_greeting") then
table.insert(actions, {app="streamFile",data="voicemail/vm-to_record_greeting.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--Tutorial To skip
if (name == "tutorial_skip") then
table.insert(actions, {app="streamFile",data="ivr/ivr-to_skip.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/2.wav"});
end
--if actions table exists then process it
if (actions) then
--set default values
tries = 1;
timeout = 100;
--loop through the action and data
for key, row in pairs(actions) do
-- freeswitch.consoleLog("notice", "[voicemail] app: " .. row.app .. " data: " .. row.data .. "\n");
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
if (row.app == "streamFile") then
if string.find(row.data, ':', nil, true) then
session:streamFile(row.data);
else
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data);
end
elseif (row.app == "playback") then
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data);
elseif (row.app == "tone_stream") then
session:streamFile("tone_stream://"..row.data);
elseif (row.app == "silence_stream") then
session:streamFile("silence_stream://100"..row.data);
elseif (row.app == "playAndGetDigits") then
--playAndGetDigits <min> <max> <tries> <timeout> <terminators> <file> <invalid_file> <var_name> <regexp> <digit_timeout>
if (not file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data)) then
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data, "", "\\d+", max_timeout);
else
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", row.data, "", "\\d+", max_timeout);
end
elseif (row.app == "say.number.pronounced") then
session:say(row.data, default_language, "number", "pronounced");
elseif (row.app == "say.number.iterated") then
session:say(row.data, default_language, "number", "iterated");
end
--session:streamFile("silence_stream://100");
end --if
end --session:ready
end --for
--get the remaining digits
if (session:ready()) then
if (string.len(dtmf_digits) < max_digits) then
dtmf_digits = dtmf_digits .. session:getDigits(max_digits, "#", max_timeout);
end
end
--return dtmf the digits
return dtmf_digits;
else
--no dtmf digits to return
return '';
end
end
end
-- Part of FusionPBX
-- Copyright (C) 2013 - 2016 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--define the macro function
function macro(session, name, max_digits, max_timeout, param)
if (session:ready()) then
--create an empty table
actions = {}
--Please enter your id followed by
if (name == "voicemail_id") then
table.insert(actions, {app="streamFile",data="phrase:voicemail_enter_id:#"});
end
--Please enter your id followed by
if (name == "voicemail_password") then
table.insert(actions, {app="streamFile",data="phrase:voicemail_enter_pass:#"});
end
--the person at extension 101 is not available record your message at the tone press any key or stop talking to end the recording
if (name == "person_not_available_record_message") then
table.insert(actions, {app="streamFile",data="voicemail/vm-person.wav"});
--pronounce the voicemail_id
if (voicemail_alternate_greet_id and string.len(voicemail_alternate_greet_id) > 0) then
table.insert(actions, {app="say.number.iterated",data=voicemail_alternate_greet_id});
elseif (voicemail_greet_id and string.len(voicemail_greet_id) > 0) then
table.insert(actions, {app="say.number.iterated",data=voicemail_greet_id});
else
table.insert(actions, {app="say.number.iterated",data=voicemail_id});
end
table.insert(actions, {app="streamFile",data="voicemail/vm-not_available.wav"});
end
--record your message at the tone press any key or stop talking to end the recording
if (name == "record_message") then
table.insert(actions, {app="streamFile",data="voicemail/vm-record_message.wav"});
end
--beep
if (name == "record_beep") then
table.insert(actions, {app="tone_stream",data="L=1;%(1000, 0, 640)"});
end
--to listen to the recording press 1
if (name == "to_listen_to_recording") then
table.insert(actions, {app="streamFile",data="voicemail/vm-listen_to_recording.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--to save the recording press 2
if (name == "to_save_recording") then
table.insert(actions, {app="streamFile",data="voicemail/vm-save_recording.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/2.wav"});
end
--to rerecord press 3
if (name == "to_rerecord") then
table.insert(actions, {app="streamFile",data="voicemail/vm-rerecord.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/3.wav"});
end
--You have zero new messages
if (name == "new_messages") then
table.insert(actions, {app="streamFile",data="phrase:voicemail_message_count:" .. param .. ":new"})
end
--You have zero saved messages
if (name == "saved_messages") then
table.insert(actions, {app="streamFile",data="phrase:voicemail_message_count:" .. param .. ":saved"})
end
--To listen to new messages press 1
if (name == "listen_to_new_messages") then
table.insert(actions, {app="streamFile",data="voicemail/vm-listen_new.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--To listen to saved messages press 2
if (name == "listen_to_saved_messages") then
table.insert(actions, {app="streamFile",data="voicemail/vm-listen_saved.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/2.wav"});
end
--For advanced options press 5
if (name == "advanced") then
table.insert(actions, {app="streamFile",data="voicemail/vm-advanced.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/5.wav"});
end
--Advanced Options Menu
--To record a greeting press 1
if (name == "to_record_greeting") then
table.insert(actions, {app="streamFile",data="voicemail/vm-to_record_greeting.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--Choose a greeting between 1 and 9
if (name == "choose_greeting_choose") then
table.insert(actions, {app="streamFile",data="voicemail/vm-choose_greeting_choose.wav"});
end
--Greeting invalid value
if (name == "choose_greeting_fail") then
table.insert(actions, {app="streamFile",data="voicemail/vm-choose_greeting_fail.wav"});
end
--Record your greeting at the tone press any key or stop talking to end the recording
if (name == "record_greeting") then
table.insert(actions, {app="streamFile",data="voicemail/vm-record_greeting.wav"});
table.insert(actions, {app="tone_stream",data="L=1;%(1000, 0, 640)"});
end
--To choose greeting press 2
if (name == "choose_greeting") then
table.insert(actions, {app="streamFile",data="voicemail/vm-choose_greeting.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/2.wav"});
end
--Greeting 1 selected
if (name == "greeting_selected") then
table.insert(actions, {app="streamFile",data="voicemail/vm-greeting.wav"});
table.insert(actions, {app="streamFile",data="digits/"..param..".wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-selected.wav"});
end
--To record your name 3
if (name == "to_record_name") then
table.insert(actions, {app="streamFile",data="voicemail/vm-record_name2.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/3.wav"});
end
--At the tone please record your name press any key or stop talking to end the recording
if (name == "record_name") then
table.insert(actions, {app="streamFile",data="voicemail/vm-record_name1.wav"});
table.insert(actions, {app="tone_stream",data="L=1;%(2000, 0, 640)"});
end
--To change your password press 6
if (name == "change_password") then
table.insert(actions, {app="streamFile",data="voicemail/vm-change_password.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/6.wav"});
end
--For the main menu press 0
if (name == "main_menu") then
table.insert(actions, {app="streamFile",data="voicemail/vm-main_menu.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/0.wav"});
end
--To exit press *
if (name == "to_exit_press") then
table.insert(actions, {app="streamFile",data="voicemail/vm-to_exit.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/star.wav"});
end
--Additional Macros
--Please enter your new password then press the # key #
if (name == "password_new") then
table.insert(actions, {app="streamFile",data="voicemail/vm-enter_new_pin.wav"});
end
--Has been changed to
if (name == "password_changed") then
table.insert(actions, {app="streamFile",data="voicemail/vm-has_been_changed_to.wav"});
table.insert(actions, {app="say.number.iterated",data=param});
end
--Login Incorrect
--if (name == "password_not_valid") then
-- table.insert(actions, {app="streamFile",data="voicemail/vm-password_not_valid.wav"});
--end
--Login Incorrect
if (name == "password_not_valid") then
table.insert(actions, {app="streamFile",data="voicemail/vm-fail_auth.wav"});
end
--Too many failed attempts
if (name == "too_many_failed_attempts") then
table.insert(actions, {app="streamFile",data="voicemail/vm-abort.wav"});
end
--Message number
if (name == "message_number") then
table.insert(actions, {app="streamFile",data="voicemail/vm-message_number.wav"});
end
--To listen to the recording press 1
if (name == "listen_to_recording") then
table.insert(actions, {app="streamFile",data="voicemail/vm-listen_to_recording.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--To save the recording press 2
if (name == "save_recording") then
table.insert(actions, {app="streamFile",data="voicemail/vm-save_recording.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/2.wav"});
end
--To delete the recording press 7
if (name == "delete_recording") then
table.insert(actions, {app="streamFile",data="voicemail/vm-delete_recording.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/7.wav"});
end
--Message deleted
if (name == "message_deleted") then
table.insert(actions, {app="streamFile",data="voicemail/vm-message.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-deleted.wav"});
end
--To return the call now press 5
if (name == "return_call") then
table.insert(actions, {app="streamFile",data="voicemail/vm-return_call.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/5.wav"});
end
--To add an introduction to this message press 1
if (name == "forward_add_intro") then
table.insert(actions, {app="streamFile",data="voicemail/vm-forward_add_intro.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--To forward this message press 8
if (name == "to_forward_message") then
table.insert(actions, {app="streamFile",data="voicemail/vm-to_forward.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/8.wav"});
end
--Please enter the extension to forward this message to followed by #
if (name == "forward_enter_extension") then
table.insert(actions, {app="streamFile",data="voicemail/vm-forward_enter_ext.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-followed_by.wav"});
table.insert(actions, {app="streamFile",data="ascii/35.wav"});
end
--To forward this recording to your email press 9
if (name == "forward_to_email") then
table.insert(actions, {app="streamFile",data="voicemail/vm-forward_to_email.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/9.wav"});
end
--Emailed
if (name == "emailed") then
table.insert(actions, {app="streamFile",data="voicemail/vm-emailed.wav"});
end
--Please enter the extension to send this message to followed by #
--if (name == "send_message_to_extension") then
-- table.insert(actions, {app="streamFile",data="voicemail/vm-zzz.wav"});
--end
--Message saved
if (name == "message_saved") then
table.insert(actions, {app="streamFile",data="voicemail/vm-message.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-saved.wav"});
end
--Your recording is below the minimal acceptable length, please try again.
if (name == "too_small") then
table.insert(actions, {app="streamFile",data="voicemail/vm-too-small.wav"});
end
--Goodbye
if (name == "goodbye") then
table.insert(actions, {app="streamFile",data="voicemail/vm-goodbye.wav"});
end
--Password is not secure
if (name == "password_not_secure") then
table.insert(actions, {app="streamFile",data="voicemail/vm-password_is_not_secure.wav"});
end
--Password is below minimum length
if (name == "password_below_minimum") then
table.insert(actions, {app="streamFile",data="voicemail/vm-pin_below_minimum_length.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-minimum_pin_length_is.wav"});
table.insert(actions, {app="streamFile",data="digits/"..param..".wav"});
end
--Tutorial
--Tutorial intro
if (name == "tutorial_intro") then
table.insert(actions, {app="streamFile",data="voicemail/vm-tutorial_yes_no.wav"});
end
--Tutorial to record your name 1
if (name == "tutorial_to_record_name") then
table.insert(actions, {app="streamFile",data="voicemail/vm-tutorial_record_name.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-record_name2.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--Tutorial to change your password press 1
if (name == "tutorial_change_password") then
table.insert(actions, {app="streamFile",data="voicemail/vm-tutorial_change_pin.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-change_password.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--Tutorial to record your greeting press 1
if (name == "tutorial_record_greeting") then
table.insert(actions, {app="streamFile",data="voicemail/vm-to_record_greeting.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/1.wav"});
end
--Tutorial To skip
if (name == "tutorial_skip") then
table.insert(actions, {app="streamFile",data="ivr/ivr-to_skip.wav"});
table.insert(actions, {app="streamFile",data="voicemail/vm-press.wav"});
table.insert(actions, {app="streamFile",data="digits/2.wav"});
end
--if actions table exists then process it
if (actions) then
--set default values
tries = 1;
timeout = 100;
--loop through the action and data
for key, row in pairs(actions) do
-- freeswitch.consoleLog("notice", "[voicemail] app: " .. row.app .. " data: " .. row.data .. "\n");
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
if (row.app == "streamFile") then
if string.find(row.data, ':', nil, true) then
session:streamFile(row.data);
else
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data);
end
elseif (row.app == "playback") then
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data);
elseif (row.app == "tone_stream") then
session:streamFile("tone_stream://"..row.data);
elseif (row.app == "silence_stream") then
session:streamFile("silence_stream://100"..row.data);
elseif (row.app == "playAndGetDigits") then
--playAndGetDigits <min> <max> <tries> <timeout> <terminators> <file> <invalid_file> <var_name> <regexp> <digit_timeout>
if (not file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data)) then
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..row.data, "", "\\d+", max_timeout);
else
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", row.data, "", "\\d+", max_timeout);
end
elseif (row.app == "say.number.pronounced") then
session:say(row.data, default_language, "number", "pronounced");
elseif (row.app == "say.number.iterated") then
session:say(row.data, default_language, "number", "iterated");
end
--session:streamFile("silence_stream://100");
end --if
end --session:ready
end --for
--get the remaining digits
if (session:ready()) then
if (string.len(dtmf_digits) < max_digits) then
dtmf_digits = dtmf_digits .. session:getDigits(max_digits, "#", max_timeout);
end
end
--return dtmf the digits
return dtmf_digits;
else
--no dtmf digits to return
return '';
end
end
end

View File

@@ -37,6 +37,7 @@
session:answer();
session:execute("sleep", "1000");
end
--new voicemail count
if (session:ready()) then
local sql = [[SELECT count(*) as new_messages FROM v_voicemail_messages
@@ -50,7 +51,7 @@
dbh:query(sql, params, function(row)
new_messages = row["new_messages"];
end);
dtmf_digits = macro(session, "new_messages", 1, 100, new_messages);
dtmf_digits = session:playAndGetDigits(0, 1, max_tries, 300, "#", "phrase:voicemail_message_count:" .. new_messages .. ":new", "", "\\d+");
end
--saved voicemail count
if (session:ready()) then
@@ -66,25 +67,26 @@
dbh:query(sql, params, function(row)
saved_messages = row["saved_messages"];
end);
dtmf_digits = macro(session, "saved_messages", 1, 100, saved_messages);
dtmf_digits = session:playAndGetDigits(0, 1, max_tries, 300, "#", "phrase:voicemail_message_count:" .. saved_messages .. ":saved", "", "\\d+");
end
end
--to listen to new message
if (session:ready() and new_messages ~= '0') then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "listen_to_new_messages", 1, 100, '');
dtmf_digits = session:playAndGetDigits(0, 1, max_tries, 100, "#", "phrase:voicemail_main_menu:new:1", "", "\\d+");
end
end
--to listen to saved message
if (session:ready() and saved_messages ~= '0') then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "listen_to_saved_messages", 1, 100, '');
dtmf_digits = session:playAndGetDigits(0, 1, max_tries, 100, "#", "phrase:voicemail_main_menu:saved:2", "", "\\d+");
end
end
--for advanced options
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "advanced", 1, 100, '');
dtmf_digits = session:playAndGetDigits(0, 1, max_tries, 3000, "#", "phrase:voicemail_main_menu:advanced:5", "", "\\d+");
end
end
--to exit press #
@@ -106,7 +108,7 @@
main_menu();
elseif (dtmf_digits == "*") then
dtmf_digits = '';
macro(session, "goodbye", 1, 100, '');
session:execute("playback", "phrase:voicemail_goodbye");
session:hangup();
else
if (session:ready()) then
@@ -114,7 +116,7 @@
if (timeouts < max_timeouts) then
main_menu();
else
macro(session, "goodbye", 1, 1000, '');
session:execute("playback", "phrase:voicemail_goodbye");
session:hangup();
end
end

View File

@@ -82,7 +82,7 @@
if (debug["info"]) then
freeswitch.consoleLog("notice", message_number.." "..string.lower(row["voicemail_message_uuid"]).." "..row["created_epoch"]);
end
listen_to_recording(message_number, string.lower(row["voicemail_message_uuid"]), row["created_epoch"], row["caller_id_name"], row["caller_id_number"]);
listen_to_recording(message_number, string.lower(row["voicemail_message_uuid"]), row["created_epoch"], row["caller_id_name"], row["caller_id_number"], message_status);
end
end);
end

View File

@@ -1,109 +1,117 @@
-- Part of FusionPBX
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
local Database = require"resources.functions.database"
--play the greeting
function play_greeting()
timeout = 100;
tries = 1;
max_timeout = 200;
--voicemail prompt
if (skip_greeting == "true") then
--skip the greeting
else
if (session:ready()) then
--set the greeting based on the voicemail_greeting_number variable
if (voicemail_greeting_number ~= nil) then
if (string.len(voicemail_greeting_number) > 0) then
greeting_id = voicemail_greeting_number;
end
end
--play the greeting
dtmf_digits = '';
if (string.len(greeting_id) > 0) then
--sleep
session:execute("playback","silence_stream://200");
--get the greeting from the database
if (storage_type == "base64") then
local dbh = Database.new('system', 'base64/read')
local sql = [[SELECT * FROM v_voicemail_greetings
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND greeting_id = :greeting_id ]];
local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id,
greeting_id = greeting_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
local saved
dbh:query(sql, params, function(row)
--set the voicemail message path
mkdir(voicemail_dir.."/"..voicemail_id);
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
--if not found, save greeting to local file system
--saved = file_exists(greeting_location)
--if not saved then
if (string.len(row["greeting_base64"]) > 32) then
--include the file io
local file = require "resources.functions.file"
--write decoded string to file
saved = file.write_base64(greeting_location, row["greeting_base64"]);
end
--end
end);
dbh:release();
if saved then
--play the greeting
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "", ".*", max_timeout);
--session:execute("playback",voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
--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
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "", ".*", max_timeout);
--session:execute("playback",storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
else
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "",".*", max_timeout);
--session:execute("playback",voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
end
else
--default greeting
session:execute("playback","silence_stream://200");
dtmf_digits = macro(session, "person_not_available_record_message", 1, 200);
end
end
end
end
-- Part of FusionPBX
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
local Database = require"resources.functions.database"
--play the greeting
function play_greeting()
timeout = 100;
tries = 1;
max_timeout = 200;
--voicemail prompt
if (skip_greeting == "true") then
--skip the greeting
else
if (session:ready()) then
--set the greeting based on the voicemail_greeting_number variable
if (voicemail_greeting_number ~= nil) then
if (string.len(voicemail_greeting_number) > 0) then
greeting_id = voicemail_greeting_number;
end
end
--play the greeting
dtmf_digits = '';
if (string.len(greeting_id) > 0) then
--sleep
session:execute("playback","silence_stream://200");
--get the greeting from the database
if (storage_type == "base64") then
local dbh = Database.new('system', 'base64/read')
local sql = [[SELECT * FROM v_voicemail_greetings
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND greeting_id = :greeting_id ]];
local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id,
greeting_id = greeting_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
local saved
dbh:query(sql, params, function(row)
--set the voicemail message path
mkdir(voicemail_dir.."/"..voicemail_id);
greeting_location = voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"; --vm_message_ext;
--if not found, save greeting to local file system
--saved = file_exists(greeting_location)
--if not saved then
if (string.len(row["greeting_base64"]) > 32) then
--include the file io
local file = require "resources.functions.file"
--write decoded string to file
saved = file.write_base64(greeting_location, row["greeting_base64"]);
end
--end
end);
dbh:release();
if saved then
--play the greeting
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "", ".*", max_timeout);
--session:execute("playback",voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
--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
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "", ".*", max_timeout);
--session:execute("playback",storage_path.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
else
dtmf_digits = session:playAndGetDigits(min_digits, max_digits, tries, timeout, "#", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "",".*", max_timeout);
--session:execute("playback",voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav");
end
else
--default greeting
session:execute("playback","silence_stream://200");
--determine the voicemail_id to say
if (voicemail_alternate_greet_id and string.len(voicemail_alternate_greet_id) > 0) then
voicemail_id_say = voicemail_alternate_greet_id;
elseif (voicemail_greet_id and string.len(voicemail_greet_id) > 0) then
voicemail_id_say = voicemail_greet_id;
else
voicemail_id_say = voicemail_id;
end
dtmf_digits = session:playAndGetDigits(0, 1, 1, 200, "#", "phrase:voicemail_play_greeting:" .. voicemail_id_say, "", "\\d+");
end
end
end
end

View File

@@ -51,7 +51,7 @@
if (greeting_id == nil) then
if (session:ready()) then
dtmf_digits = '';
greeting_id = macro(session, "choose_greeting_choose", 1, 5000, '');
greeting_id = session:playAndGetDigits(1, 1, max_tries, 5000, "#", "phrase:voicemail_choose_greeting", "", "\\d+");
freeswitch.consoleLog("notice", "[voicemail] greeting_id: " .. greeting_id .. "\n");
end
end
@@ -69,7 +69,9 @@
--record your greeting at the tone press any key or stop talking to end the recording
if (session:ready()) then
dtmf_digits = '';
macro(session, "record_greeting", 1, 100, '');
session:execute("playback", "phrase:voicemail_record_greeting");
session:execute("sleep", "1000");
session:streamFile("tone_stream://L=1;%(1000, 0, 640)");
end
--store the voicemail greeting
@@ -104,7 +106,8 @@
--invalid greeting_id
if (session:ready()) then
dtmf_digits = '';
macro(session, "choose_greeting_fail", 1, 100, '');
session:execute("playback", "phrase:voicemail_choose_greeting_fail");
session:execute("sleep", "500");
end
--send back to choose the greeting

View File

@@ -30,22 +30,10 @@
dtmf_digits = '';
--flush dtmf digits from the input buffer
session:flushDigits();
--to listen to the recording press 1
--to listen to the recording press 1, to save the recording press 2, to re-record press 3
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "to_listen_to_recording", 1, 100, '');
end
end
--to save the recording press 2
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "to_save_recording", 1, 100, '');
end
end
--to re-record press 3
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "to_rerecord", 1, 3000, '');
dtmf_digits = session:playAndGetDigits(0, 1, max_tries, 3000, "#", "phrase:voicemail_record_file_options:1:2:3", "", "\\d+");
end
end
--process the dtmf
@@ -59,10 +47,11 @@
elseif (dtmf_digits == "2") then
--save the message
dtmf_digits = '';
macro(session, "message_saved", 1, 100, '');
session:execute("playback", "phrase:voicemail_ack:saved");
session:execute("sleep", "500");
if (type == "message") then
--goodbye
macro(session, "goodbye", 1, 100, '');
session:execute("playback", "phrase:voicemail_goodbye");
--hangup the call
session:hangup();
end
@@ -204,7 +193,7 @@
--hangup
if (session:ready()) then
dtmf_digits = '';
macro(session, "goodbye", 1, 100, '');
session:execute("playback", "phrase:voicemail_goodbye");
session:hangup();
end
else
@@ -215,8 +204,9 @@
else
if (type == "message") then
dtmf_digits = '';
macro(session, "message_saved", 1, 100, '');
macro(session, "goodbye", 1, 1000, '');
session:execute("playback", "phrase:voicemail_ack:saved");
session:execute("sleep", "300");
session:execute("playback", "phrase:voicemail_goodbye");
session:hangup();
end
if (type == "greeting") then

View File

@@ -344,10 +344,10 @@
--skip the instructions
else
if (dtmf_digits and string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "record_message", 1, 100);
dtmf_digits = session:playAndGetDigits(0, 1, 1, 500, "#", "phrase:voicemail_record_message", "", "\\d+");
end
end
--voicemail ivr options
if (session:ready()) then
if (dtmf_digits == nil) then
@@ -455,7 +455,7 @@
--play the beep
dtmf_digits = '';
result = macro(session, "record_beep", 1, 100);
session:streamFile("tone_stream://L=1;%(1000, 0, 640)");
--start epoch
start_epoch = os.time();
@@ -526,7 +526,8 @@
if (session:ready()) then
--your recording is below the minimal acceptable length, please try again
dtmf_digits = '';
macro(session, "too_small", 1, 100);
session:execute("playback", "phrase:voicemail_ack:too-small");
session:execute("sleep", "500");
--record your message at the tone
timeouts = timeouts + 1;
if (timeouts < max_timeouts) then
@@ -543,8 +544,9 @@
if (skip_instructions == "true") then
--save the message
dtmf_digits = '';
macro(session, "message_saved", 1, 100, '');
macro(session, "goodbye", 1, 100, '');
session:execute("playback", "phrase:voicemail_ack:saved");
session:execute("sleep", "300");
session:execute("playback", "phrase:voicemail_goodbye");
--hangup the call
session:hangup();
else

View File

@@ -32,7 +32,9 @@
--play the name record
dtmf_digits = '';
macro(session, "record_name", 1, 100, '');
session:execute("playback", "phrase:voicemail_record_name");
session:execute("sleep", "1000");
session:streamFile("tone_stream://L=1;%(1000, 0, 640)");
--prepate to record
-- syntax is session:recordFile(file_name, max_len_secs, silence_threshold, silence_secs)

View File

@@ -1,5 +1,5 @@
-- Part of FusionPBX
-- Copyright (C) 2013 - 2020 Mark J Crane <markjcrane@fusionpbx.com>
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
@@ -73,18 +73,11 @@
dbh = Database.new('system', 'base64/read')
end
--get the time zone
local time_zone = settings:get('domain', 'time_zone', 'name');
if (time_zone == nil) then
time_zone = 'UTC';
end
--get voicemail message details
local sql = [[SELECT to_char(timezone(:time_zone, to_timestamp(created_epoch)), 'Day DD Mon YYYY HH:MM:SS PM') as message_date, *
FROM v_voicemail_messages
local sql = [[SELECT * FROM v_voicemail_messages
WHERE domain_uuid = :domain_uuid
AND voicemail_message_uuid = :uuid]]
local params = {domain_uuid = domain_uuid, uuid = uuid, time_zone = time_zone};
local params = {domain_uuid = domain_uuid, uuid = uuid};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
@@ -94,7 +87,6 @@
created_epoch = row["created_epoch"];
caller_id_name = row["caller_id_name"];
caller_id_number = row["caller_id_number"];
message_date = row["message_date"];
message_length = row["message_length"];
--message_status = row["message_status"];
--message_priority = row["message_priority"];
@@ -122,10 +114,9 @@
--format the message length and date
message_length_formatted = format_seconds(message_length);
if (debug["info"]) then
freeswitch.consoleLog("notice", "[voicemail] message date: " .. message_date .. "\n");
freeswitch.consoleLog("notice", "[voicemail] message length: " .. message_length .. "\n");
end
--local message_date = os.date("%A, %d %b %Y %I:%M %p", created_epoch);
local message_date = os.date("%A, %d %b %Y %I:%M %p", created_epoch);
--connect to the database
local dbh = Database.new('system');

View File

@@ -1,197 +1,197 @@
-- Part of FusionPBX
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--define function main menu
function tutorial (menu)
if (voicemail_uuid) then
--intro menu
if (menu == "intro") then
--clear the value
dtmf_digits = '';
--flush dtmf digits from the input buffer
session:flushDigits();
--play the tutorial press 1, to skip 2
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "tutorial_intro", 1, 3000, '');
end
end
--process the dtmf
if (session:ready()) then
if (dtmf_digits == "1") then
timeouts = 0;
tutorial("record_name");
elseif (dtmf_digits == "2") then
timeouts = 0;
tutorial("finish");
else
if (session:ready()) then
timeouts = timeouts + 1;
if (timeouts < max_timeouts) then
tutorial("intro");
else
timeouts = 0;
tutorial("finish");
end
end
end
end
end
--record name menu
if (menu == "record_name") then
--clear the value
dtmf_digits = '';
--flush dtmf digits from the input buffer
session:flushDigits();
--play the record name press 1
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "tutorial_to_record_name", 1, 100, '');
end
end
--skip the name and go to password press 2
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "tutorial_skip", 1, 3000, '');
end
end
--process the dtmf
if (session:ready()) then
if (dtmf_digits == "1") then
timeouts = 0;
record_name("tutorial");
elseif (dtmf_digits == "2") then
timeouts = 0;
tutorial("change_password");
else
if (session:ready()) then
timeouts = timeouts + 1;
if (timeouts < max_timeouts) then
tutorial("record_name");
else
tutorial("change_password");
end
end
end
end
end
--change password menu
if (menu == "change_password") then
--clear the value
dtmf_digits = '';
--flush dtmf digits from the input buffer
session:flushDigits();
--to change your password press 1
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "tutorial_change_password", 1, 100, '');
end
end
--skip the password and go to greeting press 2
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "tutorial_skip", 1, 3000, '');
end
end
--process the dtmf
if (session:ready()) then
if (dtmf_digits == "1") then
timeouts = 0;
change_password(voicemail_id, "tutorial");
elseif (dtmf_digits == "2") then
timeouts = 0;
tutorial("record_greeting");
else
if (session:ready()) then
timeouts = timeouts + 1;
if (timeouts < max_timeouts) then
tutorial("change_password");
else
tutorial("record_greeting");
end
end
end
end
end
--change greeting menu
if (menu == "record_greeting") then
--clear the value
dtmf_digits = '';
--flush dtmf digits from the input buffer
session:flushDigits();
--to record a greeting press 1
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "tutorial_record_greeting", 1, 100, '');
end
end
--skip the record greeting press 2. finishes the tutorial and routes to main menu
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = macro(session, "tutorial_skip", 1, 3000, '');
end
end
--process the dtmf
if (session:ready()) then
if (dtmf_digits == "1") then
timeouts = 0;
record_greeting(nil, "tutorial");
elseif (dtmf_digits == "2") then
timeouts = 0;
tutorial("finish");
else
if (session:ready()) then
timeouts = timeouts + 1;
if (timeouts < max_timeouts) then
tutorial("record_greeting");
else
tutorial("finish");
end
end
end
end
end
if (menu == "finish") then
--clear the value
dtmf_digits = '';
--flush dtmf digits from the input buffer
session:flushDigits();
--update play tutorial in the datebase
local sql = [[UPDATE v_voicemails
set voicemail_tutorial = 'false'
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND voicemail_enabled = 'true' ]];
local params = {domain_uuid = domain_uuid,
voicemail_id = voicemail_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params);
--go to main menu
main_menu();
end
end
end
-- Part of FusionPBX
-- Copyright (C) 2013 Mark J Crane <markjcrane@fusionpbx.com>
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
--
-- 1. Redistributions of source code must retain the above copyright notice,
-- this list of conditions and the following disclaimer.
--
-- 2. Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.
--define function main menu
function tutorial (menu)
if (voicemail_uuid) then
--intro menu
if (menu == "intro") then
--clear the value
dtmf_digits = '';
--flush dtmf digits from the input buffer
session:flushDigits();
--play the tutorial press 1, to skip 2
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = session:playAndGetDigits(0, 1, max_tries, 3000, "#", "phrase:tutorial_intro", "", "\\d+");
end
end
--process the dtmf
if (session:ready()) then
if (dtmf_digits == "1") then
timeouts = 0;
tutorial("record_name");
elseif (dtmf_digits == "2") then
timeouts = 0;
tutorial("finish");
else
if (session:ready()) then
timeouts = timeouts + 1;
if (timeouts < max_timeouts) then
tutorial("intro");
else
timeouts = 0;
tutorial("finish");
end
end
end
end
end
--record name menu
if (menu == "record_name") then
--clear the value
dtmf_digits = '';
--flush dtmf digits from the input buffer
session:flushDigits();
--play the record name press 1
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = session:playAndGetDigits(0, 1, max_tries, 200, "#", "phrase:tutorial_record_name:1", "", "\\d+");
end
end
--skip the name and go to password press 2
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = session:playAndGetDigits(0, 1, max_tries, 3000, "#", "phrase:tutorial_skip:2", "", "\\d+");
end
end
--process the dtmf
if (session:ready()) then
if (dtmf_digits == "1") then
timeouts = 0;
record_name("tutorial");
elseif (dtmf_digits == "2") then
timeouts = 0;
tutorial("change_password");
else
if (session:ready()) then
timeouts = timeouts + 1;
if (timeouts < max_timeouts) then
tutorial("record_name");
else
tutorial("change_password");
end
end
end
end
end
--change password menu
if (menu == "change_password") then
--clear the value
dtmf_digits = '';
--flush dtmf digits from the input buffer
session:flushDigits();
--to change your password press 1
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = session:playAndGetDigits(0, 1, max_tries, 200, "#", "phrase:tutorial_change_password:1", "", "\\d+");
end
end
--skip the password and go to greeting press 2
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = session:playAndGetDigits(0, 1, max_tries, 3000, "#", "phrase:tutorial_skip:2", "", "\\d+");
end
end
--process the dtmf
if (session:ready()) then
if (dtmf_digits == "1") then
timeouts = 0;
change_password(voicemail_id, "tutorial");
elseif (dtmf_digits == "2") then
timeouts = 0;
tutorial("record_greeting");
else
if (session:ready()) then
timeouts = timeouts + 1;
if (timeouts < max_timeouts) then
tutorial("change_password");
else
tutorial("record_greeting");
end
end
end
end
end
--change greeting menu
if (menu == "record_greeting") then
--clear the value
dtmf_digits = '';
--flush dtmf digits from the input buffer
session:flushDigits();
--to record a greeting press 1
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = session:playAndGetDigits(0, 1, max_tries, 200, "#", "phrase:tutorial_record_greeting:1", "", "\\d+");
end
end
--skip the record greeting press 2. finishes the tutorial and routes to main menu
if (session:ready()) then
if (string.len(dtmf_digits) == 0) then
dtmf_digits = session:playAndGetDigits(0, 1, max_tries, 3000, "#", "phrase:tutorial_skip:2", "", "\\d+");
end
end
--process the dtmf
if (session:ready()) then
if (dtmf_digits == "1") then
timeouts = 0;
record_greeting(nil, "tutorial");
elseif (dtmf_digits == "2") then
timeouts = 0;
tutorial("finish");
else
if (session:ready()) then
timeouts = timeouts + 1;
if (timeouts < max_timeouts) then
tutorial("record_greeting");
else
tutorial("finish");
end
end
end
end
end
if (menu == "finish") then
--clear the value
dtmf_digits = '';
--flush dtmf digits from the input buffer
session:flushDigits();
--update play tutorial in the datebase
local sql = [[UPDATE v_voicemails
set voicemail_tutorial = 'false'
WHERE domain_uuid = :domain_uuid
AND voicemail_id = :voicemail_id
AND voicemail_enabled = 'true' ]];
local params = {domain_uuid = domain_uuid,
voicemail_id = voicemail_id};
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n");
end
dbh:query(sql, params);
--go to main menu
main_menu();
end
end
end