Engineered the management of bridge failures in local extension, with optional variables which by default provides the standard behavior. Changed the default order for extension_queue, which has *800 prefix, before the extension-intercom, which has the *8 prefix

This commit is contained in:
Riccardo Granchi
2014-11-21 15:38:26 +00:00
parent 3daa03d2a5
commit 390a5d4724
8 changed files with 175 additions and 143 deletions

View File

@@ -29,7 +29,10 @@
$text['label-on-busy']['es-cl'] = "Concurrida";
$text['label-on-busy']['pt-pt'] = "Movimentado";
$text['label-on-busy']['fr-fr'] = "Sur Occupé";
$text['label-on-busy']['it-it'] = "Rinvio su occupato";
$text['label-on-busy']['it-it'] = "Su occupato";
$text['description-on-busy']['en-us'] = "If enabled, it overrides the value of voicemail enabling in extension";
$text['description-on-busy']['it-it'] = "Se abilitato, esegue l'override del valore di abilitazione voicemail nell'estensione";
$text['label-enabled']['en-us'] = "Enabled";
$text['label-enabled']['es-cl'] = "Activo";

View File

@@ -554,6 +554,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
unset($on_click);
echo "   ";
echo " <input class='formfld' type='text' name='forward_busy_destination' id='forward_busy_destination' maxlength='255' placeholder=\"".$text['label-destination']."\" value=\"".$forward_busy_destination."\">\n";
echo " <br />".$text['description-on-busy'].".\n";
echo "</td>\n";
echo "</tr>\n";

View File

@@ -1,5 +1,5 @@
<context name="{v_context}">
<extension name="extension_queue" app_uuid="eb837d10-890d-11e3-baa8-0800200c9a66">
<extension name="extension_queue" number="*800[ext]" app_uuid="eb837d10-890d-11e3-baa8-0800200c9a66">
<condition field="destination_number" expression="^\*800(.*)$" >
<action application="set" data="fifo_music=$${hold_music}" />
<action application="set" data="extension_queue=queue_$1@\${domain_name}" />

View File

@@ -25,6 +25,8 @@
<!--<action application="bridge" data="${sofia_contact(${dialed_extension}@${domain_name})}"/>-->
<!-- number-alias / https://confluence.freeswitch.org/display/FREESWITCH/XML+User+Directory -->
<!--<action application="bridge" data="user/${user_data(${destination_number}@${domain_name} attr id)}@${domain_name}"/> -->
<!-- handles bridge failures before answer -->
<action application="lua" data="app.lua failure_handler"/>
<action application="answer"/>
<action application="sleep" data="1000"/>
<!--<action application="voicemail" data="default ${domain_name} ${dialed_extension}"/>-->

View File

