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,21 +1,26 @@
--add the format_ringback function --add the format_ringback function
function format_ringback (ringback) function format_ringback (ringback)
if (ringback == nil or ringback == "") then --include trim
--get the default ring back require "resources.functions.trim";
ringback = session:getVariable("hold_music"); --prepare the api object
elseif (ringback:match("%${.*}")) then api = freeswitch.API();
--strip the ${ and } --handle ringback
ringback = ringback:gsub("%${", ""); if (ringback == nil or ringback == "") then
ringback = ringback:gsub("}", ""); --get the default ring back
--get the ringback variable ringback = trim(api:execute("global_getvar", "hold_music"));
ringback = session:getVariable(ringback); elseif (ringback:match("%${.*}")) then
--fallback to us-ring --strip the ${ and }
if (ringback == "") then ringback = ringback:gsub("%${", "");
ringback = session:getVariable("us-ring"); ringback = ringback:gsub("}", "");
end --get the ringback variable
--convert to tone_stream ringback = trim(api:execute("global_getvar", ringback));
ringback = "tone_stream://" .. ringback .. ";loops=-1"; --fallback to us-ring
end if (ringback == "") then
ringback = trim(api:execute("global_getvar", "us-ring"));
end
--convert to tone_stream
ringback = "tone_stream://" .. ringback .. ";loops=-1";
end
return ringback; return ringback;
end end