From ac63ced87d2fa66e5348d92b0427165e0a386f01 Mon Sep 17 00:00:00 2001 From: spag Date: Fri, 4 Jan 2013 11:44:39 +0100 Subject: clir function added --- misc/freeswitch/scripts/dialplan/functions.lua | 48 +++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (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 9a89857..d208d12 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -55,6 +55,10 @@ function Functions.dialplan_function(self, caller, dialed_number) result = self:dial_clir_off(caller, parameters[3]); elseif fid == "dcliron" then result = self:dial_clir_on(caller, parameters[3]); + elseif fid == "cliron" then + result = self:clir_on(caller); + elseif fid == "cliroff" then + result = self:clir_off(caller); elseif fid == "clipon" then result = self:clip_on(caller); elseif fid == "clipoff" then @@ -565,6 +569,48 @@ function Functions.callwaiting_off(self, caller) return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end +function Functions.clir_on(self, caller) + -- Find caller's SipAccount + 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 = 'UPDATE `sip_accounts` SET `clir` = TRUE WHERE `id` = ' .. caller_sip_account.record.id; + + if not self.database:query(sql_query) then + self.log:notice("CLIR could not be set"); + return { continue = false, code = 500, phrase = 'CLIR could not be set', no_cdr = true } + + end + + caller:answer(); + caller:send_display('CLIR on'); + caller:sleep(1000); + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } +end + +function Functions.clir_off(self, caller) + -- Find caller's SipAccount + 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 = 'UPDATE `sip_accounts` SET `clir` = FALSE WHERE `id` = ' .. caller_sip_account.record.id; + + if not self.database:query(sql_query) then + self.log:notice("CLIR could not be set"); + return { continue = false, code = 500, phrase = 'CLIR could not be set', no_cdr = true } + + end + + caller:answer(); + caller:send_display('CLIR off'); + caller:sleep(1000); + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } +end + function Functions.clip_on(self, caller) -- Find caller's SipAccount local caller_sip_account = self:ensure_caller_sip_account(caller); @@ -586,6 +632,7 @@ function Functions.clip_on(self, caller) return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end + function Functions.clip_off(self, caller) -- Find caller's SipAccount local caller_sip_account = self:ensure_caller_sip_account(caller); @@ -607,7 +654,6 @@ function Functions.clip_off(self, caller) return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end - function Functions.call_forwarding_off(self, caller, call_forwarding_service, delete) local defaults = {log = self.log, database = self.database, domain = caller.domain} -- cgit v1.2.3 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/freeswitch/scripts/dialplan/functions.lua') 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 From 495bbfdf78206c8adaec057e83900dda6754092c Mon Sep 17 00:00:00 2001 From: spag Date: Mon, 21 Jan 2013 23:21:48 +0100 Subject: order and limit added to redial query --- misc/freeswitch/scripts/dialplan/functions.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (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 3fa1589..2ca51c8 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -516,7 +516,13 @@ function Functions.redial(self, caller) 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 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 .. ' \ + ORDER BY `start_stamp` DESC LIMIT 1'; + local phone_number = self.database:query_return_value(sql_query); common_str = require 'common.str'; -- cgit v1.2.3