@@ -37,6 +37,8 @@ $vars = <<<EOD
{"var_name":"bind_server_ip","var_value":"auto","var_cat":"Dingaling","var_enabled":"true","var_description":"Q2FuIGJlIGFuIGlwIGFkZHJlc3MsIGEgZG5zIG5hbWUsIG9yICJhdXRvIi4gVGhpcyBkZXRlcm1pbmVzIGFuIGlwIGFkZHJlc3MgYXZhaWxhYmxlIG9uIHRoaXMgaG9zdCB0byBiaW5kLiBJZiB5b3UgYXJlIHNlcGFyYXRpbmcgUlRQIGFuZCBTSVAgdHJhZmZpYywgeW91IHdpbGwgd2FudCB0byBoYXZlIHVzZSBkaWZmZXJlbnQgYWRkcmVzc2VzIHdoZXJlIHRoaXMgdmFyaWFibGUgYXBwZWFycy4gVXNlZCBieTogZGluZ2FsaW5nLmNvbmYueG1s"},
{"var_name":"external_rtp_ip","var_value":"\$\${local_ip_v4}","var_cat":"IP Address","var_enabled":"true","var_description":"KElmIHlvdScncmUgZ29pbmcgdG8gbG9hZCB0ZXN0IHRoZW4gcGxlYXNlIGlucHV0IHJlYWwgSVAgYWRkcmVzc2VzIGZvciBleHRlcm5hbF9ydHBfaXAgYW5kIGV4dGVybmFsX3NpcF9pcCkNCg0KQ2FuIGJlIGFuIG9uZSBvZjoNCiAgIGlwIGFkZHJlc3M6ICIxMi4zNC41Ni43OCINCiAgIGEgc3R1biBzZXJ2ZXIgbG9va3VwOiAic3R1bjpzdHVuLnNlcnZlci5jb20iDQogICBhIEROUyBuYW1lOiAiaG9zdDpob3N0LnNlcnZlci5jb20iDQoNCndoZXJlIGZzLm15ZG9tYWluLmNvbSBpcyBhIEROUyBBIHJlY29yZC11c2VmdWwgd2hlbiBmcyBpcyBvbiBhIGR5bmFtaWMgSVAgYWRkcmVzcywgYW5kIHVzZXMgYSBkeW5hbWljIEROUyB1cGRhdGVyLiBJZiB1bnNwZWNpZmllZCwgdGhlIGJpbmRfc2VydmVyX2lwIHZhbHVlIGlzIHVzZWQuIFVzZWQgYnk6IHNvZmlhLmNvbmYueG1sIGRpbmdhbGluZy5jb25mLnhtbA=="},
{"var_name":"external_sip_ip","var_value":"\$\${local_ip_v4}","var_cat":"IP Address","var_enabled":"true","var_description":"VXNlZCBhcyB0aGUgcHVibGljIElQIGFkZHJlc3MgZm9yIFNEUC4NCg0KQ2FuIGJlIGFuIG9uZSBvZjoNCiAgIGlwIGFkZHJlc3M6ICIxMi4zNC41Ni43OCINCiAgIGEgc3R1biBzZXJ2ZXIgbG9va3VwOiAic3R1bjpzdHVuLnNlcnZlci5jb20iDQogICBhIEROUyBuYW1lOiAiaG9zdDpob3N0LnNlcnZlci5jb20iDQoNCndoZXJlIGZzLm15ZG9tYWluLmNvbSBpcyBhIEROUyBBIHJlY29yZC11c2VmdWwgd2hlbiBmcyBpcyBvbiBhIGR5bmFtaWMgSVAgYWRkcmVzcywgYW5kIHVzZXMgYSBkeW5hbWljIEROUyB1cGRhdGVyLiBJZiB1bnNwZWNpZmllZCwgdGhlIGJpbmRfc2VydmVyX2lwIHZhbHVlIGlzIHVzZWQuIFVzZWQgYnk6IHNvZmlhLmNvbmYueG1sIGRpbmdhbGluZy5jb25mLnhtbA=="},
{"var_name":"hangup_on_subscriber_absent","var_value":"true","var_cat":"SIP","var_enabled":"false","var_description":"SGFuZ3VwIG9uIFNVQlNDUklCRVJfQUJTRU5U"},
{"var_name":"hangup_on_call_reject","var_value":"true","var_cat":"SIP","var_enabled":"false","var_description":"SGFuZ3VwIG9uIENBTExfUkVKRUNU"},
{"var_name":"unroll_loops","var_value":"true","var_cat":"SIP","var_enabled":"true","var_description":"VXNlZCB0byB0dXJuIG9uIHNpcCBsb29wYmFjayB1bnJvbGxpbmcu"},
{"var_name":"call_debug","var_value":"false","var_cat":"Defaults","var_enabled":"true","var_description":""},
{"var_name":"console_loglevel","var_value":"info","var_cat":"Defaults","var_enabled":"true","var_description":""},

View File

@@ -22,25 +22,17 @@
-- 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.
--
-- Contributor(s):
-- Salvatore Caruso <salvatore.caruso@nems.it>
-- Riccardo Granchi <riccardo.granchi@nems.it>
--include config.lua
scripts_dir = string.sub(debug.getinfo(1).source,2,string.len(debug.getinfo(1).source)-(string.len(argv[0])+1));
dofile(scripts_dir.."/resources/functions/config.lua");
dofile(scripts_dir.."/resources/functions/explode.lua");
dofile(config());
--get the argv values
script_name = argv[0];
app_name = argv[1];
--set the default variables
forward_on_busy = false;
send_to_voicemail = true;
--example use command
--luarun app.lua app_name 'a' 'b 123' 'c'
@@ -53,26 +45,6 @@
end
end
--if the session exists then check originate disposition and causes
if (session ~= nil) then
originate_disposition = session:getVariable("originate_disposition");
originate_causes = session:getVariable("originate_causes");
if (originate_causes ~= nil) then
array = explode("|",originate_causes);
if (string.find(array[1], "USER_BUSY")) then
originate_disposition = "USER_BUSY";
session:setVariable("originate_disposition", originate_disposition);
end
end
if (originate_disposition ~= nil) then
if (originate_disposition == 'USER_BUSY') then
freeswitch.consoleLog("notice", "[app] forward on busy: ".. scripts_dir .. "/app/forward_on_busy/index.lua" .. arguments .."\n");
forward_on_busy = loadfile(scripts_dir .. "/app/forward_on_busy/index.lua")(argv);
freeswitch.consoleLog("notice", "[app] forward on busy: ".. tostring(forward_on_busy) .. "\n");
end
end
end
--route the request to the application
--freeswitch.consoleLog("notice", "[app] lua route: ".. scripts_dir .. "/app/" .. app_name .. "/index.lua" .. arguments .."\n");
--freeswitch.consoleLog("notice", "["..app_name.."]".. scripts_dir .. "/app/" .. app_name .. "/index.lua\n");
loadfile(scripts_dir .. "/app/" .. app_name .. "/index.lua")(argv);

