Update confirm.lua

This commit is contained in:
Mark Crane
2014-08-14 03:35:59 +00:00
parent 8d460b1148
commit 4aa3e3e2aa
+62 -50
View File
@@ -16,63 +16,75 @@
-- --
-- The Initial Developer of the Original Code is -- The Initial Developer of the Original Code is
-- Mark J Crane <markjcrane@fusionpbx.com> -- Mark J Crane <markjcrane@fusionpbx.com>
-- Copyright (C) 2010 -- Copyright (C) 2010-2014
-- the Initial Developer. All Rights Reserved. -- the Initial Developer. All Rights Reserved.
-- --
-- Contributor(s): -- Contributor(s):
-- Mark J Crane <markjcrane@fusionpbx.com> -- Mark J Crane <markjcrane@fusionpbx.com>
max_tries = "3"; --set variables
digit_timeout = "5000"; max_tries = "3";
digit_timeout = "5000";
if ( session:ready() ) then --run if the session is ready
session:answer(); if ( session:ready() ) then
context = session:getVariable("context"); --answer the call
sounds_dir = session:getVariable("sounds_dir"); session:answer();
destination_number = session:getVariable("destination_number");
--prepare the api --get the variables
api = freeswitch.API(); context = session:getVariable("context");
sounds_dir = session:getVariable("sounds_dir");
destination_number = session:getVariable("destination_number");
--set the sounds path for the language, dialect and voice --confirm or not to confirm
default_language = session:getVariable("default_language"); if (session:getVariable("confirm")) then
default_dialect = session:getVariable("default_dialect"); confirm = session:getVariable("confirm");
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
--confirm the calls
--set the default
prompt_for_digits = true;
--if an extension answer the call
-- user_exists id 1005 voip.fusionpbx.com
cmd = "user_exists id ".. destination_number .." "..context;
result = api:executeString(cmd);
freeswitch.consoleLog("NOTICE", "[confirm] "..cmd.." --"..result.."--\n");
if (result == "true") then
prompt_for_digits = false;
end end
--prompt for digits
if (prompt_for_digits) then --prepare the api
--get the digit api = freeswitch.API();
min_digits = 1;
max_digits = 1; --set the sounds path for the language, dialect and voice
digit = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-accept_reject_voicemail.wav", "", "\\d+"); default_language = session:getVariable("default_language");
--process the response default_dialect = session:getVariable("default_dialect");
if (digit == "1") then default_voice = session:getVariable("default_voice");
--freeswitch.consoleLog("NOTICE", "[confirm] accept\n"); if (not default_language) then default_language = 'en'; end
elseif (digit == "2") then if (not default_dialect) then default_dialect = 'us'; end
--freeswitch.consoleLog("NOTICE", "[confirm] reject\n"); if (not default_voice) then default_voice = 'callie'; end
session:hangup("CALL_REJECTED"); --LOSE_RACE
elseif (digit == "3") then --confirm the calls
--freeswitch.consoleLog("NOTICE", "[confirm] voicemail\n"); --if an extension answer the call
session:hangup("NO_ANSWER"); if (confirm) then
else cmd = "user_exists id ".. destination_number .." "..context;
--freeswitch.consoleLog("NOTICE", "[confirm] no answer\n"); result = api:executeString(cmd);
session:hangup("NO_ANSWER"); --freeswitch.consoleLog("NOTICE", "[confirm] "..cmd.." "..result.."\n");
if (result == "true") then
confirm = "true";
end end
else end
--freeswitch.consoleLog("NOTICE", "[confirm] automatically accepted\n"); --prompt for digits
end if (confirm == "true") then
end --send to the log
--freeswitch.consoleLog("NOTICE", "[confirm] prompt\n");
--get the digit
min_digits = 1;
max_digits = 1;
digit = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-accept_reject_voicemail.wav", "", "\\d+");
--process the response
if (digit == "1") then
--freeswitch.consoleLog("NOTICE", "[confirm] accept\n");
elseif (digit == "2") then
--freeswitch.consoleLog("NOTICE", "[confirm] reject\n");
session:hangup("CALL_REJECTED"); --LOSE_RACE
elseif (digit == "3") then
--freeswitch.consoleLog("NOTICE", "[confirm] voicemail\n");
session:hangup("NO_ANSWER");
else
--freeswitch.consoleLog("NOTICE", "[confirm] no answer\n");
session:hangup("NO_ANSWER");
end
else
--send to the log
--freeswitch.consoleLog("NOTICE", "[confirm] automatically accepted\n");
end
end