From 8bd98f826bd3d8d2c1eec96de18ed6fbc97f05aa Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Fri, 21 Jul 2017 18:05:08 -0600 Subject: [PATCH] Update index.lua --- .../install/scripts/app/ring_groups/index.lua | 93 ++++++++++++------- 1 file changed, 61 insertions(+), 32 deletions(-) diff --git a/resources/install/scripts/app/ring_groups/index.lua b/resources/install/scripts/app/ring_groups/index.lua index f3863b1c97..b4144c5a80 100644 --- a/resources/install/scripts/app/ring_groups/index.lua +++ b/resources/install/scripts/app/ring_groups/index.lua @@ -27,7 +27,8 @@ -- Mark J Crane -- Luis Daniel Lucio Qurioz -local log = require "resources.functions.log".ring_group +--include the log + local log = require "resources.functions.log".ring_group --connect to the database local Database = require "resources.functions.database"; @@ -47,26 +48,57 @@ local log = require "resources.functions.log".ring_group require "resources.functions.channel_utils" require "resources.functions.format_ringback" ---get the variables - domain_name = session:getVariable("domain_name"); - ring_group_uuid = session:getVariable("ring_group_uuid"); - recordings_dir = session:getVariable("recordings_dir"); - sounds_dir = session:getVariable("sounds_dir"); +--define the session hangup + function session_hangup_hook() ---variables that don't require ${} when used in the dialplan conditions - username = session:getVariable("username"); - dialplan = session:getVariable("dialplan"); - caller_id_name = session:getVariable("caller_id_name"); - caller_id_number = session:getVariable("caller_id_number"); - network_addr = session:getVariable("network_addr"); - ani = session:getVariable("ani"); - aniii = session:getVariable("aniii"); - rdnis = session:getVariable("rdnis"); - destination_number = session:getVariable("destination_number"); - source = session:getVariable("source"); - uuid = session:getVariable("uuid"); - context = session:getVariable("context"); - call_direction = session:getVariable("call_direction"); + --send info to the log + --freeswitch.consoleLog("notice","[ring_groups] originate_disposition: " .. session:getVariable("originate_disposition") .. "\n"); + + --run the missed called function + if ( + session:getVariable("originate_disposition") == "ALLOTTED_TIMEOUT" + or session:getVariable("originate_disposition") == "NO_ANSWER" + or session:getVariable("originate_disposition") == "NO_USER_RESPONSE" + or session:getVariable("originate_disposition") == "USER_NOT_REGISTERED" + or session:getVariable("originate_disposition") == "NORMAL_TEMPORARY_FAILURE" + or session:getVariable("originate_disposition") == "NO_ROUTE_DESTINATION" + or session:getVariable("originate_disposition") == "USER_BUSY" + or session:getVariable("originate_disposition") == "RECOVERY_ON_TIMER_EXPIRE" + or session:getVariable("originate_disposition") == "failure" + or session:getVariable("originate_disposition") == "ORIGINATOR_CANCEL" + ) then + --send missed call notification + missed(); + end + + end + +--set the hangup hook function + if (session:ready()) then + session:setHangupHook("session_hangup_hook"); + end + +--get the variables + if (session:ready()) then + session:setAutoHangup(false); + domain_name = session:getVariable("domain_name"); + ring_group_uuid = session:getVariable("ring_group_uuid"); + recordings_dir = session:getVariable("recordings_dir"); + sounds_dir = session:getVariable("sounds_dir"); + username = session:getVariable("username"); + dialplan = session:getVariable("dialplan"); + caller_id_name = session:getVariable("caller_id_name"); + caller_id_number = session:getVariable("caller_id_number"); + network_addr = session:getVariable("network_addr"); + ani = session:getVariable("ani"); + aniii = session:getVariable("aniii"); + rdnis = session:getVariable("rdnis"); + destination_number = session:getVariable("destination_number"); + source = session:getVariable("source"); + uuid = session:getVariable("uuid"); + context = session:getVariable("context"); + call_direction = session:getVariable("call_direction"); + end --default to local if nil if (call_direction == nil) then @@ -83,12 +115,14 @@ local log = require "resources.functions.log".ring_group external = "false"; --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 (session:ready()) then + default_language = session:getVariable("default_language"); + default_dialect = session:getVariable("default_dialect"); + default_voice = session:getVariable("default_voice"); + if (not default_language) then default_language = 'en'; end + if (not default_dialect) then default_dialect = 'us'; end + if (not default_voice) then default_voice = 'callie'; end + end --get record_ext record_ext = session:getVariable("record_ext"); @@ -655,15 +689,11 @@ local log = require "resources.functions.log".ring_group or session:getVariable("originate_disposition") == "RECOVERY_ON_TIMER_EXPIRE" or session:getVariable("originate_disposition") == "failure" ) then - --send missed call notification - missed(); --execute the time out action session:execute(ring_group_timeout_app, ring_group_timeout_data); end else if (ring_group_timeout_app ~= nil) then - --send missed call notification - missed(); --execute the time out action session:execute(ring_group_timeout_app, ring_group_timeout_data); else @@ -674,14 +704,13 @@ local log = require "resources.functions.log".ring_group freeswitch.consoleLog("notice", "[ring group] SQL:" .. sql .. "; params:" .. json.encode(params) .. "\n"); end dbh:query(sql, params, function(row) - --send missed call notification - missed(); --execute the time out action session:execute(row.ring_group_timeout_app, row.ring_group_timeout_data); end); end end end + end --actions