diff --git a/resources/install/scripts/call_flow.lua b/resources/install/scripts/call_flow.lua index 24c99b6691..8f59a37948 100644 --- a/resources/install/scripts/call_flow.lua +++ b/resources/install/scripts/call_flow.lua @@ -31,16 +31,13 @@ --include config.lua require "resources.functions.config"; +--create logger object + log = require "resources.functions.log".call_flow + --additional includes local presence_in = require "resources.functions.presence_in" local Database = require "resources.functions.database" - local Settings = require "resources.functions.lazy_settings" - file = require "resources.functions.file" - log = require "resources.functions.log".call_flow - require "resources.functions.basename" - require "resources.functions.is_absolute_path" - require "resources.functions.find_file" - require "resources.functions.play_file" + local play_file = require "resources.functions.play_file" --include json library local json @@ -52,19 +49,16 @@ local dbh = Database.new('system'); --get the variables - if (session:ready()) then - domain_name = session:getVariable("domain_name"); - domain_uuid = session:getVariable("domain_uuid"); - call_flow_uuid = session:getVariable("call_flow_uuid"); - sounds_dir = session:getVariable("sounds_dir"); - feature_code = session:getVariable("feature_code"); - end + if not session:ready() then return end ---set the sounds path for the language, dialect and voice - if (session:ready()) then - local default_language = session:getVariable("default_language") or 'en'; - local default_dialect = session:getVariable("default_dialect") or 'us'; - local default_voice = session:getVariable("default_voice") or 'callie'; + local domain_name = session:getVariable("domain_name"); + local domain_uuid = session:getVariable("domain_uuid"); + local call_flow_uuid = session:getVariable("call_flow_uuid"); + local feature_code = session:getVariable("feature_code"); + + if not call_flow_uuid then + log.warning('Can not get call flow uuid') + return end --get the call flow details @@ -179,6 +173,7 @@ if (session:ready()) then session:execute(app, data); end + --timeout application --if (not session:answered()) then -- session:execute(ring_group_timeout_app, ring_group_timeout_data); diff --git a/resources/install/scripts/resources/functions/basename.lua b/resources/install/scripts/resources/functions/basename.lua index 772309ee46..ef54b24f5c 100644 --- a/resources/install/scripts/resources/functions/basename.lua +++ b/resources/install/scripts/resources/functions/basename.lua @@ -1,3 +1,5 @@ function basename(file_name) return (string.match(file_name, "([^/]+)$")) end + +return basename diff --git a/resources/install/scripts/resources/functions/file.lua b/resources/install/scripts/resources/functions/file.lua index 957421a284..823f5def26 100644 --- a/resources/install/scripts/resources/functions/file.lua +++ b/resources/install/scripts/resources/functions/file.lua @@ -2,7 +2,7 @@ pcall(require, "resources.functions.base64") -- load logger for file library - local log = require "resources.functions.log".file + local log = log or require "resources.functions.log"[app_name or 'file'] local base64 = base64 diff --git a/resources/install/scripts/resources/functions/find_file.lua b/resources/install/scripts/resources/functions/find_file.lua index ce8f68d572..fac04e2f2c 100644 --- a/resources/install/scripts/resources/functions/find_file.lua +++ b/resources/install/scripts/resources/functions/find_file.lua @@ -1,6 +1,11 @@ +local log = log or require "resources.functions.log"[app_name or 'find_file'] + +local file = require "resources.functions.file" +local Settings = require "resources.functions.lazy_settings" +local basename = require "resources.functions.basename" +local is_absolute_path = require "resources.functions.is_absolute_path" function find_file(dbh, domain_name, domain_uuid, file_name) - -- if we specify e.g. full path if (is_absolute_path(file_name) and file.exists(file_name)) then log.debugf('found file `%s` in file system', file_name) @@ -43,14 +48,16 @@ function find_file(dbh, domain_name, domain_uuid, file_name) if not found then local sounds_dir if session then - -- Implemented based on stream.lua. But seems it never works. - -- because if we have file like `digits/1.wav` but full_path is `sounds_dir/digits/XXXX/1.wav` - sounds_dir = session:getVariable("sounds_dir") - local default_language = session:getVariable("default_language") or 'en' - local default_dialect = session:getVariable("default_dialect") or 'us' - local default_voice = session:getVariable("default_voice") or 'callie' + if session:ready() then + -- Implemented based on stream.lua. But seems it never works. + -- because if we have file like `digits/1.wav` but full_path is `sounds_dir/digits/XXXX/1.wav` + sounds_dir = session:getVariable("sounds_dir") + local default_language = session:getVariable("default_language") or 'en' + local default_dialect = session:getVariable("default_dialect") or 'us' + local default_voice = session:getVariable("default_voice") or 'callie' - sounds_dir = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice + sounds_dir = sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice + end else --! @todo implement for not session call. end @@ -70,3 +77,5 @@ function find_file(dbh, domain_name, domain_uuid, file_name) return file_name, is_base64 end + +return find_file \ No newline at end of file diff --git a/resources/install/scripts/resources/functions/is_absolute_path.lua b/resources/install/scripts/resources/functions/is_absolute_path.lua index 8d70986910..8f1d9bae6f 100644 --- a/resources/install/scripts/resources/functions/is_absolute_path.lua +++ b/resources/install/scripts/resources/functions/is_absolute_path.lua @@ -1,3 +1,5 @@ function is_absolute_path(file_name) return string.sub(file_name, 1, 1) == '/' or string.sub(file_name, 2, 1) == ':' end + +return is_absolute_path diff --git a/resources/install/scripts/resources/functions/play_file.lua b/resources/install/scripts/resources/functions/play_file.lua index 576565ccf6..e77329673e 100644 --- a/resources/install/scripts/resources/functions/play_file.lua +++ b/resources/install/scripts/resources/functions/play_file.lua @@ -1,3 +1,6 @@ +local log = log or require "resources.functions.log"[app_name or 'play_file'] +local find_file = require "resources.functions.find_file" + function play_file(dbh, domain_name, domain_uuid, file_name) local full_path, is_base64 = find_file(dbh, domain_name, domain_uuid, file_name) if not full_path then @@ -8,3 +11,5 @@ function play_file(dbh, domain_name, domain_uuid, file_name) end session:execute("playback", full_path); end + +return play_file \ No newline at end of file