From 24613b79d5f81e1490fd4ae32956171a87782fae Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 4 Jan 2013 12:28:28 +0100 Subject: redial function added --- misc/freeswitch/scripts/dialplan/functions.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'misc') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index d208d12..3fa1589 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -51,6 +51,8 @@ function Functions.dialplan_function(self, caller, dialed_number) result = self:user_auto_logout(caller, true); elseif fid == "loaoff" then result = self:user_auto_logout(caller, false); + elseif fid == "redial" then + result = self:redial(caller); elseif fid == "dcliroff" then result = self:dial_clir_off(caller, parameters[3]); elseif fid == "dcliron" then @@ -507,6 +509,24 @@ function Functions.user_auto_logout(self, caller, auto_logout) caller:sleep(1000); end +function Functions.redial(self, caller) + -- Ensure a valid sip account + local caller_sip_account = self:ensure_caller_sip_account(caller); + if not caller_sip_account then + return { continue = false, code = 403, phrase = 'Incompatible caller', no_cdr = true } + end + + local sql_query = 'SELECT `destination_number` FROM `call_histories` WHERE `entry_type` = "dialed" AND `call_historyable_type` = "SipAccount" AND `call_historyable_id` = ' .. caller_sip_account.record.id; + local phone_number = self.database:query_return_value(sql_query); + + common_str = require 'common.str'; + if common_str.blank(phone_number) then + return { continue = false, code = 404, phrase = 'No phone number saved', no_cdr = true } + end + + return { continue = true, number = phone_number } +end + function Functions.dial_clir_off(self, caller, phone_number) -- Ensure a valid sip account local caller_sip_account = self:ensure_caller_sip_account(caller); -- cgit v1.2.3