View File

@@ -0,0 +1,163 @@
--
-- 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-2014
-- the Initial Developer. All Rights Reserved.
--
-- Contributor(s):
-- Salvatore Caruso <salvatore.caruso@nems.it>
-- Riccardo Granchi <riccardo.granchi@nems.it>
--debug
debug["info"] = false;
debug["sql"] = false;
--include config.lua
dofile(scripts_dir .. "/resources/functions/config.lua");
dofile(scripts_dir .. "/resources/functions/explode.lua");
--handle originate_disposition
if (session ~= nil and
session:ready()) then
originate_disposition = session:getVariable("originate_disposition");
originate_causes = session:getVariable("originate_causes");
hangup_on_subscriber_absent = session:getVariable("hangup_on_subscriber_absent");
hangup_on_call_reject = session:getVariable("hangup_on_call_reject");
if (debug["info"] == true) then
freeswitch.consoleLog("INFO", "[failure_handler] originate_causes: " .. tostring(originate_causes) .. "\n");
freeswitch.consoleLog("INFO", "[failure_handler] originate_disposition: " .. tostring(originate_disposition) .. "\n");
freeswitch.consoleLog("INFO", "[failure_handler] hangup_on_subscriber_absent: " .. tostring(hangup_on_subscriber_absent) .. "\n");
freeswitch.consoleLog("INFO", "[failure_handler] hangup_on_call_reject: " .. tostring(hangup_on_call_reject) .. "\n");
end
if (originate_causes ~= nil) then
array = explode("|",originate_causes);
if (string.find(array[1], "USER_BUSY")) then
originate_disposition = "USER_BUSY";
session:setVariable("originate_disposition", originate_disposition);
end
end
if (originate_disposition ~= nil) then
if (originate_disposition == 'USER_BUSY') then
--handle USER_BUSY
dialed_extension = session:getVariable("dialed_extension");
context = session:getVariable("context");
domain_name = session:getVariable("domain_name");
uuid = session:getVariable("uuid");
last_busy_dialed_extension = session:getVariable("last_busy_dialed_extension");
if (debug["info"] ) then
freeswitch.consoleLog("INFO", "[failure_handler] last_busy_dialed_extension: " .. tostring(last_busy_dialed_extension) .. "\n");
end
--connect to the database
dofile(scripts_dir .. "/resources/functions/database_handle.lua");
dbh = database_handle('system');
--get the domain_uuid
domain_uuid = session:getVariable("domain_uuid");
if (domain_uuid == nil) then
--get the domain_uuid using the domain name required for multi-tenant
if (domain_name ~= nil) then
sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = '" .. domain_name .. "' ";
if (debug["sql"]) then
freeswitch.consoleLog("INFO", "[failure_handler] SQL: " .. sql .. "\n");
end
dbh:query(sql, function(rows)
domain_uuid = rows["domain_uuid"];
end);
end
end
domain_uuid = string.lower(domain_uuid);
if (dialed_extension ~= nil and
dialed_extension ~= last_busy_dialed_extension) then
--get the information from the database
sql = [[SELECT * FROM v_extensions
WHERE domain_uuid = ']] .. domain_uuid .. [['
AND extension = ']] .. dialed_extension .. [['
AND forward_busy_enabled = 'true' ]];
if (debug["sql"]) then
freeswitch.consoleLog("INFO", "[failure_handler] SQL: " .. sql .. "\n");
end
dbh:query(sql, function(row)
forward_busy_destination = string.lower(row["forward_busy_destination"]);
if (forward_busy_destination ~= nil and
string.len(forward_busy_destination) > 0 ) then
--handle USER_BUSY - forwarding to number
freeswitch.consoleLog("NOTICE", "[failure_handler] forwarding on busy to: " .. forward_busy_destination .. "\n");
session:setVariable("last_busy_dialed_extension", dialed_extension);
session:transfer(forward_busy_destination, "XML", context);
else
--handle USER_BUSY - hangup
freeswitch.consoleLog("NOTICE", "[failure_handler] forward on busy with empty destination: hangup(USER_BUSY)\n");
session:hangup("USER_BUSY");
end
end);
end
--close the database connection
dbh:release();
elseif (originate_disposition == "ALLOTTED_TIMEOUT") then
--handle ALLOTTED_TIMEOUT ( NO ANSWER )
if (debug["info"] ) then
freeswitch.consoleLog("NOTICE", "[failure_handler] - ALLOTTED_TIMEOUT - Doing nothing\n");
end
elseif (originate_disposition == "USER_NOT_REGISTERED") then
--handle USER_NOT_REGISTERED
if (debug["info"] ) then
freeswitch.consoleLog("NOTICE", "[failure_handler] - USER_NOT_REGISTERED - Doing nothing\n");
end
elseif (originate_disposition == "SUBSCRIBER_ABSENT" and
hangup_on_subscriber_absent == "true") then
--handle SUBSCRIBER_ABSENT
freeswitch.consoleLog("NOTICE", "[failure_handler] - SUBSCRIBER_ABSENT - hangup(UNALLOCATED_NUMBER)\n");
session:hangup("UNALLOCATED_NUMBER");
elseif (originate_disposition == "CALL_REJECTED" and
hangup_on_call_reject =="true") then
--handle CALL_REJECT
freeswitch.consoleLog("NOTICE", "[failure_handler] - CALL_REJECT - hangup()\n");
session:hangup();
end
end
end

