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

View File

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