IVR: Better support for the use of base64 Recordings, added option to use Phrases in a couple places, fixed the Exit Sound. (Note: A selected Sound with the same file name as a Recording will get trumped.)

This commit is contained in:
Nate Jones
2015-04-24 02:47:10 +00:00
parent 830238631c
commit c91b4b0b5d
5 changed files with 450 additions and 138 deletions
+1 -1
View File
@@ -441,7 +441,7 @@ $text['description-extension']['fr-fr'] = "Choisir le numéro d'extension.";
$text['description-extension']['pt-br'] = "Atribua a extensão e números ao dispositivo"; $text['description-extension']['pt-br'] = "Atribua a extensão e números ao dispositivo";
$text['description-extension']['pl'] = "Wprowadź numer wewnętrzny. Domyślna konfiguracja pozwala na 2-7 cyfrowe numery wewnętrzne"; $text['description-extension']['pl'] = "Wprowadź numer wewnętrzny. Domyślna konfiguracja pozwala na 2-7 cyfrowe numery wewnętrzne";
$text['description-exit_sound']['en-us'] = "Played when leaving the menu."; $text['description-exit_sound']['en-us'] = "Played when leaving the menu, after selecting an option.";
$text['description-exit_sound']['es-cl'] = "Reproducir cuando se deje el menú."; $text['description-exit_sound']['es-cl'] = "Reproducir cuando se deje el menú.";
$text['description-exit_sound']['pt-pt'] = "É tocado quando se abandona o menu."; $text['description-exit_sound']['pt-pt'] = "É tocado quando se abandona o menu.";
$text['description-exit_sound']['fr-fr'] = "Joué lorsque l'on quitte ce menu."; $text['description-exit_sound']['fr-fr'] = "Joué lorsque l'on quitte ce menu.";
+138 -59
View File
@@ -431,27 +431,25 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo "</optgroup>\n"; echo "</optgroup>\n";
} }
//recordings //recordings
if ($dh = opendir($_SESSION['switch']['recordings']['dir']."/")) { $tmp_selected = false;
$tmp_selected = false; if (count($recordings) > 0) {
if (count($recordings) > 0) { echo "<optgroup label='Recordings'>\n";
echo "<optgroup label='Recordings'>\n"; foreach ($recordings as &$row) {
foreach ($recordings as &$row) { $recording_name = $row["recording_name"];
$name = $row["recording_name"]; $recording_filename = $row["recording_filename"];
$file = $row["recording_filename"]; if ($ivr_menu_greet_long == $_SESSION['switch']['recordings']['dir']."/".$recording_filename && strlen($ivr_menu_greet_long) > 0) {
if ($ivr_menu_greet_long == $_SESSION['switch']['recordings']['dir']."/".$file && strlen($ivr_menu_greet_long) > 0) { $tmp_selected = true;
$tmp_selected = true; echo " <option value='".$_SESSION['switch']['recordings']['dir']."/".$recording_filename."' selected='selected'>".$recording_name."</option>\n";
echo " <option value='".$_SESSION['switch']['recordings']['dir']."/".$file."' selected='selected'>".$file."</option>\n"; }
} else if ($ivr_menu_greet_long == $recording_filename && strlen($ivr_menu_greet_long) > 0) {
else if ($ivr_menu_greet_long == $file && strlen($ivr_menu_greet_long) > 0) { $tmp_selected = true;
$tmp_selected = true; echo " <option value='".$recording_filename."' selected='selected'>".$recording_name."</option>\n";
echo " <option value='".$file."' selected='selected'>".$file."</option>\n"; }
} else {
else { echo " <option value='".$recording_filename."'>".$recording_name."</option>\n";
echo " <option value='".$file."'>".$file."</option>\n";
}
} }
echo "</optgroup>\n";
} }
echo "</optgroup>\n";
} }
//phrases //phrases
$sql = "select * from v_phrases where domain_uuid = '".$domain_uuid."' "; $sql = "select * from v_phrases where domain_uuid = '".$domain_uuid."' ";
@@ -529,27 +527,25 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo "</optgroup>\n"; echo "</optgroup>\n";
} }
//recordings //recordings
if ($dh = opendir($_SESSION['switch']['recordings']['dir']."/")) { $tmp_selected = false;
$tmp_selected = false; if (count($recordings) > 0) {
if (count($recordings) > 0) { echo "<optgroup label='Recordings'>\n";
echo "<optgroup label='Recordings'>\n"; foreach ($recordings as &$row) {
foreach ($recordings as &$row) { $recording_name = $row["recording_name"];
$name = $row["recording_name"]; $recording_filename = $row["recording_filename"];
$file = $row["recording_filename"]; if ($ivr_menu_greet_short == $_SESSION['switch']['recordings']['dir']."/".$recording_filename && strlen($ivr_menu_greet_short) > 0) {
if ($ivr_menu_greet_short == $_SESSION['switch']['recordings']['dir']."/".$file && strlen($ivr_menu_greet_short) > 0) { $tmp_selected = true;
$tmp_selected = true; echo " <option value='".$_SESSION['switch']['recordings']['dir']."/".$recording_filename."' selected='selected'>".$recording_name."</option>\n";
echo " <option value='".$_SESSION['switch']['recordings']['dir']."/".$file."' selected='selected'>".$file."</option>\n"; }
} else if ($ivr_menu_greet_short == $recording_filename && strlen($ivr_menu_greet_short) > 0) {
else if ($ivr_menu_greet_short == $file && strlen($ivr_menu_greet_short) > 0) { $tmp_selected = true;
$tmp_selected = true; echo " <option value='".$recording_filename."' selected='selected'>".$recording_name."</option>\n";
echo " <option value='".$file."' selected='selected'>".$file."</option>\n"; }
} else {
else { echo " <option value='".$recording_filename."'>".$recording_name."</option>\n";
echo " <option value='".$file."'>".$file."</option>\n";
}
} }
echo "</optgroup>\n";
} }
echo "</optgroup>\n";
} }
//phrases //phrases
$sql = "select * from v_phrases where domain_uuid = '".$domain_uuid."' "; $sql = "select * from v_phrases where domain_uuid = '".$domain_uuid."' ";
@@ -647,7 +643,9 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
$ivr_menu_option_param = str_replace($_SESSION['domain_name'], "", $ivr_menu_option_param); $ivr_menu_option_param = str_replace($_SESSION['domain_name'], "", $ivr_menu_option_param);
$ivr_menu_option_param = str_replace("\${domain_name}", "", $ivr_menu_option_param); $ivr_menu_option_param = str_replace("\${domain_name}", "", $ivr_menu_option_param);
$ivr_menu_option_param = str_replace("\${domain}", "", $ivr_menu_option_param); $ivr_menu_option_param = str_replace("\${domain}", "", $ivr_menu_option_param);
$ivr_menu_option_param = ucfirst(trim($ivr_menu_option_param)); $ivr_menu_option_param = str_replace(".".$_SESSION['domain_uuid'], "", $ivr_menu_option_param);
$ivr_menu_option_param = str_replace("//", "/", $ivr_menu_option_param);
//$ivr_menu_option_param = ucfirst(trim($ivr_menu_option_param));
echo " <tr>\n"; echo " <tr>\n";
echo " <td class='vtable'>\n"; echo " <td class='vtable'>\n";
echo " ".$field['ivr_menu_option_digits']; echo " ".$field['ivr_menu_option_digits'];
@@ -859,7 +857,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo " ".$text['label-invalid_sound']."\n"; echo " ".$text['label-invalid_sound']."\n";
echo "</td>\n"; echo "</td>\n";
echo "<td width=\"70%\" class='vtable' align='left'>\n"; echo "<td width=\"70%\" class='vtable' align='left'>\n";
echo "<select name='ivr_menu_invalid_sound' class='formfld' style='width: 400px;' ".((if_group("superadmin")) ? "onchange='changeToInput(this);'" : null)." required='required'>\n"; echo "<select name='ivr_menu_invalid_sound' class='formfld' style='width: 350px;' ".((if_group("superadmin")) ? "onchange='changeToInput(this);'" : null)." required='required'>\n";
//misc optgroup //misc optgroup
if (if_group("superadmin")) { if (if_group("superadmin")) {
echo "<optgroup label='Misc'>\n"; echo "<optgroup label='Misc'>\n";
@@ -869,27 +867,24 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo "</optgroup>\n"; echo "</optgroup>\n";
} }
//recordings //recordings
if ($dh = opendir($_SESSION['switch']['recordings']['dir']."/")) { $tmp_selected = false;
$tmp_selected = false; if (count($recordings) > 0) {
$files = Array();
echo "<optgroup label='Recordings'>\n"; echo "<optgroup label='Recordings'>\n";
while($file = readdir($dh)) { foreach ($recordings as &$row) {
if($file != "." && $file != ".." && $file[0] != '.') { $recording_name = $row["recording_name"];
if(is_dir($_SESSION['switch']['recordings']['dir'] . "/" . $file)) { $recording_filename = $row["recording_filename"];
//this is a directory if ($ivr_menu_invalid_sound == $_SESSION['switch']['recordings']['dir']."/".$recording_filename && strlen($ivr_menu_invalid_sound) > 0) {
} $tmp_selected = true;
else { echo " <option value='".$_SESSION['switch']['recordings']['dir']."/".$recording_filename."' selected='selected'>".$recording_name."</option>\n";
if ($ivr_menu_invalid_sound == $_SESSION['switch']['recordings']['dir']."/".$file && strlen($ivr_menu_invalid_sound) > 0) { }
$tmp_selected = true; else if ($ivr_menu_invalid_sound == $recording_filename && strlen($ivr_menu_invalid_sound) > 0) {
echo " <option value='".$_SESSION['switch']['recordings']['dir']."/".$file."' selected=\"selected\">".$file."</option>\n"; $tmp_selected = true;
} echo " <option value='".$recording_filename."' selected='selected'>".$recording_name."</option>\n";
else { }
echo " <option value='".$_SESSION['switch']['recordings']['dir']."/".$file."'>".$file."</option>\n"; else {
} echo " <option value='".$recording_filename."'>".$recording_name."</option>\n";
}
} }
} }
closedir($dh);
echo "</optgroup>\n"; echo "</optgroup>\n";
} }
//phrases //phrases
@@ -957,7 +952,91 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
echo " ".$text['label-exit_sound']."\n"; echo " ".$text['label-exit_sound']."\n";
echo "</td>\n"; echo "</td>\n";
echo "<td class='vtable' align='left'>\n"; echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='ivr_menu_exit_sound' maxlength='255' value=\"$ivr_menu_exit_sound\">\n"; echo "<select name='ivr_menu_exit_sound' class='formfld' style='width: 350px;' ".((if_group("superadmin")) ? "onchange='changeToInput(this);'" : null)." required='required'>\n";
//misc optgroup
if (if_group("superadmin")) {
echo "<optgroup label='Misc'>\n";
echo " <option value='phrase:'>phrase:</option>\n";
echo " <option value='say:'>say:</option>\n";
echo " <option value='tone_stream:'>tone_stream:</option>\n";
echo "</optgroup>\n";
}
//recordings
$tmp_selected = false;
if (count($recordings) > 0) {
echo "<optgroup label='Recordings'>\n";
foreach ($recordings as &$row) {
$recording_name = $row["recording_name"];
$recording_filename = $row["recording_filename"];
if ($ivr_menu_exit_sound == $_SESSION['switch']['recordings']['dir']."/".$recording_filename && strlen($ivr_menu_exit_sound) > 0) {
$tmp_selected = true;
echo " <option value='".$_SESSION['switch']['recordings']['dir']."/".$recording_filename."' selected='selected'>".$recording_name."</option>\n";
}
else if ($ivr_menu_exit_sound == $recording_filename && strlen($ivr_menu_exit_sound) > 0) {
$tmp_selected = true;
echo " <option value='".$recording_filename."' selected='selected'>".$recording_name."</option>\n";
}
else {
echo " <option value='".$recording_filename."'>".$recording_name."</option>\n";
}
}
echo "</optgroup>\n";
}
//phrases
$sql = "select * from v_phrases where domain_uuid = '".$domain_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (count($result) > 0) {
echo "<optgroup label='Phrases'>\n";
foreach ($result as &$row) {
if ($ivr_menu_exit_sound == "phrase:".$row["phrase_name"].".".$domain_uuid) {
$tmp_selected = true;
echo " <option value='phrase:".$row["phrase_name"].".".$domain_uuid."' selected='selected'>".$row["phrase_name"]."</option>\n";
}
else {
echo " <option value='phrase:".$row["phrase_name"].".".$domain_uuid."'>".$row["phrase_name"]."</option>\n";
}
}
unset ($prep_statement);
echo "</optgroup>\n";
}
//sounds
$dir_path = $_SESSION['switch']['sounds']['dir'];
recur_sounds_dir($_SESSION['switch']['sounds']['dir']);
if (count($dir_array) > 0) {
echo "<optgroup label='Sounds'>\n";
foreach ($dir_array as $key => $value) {
if (strlen($value) > 0) {
if (substr($ivr_menu_exit_sound, 0, 71) == "\$\${sounds_dir}/\${default_language}/\${default_dialect}/\${default_voice}/") {
$ivr_menu_exit_sound = substr($ivr_menu_exit_sound, 71);
}
if ($ivr_menu_exit_sound == $key) {
$tmp_selected = true;
echo " <option value='$key' selected='selected'>$key</option>\n";
}
else {
echo " <option value='$key'>$key</option>\n";
}
}
}
echo "</optgroup>\n";
}
//select
if (if_group("superadmin")) {
if (!$tmp_selected) {
echo "<optgroup label='Selected'>\n";
if (file_exists($_SESSION['switch']['recordings']['dir']."/".$ivr_menu_exit_sound)) {
echo " <option value='".$_SESSION['switch']['recordings']['dir']."/".$ivr_menu_exit_sound."' selected='selected'>".$ivr_menu_exit_sound."</option>\n";
}
else if (substr($ivr_menu_exit_sound, -3) == "wav" || substr($ivr_menu_exit_sound, -3) == "mp3") {
echo " <option value='".$ivr_menu_exit_sound."' selected='selected'>".$ivr_menu_exit_sound."</option>\n";
}
echo "</optgroup>\n";
}
unset($tmp_selected);
}
echo "</select>\n";
echo "<br />\n"; echo "<br />\n";
echo $text['description-exit_sound']."\n"; echo $text['description-exit_sound']."\n";
echo "</td>\n"; echo "</td>\n";
+167 -69
View File
@@ -182,85 +182,167 @@
if (string.sub(ivr_menu_greet_short,0,71) == "$${sounds_dir}/${default_language}/${default_dialect}/${default_voice}/") then if (string.sub(ivr_menu_greet_short,0,71) == "$${sounds_dir}/${default_language}/${default_dialect}/${default_voice}/") then
ivr_menu_greet_short = string.sub(ivr_menu_greet_short,72); ivr_menu_greet_short = string.sub(ivr_menu_greet_short,72);
end end
if (string.sub(ivr_menu_invalid_sound,0,71) == "$${sounds_dir}/${default_language}/${default_dialect}/${default_voice}/") then
ivr_menu_invalid_sound = string.sub(ivr_menu_invalid_sound,72);
end
if (string.sub(ivr_menu_exit_sound,0,71) == "$${sounds_dir}/${default_language}/${default_dialect}/${default_voice}/") then
ivr_menu_exit_sound = string.sub(ivr_menu_exit_sound,72);
end
--adjust the file path --parse file names
if (ivr_menu_greet_short) then greet_long_file_name_only = ivr_menu_greet_long:match("([^/]+)$");
--do nothing greet_short_file_name_only = ivr_menu_greet_short:match("([^/]+)$");
else invalid_sound_file_name_only = ivr_menu_invalid_sound:match("([^/]+)$");
ivr_menu_greet_short = ivr_menu_greet_long; exit_sound_file_name_only = ivr_menu_exit_sound:match("([^/]+)$");
end
if (not file_exists(ivr_menu_greet_long)) then
if (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..ivr_menu_greet_long)) then
ivr_menu_greet_long = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..ivr_menu_greet_long;
elseif (file_exists(recordings_dir.."/"..ivr_menu_greet_long)) then
ivr_menu_greet_long = recordings_dir.."/"..ivr_menu_greet_long;
end
end
if (string.len(ivr_menu_greet_short) > 1) then
if (not file_exists(ivr_menu_greet_short)) then
if (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..ivr_menu_greet_short)) then
ivr_menu_greet_short = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..ivr_menu_greet_short;
elseif (file_exists(recordings_dir.."/"..ivr_menu_greet_short)) then
ivr_menu_greet_short = recordings_dir.."/"..ivr_menu_greet_short;
end
end
else
ivr_menu_greet_short = ivr_menu_greet_long;
end
ivr_menu_invalid_entry = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..ivr_menu_invalid_sound;
--get the recordings from the database --get the recordings from the database
ivr_menu_greet_long_is_base64 = false;
ivr_menu_greet_short_is_base64 = false;
ivr_menu_invalid_sound_is_base64 = false;
ivr_menu_exit_sound_is_base64 = false;
if (storage_type == "base64") then if (storage_type == "base64") then
if (string.len(ivr_menu_greet_long) > 1) then --greet long
sql = [[SELECT * FROM v_recordings if (string.len(ivr_menu_greet_long) > 1) then
WHERE domain_uuid = ']] .. domain_uuid ..[[' if (not file_exists(recordings_dir.."/"..greet_long_file_name_only)) then
AND recording_filename = ']].. ivr_menu_greet_long.. [[' ]]; sql = [[SELECT * FROM v_recordings
if (debug["sql"]) then WHERE domain_uuid = ']]..domain_uuid..[['
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n"); AND recording_filename = ']]..greet_long_file_name_only..[[' ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
end
status = dbh:query(sql, function(row)
--add functions
dofile(scripts_dir.."/resources/functions/base64.lua");
--add the path to filename
ivr_menu_greet_long = recordings_dir.."/"..greet_long_file_name_only;
ivr_menu_greet_long_is_base64 = true;
--save the recording to the file system
if (string.len(row["recording_base64"]) > 32) then
local file = io.open(ivr_menu_greet_long, "w");
file:write(base64.decode(row["recording_base64"]));
file:close();
end
end);
end
end end
status = dbh:query(sql, function(row) --greet short
--add functions if (string.len(ivr_menu_greet_short) > 1) then
dofile(scripts_dir.."/resources/functions/base64.lua"); if (not file_exists(recordings_dir.."/"..greet_short_file_name_only)) then
sql = [[SELECT * FROM v_recordings
--add the path to filename WHERE domain_uuid = ']]..domain_uuid..[['
ivr_menu_greet_long = recordings_dir.."/"..ivr_menu_greet_long; AND recording_filename = ']]..greet_short_file_name_only..[[' ]];
if (debug["sql"]) then
--save the recording to the file system freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
if (string.len(row["recording_base64"]) > 32) then
local file = io.open(ivr_menu_greet_long, "w");
file:write(base64.decode(row["recording_base64"]));
file:close();
end end
end); status = dbh:query(sql, function(row)
end --add functions
if (string.len(ivr_menu_greet_short) > 1) then dofile(scripts_dir.."/resources/functions/base64.lua");
sql = [[SELECT * FROM v_recordings --add the path to filename
WHERE domain_uuid = ']] .. domain_uuid ..[[' ivr_menu_greet_short = recordings_dir.."/"..greet_short_file_name_only;
AND recording_filename = ']].. ivr_menu_greet_short.. [[' ]]; ivr_menu_greet_short_is_base64 = true;
--if (debug["sql"]) then --save the recording to the file system
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n"); if (string.len(row["recording_base64"]) > 32) then
--end local file = io.open(ivr_menu_greet_short, "w");
status = dbh:query(sql, function(row) file:write(base64.decode(row["recording_base64"]));
--add functions file:close();
dofile(scripts_dir.."/resources/functions/base64.lua"); end
end);
--add the path to filename end
ivr_menu_greet_short = recordings_dir.."/"..ivr_menu_greet_short; end
--invalid sound
--save the recording to the file system if (string.len(ivr_menu_invalid_sound) > 1) then
if (string.len(row["recording_base64"]) > 32) then if (not file_exists(recordings_dir.."/"..invalid_sound_file_name_only)) then
local file = io.open(ivr_menu_greet_short, "w"); sql = [[SELECT * FROM v_recordings
file:write(base64.decode(row["recording_base64"])); WHERE domain_uuid = ']]..domain_uuid..[['
file:close(); AND recording_filename = ']]..invalid_sound_file_name_only..[[' ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
end end
end); status = dbh:query(sql, function(row)
end --add functions
dofile(scripts_dir.."/resources/functions/base64.lua");
--add the path to filename
ivr_menu_invalid_sound = recordings_dir.."/"..invalid_sound_file_name_only;
ivr_menu_invalid_sound_is_base64 = true;
--save the recording to the file system
if (string.len(row["recording_base64"]) > 32) then
local file = io.open(ivr_menu_invalid_sound, "w");
file:write(base64.decode(row["recording_base64"]));
file:close();
end
end);
end
end
--exit sound
if (string.len(ivr_menu_exit_sound) > 1) then
if (not file_exists(recordings_dir.."/"..exit_sound_file_name_only)) then
sql = [[SELECT * FROM v_recordings
WHERE domain_uuid = ']]..domain_uuid..[['
AND recording_filename = ']]..exit_sound_file_name_only..[[' ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[ivr_menu] SQL: "..sql.."\n");
end
status = dbh:query(sql, function(row)
--add functions
dofile(scripts_dir.."/resources/functions/base64.lua");
--add the path to filename
ivr_menu_exit_sound = recordings_dir.."/"..exit_sound_file_name_only;
ivr_menu_exit_sound_is_base64 = true;
--save the recording to the file system
if (string.len(row["recording_base64"]) > 32) then
local file = io.open(ivr_menu_exit_sound, "w");
file:write(base64.decode(row["recording_base64"]));
file:close();
end
end);
end
end
elseif (storage_type == "http_cache") then elseif (storage_type == "http_cache") then
--add the path to file name --add the path to file name
ivr_menu_greet_long = storage_path.."/"..ivr_menu_greet_long; ivr_menu_greet_long = storage_path.."/"..ivr_menu_greet_long;
ivr_menu_greet_short = storage_path.."/"..ivr_menu_greet_short; ivr_menu_greet_short = storage_path.."/"..ivr_menu_greet_short;
ivr_menu_invalid_sound = storage_path.."/"..ivr_menu_invalid_sound;
ivr_menu_exit_sound = storage_path.."/"..ivr_menu_exit_sound;
end end
--adjust file paths
--greet long
if (not file_exists(ivr_menu_greet_long)) then
if (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..greet_long_file_name_only)) then
ivr_menu_greet_long = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..greet_long_file_name_only;
elseif (file_exists(recordings_dir.."/"..greet_long_file_name_only)) then
ivr_menu_greet_long = recordings_dir.."/"..greet_long_file_name_only;
end
end
--greet short
if (string.len(ivr_menu_greet_short) > 1) then
if (not file_exists(ivr_menu_greet_short)) then
if (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..greet_short_file_name_only)) then
ivr_menu_greet_short = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..greet_short_file_name_only;
elseif (file_exists(recordings_dir.."/"..greet_short_file_name_only)) then
ivr_menu_greet_short = recordings_dir.."/"..greet_short_file_name_only;
end
end
else
ivr_menu_greet_short = ivr_menu_greet_long;
end
--invalid sound
if (not file_exists(ivr_menu_invalid_sound)) then
if (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..invalid_sound_file_name_only)) then
ivr_menu_invalid_sound = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..invalid_sound_file_name_only;
elseif (file_exists(recordings_dir.."/"..invalid_sound_file_name_only)) then
ivr_menu_invalid_sound = recordings_dir.."/"..invalid_sound_file_name_only;
end
end
--exit sound
if (not file_exists(ivr_menu_exit_sound)) then
if (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..exit_sound_file_name_only)) then
ivr_menu_exit_sound = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..exit_sound_file_name_only;
elseif (file_exists(recordings_dir.."/"..exit_sound_file_name_only)) then
ivr_menu_exit_sound = recordings_dir.."/"..exit_sound_file_name_only;
end
end
--define the ivr menu --define the ivr menu
function menu() function menu()
--increment the tries --increment the tries
@@ -344,6 +426,9 @@
freeswitch.consoleLog("notice", "[ivr_menu] action: " .. action .. " data: ".. data .. "\n"); freeswitch.consoleLog("notice", "[ivr_menu] action: " .. action .. " data: ".. data .. "\n");
end end
--run the action --run the action
if (ivr_menu_exit_sound ~= nil) then
session:streamFile(ivr_menu_exit_sound);
end
session:execute(action, data); session:execute(action, data);
end end
end end
@@ -375,17 +460,30 @@
--execute --execute
if (action) then if (action) then
if (string.len(action) == 0) then if (string.len(action) == 0) then
session:streamFile(ivr_menu_invalid_entry); session:streamFile(ivr_menu_invalid_sound);
menu(); menu();
end end
else else
session:streamFile(ivr_menu_invalid_entry); session:streamFile(ivr_menu_invalid_sound);
menu(); menu();
end end
end --end function end --end function
--answer the session --answer the session
if ( session:ready() ) then if (session:ready()) then
session:answer(); session:answer();
menu(); menu();
end
--if base64, remove temporary audio files (increases responsiveness when files remain local)
if (storage_type == "base64") then
if (ivr_menu_greet_long_is_base64 and file_exists(ivr_menu_greet_long)) then
--os.remove(ivr_menu_greet_long);
end
if (ivr_menu_greet_short_is_base64 and file_exists(ivr_menu_greet_short)) then
--os.remove(ivr_menu_greet_short);
end
if (ivr_menu_invalid_sound_is_base64 and file_exists(ivr_menu_invalid_sound)) then
--os.remove(ivr_menu_invalid_sound);
end
end end
+113 -2
View File
@@ -2,6 +2,68 @@
script_name = argv[0]; script_name = argv[0];
file_name = argv[1]; file_name = argv[1];
--include config.lua
scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1));
dofile(scripts_dir.."/resources/functions/config.lua");
dofile(config());
--connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua");
dbh = database_handle('system');
--get the variables
domain_name = session:getVariable("domain_name");
domain_uuid = session:getVariable("domain_uuid");
--get the sounds dir, language, dialect and voice
sounds_dir = session:getVariable("sounds_dir");
default_language = session:getVariable("default_language");
default_dialect = session:getVariable("default_dialect");
default_voice = session:getVariable("default_voice");
if (not default_language) then default_language = 'en'; end
if (not default_dialect) then default_dialect = 'us'; end
if (not default_voice) then default_voice = 'callie'; end
--settings
dofile(scripts_dir.."/resources/functions/settings.lua");
settings = settings(domain_uuid);
storage_type = "";
storage_path = "";
if (settings['recordings'] ~= nil) then
if (settings['recordings']['storage_type'] ~= nil) then
if (settings['recordings']['storage_type']['text'] ~= nil) then
storage_type = settings['recordings']['storage_type']['text'];
end
end
if (settings['recordings']['storage_path'] ~= nil) then
if (settings['recordings']['storage_path']['text'] ~= nil) then
storage_path = settings['recordings']['storage_path']['text'];
storage_path = storage_path:gsub("${domain_name}", domain_name);
storage_path = storage_path:gsub("${voicemail_id}", voicemail_id);
storage_path = storage_path:gsub("${voicemail_dir}", voicemail_dir);
end
end
end
temp_dir = "";
if (settings['server'] ~= nil) then
if (settings['server']['temp'] ~= nil) then
if (settings['server']['temp']['dir'] ~= nil) then
temp_dir = settings['server']['temp']['dir'];
end
end
end
--set the recordings directory
if (domain_count > 1) then
recordings_dir = recordings_dir .. "/"..domain_name;
end
--check if a file exists
function file_exists(name)
local f=io.open(name,"r")
if f~=nil then io.close(f) return true else return false end
end
--define the on_dtmf call back function --define the on_dtmf call back function
function on_dtmf(s, type, obj, arg) function on_dtmf(s, type, obj, arg)
if (type == "dtmf") then if (type == "dtmf") then
@@ -28,10 +90,59 @@
end end
end end
--stream the file --parse file name
session:answer(); file_name_only = file_name:match("([^/]+)$");
--if base64, get from db, create temp file
if (storage_type == "base64") then
freeswitch.consoleLog("notice", "detected base64.\n");
if (not file_exists(recordings_dir.."/"..file_name_only)) then
sql = [[SELECT * FROM v_recordings
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND recording_filename = ']].. file_name_only.. [[' ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[ivr_menu] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(row)
--add functions
dofile(scripts_dir.."/resources/functions/base64.lua");
--add the path to filename
file_name = recordings_dir.."/"..file_name_only;
--save the recording to the file system
if (string.len(row["recording_base64"]) > 32) then
local file = io.open(file_name, "w");
file:write(base64.decode(row["recording_base64"]));
file:close();
end
end);
else
file_name = recordings_dir.."/"..file_name_only;
end
end
--adjust file path
if (not file_exists(file_name)) then
freeswitch.consoleLog("notice", "file " .. file_name .. " doesn't exist.\n");
if (file_exists(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name_only)) then
freeswitch.consoleLog("notice", "file " .. file_name_only .. " found in sounds.\n");
file_name = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/"..file_name_only;
elseif (file_exists(recordings_dir.."/"..file_name_only)) then
freeswitch.consoleLog("notice", "file " .. file_name_only .. " found in recordings.\n");
file_name = recordings_dir.."/"..file_name_only;
end
end
--stream file if exists
if (session:ready()) then if (session:ready()) then
session:answer();
session:sleep(1000); session:sleep(1000);
session:setInputCallback("on_dtmf", ""); session:setInputCallback("on_dtmf", "");
session:streamFile(file_name); session:streamFile(file_name);
end end
--if base64, remove temp file (increases responsiveness when files remain local)
if (storage_type == "base64") then
if (file_exists(file_name)) then
--os.remove(file_name);
end
end
+31 -7
View File
@@ -1000,16 +1000,20 @@ function switch_select_destination($select_type, $select_label, $select_name, $s
if (count($result) > 0) { if (count($result) > 0) {
$options[] = "<optgroup label='Recordings'>"; $options[] = "<optgroup label='Recordings'>";
foreach ($result as &$row) { foreach ($result as &$row) {
$name = $row["recording_name"]; $recording_name = $row["recording_name"];
$filename = $row["recording_filename"]; $recording_filename = $row["recording_filename"];
$path_mod = ($_SESSION['recordings']['storage_type']['text'] != 'base64') ? $_SESSION['switch']['recordings']['dir'] : null;
if ($select_type == "dialplan") { if ($select_type == "dialplan") {
$selected = ($select_value == "lua:streamfile.lua ".$_SESSION['switch']['recordings']['dir']."/".$filename || $select_value == "lua:streamfile.lua ".$filename) ? true : false; $execute_method = 'lua:';
$options[] = "<option value='lua:streamfile.lua ".$_SESSION['switch']['recordings']['dir']."/".$filename."' ".(($selected) ? "selected='selected'" : null).">".$name."</option>";
} }
if ($select_type == "ivr") { else if ($select_type == "ivr") {
$selected = ($select_value == "menu-exec-app:lua streamfile.lua ".$_SESSION['switch']['recordings']['dir']."/".$filename || $select_value == "menu-exec-app:lua streamfile.lua ".$_SESSION['switch']['recordings']['dir']."/".$filename) ? true : false; $execute_method = 'menu-exec-app:lua ';
$options[] = "<option value='menu-exec-app:lua streamfile.lua ".$_SESSION['switch']['recordings']['dir']."/".$filename."' ".(($selected) ? "selected='selected'" : null).">".$name."</option>";
} }
$selected = (
$select_value == $execute_method."streamfile.lua ".$_SESSION['switch']['recordings']['dir']."/".$recording_filename ||
$select_value == $execute_method."streamfile.lua ".$recording_filename
) ? true : false;
$options[] = "<option value='".$execute_method."streamfile.lua ".$path_mod.$recording_filename."' ".(($selected) ? "selected='selected'" : null).">".$recording_name."</option>";
if ($selected) { $selection_found = true; } if ($selected) { $selection_found = true; }
} }
$options[] = "</optgroup>"; $options[] = "</optgroup>";
@@ -1017,6 +1021,26 @@ function switch_select_destination($select_type, $select_label, $select_name, $s
} }
} }
//phrases
if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/app/phrases/app_config.php")) {
if ($select_type == "dialplan" || $select_type == "ivr") {
$sql = "select * from v_phrases where domain_uuid = '".$domain_uuid."' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
if (count($result) > 0) {
$options[] = "<optgroup label='Phrases'>";
foreach ($result as &$row) {
$selected = ($select_value == "phrase:".$row["phrase_name"].".".$domain_uuid) ? true : false;
$options[] = "<option value='phrase:".$row["phrase_name"].".".$domain_uuid."' ".(($selected) ? "selected='selected'" : null).">".$row["phrase_name"]."</option>";
if ($selected) { $selection_found = true; }
}
$options[] = "</optgroup>";
}
unset ($prep_statement);
}
}
//ring groups //ring groups
if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/app/ring_groups/app_config.php")) { if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/app/ring_groups/app_config.php")) {
if ($select_type == "dialplan" || $select_type == "ivr") { if ($select_type == "dialplan" || $select_type == "ivr") {