mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-02-22 02:46:30 +00:00
Add a missing file sip_profile_copy.php to the dev branch.
This commit is contained in:
80
includes/install/scripts/call_broadcast_originate.js
Normal file
80
includes/install/scripts/call_broadcast_originate.js
Normal file
@@ -0,0 +1,80 @@
|
||||
include("config.js");
|
||||
//var sounds_dir
|
||||
//var admin_pin
|
||||
//var tmp_dir
|
||||
//var recordings_dir
|
||||
|
||||
var sipuri = argv[0];
|
||||
var recording = argv[1];
|
||||
var caller_id_name = argv[2];
|
||||
var caller_id_number = argv[3];
|
||||
var call_timeout = argv[4];
|
||||
var call_count_var_name = argv[5];
|
||||
var tmp_sipuri;
|
||||
|
||||
caller_id_name = caller_id_name.replace("+", " ");
|
||||
console_log( "info", "sipuri: "+sipuri+"\n" );
|
||||
console_log( "info", "recording: "+recording+"\n" );
|
||||
console_log( "info", "caller_id_name: "+caller_id_name+"\n" );
|
||||
console_log( "info", "caller_id_number: "+caller_id_number+"\n" );
|
||||
console_log( "info", "call_timeout: "+call_timeout+"\n" );
|
||||
console_log( "info", "call_count_var_name: "+call_count_var_name+"\n" );
|
||||
|
||||
|
||||
|
||||
//function on_hangup(hup_session, how)
|
||||
//{
|
||||
// console_log("err", how + " HOOK" + " name: " + hup_session.name + " cause: " + hup_session.cause + "\n");
|
||||
// //exit here would end the script so you could cleanup and just be done
|
||||
// exit();
|
||||
//}
|
||||
|
||||
function originate (sipuri, recording, caller_id_name, caller_id_number, call_timeout, count_var_name) {
|
||||
|
||||
var dtmf = new Object();
|
||||
var cid;
|
||||
dtmf.digits = "";
|
||||
cid = ",origination_caller_id_name="+caller_id_name+",origination_caller_id_number="+caller_id_number;
|
||||
|
||||
new_session = new Session("{ignore_early_media=true,hangup_after_bridge=false,call_timeout="+call_timeout+""+cid+"}"+sipuri);
|
||||
//new_session = new Session(sipuri);
|
||||
|
||||
//new_session.execute("set", "api_after_bridge=reloadxml");
|
||||
//set the on_hangup function to be called when this session is hungup
|
||||
//new_session.setHangupHook(on_hangup);
|
||||
//result = new_session.setAutoHangup(true);
|
||||
|
||||
//console_log( "info", "followme: new_session uuid "+new_session.uuid+"\n" );
|
||||
//console_log( "info", "followme: no dtmf detected\n" );
|
||||
|
||||
digitmaxlength = 1;
|
||||
while (new_session.ready()) {
|
||||
if (recording.length > 0) {
|
||||
//new_session.streamFile( recordings_dir+"/"+recording);
|
||||
new_session.execute("playback",recordings_dir+"/"+recording);
|
||||
//new_session.hangup("NORMAL_CLEARING");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
var hangup_cause = new_session.getVariable("bridge_hangup_cause");
|
||||
console_log( "info", "hangup cause: "+hangup_cause+"\n" );
|
||||
var count = getGlobalVariable(call_count_var_name);
|
||||
setGlobalVariable(call_count_var_name, (parseInt(count)-1));
|
||||
console_log( "info", "action: hangup, count: "+count+"\n" );
|
||||
|
||||
}
|
||||
|
||||
sipuri_array = sipuri.split(",");
|
||||
for (i = 0; i < sipuri_array.length; i++){
|
||||
//var count = getGlobalVariable(call_count_var_name);
|
||||
//setGlobalVariable(call_count_var_name, (parseInt(count)+1));
|
||||
|
||||
tmp_sipuri = sipuri_array[i];
|
||||
console_log("info", "tmp_sipuri: "+tmp_sipuri);
|
||||
result = originate (tmp_sipuri, recording, caller_id_name, caller_id_number, call_timeout, call_count_var_name);
|
||||
if (result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
exit();
|
||||
127
includes/install/scripts/call_forward.lua
Normal file
127
includes/install/scripts/call_forward.lua
Normal file
@@ -0,0 +1,127 @@
|
||||
--
|
||||
-- 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>
|
||||
-- Copyright (C) 2010
|
||||
-- the Initial Developer. All Rights Reserved.
|
||||
--
|
||||
-- Contributor(s):
|
||||
-- Mark J Crane <markjcrane@fusionpbx.com>
|
||||
|
||||
pin_number = "";
|
||||
max_tries = "3";
|
||||
digit_timeout = "3000";
|
||||
|
||||
function file_exists(fname)
|
||||
local f = io.open(fname, "r")
|
||||
if (f and f:read()) then return true end
|
||||
end
|
||||
|
||||
if ( session:ready() ) then
|
||||
session:answer();
|
||||
--session:execute("info", "");
|
||||
extension = session:getVariable("user_name");
|
||||
pin_number = session:getVariable("pin_number");
|
||||
sounds_dir = session:getVariable("sounds_dir");
|
||||
dialplan_default_dir = session:getVariable("dialplan_default_dir");
|
||||
call_forward_number = session:getVariable("call_forward_number");
|
||||
extension_required = session:getVariable("extension_required");
|
||||
context = session:getVariable("context");
|
||||
if (not context ) then context = 'default'; end
|
||||
|
||||
--set the sounds path for the language, dialect and voice
|
||||
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
|
||||
|
||||
--if the pin number is provided then require it
|
||||
if (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.."/custom/please_enter_the_pin_number.wav", "", "\\d+");
|
||||
if (digits == pin_number) then
|
||||
--pin is correct
|
||||
else
|
||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/your_pin_number_is_incorect_goodbye.wav");
|
||||
session:hangup("NORMAL_CLEARING");
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
||||
--if extension_requires is true then get the extension number
|
||||
if (extension_required) then
|
||||
if (extension_required == "true") then
|
||||
extension = session:playAndGetDigits(3, 6, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/please_enter_the_extension_number.wav", "", "\\d+");
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if (file_exists(dialplan_default_dir.."/000_call_forward_"..extension..".xml")) then
|
||||
--file exists
|
||||
|
||||
--remove the call forward dialplan entry
|
||||
os.remove (dialplan_default_dir.."/000_call_forward_"..extension..".xml");
|
||||
|
||||
--stream file
|
||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/call_forward_has_been_deleted.wav");
|
||||
|
||||
--wait for the file to be written before proceeding
|
||||
session:sleep(1000);
|
||||
|
||||
else
|
||||
--file does not exist
|
||||
|
||||
dtmf = ""; --clear dtmf digits to prepare for next dtmf request
|
||||
if (call_forward_number) then
|
||||
-- do nothing
|
||||
else
|
||||
-- get the call forward number
|
||||
call_forward_number = session:playAndGetDigits(3, 15, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/please_enter_the_phone_number.wav", "", "\\d+");
|
||||
end
|
||||
if (string.len(call_forward_number) > 0) then
|
||||
--write the xml file
|
||||
xml = "<extension name=\"call_forward_"..extension.."\" >\n";
|
||||
xml = xml .. " <condition field=\"destination_number\" expression=\"^"..extension.."$\">\n";
|
||||
xml = xml .. " <action application=\"transfer\" data=\""..call_forward_number.." XML "..context.."\"/>\n";
|
||||
xml = xml .. " </condition>\n";
|
||||
xml = xml .. "</extension>\n";
|
||||
session:execute("log", xml);
|
||||
local file = assert(io.open(dialplan_default_dir.."/000_call_forward_"..extension..".xml", "w"));
|
||||
file:write(xml);
|
||||
file:close();
|
||||
|
||||
--wait for the file to be written before proceeding
|
||||
--session:sleep(20000);
|
||||
|
||||
--stream file
|
||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/call_forward_has_been_set.wav");
|
||||
end
|
||||
end
|
||||
|
||||
--reloadxml
|
||||
api = freeswitch.API();
|
||||
reply = api:executeString("reloadxml");
|
||||
|
||||
--wait for the file to be written before proceeding
|
||||
session:sleep(1000);
|
||||
|
||||
session:hangup();
|
||||
|
||||
end
|
||||
156
includes/install/scripts/disa.lua
Normal file
156
includes/install/scripts/disa.lua
Normal file
@@ -0,0 +1,156 @@
|
||||
--
|
||||
-- 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>
|
||||
-- Copyright (C) 2010
|
||||
-- the Initial Developer. All Rights Reserved.
|
||||
--
|
||||
-- Contributor(s):
|
||||
-- Mark J Crane <markjcrane@fusionpbx.com>
|
||||
|
||||
predefined_destination = "";
|
||||
max_tries = "3";
|
||||
digit_timeout = "5000";
|
||||
|
||||
function trim (s)
|
||||
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
|
||||
end
|
||||
|
||||
function explode ( seperator, str )
|
||||
local pos, arr = 0, {}
|
||||
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
|
||||
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
|
||||
pos = sp + 1 -- jump past current divider
|
||||
end
|
||||
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
|
||||
return arr
|
||||
end
|
||||
|
||||
if ( session:ready() ) then
|
||||
session:answer( );
|
||||
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");
|
||||
gateway = session:getVariable("gateway");
|
||||
context = session:getVariable("context");
|
||||
|
||||
--set the sounds path for the language, dialect and voice
|
||||
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
|
||||
|
||||
--set defaults
|
||||
if (digit_min_length) then
|
||||
--do nothing
|
||||
else
|
||||
digit_min_length = "2";
|
||||
end
|
||||
|
||||
if (digit_max_length) then
|
||||
--do nothing
|
||||
else
|
||||
digit_max_length = "11";
|
||||
end
|
||||
|
||||
--if the pin number is provided then require it
|
||||
if (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 (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
|
||||
|
||||
--set the caller id anme and number
|
||||
if (string.len(destination_number) < 7) 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
|
||||
|
||||
--transfer or bridge the call
|
||||
if (string.len(destination_number) < 7) then
|
||||
--local call
|
||||
session:execute("transfer", destination_number .. " XML " .. context);
|
||||
else
|
||||
--remote call
|
||||
if (gateway) then
|
||||
gateway_table = explode(",",gateway);
|
||||
for index,value in pairs(gateway_table) do
|
||||
session:execute("bridge", "{continue_on_fail=true,hangup_after_bridge=true,origination_caller_id_name="..caller_id_name..",origination_caller_id_number="..caller_id_number.."}sofia/gateway/"..value.."/"..destination_number);
|
||||
end
|
||||
else
|
||||
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
|
||||
|
||||
--alternate method
|
||||
--local session2 = freeswitch.Session("{ignore_early_media=true}sofia/gateway/flowroute.com/"..destination_number);
|
||||
--t1 = os.date('*t');
|
||||
--call_start_time = os.time(t1);
|
||||
--freeswitch.bridge(session, session2);
|
||||
end
|
||||
|
||||
--function HangupHook(s, status, arg)
|
||||
--session:execute("info", "");
|
||||
--freeswitch.consoleLog("NOTICE", "HangupHook: " .. status .. "\n");
|
||||
--end
|
||||
--session:setHangupHook("HangupHook", "");
|
||||
101
includes/install/scripts/eavesdrop.lua
Normal file
101
includes/install/scripts/eavesdrop.lua
Normal file
@@ -0,0 +1,101 @@
|
||||
--
|
||||
-- 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>
|
||||
-- Copyright (C) 2010
|
||||
-- the Initial Developer. All Rights Reserved.
|
||||
--
|
||||
-- Contributor(s):
|
||||
-- Mark J Crane <markjcrane@fusionpbx.com>
|
||||
|
||||
max_tries = "3";
|
||||
digit_timeout = "5000";
|
||||
|
||||
extension = argv[1];
|
||||
|
||||
--database
|
||||
--connect to the database
|
||||
--local dbh = freeswitch.Dbh("dsn","user","pass"); -- when using ODBC
|
||||
local dbh = freeswitch.Dbh("core:core"); -- when using sqlite
|
||||
|
||||
--exits the script if we didn't connect properly
|
||||
assert(dbh:connected());
|
||||
|
||||
if ( session:ready() ) then
|
||||
session:answer( );
|
||||
pin_number = session:getVariable("pin_number");
|
||||
sounds_dir = session:getVariable("sounds_dir");
|
||||
domain_name = session:getVariable("domain_name");
|
||||
|
||||
--set the sounds path for the language, dialect and voice
|
||||
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
|
||||
|
||||
--set defaults
|
||||
if (digit_min_length) then
|
||||
--do nothing
|
||||
else
|
||||
digit_min_length = "2";
|
||||
end
|
||||
|
||||
if (digit_max_length) then
|
||||
--do nothing
|
||||
else
|
||||
digit_max_length = "11";
|
||||
end
|
||||
|
||||
--if the pin number is provided then require it
|
||||
if (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.."/custom/please_enter_the_pin_number.wav", "", "\\d+");
|
||||
if (digits == pin_number) then
|
||||
--pin is correct
|
||||
else
|
||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/your_pin_number_is_incorect_goodbye.wav");
|
||||
session:hangup("NORMAL_CLEARING");
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
||||
--check the database to get the uuid
|
||||
--eavesdrop
|
||||
sql = "select uuid from channels where presence_id = '"..extension.."@"..domain_name.."' ";
|
||||
dbh:query(sql, function(result)
|
||||
for key, val in pairs(result) do
|
||||
freeswitch.consoleLog("NOTICE", "result "..key.." "..val.."\n");
|
||||
end
|
||||
uuid = result.uuid;
|
||||
end);
|
||||
|
||||
end
|
||||
|
||||
--eavesdrop
|
||||
if (uuid) then
|
||||
session:execute("eavesdrop", uuid); --call barge
|
||||
end
|
||||
|
||||
--notes
|
||||
--originate a call
|
||||
--cmd = "originate user/1007@voip.example.com &eavesdrop("..uuid..")";
|
||||
--cmd = "uuid_bridge "..caller_uuid.." "..uuid;
|
||||
--api = freeswitch.API();
|
||||
--result = api:executeString(cmd);
|
||||
70
includes/install/scripts/fax_retry.lua
Normal file
70
includes/install/scripts/fax_retry.lua
Normal file
@@ -0,0 +1,70 @@
|
||||
--set default variables
|
||||
fax_retry_sleep = 10;
|
||||
fax_retry_limit = 3;
|
||||
|
||||
-- show all channel variables
|
||||
--dat = env:serialize()
|
||||
--freeswitch.consoleLog("INFO","info:\n" .. dat .. "\n")
|
||||
|
||||
-- example channel variables relating to fax
|
||||
--variable_fax_success: 0
|
||||
--variable_fax_result_code: 49
|
||||
--variable_fax_result_text: The%20call%20dropped%20prematurely
|
||||
--variable_fax_ecm_used: off
|
||||
--variable_fax_local_station_id: SpanDSP%20Fax%20Ident
|
||||
--variable_fax_document_transferred_pages: 0
|
||||
--variable_fax_document_total_pages: 0
|
||||
--variable_fax_image_resolution: 0x0
|
||||
--variable_fax_image_size: 0
|
||||
--variable_fax_bad_rows: 0
|
||||
--variable_fax_transfer_rate: 14400
|
||||
|
||||
-- set channel variables to lua variables
|
||||
uuid = env:getHeader("uuid");
|
||||
fax_success = env:getHeader("fax_success");
|
||||
fax_result_text = env:getHeader("fax_result_text");
|
||||
fax_ecm_used = env:getHeader("fax_ecm_used");
|
||||
fax_retry_attempts = tonumber(env:getHeader("fax_retry_attempts"));
|
||||
fax_retry_limit = tonumber(env:getHeader("fax_retry_limit"));
|
||||
fax_retry_sleep = tonumber(env:getHeader("fax_retry_sleep"));
|
||||
fax_uri = env:getHeader("fax_uri");
|
||||
fax_file = env:getHeader("fax_file");
|
||||
fax_extension_number = env:getHeader("fax_extension_number");
|
||||
origination_caller_id_name = env:getHeader("origination_caller_id_name");
|
||||
origination_caller_id_number = env:getHeader("origination_caller_id_number");
|
||||
|
||||
--set default values
|
||||
if (not origination_caller_id_name) then
|
||||
origination_caller_id_name = '000000000000000';
|
||||
end
|
||||
if (not origination_caller_id_number) then
|
||||
origination_caller_id_number = '000000000000000';
|
||||
end
|
||||
|
||||
-- send the selected variables to the console
|
||||
freeswitch.consoleLog("INFO","fax_success: '" .. fax_success .. "'\n");
|
||||
freeswitch.consoleLog("INFO","fax_result_text: '" .. fax_result_text .. "'\n");
|
||||
freeswitch.consoleLog("INFO","fax_file: '" .. fax_file .. "'\n");
|
||||
freeswitch.consoleLog("INFO","uuid: '" .. uuid .. "'\n");
|
||||
freeswitch.consoleLog("INFO","fax_ecm_used: '" .. fax_ecm_used .. "'\n");
|
||||
freeswitch.consoleLog("INFO","fax_retry_attempts: " .. fax_retry_attempts.. "\n");
|
||||
freeswitch.consoleLog("INFO","fax_retry_limit: " .. fax_retry_limit.. "\n");
|
||||
freeswitch.consoleLog("INFO","fax_retry_sleep: " .. fax_retry_sleep.. "\n");
|
||||
freeswitch.consoleLog("INFO","fax_uri: '" .. fax_uri.. "'\n");
|
||||
freeswitch.consoleLog("INFO","origination_caller_id_name: " .. origination_caller_id_name .. "\n");
|
||||
freeswitch.consoleLog("INFO","origination_caller_id_number: " .. origination_caller_id_number .. "\n");
|
||||
|
||||
-- if the fax failed then try again
|
||||
if (fax_success == "0") then
|
||||
if (fax_retry_attempts < fax_retry_limit) then
|
||||
-- sleep
|
||||
freeswitch.msleep(fax_retry_sleep * 1000);
|
||||
--increment the retry attempts
|
||||
fax_retry_attempts = fax_retry_attempts + 1;
|
||||
cmd = "originate {origination_caller_id_name='"..origination_caller_id_name.. "',origination_caller_id_number="..origination_caller_id_number..",fax_uri="..fax_uri..",fax_retry_attempts="..fax_retry_attempts..",fax_retry_limit="..fax_retry_limit..",fax_retry_sleep="..fax_retry_sleep..",fax_verbose=true,fax_file='"..fax_file.."',fax_use_ecm=off,api_hangup_hook='lua fax_retry.lua'}"..fax_uri.." &txfax('"..fax_file.."')";
|
||||
--cmd = "sofia/internal/"..fax_number.."@"..domain_name.." &txfax('"..fax_file.."') XML default ";
|
||||
freeswitch.consoleLog("INFO","retry cmd: " .. cmd .. "\n");
|
||||
api = freeswitch.API();
|
||||
reply = api:executeString(cmd);
|
||||
end
|
||||
end
|
||||
99
includes/install/scripts/fifo_member.lua
Normal file
99
includes/install/scripts/fifo_member.lua
Normal file
@@ -0,0 +1,99 @@
|
||||
--
|
||||
-- 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>
|
||||
-- Copyright (C) 2010
|
||||
-- All Rights Reserved.
|
||||
--
|
||||
-- Contributor(s):
|
||||
-- Mark J Crane <markjcrane@fusionpbx.com>
|
||||
|
||||
sounds_dir = "";
|
||||
recordings_dir = "";
|
||||
pin_number = "";
|
||||
max_tries = "3";
|
||||
digit_timeout = "3000";
|
||||
|
||||
|
||||
if ( session:ready() ) then
|
||||
session:answer();
|
||||
--session:execute("info", "");
|
||||
user_name = session:getVariable("user_name");
|
||||
pin_number = session:getVariable("pin_number");
|
||||
sounds_dir = session:getVariable("sounds_dir");
|
||||
queue_name = session:getVariable("queue_name");
|
||||
fifo_simo = session:getVariable("fifo_simo");
|
||||
fifo_timeout = session:getVariable("fifo_timeout");
|
||||
fifo_lag = session:getVariable("fifo_lag");
|
||||
|
||||
--pin_number = "1234"; --for testing
|
||||
--queue_name = "5900@voip.fusionpbx.com";
|
||||
--fifo_simo = 1;
|
||||
--fifo_timeout = 10;
|
||||
--fifo_lag = 10;
|
||||
|
||||
if (pin_number) then
|
||||
digits = session:playAndGetDigits(3, 8, 3, digit_timeout, "#", sounds_dir.."/custom/please_enter_the_pin_number.wav", "", "\\d+");
|
||||
if (digits == pin_number) then
|
||||
--pin is correct
|
||||
|
||||
--press 1 to login and 2 to logout
|
||||
menu_selection = session:playAndGetDigits(1, 1, max_tries, digit_timeout, "#", sounds_dir.."/custom/please_enter_the_phone_number.wav", "", "\\d+");
|
||||
freeswitch.consoleLog("NOTICE", "menu_selection: "..menu_selection.."\n");
|
||||
if (menu_selection == "1") then
|
||||
session:execute("set", "fifo_member_add_result=${fifo_member(add "..queue_name.." {fifo_member_wait=nowait}user/"..user_name.." "..fifo_simo.." "..fifo_timeout.." "..fifo_lag.."} )"); --simo timeout lag
|
||||
fifo_member_add_result = session:getVariable("fifo_member_add_result");
|
||||
freeswitch.consoleLog("NOTICE", "fifo_member_add_result: "..fifo_member_add_result.."\n");
|
||||
session:streamFile("ivr/ivr-you_are_now_logged_in.wav");
|
||||
end
|
||||
if (menu_selection == "2") then
|
||||
session:execute("set", "fifo_member_del_result=${fifo_member(del "..queue_name.." {fifo_member_wait=nowait}user/"..user_name.."} )");
|
||||
session:streamFile("ivr/ivr-you_are_now_logged_out.wav");
|
||||
end
|
||||
|
||||
--wait for the file to be written before proceeding
|
||||
-- session:sleep(1000);
|
||||
|
||||
session:hangup();
|
||||
|
||||
else
|
||||
session:streamFile(sounds_dir.."/custom/your_pin_number_is_incorect_goodbye.wav");
|
||||
end
|
||||
else
|
||||
|
||||
--pin number is not required
|
||||
|
||||
--press 1 to login and 2 to logout
|
||||
menu_selection = session:playAndGetDigits(1, 1, max_tries, digit_timeout, "#", sounds_dir.."/custom/please_enter_the_phone_number.wav", "", "\\d+");
|
||||
freeswitch.consoleLog("NOTICE", "menu_selection: "..menu_selection.."\n");
|
||||
if (menu_selection == "1") then
|
||||
session:execute("set", "fifo_member_add_result=${fifo_member(add "..queue_name.." {fifo_member_wait=nowait}user/"..user_name.." "..fifo_simo.." "..fifo_timeout.." "..fifo_lag.."} )"); --simo timeout lag
|
||||
fifo_member_add_result = session:getVariable("fifo_member_add_result");
|
||||
freeswitch.consoleLog("NOTICE", "fifo_member_add_result: "..fifo_member_add_result.."\n");
|
||||
session:streamFile("ivr/ivr-you_are_now_logged_in.wav");
|
||||
end
|
||||
if (menu_selection == "2") then
|
||||
session:execute("set", "fifo_member_del_result=${fifo_member(del "..queue_name.." {fifo_member_wait=nowait}user/"..user_name.."} )");
|
||||
session:streamFile("ivr/ivr-you_are_now_logged_out.wav");
|
||||
end
|
||||
|
||||
--wait for the file to be written before proceeding
|
||||
-- session:sleep(1000);
|
||||
|
||||
session:hangup();
|
||||
end
|
||||
end
|
||||
108
includes/install/scripts/huntgroup_originate.lua
Normal file
108
includes/install/scripts/huntgroup_originate.lua
Normal file
@@ -0,0 +1,108 @@
|
||||
--get the argv values
|
||||
domain_name = argv[1];
|
||||
uuid = argv[2];
|
||||
sipuri = argv[3];
|
||||
extension = argv[4];
|
||||
caller_id_name = argv[5];
|
||||
caller_id_number = argv[6];
|
||||
caller_announce = argv[7];
|
||||
|
||||
--variable preparation
|
||||
tmp_sipuri = '';
|
||||
caller_id_name = string.gsub(caller_id_name, "+", " ");
|
||||
|
||||
function explode ( seperator, str )
|
||||
local pos, arr = 0, {}
|
||||
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
|
||||
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
|
||||
pos = sp + 1 -- jump past current divider
|
||||
end
|
||||
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
|
||||
return arr
|
||||
end
|
||||
|
||||
function originate (domain_name, session, sipuri, extension, caller_announce, caller_id_name, caller_id_number)
|
||||
|
||||
cid = ",origination_caller_id_name="..caller_id_name..",origination_caller_id_number="..caller_id_number;
|
||||
local new_session = freeswitch.Session("{ignore_early_media=true"..cid.."}"..sipuri);
|
||||
new_session:execute("set", "call_timeout=60");
|
||||
new_session:execute("sleep", "1000");
|
||||
|
||||
--if the session is not ready wait longer
|
||||
if ( new_session:ready() ) then
|
||||
--do nothing
|
||||
else
|
||||
new_session:execute("sleep", "1000");
|
||||
end
|
||||
|
||||
if ( new_session:ready() ) then
|
||||
--get the session id
|
||||
uuid = new_session:getVariable("uuid");
|
||||
--set the sounds path for the language, dialect and voice
|
||||
default_language = new_session:getVariable("default_language");
|
||||
default_dialect = new_session:getVariable("default_dialect");
|
||||
default_voice = new_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
|
||||
|
||||
--caller announce
|
||||
if (caller_announce) then
|
||||
new_session:streamFile(caller_announce);
|
||||
end
|
||||
|
||||
--set the sounds directory
|
||||
sounds_dir = new_session:getVariable("sounds_dir");
|
||||
|
||||
--check the fifo status if it is empty hangup the call
|
||||
api = freeswitch.API();
|
||||
cmd = "fifo count "..extension.."@"..domain_name;
|
||||
result = api:executeString(cmd);
|
||||
--freeswitch.consoleLog("notice", "result " .. result .. "\n");
|
||||
result_table = explode(":",result);
|
||||
if (result_table[3] == "0") then
|
||||
--session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/your_pin_number_is_incorect_goodbye.wav");
|
||||
new_session:hangup("NORMAL_CLEARING");
|
||||
return;
|
||||
end
|
||||
|
||||
--prompt user for action
|
||||
dtmf_digits = new_session:playAndGetDigits(1, 1, 2, 3000, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/8000/press_1_to_accept_2_to_reject_or_3_for_voicemail.wav", "", "\\d+");
|
||||
freeswitch.consoleLog("NOTICE", "followme: "..dtmf_digits.."\n");
|
||||
|
||||
if ( dtmf_digits == "1" ) then
|
||||
freeswitch.consoleLog("NOTICE", "followme: call accepted\n");
|
||||
freeswitch.consoleLog("NOTICE", extension.."@"..domain_name.." out nowait\n");
|
||||
new_session:execute("fifo", extension.."@"..domain_name.." out nowait");
|
||||
return true;
|
||||
end
|
||||
if ( dtmf_digits == "2" ) then
|
||||
freeswitch.consoleLog("NOTICE", "followme: call rejected\n");
|
||||
new_session:hangup();
|
||||
return false;
|
||||
end
|
||||
if ( dtmf_digits == "3" ) then
|
||||
freeswitch.consoleLog("NOTICE", "followme: call sent to voicemail\n");
|
||||
cmd = "uuid_transfer "..uuid.." *99"..extension;
|
||||
api = freeswitch.API();
|
||||
reply = api:executeString(cmd);
|
||||
return true;
|
||||
end
|
||||
if ( dtmf_digits == "" ) then
|
||||
freeswitch.consoleLog("NOTICE", "followme: no dtmf detected\n");
|
||||
return false;
|
||||
end
|
||||
else
|
||||
freeswitch.consoleLog("err", "followme: session not ready\n");
|
||||
end
|
||||
end
|
||||
|
||||
sipuri_table = explode(",",sipuri);
|
||||
for index,tmp_sip_uri in pairs(sipuri_table) do
|
||||
freeswitch.consoleLog("NOTICE", "sip_uri: "..tmp_sip_uri.."\n");
|
||||
result = originate (domain_name, session, tmp_sip_uri, extension, caller_announce, caller_id_name, caller_id_number);
|
||||
if (result) then
|
||||
break;
|
||||
--exit;
|
||||
end
|
||||
end
|
||||
100
includes/install/scripts/intercept.lua
Normal file
100
includes/install/scripts/intercept.lua
Normal file
@@ -0,0 +1,100 @@
|
||||
--
|
||||
-- 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>
|
||||
-- Copyright (C) 2010
|
||||
-- the Initial Developer. All Rights Reserved.
|
||||
--
|
||||
-- Contributor(s):
|
||||
-- Mark J Crane <markjcrane@fusionpbx.com>
|
||||
|
||||
max_tries = "3";
|
||||
digit_timeout = "5000";
|
||||
|
||||
extension = argv[1];
|
||||
|
||||
--database
|
||||
--connect to the database
|
||||
--local dbh = freeswitch.Dbh("dsn","user","pass"); -- when using ODBC
|
||||
local dbh = freeswitch.Dbh("core:core"); -- when using sqlite
|
||||
|
||||
--exits the script if we didn't connect properly
|
||||
assert(dbh:connected());
|
||||
|
||||
if ( session:ready() ) then
|
||||
session:answer( );
|
||||
pin_number = session:getVariable("pin_number");
|
||||
sounds_dir = session:getVariable("sounds_dir");
|
||||
domain_name = session:getVariable("domain_name");
|
||||
|
||||
--set the sounds path for the language, dialect and voice
|
||||
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
|
||||
|
||||
--set defaults
|
||||
if (digit_min_length) then
|
||||
--do nothing
|
||||
else
|
||||
digit_min_length = "2";
|
||||
end
|
||||
|
||||
if (digit_max_length) then
|
||||
--do nothing
|
||||
else
|
||||
digit_max_length = "11";
|
||||
end
|
||||
|
||||
--if the pin number is provided then require it
|
||||
if (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.."/custom/please_enter_the_pin_number.wav", "", "\\d+");
|
||||
if (digits == pin_number) then
|
||||
--pin is correct
|
||||
else
|
||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/your_pin_number_is_incorect_goodbye.wav");
|
||||
session:hangup("NORMAL_CLEARING");
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
||||
--check the database to get the uuid
|
||||
--intercept
|
||||
sql = "select call_uuid as uuid from channels where presence_id = '"..extension.."@"..domain_name.."' and callstate = 'RINGING' ";
|
||||
dbh:query(sql, function(result)
|
||||
for key, val in pairs(result) do
|
||||
freeswitch.consoleLog("NOTICE", "result "..key.." "..val.."\n");
|
||||
end
|
||||
uuid = result.uuid;
|
||||
end);
|
||||
|
||||
end
|
||||
|
||||
--intercept a call that is ringing
|
||||
if (uuid) then
|
||||
session:execute("intercept", uuid);
|
||||
end
|
||||
|
||||
--notes
|
||||
--originate a call
|
||||
--cmd = "originate user/1007@voip.example.com &intercept("..uuid..")";
|
||||
--api = freeswitch.API();
|
||||
--result = api:executeString(cmd);
|
||||
43
includes/install/scripts/originate.js
Normal file
43
includes/install/scripts/originate.js
Normal file
@@ -0,0 +1,43 @@
|
||||
include("config.js");
|
||||
//var sounds_dir
|
||||
//var admin_pin
|
||||
//var tmp_dir
|
||||
|
||||
var sipuri = argv[0];
|
||||
var caller_id_name = argv[1];
|
||||
var caller_id_number = argv[2];
|
||||
var tmp_sipuri;
|
||||
|
||||
caller_id_name = caller_id_name.replace("+", " ");
|
||||
//console_log( "info", "caller_announce: "+caller_announce+"\n" );
|
||||
|
||||
function originate (sipuri, caller_id_name, caller_id_number) {
|
||||
|
||||
var dtmf = new Object();
|
||||
var cid;
|
||||
dtmf.digits = "";
|
||||
cid = ",origination_caller_id_name="+caller_id_name+",origination_caller_id_number="+caller_id_number;
|
||||
|
||||
new_session = new Session("{ignore_early_media=true"+cid+"}"+sipuri);
|
||||
new_session.execute("set", "call_timeout=30");
|
||||
|
||||
if ( new_session.ready() ) {
|
||||
new_session.streamFile( sounds_dir+"/custom/press_1_to_accept_2_to_reject_or_3_for_voicemail.wav");
|
||||
digitmaxlength = 1;
|
||||
while (new_session.ready()) {
|
||||
//console_log( "info", "originate succeeded\n" );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sipuri_array = sipuri.split(",");
|
||||
for (i = 0; i < sipuri_array.length; i++){
|
||||
tmp_sipuri = sipuri_array[i];
|
||||
console_log("info", "tmp_sipuri: "+tmp_sipuri);
|
||||
result = originate (tmp_sipuri, caller_id_name, caller_id_number);
|
||||
if (result) {
|
||||
break;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
138
includes/install/scripts/page.lua
Normal file
138
includes/install/scripts/page.lua
Normal file
@@ -0,0 +1,138 @@
|
||||
-- page.lua
|
||||
-- Part of FusionPBX
|
||||
-- Copyright (C) 2010 Mark J Crane <markjcrane@fusionpbx.com>
|
||||
-- All rights reserved.
|
||||
--
|
||||
-- Redistribution and use in source and binary forms, with or without
|
||||
-- modification, are permitted provided that the following conditions are met:
|
||||
--
|
||||
-- 1. Redistributions of source code must retain the above copyright notice,
|
||||
-- this list of conditions and the following disclaimer.
|
||||
--
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright
|
||||
-- notice, this list of conditions and the following disclaimer in the
|
||||
-- documentation and/or other materials provided with the distribution.
|
||||
--
|
||||
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
-- POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
pin_number = "";
|
||||
max_tries = "3";
|
||||
digit_timeout = "3000";
|
||||
|
||||
function trim (s)
|
||||
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
|
||||
end
|
||||
|
||||
function explode ( seperator, str )
|
||||
local pos, arr = 0, {}
|
||||
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
|
||||
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
|
||||
pos = sp + 1 -- jump past current divider
|
||||
end
|
||||
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
|
||||
return arr
|
||||
end
|
||||
|
||||
if ( session:ready() ) then
|
||||
session:answer();
|
||||
--get the dialplan variables and set them as local variables
|
||||
destination_number = session:getVariable("destination_number");
|
||||
pin_number = session:getVariable("pin_number");
|
||||
domain_name = session:getVariable("domain_name");
|
||||
sounds_dir = session:getVariable("sounds_dir");
|
||||
extension_list = session:getVariable("extension_list");
|
||||
caller_id_name = session:getVariable("caller_id_name");
|
||||
caller_id_number = session:getVariable("caller_id_number");
|
||||
extension_table = explode(",",extension_list);
|
||||
sip_from_user = session:getVariable("sip_from_user");
|
||||
|
||||
--set the sounds path for the language, dialect and voice
|
||||
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
|
||||
|
||||
if (caller_id_name) then
|
||||
--caller id name provided do nothing
|
||||
else
|
||||
effective_caller_id_name = session:getVariable("effective_caller_id_name");
|
||||
caller_id_number = effective_caller_id_name;
|
||||
end
|
||||
|
||||
if (caller_id_number) then
|
||||
--caller id number provided do nothing
|
||||
else
|
||||
effective_caller_id_number = session:getVariable("effective_caller_id_number");
|
||||
caller_id_number = effective_caller_id_number;
|
||||
end
|
||||
|
||||
--if the pin number is provided then require it
|
||||
if (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.."/custom/please_enter_the_pin_number.wav", "", "\\d+");
|
||||
if (digits == pin_number) then
|
||||
--pin is correct
|
||||
else
|
||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/your_pin_number_is_incorect_goodbye.wav");
|
||||
session:hangup("NORMAL_CLEARING");
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
||||
api = freeswitch.API();
|
||||
for index,value in pairs(extension_table) do
|
||||
if (string.find(value, "-") == nill) then
|
||||
value = value..'-'..value;
|
||||
end
|
||||
sub_table = explode("-",value);
|
||||
for extension=sub_table[1],sub_table[2] do
|
||||
--extension_exists = "username_exists id "..extension.."@"..domain_name;
|
||||
--reply = trim(api:executeString(extension_exists));
|
||||
--if (reply == "true") then
|
||||
extension_status = "show channels like "..extension.."@";
|
||||
reply = trim(api:executeString(extension_status));
|
||||
if (reply == "0 total.") then
|
||||
--freeswitch.consoleLog("NOTICE", "extension "..extension.." available\n");
|
||||
if (extension == tonumber(sip_from_user)) then
|
||||
--this extension is the caller that initated the page
|
||||
else
|
||||
--originate the call
|
||||
cmd_string = "bgapi originate {sip_auto_answer=true,hangup_after_bridge=false,origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..extension.."@"..domain_name.." conference:page-"..destination_number.."@page+flags{mute} inline";
|
||||
api:executeString(cmd_string);
|
||||
end
|
||||
--freeswitch.consoleLog("NOTICE", "cmd_string "..cmd_string.."\n");
|
||||
else
|
||||
--look inside the reply to check for the correct domain_name
|
||||
if string.find(reply, domain_name) then
|
||||
--found: extension number is busy
|
||||
else
|
||||
--not found
|
||||
if (extension == tonumber(sip_from_user)) then
|
||||
--this extension is the caller that initated the page
|
||||
else
|
||||
--originate the call
|
||||
cmd_string = "bgapi originate {sip_auto_answer=true,hangup_after_bridge=false,origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..extension.."@"..domain_name.." conference:page-"..destination_number.."@page+flags{mute} inline";
|
||||
api:executeString(cmd_string);
|
||||
end
|
||||
end
|
||||
end
|
||||
--end
|
||||
end
|
||||
end
|
||||
|
||||
--send main call to the conference room
|
||||
session:execute("conference", "page-"..destination_number.."@page+flags{endconf}");
|
||||
|
||||
end
|
||||
229
includes/install/scripts/park.lua
Normal file
229
includes/install/scripts/park.lua
Normal file
@@ -0,0 +1,229 @@
|
||||
--example usage
|
||||
--basic
|
||||
--condition destination_number 5900
|
||||
--action set park_extension=5901
|
||||
--advanced
|
||||
--condition destination_number ^59(\d{2})$
|
||||
--action set park_extension=$1
|
||||
--additional settings
|
||||
--action set park_range=5
|
||||
--action set park_direction=in (in/out/both)
|
||||
--action set park_announce=true (not implemented yet)
|
||||
--action set park_timeout_seconds=30 (not implemented yet)
|
||||
--action set park_timeout_extension=1001 (not implemented yet)
|
||||
--action set park_music=$${hold_music}
|
||||
--action lua park.lua
|
||||
|
||||
--connect to the database
|
||||
--ODBC - data source name
|
||||
--local dbh = freeswitch.Dbh("name","user","pass");
|
||||
--FreeSWITCH core db
|
||||
local dbh = freeswitch.Dbh("core:park");
|
||||
|
||||
--get the session variables
|
||||
sounds_dir = session:getVariable("sounds_dir");
|
||||
park_direction = session:getVariable("park_direction");
|
||||
uuid = session:getVariable("uuid");
|
||||
domain_name = session:getVariable("domain_name");
|
||||
park_extension = session:getVariable("park_extension");
|
||||
park_range = session:getVariable("park_range");
|
||||
park_announce = session:getVariable("park_announce");
|
||||
park_timeout_type = session:getVariable("park_timeout_type");
|
||||
park_timeout_destination = session:getVariable("park_timeout_destination");
|
||||
park_timeout_seconds = session:getVariable("park_timeout_seconds");
|
||||
park_music = session:getVariable("park_music");
|
||||
|
||||
--add the explode function
|
||||
function explode ( seperator, str )
|
||||
local pos, arr = 0, {}
|
||||
for st, sp in function() return string.find( str, seperator, pos, true ) end do -- for each divider found
|
||||
table.insert( arr, string.sub( str, pos, st-1 ) ) -- attach chars left of current divider
|
||||
pos = sp + 1 -- jump past current divider
|
||||
end
|
||||
table.insert( arr, string.sub( str, pos ) ) -- attach chars right of last divider
|
||||
return arr
|
||||
end
|
||||
|
||||
--add the trim function
|
||||
function trim(s)
|
||||
return s:gsub("^%s+", ""):gsub("%s+$", "")
|
||||
end
|
||||
|
||||
--if park_timeout_seconds is not defined set the timeout to 5 minutes
|
||||
if (not park_timeout_seconds) then
|
||||
park_timeout_seconds = 300;
|
||||
end
|
||||
|
||||
--if park_timeout_type is not defined set to transfer
|
||||
if (not park_timeout_type) then
|
||||
park_timeout_type = "transfer";
|
||||
end
|
||||
|
||||
--prepare the api
|
||||
api = freeswitch.API();
|
||||
|
||||
--answer the call
|
||||
session:answer();
|
||||
|
||||
--database
|
||||
--exits the script if we didn't connect properly
|
||||
assert(dbh:connected());
|
||||
|
||||
--create the table if it doesn't exist
|
||||
--pgsql
|
||||
dbh:test_reactive("SELECT * FROM park", "", "CREATE TABLE park (id SERIAL, lot TEXT, domain TEXT, uuid TEXT, CONSTRAINT park_pk PRIMARY KEY(id))");
|
||||
--sqlite
|
||||
dbh:test_reactive("SELECT * FROM park", "", "CREATE TABLE park (id INTEGER PRIMARY KEY, lot TEXT, domain TEXT, uuid TEXT)");
|
||||
--mysql
|
||||
dbh:test_reactive("SELECT * FROM park", "", "CREATE TABLE park (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, lot TEXT, domain TEXT, uuid TEXT)");
|
||||
|
||||
--if park_range is defined then loop through the range to find an available parking lot
|
||||
if (park_range) then
|
||||
park_extension_start = park_extension;
|
||||
park_extension_end = ((park_extension+park_range)-1);
|
||||
extension = park_extension_start;
|
||||
while true do
|
||||
--exit the loop at the end of the range
|
||||
if (tonumber(extension) > park_extension_end) then
|
||||
break;
|
||||
end
|
||||
--check the database for an available slot
|
||||
lot_status = "available";
|
||||
sql = "SELECT count(*) as count FROM park WHERE lot = '"..extension.."' and domain = '"..domain_name.."' ";
|
||||
dbh:query(sql, function(result)
|
||||
--for key, val in pairs(result) do
|
||||
-- freeswitch.consoleLog("NOTICE", "parking result "..key.." "..val.."\n");
|
||||
--end
|
||||
count = result.count;
|
||||
end);
|
||||
--if count is 0 then the parking lot is available end the loop
|
||||
if (count == "0") then
|
||||
lot_status = "available";
|
||||
park_extension = ""..extension;
|
||||
break;
|
||||
end
|
||||
--increment the value
|
||||
extension = extension + 1;
|
||||
end
|
||||
end
|
||||
|
||||
--check the database to see if the slot is available or unavailable
|
||||
lot_status = "available";
|
||||
sql = "SELECT id, lot, uuid FROM park WHERE lot = '"..park_extension.."' and domain = '"..domain_name.."' ";
|
||||
dbh:query(sql, function(row)
|
||||
lot_uuid = row.uuid;
|
||||
lot_status = "unavailable";
|
||||
end);
|
||||
|
||||
--if park direction is set to out then unpark by bridging it to the caller
|
||||
if (park_direction == "out") then
|
||||
if (lot_uuid) then
|
||||
--set the park status
|
||||
cmd = "uuid_setvar "..lot_uuid.." park_status unparked";
|
||||
result = trim(api:executeString(cmd));
|
||||
freeswitch.consoleLog("NOTICE", "Park Status: unparked "..park_extension.."\n");
|
||||
--unpark the call with bridge
|
||||
cmd = "uuid_bridge "..uuid.." "..lot_uuid;
|
||||
result = trim(api:executeString(cmd));
|
||||
end
|
||||
else
|
||||
--check if the uuid_exists, if it does not exist then delete the uuid from the db and set presence to terminated
|
||||
if (lot_uuid) then
|
||||
cmd = "uuid_exists "..lot_uuid;
|
||||
result = trim(api:executeString(cmd));
|
||||
if (result == "false") then
|
||||
--set presence out
|
||||
event = freeswitch.Event("PRESENCE_IN");
|
||||
event:addHeader("proto", "sip");
|
||||
event:addHeader("event_type", "presence");
|
||||
event:addHeader("alt_event_type", "dialog");
|
||||
event:addHeader("Presence-Call-Direction", "outbound");
|
||||
event:addHeader("state", "Active (1 waiting)");
|
||||
event:addHeader("from", park_extension.."@"..domain_name);
|
||||
event:addHeader("login", park_extension.."@"..domain_name);
|
||||
event:addHeader("unique-id", lot_uuid);
|
||||
event:addHeader("answer-state", "terminated");
|
||||
event:fire();
|
||||
|
||||
--delete from the database
|
||||
dbh:query("DELETE from park WHERE lot = '"..park_extension.."' and domain = '"..domain_name.."' ");
|
||||
--freeswitch.consoleLog("NOTICE", "Park - Affected rows: " .. dbh:affected_rows() .. "\n");
|
||||
|
||||
--set the status to available
|
||||
lot_status = "available";
|
||||
end
|
||||
end
|
||||
|
||||
--check if the parking lot is available, if it is then add it to the db, set presenence to confirmed and park the call
|
||||
if (lot_status == "available") then
|
||||
--park the call
|
||||
cmd = "uuid_park "..uuid;
|
||||
result = trim(api:executeString(cmd));
|
||||
if (park_music) then
|
||||
cmd = "uuid_broadcast "..uuid.." "..park_music.." aleg";
|
||||
result = trim(api:executeString(cmd));
|
||||
end
|
||||
|
||||
--set the park status
|
||||
cmd = "uuid_setvar "..uuid.." park_status parked";
|
||||
result = trim(api:executeString(cmd));
|
||||
freeswitch.consoleLog("NOTICE", "Park Status: parked "..park_extension.."\n");
|
||||
|
||||
--add to the database
|
||||
dbh:query("INSERT INTO park (lot, domain, uuid) VALUES('"..park_extension.."', '"..domain_name.."', '"..uuid.."')");
|
||||
|
||||
--set presence in
|
||||
event = freeswitch.Event("PRESENCE_IN");
|
||||
event:addHeader("proto", "sip"); --park
|
||||
event:addHeader("login", park_extension.."@"..domain_name);
|
||||
event:addHeader("from", park_extension.."@"..domain_name);
|
||||
event:addHeader("status", "Active (1 waiting)");
|
||||
event:addHeader("rpid", "unknown");
|
||||
event:addHeader("event_type", "presence");
|
||||
event:addHeader("alt_event_type", "dialog");
|
||||
event:addHeader("event_count", "1");
|
||||
event:addHeader("unique-id", uuid);
|
||||
--event:addHeader("Presence-Call-Direction", "outbound")
|
||||
event:addHeader("answer-state", "confirmed");
|
||||
event:fire();
|
||||
|
||||
else
|
||||
--bridge the current call to the call that is parked
|
||||
--set the presence to terminated
|
||||
event = freeswitch.Event("PRESENCE_IN");
|
||||
event:addHeader("proto", "sip");
|
||||
event:addHeader("event_type", "presence");
|
||||
event:addHeader("alt_event_type", "dialog");
|
||||
event:addHeader("Presence-Call-Direction", "outbound");
|
||||
--event:addHeader("state", "Active (1 waiting)");
|
||||
event:addHeader("from", park_extension.."@"..domain_name);
|
||||
event:addHeader("login", park_extension.."@"..domain_name);
|
||||
event:addHeader("unique-id", uuid);
|
||||
event:addHeader("answer-state", "terminated");
|
||||
event:fire();
|
||||
|
||||
--delete the lot from the database
|
||||
dbh:query("DELETE from park WHERE lot = '"..park_extension.."' and domain = '"..domain_name.."' ");
|
||||
--freeswitch.consoleLog("NOTICE", "Park 200- Affected rows: " .. dbh:affected_rows() .. "\n");
|
||||
|
||||
--set the park status
|
||||
cmd = "uuid_setvar "..lot_uuid.." park_status unparked";
|
||||
result = trim(api:executeString(cmd));
|
||||
freeswitch.consoleLog("NOTICE", "Park Status: unparked "..park_extension.."\n");
|
||||
|
||||
--connect the calls
|
||||
cmd = "uuid_bridge "..uuid.." "..lot_uuid;
|
||||
result = trim(api:executeString(cmd));
|
||||
end
|
||||
|
||||
--continue running when the session ends
|
||||
session:setAutoHangup(false);
|
||||
|
||||
--start the fifo monitor on its own so that it doesn't block the script execution
|
||||
api = freeswitch.API();
|
||||
cmd = "luarun park_monitor.lua "..uuid.." "..domain_name.." "..park_extension.." "..park_timeout_type.." "..park_timeout_seconds.." "..park_timeout_destination;
|
||||
result = api:executeString(cmd);
|
||||
end
|
||||
|
||||
--close the database connection
|
||||
dbh:release();
|
||||
149
includes/install/scripts/park_monitor.lua
Normal file
149
includes/install/scripts/park_monitor.lua
Normal file
@@ -0,0 +1,149 @@
|
||||
--park_monitor.lua
|
||||
--Date: 4 Oct. 2011
|
||||
--Description:
|
||||
--if the call has been answered
|
||||
--then send presence terminate, and delete from the database
|
||||
|
||||
--connect to the database
|
||||
--ODBC - data source name
|
||||
--local dbh = freeswitch.Dbh("name","user","pass");
|
||||
--FreeSWITCH core db
|
||||
local dbh = freeswitch.Dbh("core:park");
|
||||
|
||||
--get the argv values
|
||||
script_name = argv[0];
|
||||
uuid = argv[1];
|
||||
domain_name = argv[2];
|
||||
park_extension = argv[3];
|
||||
park_timeout_type = argv[4];
|
||||
park_timeout_seconds = argv[5];
|
||||
park_timeout_destination = argv[6];
|
||||
|
||||
--prepare the api
|
||||
api = freeswitch.API();
|
||||
|
||||
--add a trim function
|
||||
function trim (s)
|
||||
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
|
||||
end
|
||||
|
||||
--monitor the parking lot if the call has hungup send a terminated event, and delete from the db
|
||||
x = 0
|
||||
while true do
|
||||
--sleep a moment to prevent using unecessary resources
|
||||
freeswitch.msleep(1000);
|
||||
|
||||
if (api:executeString("uuid_exists "..uuid) == "false") then
|
||||
--set the presence to terminated
|
||||
event = freeswitch.Event("PRESENCE_IN");
|
||||
event:addHeader("proto", "sip");
|
||||
event:addHeader("event_type", "presence");
|
||||
event:addHeader("alt_event_type", "dialog");
|
||||
event:addHeader("Presence-Call-Direction", "outbound");
|
||||
event:addHeader("state", "Active (1 waiting)");
|
||||
event:addHeader("from", park_extension.."@"..domain_name);
|
||||
event:addHeader("login", park_extension.."@"..domain_name);
|
||||
event:addHeader("unique-id", uuid);
|
||||
event:addHeader("answer-state", "terminated");
|
||||
event:fire();
|
||||
|
||||
--set the park status
|
||||
cmd = "uuid_setvar "..uuid.." park_status cancelled";
|
||||
result = trim(api:executeString(cmd));
|
||||
freeswitch.consoleLog("NOTICE", "Park Status: cancelled\n");
|
||||
|
||||
--delete the lot from the database
|
||||
dbh:query("DELETE from park WHERE lot = '"..park_extension.."' and domain = '"..domain_name.."' ");
|
||||
|
||||
|
||||
--end the loop
|
||||
break;
|
||||
else
|
||||
cmd = "uuid_getvar "..uuid.." park_status";
|
||||
result = trim(api:executeString(cmd));
|
||||
--freeswitch.consoleLog("notice", "" .. result .. "\n");
|
||||
if (result == "parked") then --_undef_
|
||||
--set presence in
|
||||
event = freeswitch.Event("PRESENCE_IN");
|
||||
event:addHeader("proto", "sip"); --park
|
||||
event:addHeader("login", park_extension.."@"..domain_name);
|
||||
event:addHeader("from", park_extension.."@"..domain_name);
|
||||
event:addHeader("status", "Active (1 waiting)");
|
||||
event:addHeader("rpid", "unknown");
|
||||
event:addHeader("event_type", "presence");
|
||||
event:addHeader("alt_event_type", "dialog");
|
||||
event:addHeader("event_count", "1");
|
||||
event:addHeader("unique-id", uuid);
|
||||
--event:addHeader("Presence-Call-Direction", "outbound")
|
||||
event:addHeader("answer-state", "confirmed");
|
||||
event:fire();
|
||||
else
|
||||
--set the presence to terminated
|
||||
event = freeswitch.Event("PRESENCE_IN");
|
||||
event:addHeader("proto", "sip");
|
||||
event:addHeader("event_type", "presence");
|
||||
event:addHeader("alt_event_type", "dialog");
|
||||
event:addHeader("Presence-Call-Direction", "outbound");
|
||||
event:addHeader("state", "Active (1 waiting)");
|
||||
event:addHeader("from", park_extension.."@"..domain_name);
|
||||
event:addHeader("login", park_extension.."@"..domain_name);
|
||||
event:addHeader("unique-id", uuid);
|
||||
event:addHeader("answer-state", "terminated");
|
||||
event:fire();
|
||||
|
||||
--delete the lot from the database
|
||||
dbh:query("DELETE from park WHERE lot = '"..park_extension.."' and domain = '"..domain_name.."' ");
|
||||
--freeswitch.consoleLog("NOTICE", "Affected rows: park ext "..park_extension.." " .. dbh:affected_rows() .. "\n");
|
||||
|
||||
--set the park status
|
||||
cmd = "uuid_setvar "..uuid.." park_status unparked";
|
||||
result = trim(api:executeString(cmd));
|
||||
freeswitch.consoleLog("NOTICE", "Park Status: unparked "..park_extension.."\n");
|
||||
|
||||
--end the loop
|
||||
break;
|
||||
end
|
||||
end
|
||||
|
||||
--limit the monitor to watching 60 seconds
|
||||
x = x + 1;
|
||||
if (x > tonumber(park_timeout_seconds)) then
|
||||
--set the presence to terminated
|
||||
event = freeswitch.Event("PRESENCE_IN");
|
||||
event:addHeader("proto", "sip");
|
||||
event:addHeader("event_type", "presence");
|
||||
event:addHeader("alt_event_type", "dialog");
|
||||
event:addHeader("Presence-Call-Direction", "outbound");
|
||||
event:addHeader("state", "Active (1 waiting)");
|
||||
event:addHeader("from", park_extension.."@"..domain_name);
|
||||
event:addHeader("login", park_extension.."@"..domain_name);
|
||||
event:addHeader("unique-id", uuid);
|
||||
event:addHeader("answer-state", "terminated");
|
||||
event:fire();
|
||||
|
||||
--delete the lot from the database
|
||||
dbh:query("DELETE from park WHERE lot = '"..park_extension.."' and domain = '"..domain_name.."' ");
|
||||
|
||||
--set the park status
|
||||
cmd = "uuid_setvar "..uuid.." park_status timeout";
|
||||
result = trim(api:executeString(cmd));
|
||||
freeswitch.consoleLog("NOTICE", "Park Status: timeout\n");
|
||||
|
||||
--end the loop
|
||||
break;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--if the timeout was reached transfer the call
|
||||
cmd = "uuid_getvar "..uuid.." park_status";
|
||||
park_status = trim(api:executeString(cmd));
|
||||
if (park_timeout_type == "transfer" and park_status == "timeout") then
|
||||
--set the park status
|
||||
cmd = "uuid_setvar "..uuid.." park_status unparked";
|
||||
result = trim(api:executeString(cmd));
|
||||
freeswitch.consoleLog("NOTICE", "Park Status: unparked\n");
|
||||
--transfer the call when it has timed out
|
||||
cmd = "uuid_transfer "..uuid.." "..park_timeout_destination;
|
||||
result = trim(api:executeString(cmd));
|
||||
end
|
||||
54
includes/install/scripts/pin_number.lua
Normal file
54
includes/install/scripts/pin_number.lua
Normal file
@@ -0,0 +1,54 @@
|
||||
--
|
||||
-- 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>
|
||||
-- Copyright (C) 2010
|
||||
-- the Initial Developer. All Rights Reserved.
|
||||
--
|
||||
-- Contributor(s):
|
||||
-- Mark J Crane <markjcrane@fusionpbx.com>
|
||||
|
||||
max_tries = "3";
|
||||
digit_timeout = "5000";
|
||||
|
||||
if ( session:ready() ) then
|
||||
session:answer( );
|
||||
pin_number = session:getVariable("pin_number");
|
||||
sounds_dir = session:getVariable("sounds_dir");
|
||||
|
||||
--set the sounds path for the language, dialect and voice
|
||||
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
|
||||
|
||||
--if the pin number is provided then require it
|
||||
if (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.."/custom/please_enter_the_pin_number.wav", "", "\\d+");
|
||||
if (digits == pin_number) then
|
||||
--pin is correct
|
||||
else
|
||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/your_pin_number_is_incorect_goodbye.wav");
|
||||
session:hangup("NORMAL_CLEARING");
|
||||
return;
|
||||
end
|
||||
end
|
||||
end
|
||||
162
includes/install/scripts/recordings.lua
Normal file
162
includes/install/scripts/recordings.lua
Normal file
@@ -0,0 +1,162 @@
|
||||
--
|
||||
-- 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>
|
||||
-- Copyright (C) 2010
|
||||
-- the Initial Developer. All Rights Reserved.
|
||||
--
|
||||
-- Contributor(s):
|
||||
-- Mark J Crane <markjcrane@fusionpbx.com>
|
||||
|
||||
pin_number = "";
|
||||
max_tries = "3";
|
||||
digit_timeout = "3000";
|
||||
sounds_dir = "";
|
||||
recordings_dir = "";
|
||||
file_name = "";
|
||||
recording_number = "";
|
||||
recording_slots = "";
|
||||
recording_prefix = "";
|
||||
|
||||
--dtmf call back function detects the "#" and ends the call
|
||||
function onInput(s, type, obj)
|
||||
if (type == "dtmf" and obj['digit'] == '#') then
|
||||
return "break";
|
||||
end
|
||||
end
|
||||
|
||||
--start the recording
|
||||
function begin_record(session, sounds_dir, recordings_dir)
|
||||
|
||||
--set the sounds path for the language, dialect and voice
|
||||
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
|
||||
recording_slots = session:getVariable("recording_slots");
|
||||
recording_prefix = session:getVariable("recording_prefix");
|
||||
recording_name = session:getVariable("recording_name");
|
||||
|
||||
--select the recording number
|
||||
if (recording_slots) then
|
||||
min_digits = 1;
|
||||
max_digits = 20;
|
||||
recording_number = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/please_enter_the_recording_number.wav", "", "\\d+");
|
||||
recording_name = recording_prefix..recording_number..".wav";
|
||||
end
|
||||
|
||||
--set the default recording name if one was not provided
|
||||
if (recording_name) then
|
||||
--recording name is provided do nothing
|
||||
else
|
||||
--set a default recording_name
|
||||
recording_name = "temp_"..session:get_uuid()..".wav";
|
||||
end
|
||||
|
||||
--prompt for the recording
|
||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/begin_recording.wav");
|
||||
session:execute("set", "playback_terminators=#");
|
||||
|
||||
--begin recording
|
||||
session:execute("record", recordings_dir.."/"..recording_name.." 180 200");
|
||||
|
||||
--preview the recording
|
||||
session:streamFile(recordings_dir.."/"..recording_name);
|
||||
|
||||
--approve the recording, to save the recording press 1 to re-record press 2
|
||||
min_digits="0" max_digits="1" max_tries = "1"; digit_timeout = "100";
|
||||
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "voicemail/vm-save_recording.wav", "", "\\d+");
|
||||
|
||||
if (string.len(digits) == 0) then
|
||||
min_digits="0" max_digits="1" max_tries = "1"; digit_timeout = "100";
|
||||
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "voicemail/vm-press.wav", "", "\\d+");
|
||||
end
|
||||
|
||||
if (string.len(digits) == 0) then
|
||||
min_digits="0" max_digits="1" max_tries = "1"; digit_timeout = "100";
|
||||
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "digits/1.wav", "", "\\d+");
|
||||
end
|
||||
|
||||
if (string.len(digits) == 0) then
|
||||
min_digits="0" max_digits="1" max_tries = "1"; digit_timeout = "100";
|
||||
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "voicemail/vm-rerecord.wav", "", "\\d+");
|
||||
end
|
||||
|
||||
if (string.len(digits) == 0) then
|
||||
min_digits="0" max_digits="1" max_tries = "1"; digit_timeout = "100";
|
||||
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "voicemail/vm-press.wav", "", "\\d+");
|
||||
end
|
||||
|
||||
if (string.len(digits) == 0) then
|
||||
min_digits="1" max_digits="1" max_tries = "1"; digit_timeout = "5000";
|
||||
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "digits/2.wav", "", "\\d+");
|
||||
end
|
||||
|
||||
if (digits == "1") then
|
||||
--recording saved, hangup
|
||||
session:streamFile("voicemail/vm-saved.wav");
|
||||
return;
|
||||
elseif (digits == "2") then
|
||||
--delete the old recording
|
||||
os.remove (recordings_dir.."/"..recording_name);
|
||||
--session:execute("system", "rm "..);
|
||||
--make a new recording
|
||||
begin_record(session, sounds_dir, recordings_dir);
|
||||
else
|
||||
--recording saved, hangup
|
||||
session:streamFile("voicemail/vm-saved.wav");
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
||||
if ( session:ready() ) then
|
||||
session:answer();
|
||||
|
||||
--get the dialplan variables and set them as local variables
|
||||
pin_number = session:getVariable("pin_number");
|
||||
sounds_dir = session:getVariable("sounds_dir");
|
||||
recordings_dir = session:getVariable("recordings_dir");
|
||||
|
||||
--set the sounds path for the language, dialect and voice
|
||||
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
|
||||
|
||||
--if the pin number is provided then require it
|
||||
if (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.."/custom/please_enter_the_pin_number.wav", "", "\\d+");
|
||||
if (digits == pin_number) then
|
||||
--pin is correct
|
||||
else
|
||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/your_pin_number_is_incorect_goodbye.wav");
|
||||
session:hangup("NORMAL_CLEARING");
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
||||
--start recording
|
||||
begin_record(session, sounds_dir, recordings_dir);
|
||||
|
||||
session:hangup();
|
||||
end
|
||||
98
includes/install/scripts/ring_group.lua
Normal file
98
includes/install/scripts/ring_group.lua
Normal file
@@ -0,0 +1,98 @@
|
||||
-- intercom.lua
|
||||
-- Part of FusionPBX
|
||||
-- Copyright (C) 2010 Mark J Crane <markjcrane@fusionpbx.com>
|
||||
-- All rights reserved.
|
||||
--
|
||||
-- Redistribution and use in source and binary forms, with or without
|
||||
-- modification, are permitted provided that the following conditions are met:
|
||||
--
|
||||
-- 1. Redistributions of source code must retain the above copyright notice,
|
||||
-- this list of conditions and the following disclaimer.
|
||||
--
|
||||
-- 2. Redistributions in binary form must reproduce the above copyright
|
||||
-- notice, this list of conditions and the following disclaimer in the
|
||||
-- documentation and/or other materials provided with the distribution.
|
||||
--
|
||||
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
-- POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
--include the lua script
|
||||
scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1));
|
||||
include = assert(loadfile(scripts_dir .. "/resources/config.lua"));
|
||||
include();
|
||||
|
||||
--connect to the database
|
||||
--ODBC - data source name
|
||||
if (dsn_name) then
|
||||
dbh = freeswitch.Dbh(dsn_name,dsn_username,dsn_password);
|
||||
end
|
||||
--FreeSWITCH core db handler
|
||||
if (db_type == "sqlite") then
|
||||
dbh = freeswitch.Dbh("core:"..db_path.."/"..db_name);
|
||||
end
|
||||
|
||||
--get the variables
|
||||
domain_name = session:getVariable("domain_name");
|
||||
ring_group_uuid = session:getVariable("ring_group_uuid");
|
||||
|
||||
--get the extension list
|
||||
sql =
|
||||
[[ SELECT g.ring_group_extension_uuid, e.extension_uuid, e.extension,
|
||||
r.ring_group_strategy, r.ring_group_timeout_sec, r.ring_group_timeout_app, r.ring_group_timeout_data
|
||||
FROM v_ring_groups as r, v_ring_group_extensions as g, v_extensions as e
|
||||
where g.ring_group_uuid = r.ring_group_uuid
|
||||
and g.ring_group_uuid = ']]..ring_group_uuid..[['
|
||||
and e.extension_uuid = g.extension_uuid
|
||||
and r.ring_group_enabled = 'true'
|
||||
order by e.extension asc ]]
|
||||
--freeswitch.consoleLog("notice", "SQL:" .. sql .. "\n");
|
||||
app_data = "";
|
||||
|
||||
x = 0;
|
||||
dbh:query(sql, function(row)
|
||||
ring_group_timeout_sec = row.ring_group_timeout_sec;
|
||||
ring_group_timeout_app = row.ring_group_timeout_app;
|
||||
ring_group_timeout_data = row.ring_group_timeout_data;
|
||||
if (row.ring_group_strategy == "sequence") then
|
||||
delimiter = "|";
|
||||
end
|
||||
if (row.ring_group_strategy == "simultaneous") then
|
||||
delimiter = ",";
|
||||
end
|
||||
if (x == 0) then
|
||||
app_data = "[leg_timeout="..ring_group_timeout_sec.."]user/" .. row.extension .. "@" .. domain_name;
|
||||
else
|
||||
app_data = app_data .. delimiter .. "[leg_timeout="..ring_group_timeout_sec.."]user/" .. row.extension .. "@" .. domain_name;
|
||||
end
|
||||
x = x + 1;
|
||||
end);
|
||||
|
||||
--close the database connection
|
||||
dbh:release();
|
||||
|
||||
--app_data
|
||||
--freeswitch.consoleLog("notice", "Debug:\n" .. app_data .. "\n");
|
||||
|
||||
--session actions
|
||||
if (session:ready()) then
|
||||
session:answer();
|
||||
session:execute("set", "hangup_after_bridge=true");
|
||||
session:execute("set", "continue_on_fail=true");
|
||||
session:execute("bridge", app_data);
|
||||
session:execute(ring_group_timeout_app, ring_group_timeout_data);
|
||||
end
|
||||
|
||||
--actions
|
||||
--ACTIONS = {}
|
||||
--table.insert(ACTIONS, {"set", "hangup_after_bridge=true"});
|
||||
--table.insert(ACTIONS, {"set", "continue_on_fail=true"});
|
||||
--table.insert(ACTIONS, {"bridge", app_data});
|
||||
--table.insert(ACTIONS, {ring_group_timeout_app, ring_group_timeout_data});
|
||||
91
includes/install/scripts/roku.lua
Normal file
91
includes/install/scripts/roku.lua
Normal file
@@ -0,0 +1,91 @@
|
||||
--
|
||||
-- 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>
|
||||
-- Copyright (C) 2010
|
||||
-- the Initial Developer. All Rights Reserved.
|
||||
--
|
||||
-- Contributor(s):
|
||||
-- Mark J Crane <markjcrane@fusionpbx.com>
|
||||
|
||||
predefined_destination = "";
|
||||
max_tries = "3";
|
||||
digit_timeout = "5000";
|
||||
port = "8080";
|
||||
|
||||
if ( session:ready() ) then
|
||||
session:answer( );
|
||||
pin_number = session:getVariable("pin_number");
|
||||
sounds_dir = session:getVariable("sounds_dir");
|
||||
host = session:getVariable("host");
|
||||
|
||||
--set the sounds path for the language, dialect and voice
|
||||
default_language = session:getVariable("default_language");
|
||||
default_dialect = session:getVariable("default_dialect");
|
||||
default_voice = session:getVariable("default_voice");
|
||||
if (default_language) then else default_language = 'en'; end
|
||||
if (default_dialect) then else default_dialect = 'us'; end
|
||||
if (default_voice) then else default_voice = 'callie'; end
|
||||
|
||||
digitmaxlength = 0;
|
||||
timeoutpin = 7500;
|
||||
timeouttransfer = 7500;
|
||||
|
||||
--if the pin number is provided then require it
|
||||
if (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.."/custom/please_enter_the_pin_number.wav", "", "\\d+");
|
||||
if (digits == pin_number) then
|
||||
--pin is correct
|
||||
digits = "";
|
||||
else
|
||||
session:streamFile(sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/your_pin_number_is_incorect_goodbye.wav");
|
||||
session:hangup("NORMAL_CLEARING");
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
||||
if (session:ready()) then
|
||||
session:answer();
|
||||
min_digits = 1;
|
||||
max_digits = 1;
|
||||
digitmaxlength = 1;
|
||||
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", sounds_dir.."/"..default_language.."/"..default_dialect.."/"..default_voice.."/custom/please_enter_the_phone_number.wav", "", "\\d+");
|
||||
|
||||
x = 0;
|
||||
while (session:ready() == true) do
|
||||
if (string.len(digits) == 0) then
|
||||
--getDigits(length, terminators, timeout, digit_timeout, abs_timeout)
|
||||
digits = session:getDigits(1, "#", 40000);
|
||||
end
|
||||
if (string.len(digits) > 0) then
|
||||
--press star to exit
|
||||
if (digits == "*") then
|
||||
break;
|
||||
end
|
||||
--send the command to php
|
||||
session:execute("system","/usr/local/bin/php /usr/local/www/fusionpbx/mod/roku/roku.php "..digits.." "..host.." "..port);
|
||||
end
|
||||
digits = "";
|
||||
if (x > 17500) then
|
||||
break;
|
||||
end
|
||||
end
|
||||
session:hangup("NORMAL_CLEARING");
|
||||
end
|
||||
end
|
||||
203
includes/install/scripts/wakeup.lua
Normal file
203
includes/install/scripts/wakeup.lua
Normal file
@@ -0,0 +1,203 @@
|
||||
--
|
||||
-- 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>
|
||||
-- Copyright (C) 2010
|
||||
-- the Initial Developer. All Rights Reserved.
|
||||
--
|
||||
-- Contributor(s):
|
||||
-- Mark J Crane <markjcrane@fusionpbx.com>
|
||||
|
||||
--get the argv values
|
||||
script_name = argv[0];
|
||||
domain_name = argv[1];
|
||||
wakeup_number = argv[2];
|
||||
|
||||
--add the trim function
|
||||
function trim(s)
|
||||
return s:gsub("^%s+", ""):gsub("%s+$", "")
|
||||
end
|
||||
|
||||
--add is_numeric
|
||||
function is_numeric(text)
|
||||
if type(text)~="string" and type(text)~="number" then return false end
|
||||
return tonumber(text) and true or false
|
||||
end
|
||||
|
||||
--set the default values for the variables
|
||||
pin_number = "";
|
||||
max_tries = "3";
|
||||
digit_timeout = "3000";
|
||||
sounds_dir = "";
|
||||
extension_type = ""; --number,caller_id_number,prompt
|
||||
extension_number = "";
|
||||
|
||||
if (wakeup_number) then
|
||||
--begin the wakeup call
|
||||
if ( session:ready() ) then
|
||||
--prepare the api object
|
||||
api = freeswitch.API();
|
||||
|
||||
--set session settings
|
||||
session:answer();
|
||||
session:setAutoHangup(false);
|
||||
|
||||
--wakeup confirm press 1 to 3
|
||||
min_digits = 1;
|
||||
max_digits = 1;
|
||||
digits = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:wakeup-call", "", "\\d+");
|
||||
|
||||
--reschedule the call for snooze
|
||||
if (digits == "2") then
|
||||
freeswitch.consoleLog("NOTICE", "wakeup call: snooze selected - rescheduled the call\n");
|
||||
api = freeswitch.API();
|
||||
caller_id_name = "wakeup call";
|
||||
caller_id_number = wakeup_number;
|
||||
sched_api_time = "600";
|
||||
cmd_string = "sched_api +"..sched_api_time.." wakeup-call-"..wakeup_number.." originate {hangup_after_bridge=false,origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..wakeup_number.."@"..domain_name.." &lua('wakeup.lua "..domain_name.." "..wakeup_number.."') ";
|
||||
freeswitch.consoleLog("NOTICE", "wakeup: "..cmd_string.."\n");
|
||||
reply = api:executeString(cmd_string);
|
||||
end
|
||||
end
|
||||
else
|
||||
--prompt for the wakeup call information
|
||||
|
||||
if ( session:ready() ) then
|
||||
session:answer();
|
||||
session:setAutoHangup(false);
|
||||
|
||||
--get the dialplan variables and set them as local variables
|
||||
sounds_dir = session:getVariable("sounds_dir");
|
||||
domain_name = session:getVariable("domain_name");
|
||||
extension_number = session:getVariable("extension_number");
|
||||
extension_type = session:getVariable("extension_type");
|
||||
time_zone_offset = session:getVariable("time_zone_offset");
|
||||
sip_number_alias = session:getVariable("sip_number_alias");
|
||||
sip_from_user = session:getVariable("sip_from_user");
|
||||
if (is_numeric(sip_number_alias)) then
|
||||
wakeup_number = sip_number_alias;
|
||||
else
|
||||
wakeup_number = sip_from_user;
|
||||
end
|
||||
|
||||
--get the extension number
|
||||
if (extension_type == "prompt") then
|
||||
min_digits = 1;
|
||||
max_digits = 11;
|
||||
wakeup_time = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:wakeup-get-extension", "", "\\d+");
|
||||
end
|
||||
|
||||
--get the wakeup time
|
||||
min_digits = 4;
|
||||
max_digits = 4;
|
||||
wakeup_time = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:wakeup-greeting", "", "\\d+");
|
||||
freeswitch.consoleLog("NOTICE", "wakeup time: "..wakeup_time.."\n");
|
||||
|
||||
--get the current time
|
||||
current_hours = tonumber(os.date("%H"));
|
||||
current_minutes = tonumber(os.date("%M"));
|
||||
current_seconds = tonumber(os.date("%S"));
|
||||
|
||||
--adjust the time zone offset
|
||||
if (time_zone_offset) then
|
||||
current_hours = time_zone_offset + current_hours;
|
||||
if (current_hours < 0) then
|
||||
current_hours = current_hours + 24;
|
||||
end
|
||||
if (current_hours > 23) then
|
||||
current_hours = current_hours - 24;
|
||||
end
|
||||
end
|
||||
|
||||
--show the current hours minutes and seconds to the log
|
||||
--freeswitch.consoleLog("NOTICE", "Hours: " .. current_hours .. "\n");
|
||||
--freeswitch.consoleLog("NOTICE", "Mins: " .. current_minutes .. "\n");
|
||||
--freeswitch.consoleLog("NOTICE", "Seconds: " .. current_seconds .. "\n");
|
||||
|
||||
--prepare the current time
|
||||
current_time = (current_hours * 100) + current_minutes;
|
||||
|
||||
--get the wakeup hours and minutes
|
||||
wakeup_hours = string.sub(wakeup_time, 1, 2);
|
||||
wakeup_minutes = string.sub(wakeup_time, 3);
|
||||
|
||||
--show the wakeup time, hours, and minutes to the log
|
||||
--freeswitch.consoleLog("NOTICE", "wakeup_time "..wakeup_time.."\n");
|
||||
--freeswitch.consoleLog("NOTICE", "wakeup_hours "..wakeup_hours.."\n");
|
||||
--freeswitch.consoleLog("NOTICE", "wakeup_minutes "..wakeup_minutes.."\n");
|
||||
|
||||
--convert the time, hours and minutes to numbers
|
||||
wakeup_time = tonumber(wakeup_time);
|
||||
wakeup_hours = tonumber(wakeup_hours);
|
||||
wakeup_minutes = tonumber(wakeup_minutes);
|
||||
if (current_time > wakeup_time) then
|
||||
--get the current_time_in_seconds
|
||||
current_time_in_seconds = (current_hours * 3600) + (current_minutes * 60);
|
||||
--freeswitch.consoleLog("NOTICE", "sched_api_time = ("..current_hours.." * 3600) + ("..current_minutes.." * 60)\n");
|
||||
--get the seconds until midnight
|
||||
seconds_until_midnight = (24 * 3600) - current_time_in_seconds;
|
||||
--freeswitch.consoleLog("NOTICE", "sched_api_time = (24 * 3600) - "..current_time_in_seconds.."\n");
|
||||
--get the wakeup_time_in_seconds
|
||||
wakeup_time_in_seconds = (wakeup_hours * 3600) + (wakeup_minutes * 60);
|
||||
--freeswitch.consoleLog("NOTICE", "sched_api_time = ("..wakeup_hours.." * 3600) + ("..wakeup_minutes.." * 60)\n");
|
||||
--add the seconds_until_midnight to the wakeup_time_in_seconds
|
||||
sched_api_time = wakeup_time_in_seconds + seconds_until_midnight;
|
||||
--freeswitch.consoleLog("NOTICE", "sched_api_time = "..wakeup_time_in_seconds.." + "..seconds_until_midnight.."\n");
|
||||
else
|
||||
--get the current_time_in_seconds
|
||||
current_time_in_seconds = (current_hours * 3600) + (current_minutes * 60);
|
||||
--freeswitch.consoleLog("NOTICE", "current_time_in_seconds = ("..current_hours.." * 3600) + ("..current_minutes.." * 60);\n");
|
||||
--get the wakeup_time_in_seconds
|
||||
wakeup_time_in_seconds = (wakeup_hours * 3600) + (wakeup_minutes * 60);
|
||||
--freeswitch.consoleLog("NOTICE", "wakeup_time_in_seconds = ("..wakeup_hours.." * 3600) + ("..wakeup_minutes.." * 60);\n");
|
||||
--subtract the current time from wakeup_time_in_seconds
|
||||
sched_api_time = wakeup_time_in_seconds - current_time_in_seconds;
|
||||
--freeswitch.consoleLog("NOTICE", "sched_api_time = "..wakeup_time_in_seconds.." - "..current_time_in_seconds.."\n");
|
||||
end
|
||||
--freeswitch.consoleLog("NOTICE", "sched_api_time "..sched_api_time.."\n");
|
||||
|
||||
--wakeup call has been scheduled
|
||||
session:streamFile("phrase:wakeup-scheduled");
|
||||
session:say(wakeup_time, "en", "number", "ITERATED");
|
||||
|
||||
--wakeup confirm press 1 to 3
|
||||
min_digits = 1;
|
||||
max_digits = 1;
|
||||
wakeup_accept = session:playAndGetDigits(min_digits, max_digits, max_tries, digit_timeout, "#", "phrase:wakeup-accept", "", "\\d+");
|
||||
--accept
|
||||
if (wakeup_accept == "1") then
|
||||
--send a message to the console
|
||||
freeswitch.consoleLog("NOTICE", "wakeup: accepted\n");
|
||||
--schedule the wakeup call
|
||||
caller_id_name = "wakeup call";
|
||||
caller_id_number = wakeup_number;
|
||||
cmd_string = "sched_api +"..sched_api_time.." wakeup-call-"..wakeup_number.." originate {hangup_after_bridge=false,origination_caller_id_name='"..caller_id_name.."',origination_caller_id_number="..caller_id_number.."}user/"..wakeup_number.."@"..domain_name.." &lua('wakeup.lua "..domain_name.." "..wakeup_number.."') ";
|
||||
freeswitch.consoleLog("NOTICE", "wakeup: "..cmd_string.."\n");
|
||||
api = freeswitch.API();
|
||||
reply = api:executeString(cmd_string);
|
||||
--hangup
|
||||
session:hangup();
|
||||
end
|
||||
--cancel
|
||||
if (wakeup_accept == "2") then
|
||||
--send a message to the console
|
||||
freeswitch.consoleLog("NOTICE", "wakeup: cancelled\n");
|
||||
--hangup
|
||||
session:hangup();
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user