From 71ed94d7048b97dd804900fb6fba987b26d5a32a Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 12 Feb 2013 14:10:08 +0100 Subject: call parking dialplan function added --- misc/freeswitch/scripts/dialplan/functions.lua | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index 4430be1..acfa336 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -111,8 +111,8 @@ function Functions.dialplan_function(self, caller, dialed_number) result = "+" .. tostring(parameters[3]); elseif fid == "hangup" then result = self:hangup(caller, parameters[3], parameters[4]); - elseif fid == "park" then - result = self:park(caller, parameters[3]); + elseif fid == "cpa" then + result = self:call_parking_inout(caller, parameters[3], parameters[4]); end return result; @@ -898,6 +898,7 @@ function Functions.acd_membership_toggle(self, caller, agent_id, phone_number) return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end + function Functions.hangup(self, caller, code, phrase) require 'common.str' @@ -914,8 +915,20 @@ function Functions.hangup(self, caller, code, phrase) return { continue = false, code = code, phrase = phrase:gsub('_', ' '), no_cdr = true } end -function Functions.park(self, caller, lot) - self.log:info("FUNCTION_PARK lot: ", lot); - caller:execute("valet_park", 'valet_lot ' .. lot); + +function Functions.call_parking_inout(self, caller, stall_name, lot_name) + require 'dialplan.call_parking'; + local parking_stall = dialplan.call_parking.CallParking:new{ log = self.log, database = self.database, caller = caller }:find_by_name(stall_name); + + if not parking_stall then + return { continue = false, code = 404, phrase = 'Parking stall not found', no_cdr = true } + end + + if lot_name and parking_stall.lot ~= lot_name then + return { continue = false, code = 404, phrase = 'Parking lot not found', no_cdr = true } + end + + parking_stall:park_retrieve(); + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end -- cgit v1.2.3 From fbdb5dca9b3979010b87b16fcb3bf9410c453e91 Mon Sep 17 00:00:00 2001 From: spag Date: Tue, 12 Feb 2013 14:10:26 +0100 Subject: call parking class added --- misc/freeswitch/scripts/dialplan/call_parking.lua | 83 +++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 misc/freeswitch/scripts/dialplan/call_parking.lua (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/call_parking.lua b/misc/freeswitch/scripts/dialplan/call_parking.lua new file mode 100644 index 0000000..cc2cf4b --- /dev/null +++ b/misc/freeswitch/scripts/dialplan/call_parking.lua @@ -0,0 +1,83 @@ +-- Gemeinschaft 5 module: call parking class +-- (c) AMOOMA GmbH 2013 +-- + +module(...,package.seeall) + +PARKING_STALL_FORMAT = '[0-9A-Z_%+%-]+'; +UUID_FORMAT = '[0-9a-f%-]+'; + +CallParking = {} + +-- create acd object +function CallParking.new(self, arg) + arg = arg or {} + object = arg.object or {} + setmetatable(object, self); + self.__index = self; + self.class = 'parkingstall'; + self.log = arg.log; + self.database = arg.database; + self.lot = arg.lot or 'default'; + self.caller = arg.caller; + return object; +end + + +function CallParking.find_by_name(self, name) + local sql_query = 'SELECT * FROM `parking_stalls` WHERE `name`= '.. self.database:escape(name, '"') .. ' LIMIT 1'; + local parking_stall = nil; + + self.database:query(sql_query, function(entry) + parking_stall = CallParking:new(self); + parking_stall.record = entry; + parking_stall.id = tonumber(entry.id); + parking_stall.name = entry.name; + end) + + return parking_stall; +end + + +function CallParking.list_occupied(self, lot) + lot = lot or self.lot; + + require 'common.fapi' + local valet_info = common.fapi.FApi:new{ log = self.log }:execute('valet_info', lot); + + local parking_stalls = {}; + tostring(valet_info):gsub('(' .. PARKING_STALL_FORMAT .. ')', function(channel_uuid, parking_stall) + parking_stalls[parking_stall] = channel_uuid; + end); + + return parking_stalls; +end + + +function CallParking.occupied(self) + local occupied_stalls = self:list_occupied(); + if occupied_stalls then + return occupied_stalls[self.name]; + end +end + + +function CallParking.park_retrieve(self) + self.caller:execute("valet_park", self.lot .. ' ' .. self.name); +end + + +function CallParking.park(self) + if self:occupied() then + return false; + end + self.caller:execute("valet_park", self.lot .. ' ' .. self.name); +end + + +function CallParking.retrieve(self) + if not self:occupied() then + return false; + end + self.caller:execute("valet_park", self.lot .. ' ' .. self.name); +end -- cgit v1.2.3 From 2fc71d2c420fcb328165f91806080367a9fa2928 Mon Sep 17 00:00:00 2001 From: spag Date: Wed, 13 Feb 2013 12:13:19 +0100 Subject: dialplan language handling --- misc/freeswitch/scripts/dialplan/dialplan.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 72503e5..b27bb9d 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -270,7 +270,10 @@ function Dialplan.retrieve_caller_data(self) for index, caller_number in ipairs(self.caller.caller_phone_numbers) do self.caller.caller_phone_numbers_hash[caller_number] = true; end - self.log:info('CALLER_DATA - caller account: ', self.caller.account.class, '=', self.caller.account.id, '/', self.caller.account.uuid, ', phone_numbers: ', #self.caller.caller_phone_numbers); + if not common.str.blank(self.caller.account.record.language_code) then + self.caller.language = self.caller.account.record.language_code; + end + self.log:info('CALLER_DATA - caller account: ', self.caller.account.class, '=', self.caller.account.id, '/', self.caller.account.uuid, ', phone_numbers: ', #self.caller.caller_phone_numbers, ', language: ', self.caller.language); if self.caller.account.owner then self.log:info('CALLER_DATA - caller owner: ', self.caller.account.owner.class, '=', self.caller.account.owner.id, '/', self.caller.account.owner.uuid); else @@ -859,7 +862,6 @@ function Dialplan.run(self, destination) self.caller:set_variable('hangup_after_bridge', false); self.caller:set_variable('bridge_early_media', 'true'); - self.caller:set_variable('default_language', self.default_language); self.caller:set_variable('gs_save_cdr', true); self.caller:set_variable('gs_call_service', 'dial'); self.caller.session:setAutoHangup(false); @@ -876,6 +878,8 @@ function Dialplan.run(self, destination) self:retrieve_caller_data(); self.route_failover = common.configuration_table.get(self.database, 'call_route', 'failover'); + self.caller.language = self.caller.language or self.default_language; + if not destination or destination.type == 'unknown' then local route = nil; if self.caller.gateway then @@ -937,7 +941,9 @@ function Dialplan.run(self, destination) end end - self.log:info('DIALPLAN start - caller_id: ',self.caller.caller_id_number, ' "', self.caller.caller_id_name, '" , number: ', destination.number); + self.caller:set_variable('default_language', self.caller.language); + self.caller:set_variable('sound_prefix', common.str.try(self.config, 'sounds.' .. tostring(self.caller.language))); + self.log:info('DIALPLAN start - caller_id: ',self.caller.caller_id_number, ' "', self.caller.caller_id_name, '" , number: ', destination.number, ', language: ', self.caller.language); local result = { continue = false }; local loop = self.caller.loop_count; -- cgit v1.2.3