Make the ivr_menu.lua file multi-lingual capable.

This commit is contained in:
Mark Crane 2012-11-25 07:13:14 +00:00
parent 25f5013a69
commit 8e816ceaf3
1 changed files with 75 additions and 36 deletions

View File

@ -45,7 +45,13 @@
caller_id_name = session:getVariable("caller_id_name");
caller_id_number = session:getVariable("caller_id_number");
--get the ivr menu
--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
--get the ivr menu from the database
sql = [[SELECT * FROM v_ivr_menus
WHERE ivr_menu_uuid = ']] .. ivr_menu_uuid ..[['
AND ivr_menu_enabled = 'true' ]];
@ -76,7 +82,40 @@
ivr_menu_ringback = row["ivr_menu_ringback"];
end);
hash = {
--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
--make the path relative
if (string.sub(ivr_menu_greet_long,0,71) == "$${sounds_dir}/${default_language}/${default_dialect}/${default_voice}/") then
ivr_menu_greet_long = string.sub(ivr_menu_greet_long,72);
end
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);
end
--adjust the file path
if (not ivr_menu_greet_short) then
ivr_menu_greet_short = ivr_menu_greet_long;
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;
end
end
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;
end
end
--prepare the ivr menu data
hash = {
["main"] = undef,
["name"] = ivr_menu_name,
["greet_long"] = ivr_menu_greet_long,
@ -93,9 +132,9 @@ hash = {
["digit_len"] = ivr_menu_digit_len,
["timeout"] = ivr_menu_timeout,
["max_failures"] = ivr_menu_max_failures
}
}
top = freeswitch.IVRMenu(
top = freeswitch.IVRMenu(
hash["main"],
hash["name"],
hash["greet_long"],