From 972bdbb01785be4d645cfd472ef43c779aaa70b9 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 21 Feb 2013 11:03:47 +0100 Subject: cpai function added --- misc/freeswitch/scripts/dialplan/functions.lua | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'misc/freeswitch/scripts/dialplan/functions.lua') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index acfa336..e65aa32 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -113,6 +113,8 @@ function Functions.dialplan_function(self, caller, dialed_number) result = self:hangup(caller, parameters[3], parameters[4]); elseif fid == "cpa" then result = self:call_parking_inout(caller, parameters[3], parameters[4]); + elseif fid == "cpai" then + result = self:call_parking_inout_index(caller, parameters[3]); end return result; @@ -932,3 +934,39 @@ function Functions.call_parking_inout(self, caller, stall_name, lot_name) return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end + + +function Functions.call_parking_inout_index(self, caller, stall_index) + if not tonumber(stall_index) then + self.log:notice('FUNCTION_CALL_PARKING_INOUT_INDEX - malformed index: ', stall_index); + return { continue = false, code = 404, phrase = 'No parkings stall specified', no_cdr = true } + end + + require 'common.str'; + local owner = common.str.try(caller, 'auth_account.owner'); + + if not owner then + self.log:notice('FUNCTION_CALL_PARKING_INOUT_INDEX - stall owner not specified'); + return { continue = false, code = 404, phrase = 'No parkings stalls owner' , no_cdr = true } + end + + require 'dialplan.call_parking'; + local parking_stalls = dialplan.call_parking.CallParking:new{ log = self.log, database = self.database, caller = caller }:find_by_owner(owner.id, owner.class); + + if not parking_stalls or #parking_stalls < 1 then + self.log:notice('FUNCTION_CALL_PARKING_INOUT_INDEX - no parkings stalls found'); + return { continue = false, code = 404, phrase = 'No parkings stalls', no_cdr = true } + end + + local parking_stall = parking_stalls[tonumber(stall_index)]; + + if not parking_stall then + self.log:notice('FUNCTION_CALL_PARKING_INOUT_INDEX - no parkings stall found with index: ', stall_index); + return { continue = false, code = 404, phrase = 'Parking stall not found', no_cdr = true } + end + + self.log:info('FUNCTION_CALL_PARKING_INOUT_INDEX parking/retrieving call - parkingstall=', parking_stall.id, '/', parking_stall.name, ', index: ', stall_index); + parking_stall:park_retrieve(); + + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } +end -- cgit v1.2.3 From 4d73d669131d06e6a4827b70de037ab2c2c65b1b Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 21 Feb 2013 12:05:29 +0100 Subject: pickup fixed --- misc/freeswitch/scripts/dialplan/functions.lua | 45 +++++++++++++++----------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan/functions.lua') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index e65aa32..eddce74 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -38,7 +38,7 @@ function Functions.dialplan_function(self, caller, dialed_number) elseif fid == "in" then result = self:intercept_extensions(caller, parameters[3]); elseif fid == "ia" then - result = self:intercept_any_extension(caller, parameters[3]); + result = self:intercept_any_number(caller, parameters[3]); elseif fid == "anc" then result = self:account_node_change(caller); elseif fid == "li" then @@ -117,7 +117,7 @@ function Functions.dialplan_function(self, caller, dialed_number) result = self:call_parking_inout_index(caller, parameters[3]); end - return result; + return result or { continue = false, code = 505, phrase = 'Error executing function', no_cdr = true }; end -- Transfer all calls to a conference @@ -178,14 +178,14 @@ end -- intercept call to destination (e.g. sip_account) function Functions.intercept_destination(self, caller, destination) - self.log:debug("Intercept call to destination " .. destination); - local result = false; - local sql_query = 'SELECT `call_uuid`, `uuid` FROM `channels` WHERE `callstate` = "RINGING" AND `dest` = "' .. destination .. '" LIMIT 1'; + self.log:debug('FUNCTION_INTERCEPT_DESTINATION - destination: ', destination); + local result = { continue = false, code = 404, phrase = 'No calls found', no_cdr = true }; + local sql_query = 'SELECT `call_uuid`, `uuid` FROM `detailed_calls` WHERE `callstate` = "RINGING" AND `presence_id` LIKE "' .. destination .. '@%" LIMIT 1'; caller:set_caller_id(caller.caller_phone_numbers[1] ,caller.caller_id_name); self.database:query(sql_query, function(call_entry) if call_entry.call_uuid and tostring(call_entry.call_uuid) then - self.log:debug("intercepting call - uuid: " .. call_entry.call_uuid); + self.log:notice('FUNCTION_INTERCEPT_DESTINATION intercepting call - destination: ', destination, ', call_uuid: ' .. call_entry.call_uuid); caller:intercept(call_entry.call_uuid); result = { continue = false, code = 200, call_service = 'pickup' } require 'common.str' @@ -221,24 +221,31 @@ function Functions.intercept_destination(self, caller, destination) return result; end --- intercept call to owner of destination_number -function Functions.intercept_any_extension(self, caller, destination_number) + +function Functions.intercept_any_number(self, caller, destination_number) require 'common.phone_number' - local phone_number_object = common.phone_number.PhoneNumber:new{ log = self.log, database = self.database }:find_by_number(destination_number); + local phone_number = common.phone_number.PhoneNumber:new{ log = self.log, database = self.database }:find_by_number(destination_number); + + if not phone_number or not phone_number.record then + self.log:notice('FUNCTION_INTERCEPT_ANY_NUMBER - number not found: ', destination_number); + return { continue = false, code = 404, phrase = 'Number not found', no_cdr = true }; + end - if not phone_number_object or not phone_number_object.record then - self.log:notice("unallocated number: " .. tostring(destination_number)); - return false; + if not phone_number.record.phone_numberable_type:lower() == 'sipaccount' or not tonumber(phone_number.record.phone_numberable_id) then + self.log:notice('FUNCTION_INTERCEPT_ANY_NUMBER - destination: ', phone_number.record.phone_numberable_type:lower(), '=', phone_number.record.phone_numberable_id, ', number: ', destination_number); + return { continue = false, code = 505, phrase = 'Incompatible destination', no_cdr = true }; end + + require 'common.sip_account' + local sip_account = common.sip_account.SipAccount:new{ log = self.log, database = self.database }:find_by_id(phone_number.record.phone_numberable_id) - if phone_number_object.record.phone_numberable_type == 'SipAccount' then - require "common.sip_account" - local sip_account_class = common.sip_account.SipAccount:new{ log = self.log, database = self.database } - local sip_account = sip_account_class:find_by_id(phone_number_object.record.phone_numberable_id) - if sip_account then - return self:intercept_destination(caller, sip_account.record.auth_name); - end + if not sip_account then + self.log:notice('FUNCTION_INTERCEPT_ANY_NUMBER - no sip_account found for number: ', destination_number); + return { continue = false, code = 505, phrase = 'Incompatible destination', no_cdr = true }; end + + self.log:info('FUNCTION_INTERCEPT_ANY_NUMBER intercepting call - to: ', phone_number.record.phone_numberable_type:lower(), '=', phone_number.record.phone_numberable_id, ', name: ', sip_account.record.auth_name); + return self:intercept_destination(caller, sip_account.record.auth_name); end -- cgit v1.2.3 From aee59991ee59c6b3a49133ca1afa080d0ead6440 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 21 Feb 2013 14:03:47 +0100 Subject: pickup groups support added --- misc/freeswitch/scripts/dialplan/functions.lua | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan/functions.lua') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index eddce74..b4ebf56 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -236,16 +236,12 @@ function Functions.intercept_any_number(self, caller, destination_number) return { continue = false, code = 505, phrase = 'Incompatible destination', no_cdr = true }; end - require 'common.sip_account' - local sip_account = common.sip_account.SipAccount:new{ log = self.log, database = self.database }:find_by_id(phone_number.record.phone_numberable_id) - - if not sip_account then - self.log:notice('FUNCTION_INTERCEPT_ANY_NUMBER - no sip_account found for number: ', destination_number); - return { continue = false, code = 505, phrase = 'Incompatible destination', no_cdr = true }; - end + self.log:info('FUNCTION_INTERCEPT_ANY_NUMBER intercepting call - to: ', phone_number.record.phone_numberable_type:lower(), '=', phone_number.record.phone_numberable_id, ', number: ', destination_number); - self.log:info('FUNCTION_INTERCEPT_ANY_NUMBER intercepting call - to: ', phone_number.record.phone_numberable_type:lower(), '=', phone_number.record.phone_numberable_id, ', name: ', sip_account.record.auth_name); - return self:intercept_destination(caller, sip_account.record.auth_name); + caller:set_variable('gs_pickup_group_pick', 's' .. phone_number.record.phone_numberable_id); + caller:execute('pickup', 's' .. phone_number.record.phone_numberable_id); + + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end -- cgit v1.2.3 From d6009d77ffa221c14a4536be98a04e8e4b6474a9 Mon Sep 17 00:00:00 2001 From: spag Date: Thu, 21 Feb 2013 16:24:08 +0100 Subject: obsolete functions --- misc/freeswitch/scripts/dialplan/functions.lua | 74 +------------------------- 1 file changed, 1 insertion(+), 73 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan/functions.lua') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index b4ebf56..3706872 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -35,8 +35,6 @@ function Functions.dialplan_function(self, caller, dialed_number) if fid == "ta" then result = self:transfer_all(caller, parameters[3]); - elseif fid == "in" then - result = self:intercept_extensions(caller, parameters[3]); elseif fid == "ia" then result = self:intercept_any_number(caller, parameters[3]); elseif fid == "anc" then @@ -151,76 +149,6 @@ function Functions.transfer_all(self, caller, destination_number) return destination_number; end --- Intercept Extensions -function Functions.intercept_extensions(self, caller, destination_numbers) - if type(destination_numbers) == "string" then - destination_numbers = "\"" .. destination_numbers .. "\""; - else - destination_numbers = "\"" .. table.concat(destination_numbers, "\",\"") .. "\""; - end - - self.log:debug("Intercept call to number(s): " .. destination_numbers); - - if caller.account_type ~= "SipAccount" then - self.log:error("caller is not a SipAccount"); - return { continue = false, code = 403, phrase = 'Incompatible caller' } - end - - local sql_query = 'SELECT * FROM `channels` WHERE `callstate` IN ("EARLY", "ACTIVE") AND `dest` IN (' .. destination_numbers .. ') LIMIT 1'; - - self.database:query(sql_query, function(call_entry) - self.log:debug("intercepting call with uid: " .. call_entry.uuid); - caller:intercept(call_entry.uuid); - end) - - return nil; -end - --- intercept call to destination (e.g. sip_account) -function Functions.intercept_destination(self, caller, destination) - self.log:debug('FUNCTION_INTERCEPT_DESTINATION - destination: ', destination); - local result = { continue = false, code = 404, phrase = 'No calls found', no_cdr = true }; - local sql_query = 'SELECT `call_uuid`, `uuid` FROM `detailed_calls` WHERE `callstate` = "RINGING" AND `presence_id` LIKE "' .. destination .. '@%" LIMIT 1'; - - caller:set_caller_id(caller.caller_phone_numbers[1] ,caller.caller_id_name); - self.database:query(sql_query, function(call_entry) - if call_entry.call_uuid and tostring(call_entry.call_uuid) then - self.log:notice('FUNCTION_INTERCEPT_DESTINATION intercepting call - destination: ', destination, ', call_uuid: ' .. call_entry.call_uuid); - caller:intercept(call_entry.call_uuid); - result = { continue = false, code = 200, call_service = 'pickup' } - require 'common.str' - require 'common.fapi' - local fapi = common.fapi.FApi:new{ log = self.log, uuid = call_entry.call_uuid } - if fapi:channel_exists() then - caller:set_caller_id( - common.str.to_s(fapi:get_variable('effective_caller_id_number')), - common.str.to_s(fapi:get_variable('effective_caller_id_name')) - ); - caller:set_callee_id( - common.str.to_s(fapi:get_variable('effective_callee_id_number')), - common.str.to_s(fapi:get_variable('effective_callee_id_name')) - ); - - caller:set_variable('gs_destination_type', fapi:get_variable('gs_destination_type')); - caller:set_variable('gs_destination_id', fapi:get_variable('gs_destination_id')); - caller:set_variable('gs_destination_uuid', fapi:get_variable('gs_destination_uuid')); - - caller:set_variable('gs_caller_account_type', fapi:get_variable('gs_account_type')); - caller:set_variable('gs_caller_account_id', fapi:get_variable('gs_account_id')); - caller:set_variable('gs_caller_account_uuid', fapi:get_variable('gs_account_uuid')); - - caller:set_variable('gs_auth_account_type', fapi:get_variable('gs_auth_account_type')); - caller:set_variable('gs_auth_account_id', fapi:get_variable('gs_auth_account_id')); - caller:set_variable('gs_auth_account_uuid', fapi:get_variable('gs_auth_account_uuid')); - end - else - self.log:error('FUNCTION - failed to intercept call - no caller uuid for callee uuid: ', call_entry.uuid); - end - end) - - return result; -end - function Functions.intercept_any_number(self, caller, destination_number) require 'common.phone_number' @@ -240,7 +168,7 @@ function Functions.intercept_any_number(self, caller, destination_number) caller:set_variable('gs_pickup_group_pick', 's' .. phone_number.record.phone_numberable_id); caller:execute('pickup', 's' .. phone_number.record.phone_numberable_id); - + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end -- cgit v1.2.3