fusionpbx/resources/install/scripts/disa.lua

153 lines
5.3 KiB
Lua
Raw Normal View History

--
-- FusionPBX
-- Version: MPL 1.1
--
-- The contents of this file are subject to the Mozilla Public License Version
-- 1.1 (the "License"); you may not use this file except in compliance with
-- the License. You may obtain a copy of the License at
-- http://www.mozilla.org/MPL/
--
-- Software distributed under the License is distributed on an "AS IS" basis,
-- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-- for the specific language governing rights and limitations under the
-- License.
--
-- The Original Code is FusionPBX
--
-- The Initial Developer of the Original Code is
-- Mark J Crane <markjcrane@fusionpbx.com>
2018-01-17 09:52:59 +01:00
-- Copyright (C) 2010-2018
-- the Initial Developer. All Rights Reserved.
--
-- Contributor(s):
-- Mark J Crane <markjcrane@fusionpbx.com>
--predefined variables
predefined_destination = "";
max_tries = "3";
digit_timeout = "5000";
--define the trim function
require "resources.functions.trim";
--define the explode function
require "resources.functions.explode";
2018-01-17 09:52:59 +01:00
--prepare the api object
api = freeswitch.API();
--answer the call
if (session:ready()) then
session:answer();
end
--get and save the variables
if (session:ready()) then
pin_number = session:getVariable("pin_number");
sounds_dir = session:getVariable("sounds_dir");
caller_id_name = session:getVariable("caller_id_name");
caller_id_number = session:getVariable("caller_id_number");
predefined_destination = session:getVariable("predefined_destination");
digit_min_length = session:getVariable("digit_min_length");
digit_max_length = session:getVariable("digit_max_length");
context = session:getVariable("context");
privacy = session:getVariable("privacy");
end
--set the sounds path for the language, dialect and voice
if (session:ready()) then
default_language = session:getVariable("default_language");
default_dialect = session:getVariable("default_dialect");
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
end
--set defaults
2018-01-17 09:52:59 +01:00
if (not digit_min_length) then
digit_min_length = "2";
end
2018-01-17 09:52:59 +01:00
if (not digit_max_length) then
digit_max_length = "11";
end
--if the pin number is provided then require it
if (session:ready() and pin_number) then
min_digits = string.len(pin_number);
max_digits = string.len(pin_number)+1;
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-please_enter_pin_followed_by_pound.wav", "", "\\d+");
if (digits == pin_number) then
--pin is correct
else
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-pin_or_extension_is-invalid.wav");
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-im_sorry.wav");
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-goodbye.wav");
session:hangup("NORMAL_CLEARING");
return;
end
end
--if a predefined_destination is provided then set the number to the predefined_destination
if (session:ready()) then
if (predefined_destination) then
destination_number = predefined_destination;
else
dtmf = ""; --clear dtmf digits to prepare for next dtmf request
destination_number = session:playAndGetDigits(digit_min_length, digit_max_length, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/ivr/ivr-enter_destination_telephone_number.wav", "", "\\d+");
--if (string.len(destination_number) == 10) then destination_number = "1"..destination_number; end
end
end
2018-01-17 09:52:59 +01:00
--set privacy
if (session:ready()) then
if (privacy == "true") then
session:execute("privacy", "full");
session:execute("set", "sip_h_Privacy=id");
session:execute("set", "privacy=yes");
end
end
--set the caller id name and number
if (session:ready()) then
2018-01-17 09:52:59 +01:00
cmd = "user_exists id ".. destination_number .." "..context;
user_exists = trim(api:executeString(cmd));
if (user_exists == "true") then
if (caller_id_name) then
--caller id name provided do nothing
else
caller_id_number = session:getVariable("effective_caller_id_name");
end
if (caller_id_number) then
--caller id number provided do nothing
else
caller_id_number = session:getVariable("effective_caller_id_number");
end
else
if (caller_id_name) then
--caller id name provided do nothing
else
caller_id_number = session:getVariable("outbound_caller_id_name");
end
if (caller_id_number) then
--caller id number provided do nothing
else
caller_id_number = session:getVariable("outbound_caller_id_number");
end
end
end
2018-01-17 09:52:59 +01:00
--send the destination
if (session:ready()) then
2018-01-17 09:52:59 +01:00
if (user_exists == true) then
--local call
session:execute("transfer", destination_number .. " XML " .. context);
else
2018-01-17 09:52:59 +01:00
--exteernal call
session:execute("set", "effective_caller_id_name="..caller_id_name);
session:execute("set", "effective_caller_id_number="..caller_id_number);
session:execute("transfer", destination_number .. " XML " .. context);
end
end