View File

@@ -1,111 +0,0 @@
--
-- 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-2014
-- the Initial Developer. All Rights Reserved.
--
-- Contributor(s):
-- Salvatore Caruso <salvatore.caruso@nems.it>
-- Riccardo Granchi <riccardo.granchi@nems.it>
--set default values
forward = false;
--debug
debug["info"] = false;
debug["sql"] = false;
--connect to the database
dofile(scripts_dir.."/resources/functions/database_handle.lua");
dbh = database_handle('system');
if (session ~= nil) then
originate_disposition = session:getVariable("originate_disposition");
if ( originate_disposition=='USER_BUSY' ) then
dialed_extension = session:getVariable("dialed_extension");
context = session:getVariable("context");
domain_name = session:getVariable("domain_name");
uuid = session:getVariable("uuid");
send_to_voicemail = session:getVariable("send_to_voicemail");
if (send_to_voicemail == nil) then
send_to_voicemail = "true";
end
--get the domain_uuid
domain_uuid = session:getVariable("domain_uuid");
if (domain_uuid == nil) then
--get the domain_uuid using the domain name required for multi-tenant
if (domain_name ~= nil) then
sql = "SELECT domain_uuid FROM v_domains ";
sql = sql .. "WHERE domain_name = '" .. domain_name .. "' ";
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[forward_on_busy] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(rows)
domain_uuid = rows["domain_uuid"];
end);
end
end
domain_uuid = string.lower(domain_uuid);
if ( debug["info"] ) then
freeswitch.consoleLog("info", "[forward_on_busy] originate_disposition: " .. originate_disposition .. "\n");
freeswitch.consoleLog("info", "[forward_on_busy] dialed_extension : " .. dialed_extension .. "\n");
end
if (dialed_extension ~= nil) then
if (session:ready()) then
--get the information from the database
sql = [[SELECT * FROM v_extensions
WHERE domain_uuid = ']] .. domain_uuid ..[['
AND extension = ']] .. dialed_extension ..[['
AND forward_busy_enabled = 'true' ]];
if (debug["sql"]) then
freeswitch.consoleLog("notice", "[forward_on_busy] SQL: " .. sql .. "\n");
end
status = dbh:query(sql, function(row)
forward_busy_destination = string.lower(row["forward_busy_destination"]);
end);
--set default values
if (forward_busy_destination ~= nil and string.len(forward_busy_destination) > 0 ) then
if ( debug["info"] ) then
freeswitch.consoleLog("notice", "[forward_on_busy] forward_busy_destination: " .. forward_busy_destination .. "\n");
end
session:transfer(forward_busy_destination, "XML", context);
forward = true;
else
if ( debug["info"] ) then
freeswitch.consoleLog("notice", "[forward_on_busy] forward on busy disabled or destination unset - HANGUP WITH USER BUSY \n");
end
if (send_to_voicemail == "false") then
session:hangup("USER_BUSY");
end
forward = false;
end
end
end
end
end
--close the database connection
dbh:release();
return forward;