Improve the indentation
This commit is contained in:
parent
50e0dd33e8
commit
4f7c5789fc
|
|
@ -105,201 +105,213 @@ if ( session:ready() ) then
|
||||||
channel_result = api:executeString(cmd_string);
|
channel_result = api:executeString(cmd_string);
|
||||||
end
|
end
|
||||||
|
|
||||||
--referredy by is nill
|
--referredy by is nill
|
||||||
if (referred_by == nil) then
|
if (referred_by == nil) then
|
||||||
|
|
||||||
--determine whether to check if the destination is available
|
--determine whether to check if the destination is available
|
||||||
check_destination_status = session:getVariable("check_destination_status");
|
check_destination_status = session:getVariable("check_destination_status");
|
||||||
if (not check_destination_status) then check_destination_status = 'true'; end
|
if (not check_destination_status) then check_destination_status = 'true'; end
|
||||||
|
|
||||||
--set the type of auto answer
|
--set the type of auto answer
|
||||||
auto_answer = session:getVariable("auto_answer");
|
auto_answer = session:getVariable("auto_answer");
|
||||||
if (not auto_answer) then auto_answer = 'call_info'; end
|
if (not auto_answer) then auto_answer = 'call_info'; end
|
||||||
if (auto_answer == 'call_info') then
|
if (auto_answer == 'call_info') then
|
||||||
auto_answer = "sip_h_Call-Info=<sip:"..domain_name..">;answer-after=0";
|
auto_answer = "sip_h_Call-Info=<sip:"..domain_name..">;answer-after=0";
|
||||||
end
|
end
|
||||||
if (auto_answer == 'sip_auto_answer') then
|
if (auto_answer == 'sip_auto_answer') then
|
||||||
auto_answer = "sip_auto_answer=true";
|
auto_answer = "sip_auto_answer=true";
|
||||||
end
|
end
|
||||||
|
|
||||||
--set sip header Alert-Info
|
--set sip header Alert-Info
|
||||||
alert_info = session:getVariable("alert_info");
|
alert_info = session:getVariable("alert_info");
|
||||||
if (not alert_info) then alert_info = 'ring_answer'; end
|
if (not alert_info) then alert_info = 'ring_answer'; end
|
||||||
if (alert_info == 'auto_answer') then
|
if (alert_info == 'auto_answer') then
|
||||||
alert_info = "sip_h_Alert-Info='Auto Answer'";
|
alert_info = "sip_h_Alert-Info='Auto Answer'";
|
||||||
elseif (alert_info == 'ring_answer') then
|
elseif (alert_info == 'ring_answer') then
|
||||||
alert_info = "sip_h_Alert-Info='Ring Answer'";
|
alert_info = "sip_h_Alert-Info='Ring Answer'";
|
||||||
else
|
else
|
||||||
alert_info = "sip_h_Alert-Info='"..alert_info.."'";
|
alert_info = "sip_h_Alert-Info='"..alert_info.."'";
|
||||||
end
|
end
|
||||||
|
|
||||||
--set the sounds path for the language, dialect and voice
|
--set the sounds path for the language, dialect and voice
|
||||||
default_language = session:getVariable("default_language");
|
default_language = session:getVariable("default_language");
|
||||||
default_dialect = session:getVariable("default_dialect");
|
default_dialect = session:getVariable("default_dialect");
|
||||||
default_voice = session:getVariable("default_voice");
|
default_voice = session:getVariable("default_voice");
|
||||||
if (not default_language) then default_language = 'en'; end
|
if (not default_language) then default_language = 'en'; end
|
||||||
if (not default_dialect) then default_dialect = 'us'; end
|
if (not default_dialect) then default_dialect = 'us'; end
|
||||||
if (not default_voice) then default_voice = 'callie'; end
|
if (not default_voice) then default_voice = 'callie'; end
|
||||||
|
|
||||||
--set rtp_secure_media to an empty string if not provided.
|
--set rtp_secure_media to an empty string if not provided.
|
||||||
if (rtp_secure_media == nil) then
|
if (rtp_secure_media == nil) then
|
||||||
rtp_secure_media = 'false';
|
rtp_secure_media = 'false';
|
||||||
end
|
end
|
||||||
|
|
||||||
--setup the database connection
|
--setup the database connection
|
||||||
local Database = require "resources.functions.database";
|
local Database = require "resources.functions.database";
|
||||||
local db = dbh or Database.new('system');
|
local db = dbh or Database.new('system');
|
||||||
|
|
||||||
--load lazy settings library
|
--load lazy settings library
|
||||||
local Settings = require "resources.functions.lazy_settings";
|
local Settings = require "resources.functions.lazy_settings";
|
||||||
|
|
||||||
--get the recordings settings
|
--get the recordings settings
|
||||||
local settings = Settings.new(db, domain_name, domain_uuid, nil);
|
local settings = Settings.new(db, domain_name, domain_uuid, nil);
|
||||||
|
|
||||||
--set the recordings variables
|
--set the recordings variables
|
||||||
recording_max_length = settings:get('recordings', 'recording_max_length', 'numeric') or 90;
|
recording_max_length = settings:get('recordings', 'recording_max_length', 'numeric') or 90;
|
||||||
silence_threshold = settings:get('recordings', 'recording_silence_threshold', 'numeric') or 200;
|
silence_threshold = settings:get('recordings', 'recording_silence_threshold', 'numeric') or 200;
|
||||||
silence_seconds = settings:get('recordings', 'recording_silence_seconds', 'numeric') or 3;
|
silence_seconds = settings:get('recordings', 'recording_silence_seconds', 'numeric') or 3;
|
||||||
|
|
||||||
--define the conference name
|
--define the conference name
|
||||||
local conference_profile = "page";
|
local conference_profile = "page";
|
||||||
local conference_name = "page-"..destination_number.."@"..domain_name;
|
local conference_name = "page-"..destination_number.."@"..domain_name;
|
||||||
local conference_bridge = conference_name.."@"..conference_profile;
|
local conference_bridge = conference_name.."@"..conference_profile;
|
||||||
|
|
||||||
--set the caller id
|
--set the caller id
|
||||||
if (caller_id_name) then
|
if (caller_id_name) then
|
||||||
--caller id name provided do nothing
|
--caller id name provided do nothing
|
||||||
else
|
else
|
||||||
effective_caller_id_name = session:getVariable("effective_caller_id_name");
|
effective_caller_id_name = session:getVariable("effective_caller_id_name");
|
||||||
caller_id_name = effective_caller_id_name;
|
caller_id_name = effective_caller_id_name;
|
||||||
end
|
end
|
||||||
|
|
||||||
if (caller_id_number) then
|
if (caller_id_number) then
|
||||||
--caller id number provided do nothing
|
--caller id number provided do nothing
|
||||||
else
|
else
|
||||||
effective_caller_id_number = session:getVariable("effective_caller_id_number");
|
effective_caller_id_number = session:getVariable("effective_caller_id_number");
|
||||||
caller_id_number = effective_caller_id_number;
|
caller_id_number = effective_caller_id_number;
|
||||||
end
|
end
|
||||||
|
|
||||||
--set conference flags
|
--set conference flags
|
||||||
if (mute == "true") then
|
if (mute == "true") then
|
||||||
flags = "flags{mute}";
|
flags = "flags{mute}";
|
||||||
else
|
else
|
||||||
flags = "flags{}";
|
flags = "flags{}";
|
||||||
end
|
end
|
||||||
|
|
||||||
--if annouce delay is active then prompt for recording
|
--if annouce delay is active then prompt for recording
|
||||||
if (delay == "true") then
|
if (delay == "true") then
|
||||||
--callback function for the delayed recording
|
--callback function for the delayed recording
|
||||||
function onInputCBF(s, _type, obj, arg)
|
function onInputCBF(s, _type, obj, arg)
|
||||||
local k, v = nil, nil
|
local k, v = nil, nil
|
||||||
if (_type == "dtmf") then
|
if (_type == "dtmf") then
|
||||||
dtmf_entered = 1; --set this variable to know that the user entered DTMF
|
dtmf_entered = 1; --set this variable to know that the user entered DTMF
|
||||||
return 'break'
|
return 'break'
|
||||||
else
|
else
|
||||||
return ''
|
return ''
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
--sleep
|
--sleep
|
||||||
session:sleep(500);
|
session:sleep(500);
|
||||||
|
|
||||||
--set variables for page recording
|
--set variables for page recording
|
||||||
recording_dir = '/tmp/';
|
recording_dir = '/tmp/';
|
||||||
filename = "page-"..destination_number.."@"..domain_name..".wav";
|
filename = "page-"..destination_number.."@"..domain_name..".wav";
|
||||||
recording_filename = string.format('%s%s', recording_dir, filename);
|
recording_filename = string.format('%s%s', recording_dir, filename);
|
||||||
dtmf_entered = 0;
|
dtmf_entered = 0;
|
||||||
silence_triggered = 0;
|
silence_triggered = 0;
|
||||||
|
|
||||||
--ask user to record
|
--ask user to record
|
||||||
session:execute("playback", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-record_message.wav")
|
session:execute("playback", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/voicemail/vm-record_message.wav")
|
||||||
session:streamFile("tone_stream://L=1;%(1000, 0, 640)");
|
session:streamFile("tone_stream://L=1;%(1000, 0, 640)");
|
||||||
|
|
||||||
--set callback function for when a user clicks DTMF
|
--set callback function for when a user clicks DTMF
|
||||||
session:setInputCallback('onInputCBF', '');
|
session:setInputCallback('onInputCBF', '');
|
||||||
|
|
||||||
--time before starting the recording
|
--time before starting the recording
|
||||||
startUTCTime = os.time(os.date('!*t'));
|
startUTCTime = os.time(os.date('!*t'));
|
||||||
|
|
||||||
--record the page message
|
--record the page message
|
||||||
silence_triggered = session:recordFile(recording_filename, recording_max_length, silence_threshold, silence_seconds);
|
silence_triggered = session:recordFile(recording_filename, recording_max_length, silence_threshold, silence_seconds);
|
||||||
|
|
||||||
--time after starting the recording
|
--time after starting the recording
|
||||||
endUTCTime = os.time(os.date('!*t'));
|
endUTCTime = os.time(os.date('!*t'));
|
||||||
|
|
||||||
--total recording time
|
--total recording time
|
||||||
recording_length = endUTCTime - startUTCTime;
|
recording_length = endUTCTime - startUTCTime;
|
||||||
end
|
end
|
||||||
|
|
||||||
--if the pin number is provided then require it
|
--if the pin number is provided then require it
|
||||||
if (pin_number) then
|
if (pin_number) then
|
||||||
--sleep
|
--sleep
|
||||||
session:sleep(500);
|
session:sleep(500);
|
||||||
|
|
||||||
--get the user pin number
|
--get the user pin number
|
||||||
min_digits = 2;
|
min_digits = 2;
|
||||||
max_digits = 20;
|
max_digits = 20;
|
||||||
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
|
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:voicemail_enter_pass:#", "", "\\d+");
|
||||||
|
|
||||||
--validate the user pin number
|
--validate the user pin number
|
||||||
pin_number_table = explode(",",pin_number);
|
pin_number_table = explode(",",pin_number);
|
||||||
for index,pin_number in pairs(pin_number_table) do
|
for index,pin_number in pairs(pin_number_table) do
|
||||||
if (digits == pin_number) then
|
if (digits == pin_number) then
|
||||||
--set the variable to true
|
--set the variable to true
|
||||||
auth = true;
|
auth = true;
|
||||||
--set the authorized pin number that was used
|
--set the authorized pin number that was used
|
||||||
session:setVariable("pin_number", pin_number);
|
session:setVariable("pin_number", pin_number);
|
||||||
--end the loop
|
--end the loop
|
||||||
break;
|
break;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
--if not authorized play a message and then hangup
|
--if not authorized play a message and then hangup
|
||||||
if (not auth) then
|
if (not auth) then
|
||||||
session:streamFile("phrase:voicemail_fail_auth:#");
|
session:streamFile("phrase:voicemail_fail_auth:#");
|
||||||
session:hangup("NORMAL_CLEARING");
|
session:hangup("NORMAL_CLEARING");
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--log the destinations
|
--log the destinations
|
||||||
freeswitch.consoleLog("NOTICE", "[page] destinations "..destinations.." available\n");
|
freeswitch.consoleLog("NOTICE", "[page] destinations "..destinations.." available\n");
|
||||||
|
|
||||||
--create the api object
|
--create the api object
|
||||||
api = freeswitch.API();
|
api = freeswitch.API();
|
||||||
|
|
||||||
--get the channels
|
--get the channels
|
||||||
if (check_destination_status == 'true') then
|
if (check_destination_status == 'true') then
|
||||||
cmd_string = "show channels";
|
cmd_string = "show channels";
|
||||||
channel_result = api:executeString(cmd_string);
|
channel_result = api:executeString(cmd_string);
|
||||||
end
|
end
|
||||||
|
|
||||||
--originate the calls
|
--originate the calls
|
||||||
destination_count = 0;
|
destination_count = 0;
|
||||||
if (delay ~= "true" or (dtmf_entered == 1 or silence_triggered == 1)) then
|
if (delay ~= "true" or (dtmf_entered == 1 or silence_triggered == 1)) then
|
||||||
|
|
||||||
for index,value in pairs(destination_table) do
|
for index,value in pairs(destination_table) do
|
||||||
for destination in each_number(value) do
|
for destination in each_number(value) do
|
||||||
|
|
||||||
--get the destination required for number-alias
|
--get the destination required for number-alias
|
||||||
destination = api:execute("user_data", destination .. "@" .. domain_name .. " attr id");
|
destination = api:execute("user_data", destination .. "@" .. domain_name .. " attr id");
|
||||||
|
|
||||||
--prevent calling the user that initiated the page
|
--prevent calling the user that initiated the page
|
||||||
if (sip_from_user ~= destination) then
|
if (sip_from_user ~= destination) then
|
||||||
if (check_destination_status == 'true') then
|
if (check_destination_status == 'true') then
|
||||||
--detect if the destination is available or busy
|
--detect if the destination is available or busy
|
||||||
destination_status = 'available';
|
destination_status = 'available';
|
||||||
channel_array = explode("\n", channel_result);
|
channel_array = explode("\n", channel_result);
|
||||||
for index,row in pairs(channel_array) do
|
for index,row in pairs(channel_array) do
|
||||||
if string.find(row, destination..'@'..domain_name, nil, true) then
|
if string.find(row, destination..'@'..domain_name, nil, true) then
|
||||||
destination_status = 'busy';
|
destination_status = 'busy';
|
||||||
break;
|
break;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
--if available then page then originate the call with auto answer
|
--if available then page then originate the call with auto answer
|
||||||
if (destination_status == 'available') then
|
if (destination_status == 'available') then
|
||||||
freeswitch.consoleLog("NOTICE", "[page] destination "..destination.." available\n");
|
freeswitch.consoleLog("NOTICE", "[page] destination "..destination.." available\n");
|
||||||
|
if destination == sip_from_user then
|
||||||
|
--this destination is the caller that initated the page
|
||||||
|
else
|
||||||
|
--originate the call
|
||||||
|
cmd_string = "bgapi originate {"..auto_answer..","..alert_info..",hangup_after_bridge=false,rtp_secure_media="..rtp_secure_media..",origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..destination.."@"..domain_name.." conference:"..conference_bridge.."+"..flags.." inline";
|
||||||
|
api:executeString(cmd_string);
|
||||||
|
destination_count = destination_count + 1;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
--endpoint determines what to do with the call when the destination is active
|
||||||
|
freeswitch.consoleLog("NOTICE", "[page] endpoint determines what to do if the it has an active call.\n");
|
||||||
if destination == sip_from_user then
|
if destination == sip_from_user then
|
||||||
--this destination is the caller that initated the page
|
--this destination is the caller that initated the page
|
||||||
else
|
else
|
||||||
|
|
@ -309,47 +321,34 @@ if (referred_by == nil) then
|
||||||
destination_count = destination_count + 1;
|
destination_count = destination_count + 1;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
--endpoint determines what to do with the call when the destination is active
|
|
||||||
freeswitch.consoleLog("NOTICE", "[page] endpoint determines what to do if the it has an active call.\n");
|
|
||||||
if destination == sip_from_user then
|
|
||||||
--this destination is the caller that initated the page
|
|
||||||
else
|
|
||||||
--originate the call
|
|
||||||
cmd_string = "bgapi originate {"..auto_answer..","..alert_info..",hangup_after_bridge=false,rtp_secure_media="..rtp_secure_media..",origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..destination.."@"..domain_name.." conference:"..conference_bridge.."+"..flags.." inline";
|
|
||||||
api:executeString(cmd_string);
|
|
||||||
destination_count = destination_count + 1;
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
--send main call to the conference room
|
--send main call to the conference room
|
||||||
if (destination_count > 0) then
|
if (destination_count > 0) then
|
||||||
--set moderator flag
|
--set moderator flag
|
||||||
if (session:getVariable("moderator") == "true") then
|
if (session:getVariable("moderator") == "true") then
|
||||||
moderator_flag = ",moderator";
|
moderator_flag = ",moderator";
|
||||||
else
|
else
|
||||||
moderator_flag = "";
|
moderator_flag = "";
|
||||||
end
|
end
|
||||||
|
|
||||||
--check if delay is true
|
--check if delay is true
|
||||||
if (delay == "true" and (dtmf_entered == 1 or silence_triggered == 1)) then
|
if (delay == "true" and (dtmf_entered == 1 or silence_triggered == 1)) then
|
||||||
--play the recorded file into the page/conference. Need to wait for the page/conference to actually be started before we can end it.
|
--play the recorded file into the page/conference. Need to wait for the page/conference to actually be started before we can end it.
|
||||||
response = api:executeString("sched_api +2 none conference "..conference_name.." play "..recording_filename);
|
response = api:executeString("sched_api +2 none conference "..conference_name.." play "..recording_filename);
|
||||||
|
|
||||||
--wait for recording to finish then end page/conference
|
--wait for recording to finish then end page/conference
|
||||||
response = api:executeString("sched_api +"..tostring(recording_length+4).." none conference "..conference_name.." hup all");
|
response = api:executeString("sched_api +"..tostring(recording_length+4).." none conference "..conference_name.." hup all");
|
||||||
else
|
else
|
||||||
--join the moderator into the page
|
--join the moderator into the page
|
||||||
session:execute("conference", conference_bridge.."+flags{endconf,mintwo"..moderator_flag.."}");
|
session:execute("conference", conference_bridge.."+flags{endconf,mintwo"..moderator_flag.."}");
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
--error tone due to no destinations
|
--error tone due to no destinations
|
||||||
session:execute("playback", "tone_stream://%(500,500,480,620);loops=3");
|
session:execute("playback", "tone_stream://%(500,500,480,620);loops=3");
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue