Call center used with xml handler does not have access to the session. Remove session and replace it with api global_getvar as session is not always available.

This commit is contained in:
markjcrane
2016-02-01 11:16:23 -07:00
parent 9ec2da1b7e
commit be2c690a1d
@@ -1,18 +1,23 @@
--add the format_ringback function --add the format_ringback function
function format_ringback (ringback) function format_ringback (ringback)
--include trim
require "resources.functions.trim";
--prepare the api object
api = freeswitch.API();
--handle ringback
if (ringback == nil or ringback == "") then if (ringback == nil or ringback == "") then
--get the default ring back --get the default ring back
ringback = session:getVariable("hold_music"); ringback = trim(api:execute("global_getvar", "hold_music"));
elseif (ringback:match("%${.*}")) then elseif (ringback:match("%${.*}")) then
--strip the ${ and } --strip the ${ and }
ringback = ringback:gsub("%${", ""); ringback = ringback:gsub("%${", "");
ringback = ringback:gsub("}", ""); ringback = ringback:gsub("}", "");
--get the ringback variable --get the ringback variable
ringback = session:getVariable(ringback); ringback = trim(api:execute("global_getvar", ringback));
--fallback to us-ring --fallback to us-ring
if (ringback == "") then if (ringback == "") then
ringback = session:getVariable("us-ring"); ringback = trim(api:execute("global_getvar", "us-ring"));
end end
--convert to tone_stream --convert to tone_stream
ringback = "tone_stream://" .. ringback .. ";loops=-1"; ringback = "tone_stream://" .. ringback .. ";loops=-1";