From d79da64a619f83e06990c372dd1f2787b3109e7a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Mar 2013 15:52:40 +0100 Subject: ivr methods --- misc/freeswitch/scripts/dialplan/ivr.lua | 67 ++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 11 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/ivr.lua b/misc/freeswitch/scripts/dialplan/ivr.lua index f8b8a2d..2a16e3b 100644 --- a/misc/freeswitch/scripts/dialplan/ivr.lua +++ b/misc/freeswitch/scripts/dialplan/ivr.lua @@ -21,29 +21,51 @@ function Ivr.new(self, arg) end -function Ivr.ivr_phrase(self, phrase, keys, timeout, ivr_repeat) +function Ivr.ivr_break(self) + return self.exit or not self.caller:ready(); +end + + +function Ivr.ivr_phrase(self, phrase, keys, timeout, ivr_repeat, phrase_data) ivr_repeat = ivr_repeat or 3; timeout = timeout or 30; self.digit = ''; self.exit = false; self.break_keys = {}; + local query_keys = {}; + for index=1, #keys do - self.break_keys[keys[index]] = true; + if type(keys[index]) == 'table' then + if tostring(keys[index].key) ~= '' then + table.insert(query_keys, keys[index].key); + end + self.break_keys[keys[index].key] = keys[index]; + else + if tostring(keys[index]) ~= '' then + table.insert(query_keys, keys[index]); + end + self.break_keys[keys[index]] = true; + end end global_callback:callback('dtmf', 'ivr_ivr_phrase', self.ivr_phrase_dtmf, self); - + local continue = true; for index=0, ivr_repeat do - self.caller.session:sayPhrase(phrase, table.concat(keys, ':')); - self.caller:sleep(timeout * 1000); - if self.exit then + continue = self:ivr_break() or self.caller.session:sayPhrase(phrase, phrase_data or table.concat(query_keys, ':')); + continue = self:ivr_break() or self.caller:sleep(timeout * 1000); + + if self:ivr_break() then break; end end global_callback:callback_unset('dtmf', 'ivr_ivr_phrase'); + if type(self.break_keys[self.digit]) == 'table' then + return self.digit, self.break_keys[self.digit]; + end + return self.digit; end @@ -66,8 +88,8 @@ function Ivr.read_phrase(self, phrase, phrase_data, max_keys, min_keys, timeout, timeout = timeout or 30; global_callback:callback('dtmf', 'ivr_read_phrase', self.read_phrase_dtmf, self); - self.caller.session:sayPhrase(phrase, phrase_data or enter_key or ''); - self.caller:sleep(timeout * 1000); + local continue = self:ivr_break() or self.caller.session:sayPhrase(phrase, phrase_data or enter_key or ''); + continue = self:ivr_break() or self.caller:sleep(timeout * 1000); global_callback:callback_unset('dtmf', 'ivr_read_phrase'); return self.digits; @@ -88,7 +110,7 @@ function Ivr.read_phrase_dtmf(self, dtmf) end -function Ivr.check_pin(self, phrase, pin, pin_timeout, pin_repeat, key_enter) +function Ivr.check_pin(self, phrase_enter, phrase_incorrect, pin, pin_timeout, pin_repeat, key_enter) if not pin then return nil; end @@ -101,19 +123,42 @@ function Ivr.check_pin(self, phrase, pin, pin_timeout, pin_repeat, key_enter) for i = 1, pin_repeat do if digits == pin then self.caller:send_display('PIN: OK'); - break + break; elseif digits ~= "" then self.caller:send_display('PIN: wrong'); + self.caller.session:sayPhrase(phrase_incorrect, ''); + elseif self:ivr_break() then + break; end self.caller:send_display('Enter PIN'); - digits = ivr:read_phrase(phrase, nil, 0, pin:len() + 1, pin_timeout, key_enter); + digits = ivr:read_phrase(phrase_enter, nil, 0, pin:len() + 1, pin_timeout, key_enter); end if digits ~= pin then self.caller:send_display('PIN: wrong'); + self.caller.session:sayPhrase(phrase_incorrect, ''); return false end self.caller:send_display('PIN: OK'); return true; end + + +function Ivr.record(self, file_name, phrase_record, phrase_too_short, record_length_max, record_length_min, record_repeat, silence_level, silence_lenght_abort) + local duration = nil; + for index=1, record_repeat do + if (duration and duration >= record_length_min) or not self.caller:ready() then + break; + elseif duration then + self.caller:send_display('Recording too short'); + self.caller.session:sayPhrase(phrase_too_short); + end + self.caller.session:sayPhrase(phrase_record); + self.caller:send_display('Recording...'); + local result = self.caller.session:recordFile(file_name, record_length_max, silence_level, silence_lenght_abort); + duration = self.caller:to_i('record_seconds'); + end + + return duration or 0; +end -- cgit v1.2.3 From ecfea29b48d9581725bd6d8a8eb25b090f25b55e Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Mar 2013 15:53:56 +0100 Subject: voicemail_check dialplan function --- misc/freeswitch/scripts/dialplan/functions.lua | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index a47d9d3..6399c5e 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -756,31 +756,28 @@ function Functions.voicemail_message_leave(self, caller, phone_number) end -function Functions.voicemail_check(self, caller, phone_number) +function Functions.voicemail_check(self, caller, number) + require 'dialplan.voicemail'; local voicemail_account = nil; local voicemail_authorized = false; - - require 'dialplan.voicemail' - - if phone_number then - voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_number(phone_number); - else - if caller.auth_account_type == 'SipAccount' then - voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_sip_account_id(caller.auth_account.id); - voicemail_authorized = true; - end + + if number then + voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_number(number); + elseif caller.auth_account and tostring(caller.auth_account.class):lower() == 'sipaccount' then + voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_sip_account_id(caller.auth_account.id); + voicemail_authorized = true; end if not voicemail_account then + self.log:notice('FUNCTION_VOICEMAIL_CHECK - mailbox not found'); return { continue = false, code = 404, phrase = 'Mailbox not found', no_cdr = true } end - voicemail_account:menu(caller, voicemail_authorized); - - return { continue = false, code = 200, phrase = 'OK', no_cdr = true } + return voicemail_account:menu_main(caller, voicemail_authorized); end + function Functions.acd_membership_toggle(self, caller, agent_id, phone_number) -- Find caller's SipAccount local caller_sip_account = self:ensure_caller_sip_account(caller); -- cgit v1.2.3 From 479d5b9353a518e456a68d74e81730eeb4230890 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Mar 2013 15:54:41 +0100 Subject: voicemail refactored --- misc/freeswitch/scripts/dialplan/voicemail.lua | 378 ++++++++++++++++++++----- 1 file changed, 301 insertions(+), 77 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index caeeb48..4fd5612 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -1,17 +1,39 @@ -- Gemeinschaft 5 module: voicemail class --- (c) AMOOMA GmbH 2012-2013 +-- (c) AMOOMA GmbH 2013 -- module(...,package.seeall) Voicemail = {} -MESSAGE_LENGTH_MIN = 3; -MESSAGE_LENGTH_MAX = 120; -SILENCE_LENGTH_ABORT = 5; -SILENCE_LEVEL = 500; -BEEP = 'tone_stream://%(1000,0,500)'; -RECORD_FILE_PREFIX = '/var/spool/freeswitch/voicemail_'; +DEFAULT_SETTINGS = { + pin_length_max = 10, + pin_length_min = 2, + pin_timeout = 20, + key_new_messages = '1', + key_saved_messages = '2', + key_config_menu = '0', + key_terminator = '#', + key_previous = '4', + key_next = '6', + key_delete = '7', + key_save = '2', + key_main_menu = '#', + record_length_max = 300, + record_length_min = 4, + records_max = 100, + silence_lenght_abort = 3, + silence_level = 500, + beep = 'tone_stream://%(1000,0,500)', + record_file_prefix = 'voicemail_', + record_file_suffix = '.wav', + record_file_path = '/var/spool/freeswitch/', + record_repeat = 3, + notify = true, + attachment = true, + mark_read = true, + purge = false, +} -- create voicemail object function Voicemail.new(self, arg) @@ -23,93 +45,313 @@ function Voicemail.new(self, arg) self.log = arg.log; self.database = arg.database; self.record = arg.record; + self.domain = arg.domain; return object end --- find voicemail account by sip account id -function Voicemail.find_by_sip_account_id(self, id) - local sql_query = 'SELECT `a`.`id`, `a`.`uuid`, `a`.`auth_name`, `a`.`caller_name`, `b`.`name_path`, `b`.`greeting_path`, `a`.`voicemail_pin`, `b`.`password`, `c`.`host` AS `domain` \ - FROM `sip_accounts` `a` LEFT JOIN `voicemail_prefs` `b` ON `a`.`auth_name` = `b`.`username` \ - JOIN `sip_domains` `c` ON `a`.`sip_domain_id` = `c`.`id` \ - WHERE `a`.`id` = ' .. tonumber(id); +function Voicemail.find_by_sql(self, sql_query) local voicemail_account = nil; self.database:query(sql_query, function(entry) voicemail_account = Voicemail:new(self); voicemail_account.record = entry; voicemail_account.id = tonumber(entry.id); voicemail_account.uuid = entry.uuid; - end) + voicemail_account.name = entry.name; + voicemail_account.settings = self:settings_get(entry.id); + end); return voicemail_account; end --- Find Voicemail account by name -function Voicemail.find_by_name(self, account_name) - id = tonumber(id) or 0; - local sql_query = string.format('SELECT * FROM `voicemail_prefs` WHERE `username`= "%s" LIMIT 1', account_name) - local record = nil - self.database:query(sql_query, function(voicemail_entry) - record = voicemail_entry - end) +function Voicemail.find_by_name(self, name) + local sql_query = 'SELECT * FROM `voicemail_accounts` \ + WHERE `name` = ' .. self.database:escape(name, '"') .. ' LIMIT 1'; + + return self:find_by_sql(sql_query); +end + + +function Voicemail.find_by_id(self, id) + local sql_query = 'SELECT * FROM `voicemail_accounts` \ + WHERE `id` = ' .. self.database:escape(id, '"') .. ' LIMIT 1'; + + return self:find_by_sql(sql_query); +end + + +function Voicemail.find_by_sip_account_id(self, id) + local sql_query = 'SELECT `a`.* FROM `voicemail_accounts` `a` \ + JOIN `sip_accounts` `b` ON `a`.`id` = `b`.`voicemail_account_id` \ + WHERE `b`.`id` = ' .. self.database:escape(id, '"') .. ' LIMIT 1'; + + return self:find_by_sql(sql_query); +end + + +function Voicemail.find_by_number(self, number) + local sql_query = 'SELECT `a`.* FROM `voicemail_accounts` `a` \ + JOIN `sip_accounts` `b` ON `a`.`id` = `b`.`voicemail_account_id` \ + JOIN `phone_numbers` `c` ON `b`.`id` = `c`.`phone_numberable_id` \ + WHERE `c`.`number` = ' .. self.database:escape(number, '"') .. ' \ + AND `c`.`phone_numberable_type` = "SipAccount" LIMIT 1'; + + return self:find_by_sql(sql_query); +end + + +function Voicemail.settings_get(self, id) + require 'common.configuration_table'; + local parameters = common.configuration_table.get(self.database, 'voicemail', 'settings', { settings = DEFAULT_SETTINGS }); - if voicemail_account then - voicemail_account.account_name = account_name; - if record then - voicemail_account.name_path = record.name_path; - voicemail_account.greeting_path = record.greeting_path; - voicemail_account.password = record.password; + return common.configuration_table.settings(self.database, 'voicemail_settings', 'voicemail_account_id', id or self.id, parameters) +end + + +function Voicemail.messages_get(self, status) + local sql_query = 'SELECT * FROM `voicemail_msgs` WHERE `username` = ' .. self.database:escape(self.name, '"'); + + status = status or 'all'; + + if status == 'read' then + sql_query = sql_query .. ' AND `read_epoch` > 0'; + elseif status == 'unread' then + sql_query = sql_query .. ' AND (`read_epoch` = 0 OR `read_epoch` IS NULL)'; + elseif status == 'new' then + sql_query = sql_query .. ' AND `in_folder` != "save" AND `flags` != "save"'; + elseif status == 'saved' then + sql_query = sql_query .. ' AND (`in_folder` = "save" OR `flags` = "save")'; + end + + return self.database:query_return_all(sql_query); +end + + +function Voicemail.check_pin(self, pin) + self.caller:answer(); + self.caller:sleep(1000); + + require 'dialplan.ivr'; + local ivr = dialplan.ivr.Ivr:new{ caller = self.caller, log = self.log }; + + local digits = ''; + for i = 1, 3 do + if digits == pin then + self.caller:send_display('PIN: OK'); + break + elseif digits ~= "" then + self.caller:send_display('PIN: wrong'); end + self.caller:send_display('Enter PIN'); + digits = ivr:read_phrase('voicemail_enter_pass', nil, self.settings.pin_length_min, self.settings.pin_length_max, self.settings.pin_timeout, self.settings.terminator_key); + end + + if digits ~= pin then + return false + end + + return true; +end + + +function Voicemail.menu_main(self, caller, authorized) + self.caller = caller; + + require 'dialplan.ivr'; + self.ivr = dialplan.ivr.Ivr:new{ caller = self.caller, log = self.log }; + + if not authorized then + if common.str.blank(self.pin) then + self.log:notice('VOICEMAIL_MAIN_MENU - unaunthorized, no PIN, ', self.class, '=', self.id, '/', self.uuid, '|', self.name); + return { continue = false, code = 500, phrase = 'Unauthorized', no_cdr = true } + end + + self.caller:answer(); + self.caller:sleep(1000); + + if not self.ivr:check_pin('voicemail_enter_pass', 'voicemail_fail_auth', self.pin) then + self.log:notice('VOICEMAIL_MAIN_MENU - wrong PIN, ', self.class, '=', self.id, '/', self.uuid, '|', self.name); + caller.session:sayPhrase('voicemail_goodbye'); + return { continue = false, code = 500, phrase = 'Unauthorized', no_cdr = true } + end + end + + local messages_new = self:messages_get('unread'); + local messages_saved = self:messages_get('read'); + + if not caller:answered() then + self.caller:answer(); + self.caller:sleep(1000); end - return voicemail_account + if self.settings.voicemail_hello then + caller.session:sayPhrase('voicemail_hello'); + end + + if self.settings.voicemail_message_count then + caller.session:sayPhrase('voicemail_message_count', #messages_new .. ':new'); + end + + while true do + self.log:info('VOICEMAIL_MAIN_MENU - ', self.class, '=', self.id, '/', self.uuid, '|', self.name, ', messages: ', #messages_new, ':', #messages_saved); + self.caller:send_display(#messages_new .. ' new messages'); + + local main_menu = { + { key = self.settings.key_new_messages, method = self.menu_messages, parameters = { self, 'new', messages_new } }, + { key = self.settings.key_saved_messages, method = self.menu_messages, parameters = { self, 'saved', messages_saved } }, + { key = self.settings.key_config_menu, method = self.menu_options, parameters = { self } }, + { key = self.settings.key_terminator, exit = true }, + { key = '', exit = true }, + }; + + local digits, key = self.ivr:ivr_phrase('voicemail_menu', main_menu); + self.log:debug('VOICEMAIL_MAIN_MENU - digit: ', digits); + if key.exit then + break; + end + + key.method(unpack(key.parameters)); + + messages_new = self:messages_get('unread'); + messages_saved = self:messages_get('read'); + end + self.caller:send_display('Goodbye'); + caller.session:sayPhrase('voicemail_goodbye'); end --- Find Voicemail account by number -function Voicemail.find_by_number(self, phone_number) - local sip_account = nil; - require "common.phone_number" - local destination_number_object = common.phone_number.PhoneNumber:new{ log = self.log, database = self.database }:find_by_number(phone_number); - if destination_number_object and destination_number_object.record.phone_numberable_type:lower() == "sipaccount" then - return self:find_by_sip_account_id(destination_number_object.record.phone_numberable_id); +function Voicemail.menu_messages(self, folder, messages) + self.log:info('VOICEMAIL_MESSAGES_MENU - ', folder,' messages: ', #messages); + + local digits = nil; + local key = nil; + + local message_menu = { + { key = self.settings.key_previous, action = 'previous' }, + { key = self.settings.key_delete, action = 'delete' }, + { key = self.settings.key_save, action = 'save' }, + { key = self.settings.key_next, action = 'next' }, + { key = self.settings.key_main_menu, exit = true }, + }; + + if folder == 'saved' then + message_menu = { + { key = self.settings.key_previous, action = 'previous' }, + { key = self.settings.key_delete, action = 'delete' }, + { key = self.settings.key_next, action = 'next' }, + { key = self.settings.key_main_menu, exit = true }, + }; + end + + if #messages == 0 then + digits, key = self.ivr:ivr_phrase('voicemail_no_messages', message_menu, 0, 0); + return; end - return false; + local index = 1; + while index <= #messages do + local message = messages[index]; + self.caller:send_display(index .. ': ' .. message.cid_name .. ' ' .. message.cid_number); + digits, key = self.ivr:ivr_phrase('voicemail_message_play', message_menu, 0, 0, + index .. ':' .. message.created_epoch .. ':' .. message.file_path + ); + if digits == '' then + if common.str.to_i(message.read_epoch) == 0 then + self:message_mark_read(message); + end + digits, key = self.ivr:ivr_phrase('voicemail_message_menu_' .. folder, message_menu, 15, 0); + end + + if not key or key.exit then + break; + end + + if key.action == 'previous' then + if index > 1 then + index = index - 1; + end + else + index = index + 1; + end + + if index > #messages then + digits, key = self.ivr:ivr_phrase('voicemail_no_messages', message_menu, 0, 0); + return; + end + + if key.action == 'delete' and self:message_delete(message) then + self.caller:send_display('Message deleted'); + digits = self.caller.session:sayPhrase('voicemail_ack', 'deleted'); + elseif key.action == 'save' and self:message_save(message) then + self.caller:send_display('Message saved'); + digits = self.caller.session:sayPhrase('voicemail_ack', 'saved'); + end + end end -function Voicemail.leave(self, caller, phone_number) - require 'common.str' +function Voicemail.menu_options(self) + self.log:info('VOICEMAIL_OPTIONS_MENU'); + self.caller:send_display('Voicemail options'); +end + + +function Voicemail.message_delete(self, message) + self.log:debug('VOICEMAIL_MESSAGE_DELETE - message: ', message.uuid); + require 'common.fapi'; + return common.fapi.FApi:new{ log = self.log }:execute('vm_delete', message.username .. '@' .. message.domain .. ' ' .. message.uuid); +end + +function Voicemail.message_mark_read(self, message) + self.log:debug('VOICEMAIL_MESSAGE_MARK_READ - message: ', message.uuid); + require 'common.fapi'; + return common.fapi.FApi:new{ log = self.log }:execute('vm_read', message.username .. '@' .. message.domain .. ' read ' .. message.uuid); +end - self.log:info('VOICEMAIL_LEAVE - account=', self.record.id, '/', self.record.uuid, ', auth_name: ', self.record.auth_name, ', caller_name: ', self.record.caller_name); - caller:set_callee_id(phone_number, self.record.caller_name); +function Voicemail.message_save(self, message) + self.log:debug('VOICEMAIL_MESSAGE_SAVE - message: ', message.uuid); + require 'common.fapi'; + return common.fapi.FApi:new{ log = self.log }:execute('vm_fsdb_msg_save', 'default ' .. message.domain .. ' ' .. message.username .. ' ' .. message.uuid); +end + + +function Voicemail.leave(self, caller, greeting) + local forwarding_number = caller.forwarding_number; + self.log:info('VOICEMAIL_LEAVE - voicemail_account=', self.record.id, '/', self.record.uuid, '|', self.record.name, ', forwarding_number: ', forwarding_number); + + caller:set_callee_id(forwarding_number, common.array.try(caller, 'auth_account.caller_name') or common.array.try(caller, 'auth_account.name')); caller:answer(); - caller:send_display(common.str.to_s(self.record.caller_name), common.str.to_s(phone_number)); + caller:send_display(common.array.try(caller, 'auth_account.caller_name') or common.array.try(caller, 'auth_account.name')); caller:sleep(1000); - if not common.str.blank(self.record.greeting_path) then - caller.session:sayPhrase('voicemail_play_greeting', 'greeting:' .. tostring(self.record.greeting_path)); - elseif not common.str.blank(self.record.name_path) then - caller.session:sayPhrase('voicemail_play_greeting', 'name:' .. tostring(self.record.name_path)); - elseif not common.str.blank(phone_number) then - caller.session:sayPhrase('voicemail_play_greeting', (tostring(phone_number):gsub('[%D]', ''))); + if not common.str.blank(forwarding_number) then + caller.session:sayPhrase('voicemail_play_greeting', (tostring(forwarding_number):gsub('[%D]', ''))); end - local record_file_name = RECORD_FILE_PREFIX .. caller.uuid .. '.wav'; - caller.session:streamFile(BEEP); + local record_file_name = self.settings.record_file_path ..self.settings.record_file_prefix .. caller.uuid .. self.settings.record_file_suffix; self.log:info('VOICEMAIL_LEAVE - recording to file: ', tostring(record_file_name)); - local result = caller.session:recordFile(record_file_name, MESSAGE_LENGTH_MAX, SILENCE_LEVEL, SILENCE_LENGTH_ABORT); - local duration = caller:to_i('record_seconds'); + + require 'dialplan.ivr'; + local ivr = dialplan.ivr.Ivr:new{ caller = caller, log = self.log }; + + local duration = ivr:record( + record_file_name, + 'voicemail_record_message', + 'voicemail_message_too_short', + self.settings.record_length_max, + self.settings.record_length_min, + self.settings.record_repeat, + self.settings.silence_level, + self.settings.silence_lenght_abort); - if duration >= MESSAGE_LENGTH_MIN then + if duration >= self.settings.record_length_min then self.log:info('VOICEMAIL_LEAVE - saving recorded message to voicemail, duration: ', duration); require 'common.fapi' common.fapi.FApi:new{ log = self.log, uuid = caller.uuid }:execute('vm_inject', - self.record.auth_name .. - '@' .. self.record.domain .. " '" .. + self.record.name .. + '@' .. self.domain .. " '" .. record_file_name .. "' '" .. caller.caller_id_number .. "' '" .. caller.caller_id_name .. "' '" .. @@ -121,32 +363,14 @@ function Voicemail.leave(self, caller, phone_number) caller:set_variable('voicemail_message_len'); end os.remove(record_file_name); - return true; + caller:send_display('Goodbye'); + caller.session:sayPhrase('voicemail_goodbye'); end function Voicemail.trigger_notification(self, caller) - local command = 'http_request.lua ' .. caller.uuid .. ' http://127.0.0.1/trigger/voicemail?sip_account_id=' .. tostring(self.id); + local command = 'http_request.lua ' .. caller.uuid .. ' http://127.0.0.1/trigger/voicemail?voicemail_account_id=' .. tostring(self.id); - require 'common.fapi' + require 'common.fapi'; return common.fapi.FApi:new():execute('luarun', command); end - - -function Voicemail.menu(self, caller, authorized) - self.log:info('VOICEMAIL_MENU - account: ', self.record.auth_name); - - if authorized then - caller:set_variable('voicemail_authorized', true); - end - - caller:set_callee_id(phone_number, self.record.caller_name); - caller:answer(); - caller:send_display(common.str.to_s(self.record.caller_name), common.str.to_s(phone_number)); - - caller:sleep(1000); - caller:set_variable('skip_greeting', true); - caller:set_variable('skip_instructions', true); - - caller:execute('voicemail', 'check default ' .. self.record.domain .. ' ' .. self.record.auth_name); -end -- cgit v1.2.3 From ed7625053860e646824e3213dbff96c312e4c9b7 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 26 Mar 2013 15:55:17 +0100 Subject: voicemail dialplan method --- misc/freeswitch/scripts/dialplan/dialplan.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 5335328..7ed835b 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -590,19 +590,21 @@ end function Dialplan.voicemail(self, destination) - require 'dialplan.voicemail' + require 'dialplan.voicemail'; local voicemail_account = nil; - - local sip_account_id - if not common.str.blank(destination.number) and false then - voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_number(destination.number); + if common.str.to_i(destination.id) > 0 then + voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_id(destination.id); + elseif not common.str.blank(destination.number) then + voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_number(destination.number); elseif self.caller.auth_account and self.caller.auth_account.class == 'sipaccount' then - voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_sip_account_id(self.caller.auth_account.id); + voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_sip_account_id(self.caller.auth_account.id); + elseif self.caller.forwarding_number then + voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_number(self.caller.forwarding_number); end if not voicemail_account then - self.log:error('VOICEMAIL - no mailbox'); + self.log:error('VOICEMAIL - mailbox not found, '); return { continue = false, code = 404, phrase = 'Mailbox not found' } end -- cgit v1.2.3 From 8e9f9fd6f76356c18f43a1a1526e5a5ac40bb1f5 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 27 Mar 2013 08:20:46 +0100 Subject: deletion of last message fixed --- misc/freeswitch/scripts/dialplan/voicemail.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index 4fd5612..522f9c2 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -275,11 +275,6 @@ function Voicemail.menu_messages(self, folder, messages) index = index + 1; end - if index > #messages then - digits, key = self.ivr:ivr_phrase('voicemail_no_messages', message_menu, 0, 0); - return; - end - if key.action == 'delete' and self:message_delete(message) then self.caller:send_display('Message deleted'); digits = self.caller.session:sayPhrase('voicemail_ack', 'deleted'); @@ -287,6 +282,9 @@ function Voicemail.menu_messages(self, folder, messages) self.caller:send_display('Message saved'); digits = self.caller.session:sayPhrase('voicemail_ack', 'saved'); end + if index > #messages then + digits = self.ivr:ivr_phrase('voicemail_no_messages', message_menu, 0, 0); + end end end -- cgit v1.2.3 From 24a63bc91adf2b9c8d3869be80a0654b22de2636 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 27 Mar 2013 08:23:55 +0100 Subject: messages count --- misc/freeswitch/scripts/dialplan/voicemail.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index 522f9c2..eaa8064 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -189,7 +189,7 @@ function Voicemail.menu_main(self, caller, authorized) caller.session:sayPhrase('voicemail_hello'); end - if self.settings.voicemail_message_count then + if #messages_new > 0 then caller.session:sayPhrase('voicemail_message_count', #messages_new .. ':new'); end -- cgit v1.2.3 From c2e5547c22d2021bfa0dbafadd55723485e1c7d1 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 27 Mar 2013 10:37:12 +0100 Subject: handle voicemailaccount destinations --- misc/freeswitch/scripts/dialplan/dialplan.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index 7ed835b..31b88fd 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -711,7 +711,7 @@ function Dialplan.switch(self, destination) end end return result; - elseif destination.type == 'voicemail' then + elseif destination.type == 'voicemail' or destination.type == 'voicemailaccount' then return self:voicemail(destination); elseif destination.type == 'dialplanfunction' then return self:dialplanfunction(destination); -- cgit v1.2.3 From 22ba2cab06b81120d8ac3ff99815fab293566932 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 27 Mar 2013 15:58:39 +0100 Subject: log line deleted --- misc/freeswitch/scripts/dialplan/hunt_group.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/hunt_group.lua b/misc/freeswitch/scripts/dialplan/hunt_group.lua index b1728c3..e87c6b2 100644 --- a/misc/freeswitch/scripts/dialplan/hunt_group.lua +++ b/misc/freeswitch/scripts/dialplan/hunt_group.lua @@ -108,7 +108,6 @@ function HuntGroup.run(self, dialplan_object, caller, destination) table.insert(caller.caller_id_numbers, number); end - self.log:debug('HUNTGROUP ', self.record.id, ' - auth: ', caller.auth_account.class, '=', caller.auth_account.id, '/', caller.auth_account.uuid, ', caller: ', caller.account.class, '=', caller.account.id, '/', caller.account.uuid); self.log:info('HUNTGROUP ', self.record.id, ' - clir: ', caller.clir, ', caller_id_numbers: ', table.concat(caller.caller_id_numbers, ',')); local hunt_group_destination = caller.destination; -- cgit v1.2.3 From 6c8f3e9536da2e8364de6696f8e0bb38032d067c Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 28 Mar 2013 09:09:57 +0100 Subject: vmplay dialplan function added --- misc/freeswitch/scripts/dialplan/functions.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index 6399c5e..ce99953 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -102,6 +102,8 @@ function Functions.dialplan_function(self, caller, dialed_number) result = self:voicemail_message_leave(caller, parameters[3]); elseif fid == "vmcheck" then result = self:voicemail_check(caller, parameters[3]); + elseif fid == "vmplay" then + result = self:voicemail_play(caller, tostring(parameters[3]) .. '-' .. tostring(parameters[4]) .. '-' .. tostring(parameters[5]) .. '-' .. tostring(parameters[6]) .. '-' .. tostring(parameters[7])); elseif fid == "vmtg" then result = self:call_forwarding_toggle(caller, nil, parameters[3]); elseif fid == "acdmtg" then @@ -777,6 +779,18 @@ function Functions.voicemail_check(self, caller, number) end +function Functions.voicemail_play(self, caller, uuid) + require 'dialplan.voicemail'; + + local voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database }:find_by_sip_account_id(caller.auth_account.id); + + if voicemail_account then + local message = voicemail_account:message_play(caller, uuid); + end + + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } +end + function Functions.acd_membership_toggle(self, caller, agent_id, phone_number) -- Find caller's SipAccount -- cgit v1.2.3 From 19b259d1bcba979b6af0b494029ed8be547afa45 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 28 Mar 2013 09:12:47 +0100 Subject: options menu added --- misc/freeswitch/scripts/dialplan/voicemail.lua | 72 +++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 6 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index eaa8064..bdbb223 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -109,6 +109,12 @@ function Voicemail.settings_get(self, id) end +function Voicemail.find_message_by_uuid(self, uuid) + local sql_query = 'SELECT * FROM `voicemail_msgs` WHERE `uuid` = ' .. self.database:escape(uuid, '"') .. ' LIMIT 1'; + return self.database:query_return_first(sql_query); +end + + function Voicemail.messages_get(self, status) local sql_query = 'SELECT * FROM `voicemail_msgs` WHERE `username` = ' .. self.database:escape(self.name, '"'); @@ -289,12 +295,6 @@ function Voicemail.menu_messages(self, folder, messages) end -function Voicemail.menu_options(self) - self.log:info('VOICEMAIL_OPTIONS_MENU'); - self.caller:send_display('Voicemail options'); -end - - function Voicemail.message_delete(self, message) self.log:debug('VOICEMAIL_MESSAGE_DELETE - message: ', message.uuid); require 'common.fapi'; @@ -372,3 +372,63 @@ function Voicemail.trigger_notification(self, caller) require 'common.fapi'; return common.fapi.FApi:new():execute('luarun', command); end + + +function Voicemail.message_play(self, caller, uuid) + local message = self:find_message_by_uuid(uuid); + + if message and message.file_path then + if not caller:answered() then + caller:answer(); + caller:sleep(1000); + end + caller:send_display(message.cid_name .. ' ' .. message.cid_number); + caller:playback(message.file_path); + end + + return message; +end + + +function Voicemail.menu_options(self) + self.log:info('VOICEMAIL_OPTIONS_MENU'); + self.caller:send_display('Voicemail options'); + + local menu = { + { key = '1', method = self.greeting_record, parameters = { self } }, + { key = '2', method = self.greeting_choose, parameters = { self } }, + { key = '3', method = self.name_record, parameters = { self } }, + { key = '4', method = self.pin_change, parameters = { self } }, + { key = self.settings.key_terminator, exit = true }, + { key = '', exit = true }, + }; + + while true do + local digits, key = self.ivr:ivr_phrase('voicemail_config_menu', menu); + self.log:debug('VOICEMAIL_MAIN_MENU - digit: ', digits); + if key.exit then + break; + end + + key.method(unpack(key.parameters)); + end +end + +function Voicemail.greeting_record(self) + self.log:info('VOICEMAIL_GREETING_RECORD'); +end + +function Voicemail.greeting_choose(self) + self.log:info('VOICEMAIL_GREETING_CHOSE'); + +end + +function Voicemail.name_record(self) + self.log:info('VOICEMAIL_NAME_RECORD'); +end + +function Voicemail.pin_change(self) + self.log:info('VOICEMAIL_PIN_CHANGE'); + + +end -- cgit v1.2.3 From cd91f754501e2c29348276b975462411fe170ba9 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 28 Mar 2013 10:09:44 +0100 Subject: consistent variable naming --- misc/freeswitch/scripts/dialplan/ivr.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/ivr.lua b/misc/freeswitch/scripts/dialplan/ivr.lua index 2a16e3b..e6ddd58 100644 --- a/misc/freeswitch/scripts/dialplan/ivr.lua +++ b/misc/freeswitch/scripts/dialplan/ivr.lua @@ -79,16 +79,16 @@ function Ivr.ivr_phrase_dtmf(self, dtmf) end -function Ivr.read_phrase(self, phrase, phrase_data, max_keys, min_keys, timeout, enter_key) +function Ivr.read_phrase(self, phrase, phrase_data, max_keys, min_keys, timeout, key_terminator) self.max_keys = max_keys or 64; self.min_keys = min_keys or 1; - self.enter_key = enter_key or '#'; + self.key_terminator = key_terminator or '#'; self.digits = ''; self.exit = false; timeout = timeout or 30; global_callback:callback('dtmf', 'ivr_read_phrase', self.read_phrase_dtmf, self); - local continue = self:ivr_break() or self.caller.session:sayPhrase(phrase, phrase_data or enter_key or ''); + local continue = self:ivr_break() or self.caller.session:sayPhrase(phrase, phrase_data or key_terminator or ''); continue = self:ivr_break() or self.caller:sleep(timeout * 1000); global_callback:callback_unset('dtmf', 'ivr_read_phrase'); @@ -101,7 +101,7 @@ function Ivr.read_phrase_dtmf(self, dtmf) return nil; end - if self.enter_key == dtmf.digit then + if self.key_terminator == dtmf.digit then self.exit = true; return false; end @@ -110,14 +110,15 @@ function Ivr.read_phrase_dtmf(self, dtmf) end -function Ivr.check_pin(self, phrase_enter, phrase_incorrect, pin, pin_timeout, pin_repeat, key_enter) +function Ivr.check_pin(self, phrase_enter, phrase_incorrect, pin, pin_timeout, pin_repeat, key_terminator) if not pin then return nil; end + self.exit = false; pin_timeout = pin_timeout or 30; pin_repeat = pin_repeat or 3; - key_enter = key_enter or '#'; + key_terminator = key_terminator or '#'; local digits = ''; for i = 1, pin_repeat do @@ -131,7 +132,7 @@ function Ivr.check_pin(self, phrase_enter, phrase_incorrect, pin, pin_timeout, p break; end self.caller:send_display('Enter PIN'); - digits = ivr:read_phrase(phrase_enter, nil, 0, pin:len() + 1, pin_timeout, key_enter); + digits = ivr:read_phrase(phrase_enter, nil, 0, pin:len() + 1, pin_timeout, key_terminator); end if digits ~= pin then -- cgit v1.2.3 From 5f403c5ac7f029001cec5f2a533e213865834b3b Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 28 Mar 2013 10:10:13 +0100 Subject: unset callback fixed --- misc/freeswitch/scripts/dialplan/callback.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/callback.lua b/misc/freeswitch/scripts/dialplan/callback.lua index f6fd48e..ce1068c 100644 --- a/misc/freeswitch/scripts/dialplan/callback.lua +++ b/misc/freeswitch/scripts/dialplan/callback.lua @@ -46,7 +46,7 @@ end function Callback.callback_unset(self, class, identifier, callback_session) - local session_record = self.sessions[tostring(callback_session or self.session)]; + local session_record = self.sessions[common.str.to_i(callback_session or self.session)]; if not session_record then return false; end -- cgit v1.2.3 From b1c47ccb599044130cdff3b32bc7bc431815636a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 28 Mar 2013 14:24:53 +0100 Subject: voicemail menu added --- misc/freeswitch/scripts/dialplan/voicemail.lua | 61 +++++++++++++------------- 1 file changed, 30 insertions(+), 31 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index bdbb223..e955101 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -134,41 +134,17 @@ function Voicemail.messages_get(self, status) end -function Voicemail.check_pin(self, pin) - self.caller:answer(); - self.caller:sleep(1000); - - require 'dialplan.ivr'; - local ivr = dialplan.ivr.Ivr:new{ caller = self.caller, log = self.log }; - - local digits = ''; - for i = 1, 3 do - if digits == pin then - self.caller:send_display('PIN: OK'); - break - elseif digits ~= "" then - self.caller:send_display('PIN: wrong'); - end - self.caller:send_display('Enter PIN'); - digits = ivr:read_phrase('voicemail_enter_pass', nil, self.settings.pin_length_min, self.settings.pin_length_max, self.settings.pin_timeout, self.settings.terminator_key); - end - - if digits ~= pin then - return false - end - - return true; -end - - function Voicemail.menu_main(self, caller, authorized) + -- authorized = false; + self.settings.pin = '1234'; + self.caller = caller; require 'dialplan.ivr'; self.ivr = dialplan.ivr.Ivr:new{ caller = self.caller, log = self.log }; if not authorized then - if common.str.blank(self.pin) then + if common.str.blank(self.settings.pin) then self.log:notice('VOICEMAIL_MAIN_MENU - unaunthorized, no PIN, ', self.class, '=', self.id, '/', self.uuid, '|', self.name); return { continue = false, code = 500, phrase = 'Unauthorized', no_cdr = true } end @@ -176,7 +152,7 @@ function Voicemail.menu_main(self, caller, authorized) self.caller:answer(); self.caller:sleep(1000); - if not self.ivr:check_pin('voicemail_enter_pass', 'voicemail_fail_auth', self.pin) then + if not self.ivr:check_pin('voicemail_enter_pass', 'voicemail_fail_auth', self.settings.pin) then self.log:notice('VOICEMAIL_MAIN_MENU - wrong PIN, ', self.class, '=', self.id, '/', self.uuid, '|', self.name); caller.session:sayPhrase('voicemail_goodbye'); return { continue = false, code = 500, phrase = 'Unauthorized', no_cdr = true } @@ -414,21 +390,44 @@ function Voicemail.menu_options(self) end end + function Voicemail.greeting_record(self) self.log:info('VOICEMAIL_GREETING_RECORD'); end + function Voicemail.greeting_choose(self) self.log:info('VOICEMAIL_GREETING_CHOSE'); end + function Voicemail.name_record(self) self.log:info('VOICEMAIL_NAME_RECORD'); end + function Voicemail.pin_change(self) - self.log:info('VOICEMAIL_PIN_CHANGE'); + self.log:info('VOICEMAIL_PIN_CHANGE - lenght: ', self.settings.pin_length_min, '-', self.settings.pin_length_max); - + if not common.str.blank(self.settings.pin) then + if not self.ivr:check_pin('voicemail_enter_pass', 'voicemail_fail_auth', self.settings.pin) then + self.log:notice('VOICEMAIL_PIN_CHANGE - wrong old PIN, ', self.class, '=', self.id, '/', self.uuid, '|', self.name); + return false; + end + end + + local digits = ''; + for i = 1, 3 do + if digits:len() < self.settings.pin_length_min then + self.caller:send_display('PIN too short'); + elseif digits:len() > self.settings.pin_length_max then + self.caller:send_display('PIN too long'); + else + self.caller:send_display('PIN: OK'); + break + end + self.caller:send_display('Enter new PIN'); + digits = self.ivr:read_phrase('voicemail_enter_pass', nil, self.settings.pin_length_max, self.settings.pin_length_min, self.settings.pin_timeout, self.settings.terminator_key); + end end -- cgit v1.2.3 From edf06bf6f7d4f20d5a9145a5bbf8db409fe6ab1b Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 2 Apr 2013 13:14:07 +0200 Subject: pin changing dialog added --- misc/freeswitch/scripts/dialplan/voicemail.lua | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index e955101..e5579f8 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -135,9 +135,6 @@ end function Voicemail.menu_main(self, caller, authorized) - -- authorized = false; - self.settings.pin = '1234'; - self.caller = caller; require 'dialplan.ivr'; @@ -430,4 +427,25 @@ function Voicemail.pin_change(self) self.caller:send_display('Enter new PIN'); digits = self.ivr:read_phrase('voicemail_enter_pass', nil, self.settings.pin_length_max, self.settings.pin_length_min, self.settings.pin_timeout, self.settings.terminator_key); end + + if digits:len() < self.settings.pin_length_min or digits:len() > self.settings.pin_length_max then + self.caller:send_display('PIN not changed'); + return false; + end + + local sql_query = 'UPDATE `voicemail_settings` \ + SET `value` = ' .. self.database:escape(digits, '"') .. ', `class_type` = "String", `updated_at` = NOW() \ + WHERE `name`="pin" AND `voicemail_account_id` = ' .. self.id; + if not self.settings.pin then + sql_query = 'INSERT INTO `voicemail_settings` \ + (`voicemail_account_id`, `name`, `value`, `class_type`, `description`, `created_at`, `updated_at`) \ + VALUES (' .. self.id .. ', "pin", "' .. digits .. '", "String", "Voicemail PIN", NOW(), NOW())'; + end + + if self.database:query(sql_query) then + self.settings.pin = digits; + self.caller:send_display('PIN changed'); + self.caller.session:sayPhrase('voicemail_change_pass_success'); + return true; + end end -- cgit v1.2.3 From 1b5cd43bcabd516f98117a16d44d2a7f1bf70600 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 8 Apr 2013 15:36:30 +0200 Subject: dtmf test --- misc/freeswitch/scripts/dialplan/functions.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index ce99953..2edc131 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -116,6 +116,8 @@ function Functions.dialplan_function(self, caller, dialed_number) result = self:call_parking_inout(caller, parameters[3], parameters[4]); elseif fid == "cpai" then result = self:call_parking_inout_index(caller, parameters[3]); + elseif fid == "test" then + result = self:test(caller, parameters[3]); end return result or { continue = false, code = 505, phrase = 'Error executing function', no_cdr = true }; @@ -912,3 +914,20 @@ function Functions.call_parking_inout_index(self, caller, stall_index) return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end + + +function Functions.test(self, caller, name) + if tostring(name) == 'dtmf' then + while caller:ready() do + local digits = caller.session:read(1, 1, '', 30000, ''); + if digits == "" then + break; + end + caller:send_display('DTMF: ', digits); + caller.session:say(digits, "en", "number", "pronounced"); + self.log:devel('DTMF: ', digits); + end + end + + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } +end -- cgit v1.2.3 From 8d8bf48aa95f979da8f67d274b66d5c207b8b667 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 8 Apr 2013 16:01:52 +0200 Subject: dtmf test --- misc/freeswitch/scripts/dialplan/functions.lua | 17 ++++++++++++----- 1 file changed, 12 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 2edc131..0c30b86 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -918,14 +918,21 @@ end function Functions.test(self, caller, name) if tostring(name) == 'dtmf' then + local digits = ''; while caller:ready() do - local digits = caller.session:read(1, 1, '', 30000, ''); - if digits == "" then - break; + if digits == '' then + caller:playback('ivr/ivr-love_those_touch_tones.wav'); end - caller:send_display('DTMF: ', digits); - caller.session:say(digits, "en", "number", "pronounced"); + digits = caller.session:read(1, 1, '', 5000, ''); self.log:devel('DTMF: ', digits); + caller:send_display('DTMF: ', digits); + if digits == '*' then + caller:playback('digits/star.wav'); + elseif digits == '#' then + caller:playback('digits/pound.wav'); + elseif digits ~= '' then + caller.session:say(digits, "en", "number", "pronounced"); + end end end -- cgit v1.2.3 From d6adfbba723de9732f24efd71f80c422ae1a40f0 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 8 Apr 2013 16:05:16 +0200 Subject: dtmf test --- misc/freeswitch/scripts/dialplan/functions.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index 0c30b86..7519ff9 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -918,13 +918,15 @@ end function Functions.test(self, caller, name) if tostring(name) == 'dtmf' then + self.log:info('FUNCTION_TEST_DTMF'); local digits = ''; + caller:answer(); while caller:ready() do if digits == '' then caller:playback('ivr/ivr-love_those_touch_tones.wav'); end digits = caller.session:read(1, 1, '', 5000, ''); - self.log:devel('DTMF: ', digits); + self.log:info('DTMF: ', digits); caller:send_display('DTMF: ', digits); if digits == '*' then caller:playback('digits/star.wav'); -- cgit v1.2.3 From f89c54f914741e2aaa6d4910cd33eaa2bd7fedf3 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 11 Apr 2013 10:47:24 +0200 Subject: pass number as greeting --- misc/freeswitch/scripts/dialplan/dialplan.lua | 4 +--- 1 file changed, 1 insertion(+), 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 31b88fd..a8054ff 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -595,8 +595,6 @@ function Dialplan.voicemail(self, destination) local voicemail_account = nil; if common.str.to_i(destination.id) > 0 then voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_id(destination.id); - elseif not common.str.blank(destination.number) then - voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_number(destination.number); elseif self.caller.auth_account and self.caller.auth_account.class == 'sipaccount' then voicemail_account = dialplan.voicemail.Voicemail:new{ log = self.log, database = self.database, domain = self.domain }:find_by_sip_account_id(self.caller.auth_account.id); elseif self.caller.forwarding_number then @@ -608,7 +606,7 @@ function Dialplan.voicemail(self, destination) return { continue = false, code = 404, phrase = 'Mailbox not found' } end - voicemail_account:leave(self.caller, self.caller.forwarding_number); + voicemail_account:leave(self.caller, destination.number, self.caller.forwarding_number); if self.caller:to_s("voicemail_message_len") == '' then self.log:info('VOICEMAIL - no message saved'); -- cgit v1.2.3 From 720a55fd2540e74a84ef2113ad9475bb56f364c0 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 11 Apr 2013 10:49:30 +0200 Subject: beep added --- misc/freeswitch/scripts/dialplan/ivr.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/ivr.lua b/misc/freeswitch/scripts/dialplan/ivr.lua index e6ddd58..6b230dc 100644 --- a/misc/freeswitch/scripts/dialplan/ivr.lua +++ b/misc/freeswitch/scripts/dialplan/ivr.lua @@ -146,16 +146,23 @@ function Ivr.check_pin(self, phrase_enter, phrase_incorrect, pin, pin_timeout, p end -function Ivr.record(self, file_name, phrase_record, phrase_too_short, record_length_max, record_length_min, record_repeat, silence_level, silence_lenght_abort) +function Ivr.record(self, file_name, beep, phrase_record, phrase_too_short, record_length_max, record_length_min, record_repeat, silence_level, silence_lenght_abort) local duration = nil; for index=1, record_repeat do if (duration and duration >= record_length_min) or not self.caller:ready() then break; elseif duration then self.caller:send_display('Recording too short'); - self.caller.session:sayPhrase(phrase_too_short); + if phrase_too_short then + self.caller.session:sayPhrase(phrase_too_short); + end + end + if phrase_record then + self.caller.session:sayPhrase(phrase_record); + end + if beep then + self.caller:playback(beep); end - self.caller.session:sayPhrase(phrase_record); self.caller:send_display('Recording...'); local result = self.caller.session:recordFile(file_name, record_length_max, silence_level, silence_lenght_abort); duration = self.caller:to_i('record_seconds'); -- cgit v1.2.3 From 145d774adece71282020603b699ab684537cc1b3 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 11 Apr 2013 10:50:04 +0200 Subject: greeting added --- misc/freeswitch/scripts/dialplan/voicemail.lua | 50 +++++++++++++++++++++----- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index e5579f8..6418c46 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -288,28 +288,40 @@ function Voicemail.message_save(self, message) end -function Voicemail.leave(self, caller, greeting) - local forwarding_number = caller.forwarding_number; - self.log:info('VOICEMAIL_LEAVE - voicemail_account=', self.record.id, '/', self.record.uuid, '|', self.record.name, ', forwarding_number: ', forwarding_number); +function Voicemail.leave(self, caller, greeting, number) + self.log:info('VOICEMAIL_LEAVE - voicemail_account=', self.record.id, '/', self.record.uuid, '|', self.record.name, ', forwarding_number: ', number, ', greeting: ', greeting); - caller:set_callee_id(forwarding_number, common.array.try(caller, 'auth_account.caller_name') or common.array.try(caller, 'auth_account.name')); + caller:set_callee_id(number, common.array.try(caller, 'auth_account.caller_name') or common.array.try(caller, 'auth_account.name')); caller:answer(); caller:send_display(common.array.try(caller, 'auth_account.caller_name') or common.array.try(caller, 'auth_account.name')); caller:sleep(1000); - if not common.str.blank(forwarding_number) then - caller.session:sayPhrase('voicemail_play_greeting', (tostring(forwarding_number):gsub('[%D]', ''))); + local greeting_file = nil; + if not common.str.blank(greeting) then + greeting_file = self:greeting_get(greeting, caller.auth_account.owner.class, caller.auth_account.owner.id) + end + + if not common.str.blank(greeting_file) then + self.log:debug('VOICEMAIL_LEAVE greeting_file: ', greeting_file); + caller:playback(greeting_file); + elseif not common.str.blank(number) then + caller.session:sayPhrase('voicemail_play_greeting', (tostring(number):gsub('[%D]', ''))); end local record_file_name = self.settings.record_file_path ..self.settings.record_file_prefix .. caller.uuid .. self.settings.record_file_suffix; self.log:info('VOICEMAIL_LEAVE - recording to file: ', tostring(record_file_name)); + local voicemail_record_message = nil; + if common.str.blank(greeting_file) then + voicemail_record_message = 'voicemail_record_message'; + end + require 'dialplan.ivr'; local ivr = dialplan.ivr.Ivr:new{ caller = caller, log = self.log }; - local duration = ivr:record( - record_file_name, - 'voicemail_record_message', + record_file_name, + self.settings.beep, + voicemail_record_message, 'voicemail_message_too_short', self.settings.record_length_max, self.settings.record_length_min, @@ -363,6 +375,26 @@ function Voicemail.message_play(self, caller, uuid) end +function Voicemail.greeting_get(self, name, owner_type, owner_id, file_types) + local store_dir = '/var/opt/gemeinschaft/generic_files/'; + + file_types = file_types or {'audio/x-wav'} + local sql_query = 'SELECT * FROM `generic_files` \ + WHERE `name` = ' .. self.database:escape(name, '"') .. ' \ + AND `owner_type` = ' .. self.database:escape(owner_type, '"') .. ' \ + AND `owner_id` = ' .. self.database:escape(owner_id, '"') .. ' \ + AND `file_type` IN ("' .. table.concat(file_types, '","') .. '") LIMIT 1'; + + local greeting = self.database:query_return_first(sql_query); + + if not greeting or common.str.blank(greeting.file) then + return nil; + end + + return store_dir .. greeting.id .. '/' .. greeting.file; +end + + function Voicemail.menu_options(self) self.log:info('VOICEMAIL_OPTIONS_MENU'); self.caller:send_display('Voicemail options'); -- cgit v1.2.3 From 9e571115056c83adf34fcc55089f0c3781d76122 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 12 Apr 2013 11:46:11 +0200 Subject: greeting recording added --- misc/freeswitch/scripts/dialplan/voicemail.lua | 61 ++++++++++++++++++++------ 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/voicemail.lua b/misc/freeswitch/scripts/dialplan/voicemail.lua index 6418c46..3358d2b 100644 --- a/misc/freeswitch/scripts/dialplan/voicemail.lua +++ b/misc/freeswitch/scripts/dialplan/voicemail.lua @@ -32,9 +32,11 @@ DEFAULT_SETTINGS = { notify = true, attachment = true, mark_read = true, - purge = false, + purge = false, + generic_file_path = '/var/opt/gemeinschaft/generic_files/', } + -- create voicemail object function Voicemail.new(self, arg) arg = arg or {} @@ -376,8 +378,6 @@ end function Voicemail.greeting_get(self, name, owner_type, owner_id, file_types) - local store_dir = '/var/opt/gemeinschaft/generic_files/'; - file_types = file_types or {'audio/x-wav'} local sql_query = 'SELECT * FROM `generic_files` \ WHERE `name` = ' .. self.database:escape(name, '"') .. ' \ @@ -391,7 +391,7 @@ function Voicemail.greeting_get(self, name, owner_type, owner_id, file_types) return nil; end - return store_dir .. greeting.id .. '/' .. greeting.file; + return self.settings.generic_file_path .. greeting.id .. '/' .. greeting.file; end @@ -401,9 +401,7 @@ function Voicemail.menu_options(self) local menu = { { key = '1', method = self.greeting_record, parameters = { self } }, - { key = '2', method = self.greeting_choose, parameters = { self } }, - { key = '3', method = self.name_record, parameters = { self } }, - { key = '4', method = self.pin_change, parameters = { self } }, + { key = '3', method = self.pin_change, parameters = { self } }, { key = self.settings.key_terminator, exit = true }, { key = '', exit = true }, }; @@ -422,17 +420,53 @@ end function Voicemail.greeting_record(self) self.log:info('VOICEMAIL_GREETING_RECORD'); -end + local record_file_name = self.settings.record_file_path ..self.settings.record_file_prefix .. self.caller.uuid .. self.settings.record_file_suffix; + + require 'dialplan.ivr'; + local ivr = dialplan.ivr.Ivr:new{ caller = self.caller, log = self.log }; + local duration = ivr:record( + record_file_name, + self.settings.beep, + 'voicemail_record_greeting', + 'voicemail_message_too_short', + self.settings.record_length_max, + 1, + self.settings.record_repeat, + self.settings.silence_level, + self.settings.silence_lenght_abort); -function Voicemail.greeting_choose(self) - self.log:info('VOICEMAIL_GREETING_CHOSE'); + if duration >= 0 then + self.caller:playback(record_file_name); + end -end + if duration >= 1 then + local name = 'greeting_' .. os.time(); + local file_name = name .. self.settings.record_file_suffix + + local generic_file_record = { + name = name, + file = file_name, + file_type = 'audio/x-wav', + category = 'greeting', + owner_id = self.record.voicemail_accountable_id, + owner_type = self.record.voicemail_accountable_type, + updated_at = { 'NOW()', raw = true }, + created_at = { 'NOW()', raw = true }, + }; + if self.database:insert_or_update('generic_files', generic_file_record) then + local file_id = self.database:last_insert_id(); -function Voicemail.name_record(self) - self.log:info('VOICEMAIL_NAME_RECORD'); + local destination_directory = self.settings.generic_file_path .. file_id; + self.log:info('VOICEMAIL_GREETING_RECORD recorded greeting - id: ', file_id, ', file: ', destination_directory .. '/' .. file_name, ', duration: ', duration); + os.execute('mkdir ' .. destination_directory); + local result, error_string = os.rename(record_file_name, destination_directory .. '/' .. file_name); + if not result then + self.log:error('VOICEMAIL_GREETING_RECORD - ', error_string); + end + end + end end @@ -481,3 +515,4 @@ function Voicemail.pin_change(self) return true; end end + -- cgit v1.2.3 From d3747bd38f106669d7b57a9c9b64d99b98c6aa59 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 16 Apr 2013 15:14:33 +0200 Subject: pass caller record to call forwarding class --- misc/freeswitch/scripts/dialplan/dialplan.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index a8054ff..3f84007 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -248,7 +248,7 @@ function Dialplan.destination_new(self, arg) destination.account = self:object_find{ class = destination.type, id = destination.id}; if self.caller then require 'common.call_forwarding'; - local call_forwarding_class = common.call_forwarding.CallForwarding:new{ log = self.log, database = self.database } + local call_forwarding_class = common.call_forwarding.CallForwarding:new{ log = self.log, database = self.database, caller = self.caller } destination.call_forwarding = call_forwarding_class:list_by_owner(destination.id, destination.type, self.caller.caller_phone_numbers); for service, call_forwarding_entry in pairs(call_forwarding_class:list_by_owner(destination.phone_number.id, destination.phone_number.class, self.caller.caller_phone_numbers)) do destination.call_forwarding[service] = call_forwarding_entry; -- cgit v1.2.3 From 34ac090e79942dd8d9b65eb7f4b7f4873135e221 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 17 Apr 2013 16:50:47 +0200 Subject: numbers method added --- misc/freeswitch/scripts/dialplan/phone_book.lua | 29 +++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/phone_book.lua b/misc/freeswitch/scripts/dialplan/phone_book.lua index 6653789..50972ac 100644 --- a/misc/freeswitch/scripts/dialplan/phone_book.lua +++ b/misc/freeswitch/scripts/dialplan/phone_book.lua @@ -19,7 +19,7 @@ function PhoneBook.new(self, arg) end -function PhoneBook.find_entry_by_number_user_tenant(self, numbers, user_id, tenant_id) +function PhoneBook.find_entry_by_number_user_tenant(self, numbers, user_id, tenant_id, name) user_id = tonumber(user_id) or 0; tenant_id = tonumber(tenant_id) or 0; @@ -37,7 +37,7 @@ function PhoneBook.find_entry_by_number_user_tenant(self, numbers, user_id, tena `c`.`name` AS `phone_book_name`, \ `d`.`bellcore_id` \ FROM `phone_numbers` `a` \ - JOIN `phone_book_entries` `b` ON `a`.`phone_numberable_id` = `b`.`id` AND `a`.`phone_numberable_type` = "PhoneBookENtry" \ + JOIN `phone_book_entries` `b` ON `a`.`phone_numberable_id` = `b`.`id` AND `a`.`phone_numberable_type` = "PhoneBookEntry" \ JOIN `phone_books` `c` ON `b`.`phone_book_id` = `c`.`id` \ LEFT JOIN `ringtones` `d` ON `a`.`id` = `d`.`ringtoneable_id` AND `d`.`ringtoneable_type` = "PhoneNumber" \ WHERE ((`c`.`phone_bookable_type` = "User" AND `c`.`phone_bookable_id` = ' .. user_id .. ') \ @@ -45,8 +45,13 @@ function PhoneBook.find_entry_by_number_user_tenant(self, numbers, user_id, tena AND `a`.`number` IN (' .. numbers_sql .. ') \ AND `a`.`state` = "active" \ AND `b`.`state` = "active" \ - AND `c`.`state` = "active" \ - ORDER BY `c`.`phone_bookable_type` DESC LIMIT 1'; + AND `c`.`state` = "active"'; + + if name then + sql_query = sql_query ..' AND `a`.`name` = ' .. self.database:escape(name, '"'); + end + + sql_query = sql_query ..' ORDER BY `c`.`phone_bookable_type` DESC LIMIT 1'; local phone_book_entry = nil; @@ -61,3 +66,19 @@ function PhoneBook.find_entry_by_number_user_tenant(self, numbers, user_id, tena return phone_book_entry; end + + +function PhoneBook.numbers(self, phone_book_entry_id, name, not_name) + local sql_query = 'SELECT * FROM `phone_numbers` \ + WHERE `phone_numberable_id` = ' .. phone_book_entry_id .. ' AND `phone_numberable_type` = "PhoneBookEntry"'; + + if name then + sql_query = sql_query ..' AND `name` = ' .. self.database:escape(name, '"'); + end + + if not_name then + sql_query = sql_query ..' AND `name` != ' .. self.database:escape(not_name, '"'); + end + + return self.database:query_return_all(sql_query); +end -- cgit v1.2.3 From ccb2ccc255218ec44a1694431cfbccd6308be6d5 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 17 Apr 2013 16:51:30 +0200 Subject: router function speeddial added --- misc/freeswitch/scripts/dialplan/router.lua | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 322c748..d6d00de 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -149,6 +149,14 @@ function Router.route_match(self, route) elseif command == 'hdr' then local search_string = self.caller:to_s('sip_h_' .. variable_name); result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement)); + elseif command == 'fun' then + if self['fun_' .. variable_name] then + local arguments = {}; + for index, argument in ipairs(common.str.to_a(element.replacement, ',')) do + table.insert(arguments, common.array.expand_variables(argument, destination, self.variables)); + end + result, replacement = self['fun_' .. variable_name](self, unpack(arguments)) + end end end @@ -214,3 +222,32 @@ function Router.route_run(self, table_name, find_first) return routes; end end + + +function Router.fun_speeddial(self, number, name) + local owner_class = common.array.try(self, 'caller.auth_account.owner.class'); + local owner_id = common.array.try(self, 'caller.auth_account.owner.id') + + local user_id = nil; + local tenant_id = nil; + + if tostring(owner_class) == 'user' then + user_id = owner_id; + tenant_id = common.array.try(self, 'caller.auth_account.owner.record.current_nenant_id'); + elseif + tostring(owner_class) == 'tenant' then + tenant_id = owner_id; + end + + require 'dialplan.phone_book' + local phone_book_class = dialplan.phone_book.PhoneBook:new{ log = self.log, database = self.database } + local phone_book_entry = phone_book_class:find_entry_by_number_user_tenant({number}, user_id, tenant_id, 'speeddial'); + + if phone_book_entry then + local phone_numbers = phone_book_class:numbers(phone_book_entry.id, name, 'speeddial'); + for index, phone_number in ipairs(phone_numbers) do + self.log:info('SPEEDDIAL: ', number, ' => ', phone_number.number) + return true, phone_number.number; + end + end +end -- cgit v1.2.3 From 75047661f380c62dae7bab4942c9e8a8cf39501a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 18 Apr 2013 08:30:06 +0200 Subject: logging --- misc/freeswitch/scripts/dialplan/router.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index d6d00de..dde527c 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -156,6 +156,13 @@ function Router.route_match(self, route) table.insert(arguments, common.array.expand_variables(argument, destination, self.variables)); end result, replacement = self['fun_' .. variable_name](self, unpack(arguments)) + if self.log_details or true then + if result then + self.log:debug('ELEMENT_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); + else + self.log:debug('ELEMENT_NO_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', tostring(replacement)); + end + end end end end @@ -233,7 +240,7 @@ function Router.fun_speeddial(self, number, name) if tostring(owner_class) == 'user' then user_id = owner_id; - tenant_id = common.array.try(self, 'caller.auth_account.owner.record.current_nenant_id'); + tenant_id = common.array.try(self, 'caller.auth_account.owner.record.current_tenant_id'); elseif tostring(owner_class) == 'tenant' then tenant_id = owner_id; @@ -243,10 +250,12 @@ function Router.fun_speeddial(self, number, name) local phone_book_class = dialplan.phone_book.PhoneBook:new{ log = self.log, database = self.database } local phone_book_entry = phone_book_class:find_entry_by_number_user_tenant({number}, user_id, tenant_id, 'speeddial'); + self.log:debug('SPEEDDIAL - user=', user_id, ', tenant=', tenant_id, ', entry: "', common.array.try(phone_book_entry, 'phone_book_name'), '" => "', common.array.try(phone_book_entry, 'caller_id_name'), '"'); + if phone_book_entry then local phone_numbers = phone_book_class:numbers(phone_book_entry.id, name, 'speeddial'); for index, phone_number in ipairs(phone_numbers) do - self.log:info('SPEEDDIAL: ', number, ' => ', phone_number.number) + self.log:info('SPEEDDIAL - ', number, ' => ', phone_number.number) return true, phone_number.number; end end -- cgit v1.2.3 From 7804dbb985f25c8bafbcfad1f9345d14a9a6adc3 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 23 Apr 2013 22:04:07 +0200 Subject: elements loading order fixed --- misc/freeswitch/scripts/dialplan/router.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index dde527c..10551f1 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -38,15 +38,19 @@ function Router.read_table(self, table_name, force_reload) JOIN `route_elements` `b` ON `a`.`id` = `b`.`call_route_id`\ WHERE `a`.`routing_table` = "' .. table_name .. '" \ ORDER BY `a`.`position`, `b`.`position`'; - - local last_id = 0; + + local call_routes = {}; + self.database:query(sql_query, function(route) - if last_id ~= tonumber(route.call_route_id) then - last_id = tonumber(route.call_route_id); - table.insert(routing_table, {id = route.call_route_id, name = route.name, endpoint_type = route.endpoint_type , endpoint_id = route.endpoint_id, elements = {} }); + if call_routes[route.call_route_id] then + call_route = call_routes[route.call_route_id]; + else + call_route = {id = route.call_route_id, name = route.name, endpoint_type = route.endpoint_type , endpoint_id = route.endpoint_id, elements = {} }; + call_routes[route.call_route_id] = call_route; + table.insert(routing_table, call_route); end - table.insert(routing_table[#routing_table].elements, { + table.insert(call_route.elements, { var_in = route.var_in, var_out = route.var_out, pattern = route.pattern, -- cgit v1.2.3 From af21d33a75e856e875f170498ea702b7e9d2e19c Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Mon, 6 May 2013 14:23:55 +0200 Subject: start_dtmf only if out-of-band DTMF is absend in SDP description --- misc/freeswitch/scripts/dialplan/sip_call.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 0cde601..f401c5c 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -233,11 +233,19 @@ function SipCall.fork(self, destinations, arg ) end if arg.detect_dtmf_after_bridge_caller and self.caller.auth_account then - session:execute('start_dtmf'); + if not string.match(self.caller:to_s('switch_r_sdp'), '101 telephone%-event') then + self.log:notice('FORK A_LEG inband dtmf detection - channel_uuid: ', session:get_uuid()); + session:execute('start_dtmf'); + end end + if arg.detect_dtmf_after_bridge_callee and destination.type == 'sipaccount' then - session_callee:execute('start_dtmf'); + if not string.match(tostring(session_callee:getVariable('switch_r_sdp')), '101 telephone%-event') then + self.log:notice('FORK B_LEG inband dtmf detection - channel_uuid: ', session_callee:get_uuid()); + session_callee:execute('start_dtmf'); + end end + if arg.bypass_media_network then local callee_uuid = session_callee:get_uuid(); -- cgit v1.2.3 From f89becb96fdfe7a247f04b6f472496972ba5827e Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 4 Jun 2013 11:22:24 +0200 Subject: pager function added --- misc/freeswitch/scripts/dialplan/functions.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/functions.lua b/misc/freeswitch/scripts/dialplan/functions.lua index 7519ff9..efd1f05 100644 --- a/misc/freeswitch/scripts/dialplan/functions.lua +++ b/misc/freeswitch/scripts/dialplan/functions.lua @@ -118,6 +118,8 @@ function Functions.dialplan_function(self, caller, dialed_number) result = self:call_parking_inout_index(caller, parameters[3]); elseif fid == "test" then result = self:test(caller, parameters[3]); + elseif fid == "pager" then + result = self:pager(caller, parameters[3]); end return result or { continue = false, code = 505, phrase = 'Error executing function', no_cdr = true }; @@ -940,3 +942,20 @@ function Functions.test(self, caller, name) return { continue = false, code = 200, phrase = 'OK', no_cdr = true } end + + +function Functions.pager(self, caller, pager_group_id) + require 'common.pager'; + local pager = common.pager.Pager:new{ log = self.log, database = self.database, caller = caller }:find_by_id(pager_group_id); + + if not pager then + self.log:notice('FUNCTION_PAGER not found - pager_group=', pager_group_id); + return { continue = false, code = 404, phrase = 'No such pager group', no_cdr = true } + end + + self.log:info('FUNCTION_PAGER pager_group=', pager_group_id); + caller:answer(); + pager:enter(); + + return { continue = false, code = 200, phrase = 'OK', no_cdr = true } +end -- cgit v1.2.3 From 4f2e4d63597904c0f2b71398619ee3d1294f297a Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 11 Jun 2013 14:54:12 +0200 Subject: set_privacy removed --- misc/freeswitch/scripts/dialplan/dialplan.lua | 3 --- 1 file changed, 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 3f84007..f96f857 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -372,7 +372,6 @@ function Dialplan.dial(self, destination) self.caller:set_caller_id(destination.caller_id_number, destination.caller_id_name or self.caller.caller_id_name); else self.caller:set_caller_id('anonymous', 'Unknown'); - self.caller:set_privacy(true); end local destinations = { destination }; @@ -418,7 +417,6 @@ function Dialplan.huntgroup(self, destination) end else self.caller:set_caller_id('anonymous', tostring(hunt_group.record.name)); - self.caller:set_privacy(true); end self.caller.auth_account = hunt_group; @@ -449,7 +447,6 @@ function Dialplan.acd(self, destination) end else self.caller:set_caller_id('anonymous', tostring(acd.record.name)); - self.caller:set_privacy(true); end self.caller.auth_account = acd; -- cgit v1.2.3 From c51e4bad9ed2a2e1adaeda94ff1ac983106462f6 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 11 Jun 2013 14:54:31 +0200 Subject: set_privacy method removed --- misc/freeswitch/scripts/dialplan/session.lua | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/session.lua b/misc/freeswitch/scripts/dialplan/session.lua index 9c43e74..1d907c5 100644 --- a/misc/freeswitch/scripts/dialplan/session.lua +++ b/misc/freeswitch/scripts/dialplan/session.lua @@ -211,17 +211,6 @@ function Session.set_callee_id(self, number, name) end end --- Set caller Privacy header -function Session.set_privacy(self, privacy) - if privacy then - self.session:setVariable('cid_type', 'none'); - self.session:setVariable('sip_h_Privacy', 'id'); - else - self.session:setVariable('cid_type', 'none'); - self.session:setVariable('sip_h_Privacy', 'none'); - end -end - function Session.set_auth_account(self, auth_account) if auth_account then -- cgit v1.2.3 From 9a34bfecca1bb3d6da4af4faa4e8f8c3cf13b153 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Tue, 11 Jun 2013 14:55:22 +0200 Subject: privacy and cid_type options added --- misc/freeswitch/scripts/dialplan/sip_call.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index f401c5c..66cba0e 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -96,6 +96,18 @@ function SipCall.fork(self, destinations, arg ) table.insert(origination_variables, 'ignore_display_updates=true'); end + local origination_privacy = ''; + + if self.caller.clir then + origination_privacy = 'hide_name:hide_number'; + end + + if self.caller.account then + origination_privacy = origination_privacy .. ':screen'; + end + + table.insert(origination_variables, 'origination_privacy=' .. origination_privacy); + if not destination.node_local or destination.type == 'node' then require 'common.node' local node = nil; @@ -168,6 +180,9 @@ function SipCall.fork(self, destinations, arg ) if destination.caller_id_name then table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'"); end + if gateway.settings.sip_cid_type then + table.insert(origination_variables, "sip_cid_type='" .. gateway.settings.sip_cid_type .. "'"); + end if destination.channel_variables then for key, value in pairs(destination.channel_variables) do table.insert(origination_variables, tostring(key) .. "='" .. tostring(value) .. "'"); -- cgit v1.2.3 From f024d2383255847847de9cba4f1aa454a207de84 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 12 Jun 2013 09:19:38 +0200 Subject: set_caller_id removed --- misc/freeswitch/scripts/dialplan/dialplan.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/dialplan.lua b/misc/freeswitch/scripts/dialplan/dialplan.lua index f96f857..913d7a5 100644 --- a/misc/freeswitch/scripts/dialplan/dialplan.lua +++ b/misc/freeswitch/scripts/dialplan/dialplan.lua @@ -370,8 +370,6 @@ function Dialplan.dial(self, destination) end end self.caller:set_caller_id(destination.caller_id_number, destination.caller_id_name or self.caller.caller_id_name); - else - self.caller:set_caller_id('anonymous', 'Unknown'); end local destinations = { destination }; @@ -416,7 +414,7 @@ function Dialplan.huntgroup(self, destination) self:set_caller_picture(self.caller.account.owner.id, self.caller.account.owner.class); end else - self.caller:set_caller_id('anonymous', tostring(hunt_group.record.name)); + self.caller.anonymous_name = tostring(hunt_group.record.name); end self.caller.auth_account = hunt_group; @@ -446,7 +444,7 @@ function Dialplan.acd(self, destination) self:set_caller_picture(self.caller.account.owner.id, self.caller.account.owner.class); end else - self.caller:set_caller_id('anonymous', tostring(acd.record.name)); + self.caller.anonymous_name = tostring(acd.record.name); end self.caller.auth_account = acd; @@ -814,6 +812,10 @@ function Dialplan.run(self, destination) self.caller.date = os.date('%y%m%d%w'); self.caller.time = os.date('%H%M%S'); + if self.config then + self.caller:export_variable('sip_cid_type=' .. (self.config.sip_cid_type or 'none')); + end + if type(self.config.variables) == 'table' then for key, value in pairs(self.config.variables) do self.caller:set_variable(key, value); -- cgit v1.2.3 From 8f05b452f8d57e87fa8927b0960a17aa386c0864 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 12 Jun 2013 09:20:37 +0200 Subject: caller_id and privacy --- misc/freeswitch/scripts/dialplan/sip_call.lua | 60 ++++++++++++++++++--------- 1 file changed, 40 insertions(+), 20 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 66cba0e..c8e40fc 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -96,18 +96,6 @@ function SipCall.fork(self, destinations, arg ) table.insert(origination_variables, 'ignore_display_updates=true'); end - local origination_privacy = ''; - - if self.caller.clir then - origination_privacy = 'hide_name:hide_number'; - end - - if self.caller.account then - origination_privacy = origination_privacy .. ':screen'; - end - - table.insert(origination_variables, 'origination_privacy=' .. origination_privacy); - if not destination.node_local or destination.type == 'node' then require 'common.node' local node = nil; @@ -124,6 +112,7 @@ function SipCall.fork(self, destinations, arg ) table.insert(origination_variables, 'sip_h_X-GS_auth_account_type=' .. tostring(self.caller.auth_account_type)); table.insert(origination_variables, 'sip_h_X-GS_auth_account_uuid=' .. tostring(self.caller.auth_account_uuid)); table.insert(origination_variables, 'sip_h_X-GS_loop_count=' .. tostring(self.caller.loop_count)); + table.insert(origination_variables, 'sip_h_X-GS_clir=' .. tostring(self.caller.clir)); table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/gateway/' .. node.record.name .. '/' .. destination.number); end elseif destination.type == 'sipaccount' then @@ -158,6 +147,11 @@ function SipCall.fork(self, destinations, arg ) table.insert(origination_variables, "gs_auth_account_uuid='" .. common.str.to_s(self.caller.auth_account.uuid) .. "'"); end + if self.caller.clir then + table.insert(origination_variables, "origination_caller_id_number='anonymous'"); + table.insert(origination_variables, "origination_caller_id_name='" .. ( self.caller.anonymous_name or 'Anonymous') .. "'"); + end + table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/' .. sip_account.record.profile_name .. '/' .. sip_account.record.auth_name .. '%' .. sip_account.record.sip_host); if destination.pickup_groups and #destination.pickup_groups > 0 then for key=1, #destination.pickup_groups do @@ -174,15 +168,41 @@ function SipCall.fork(self, destinations, arg ) local gateway = common.gateway.Gateway:new{ log = self.log, database = self.database}:find_by_id(destination.id); if gateway and gateway.outbound then - if destination.caller_id_number then - table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'"); - end - if destination.caller_id_name then - table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'"); - end - if gateway.settings.sip_cid_type then - table.insert(origination_variables, "sip_cid_type='" .. gateway.settings.sip_cid_type .. "'"); + local caller_id_type = tostring(gateway.settings.caller_id_type); + + if caller_id_type == 'pid' or caller_id_type == '' or caller_id_type == 'nil' then + local identity = '"' .. (destination.caller_id_name or self.caller.caller_id_name) .. '" '; + + local account_uuid = common.array.try(self.caller, 'account.uuid'); + local auth_account_uuid = common.array.try(self.caller, 'auth_account.uuid'); + + if account_uuid and auth_account_uuid and account_uuid == auth_account_uuid then + table.insert(origination_variables, "sip_h_P-Asserted-Identity='" .. identity .. "'"); + else + table.insert(origination_variables, "sip_h_P-Preferred-Identity='" .. identity .. "'"); + end + + if self.caller.clir then + table.insert(origination_variables, "origination_caller_id_number='anonymous'"); + table.insert(origination_variables, "origination_caller_id_name='" .. ( self.caller.anonymous_name or 'Anonymous') .. "'"); + table.insert(origination_variables, "sip_h_P-Privacy='id'"); + else + if destination.caller_id_number then + table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'"); + end + if destination.caller_id_name then + table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'"); + end + end + else + if destination.caller_id_number then + table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'"); + end + if destination.caller_id_name then + table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'"); + end end + if destination.channel_variables then for key, value in pairs(destination.channel_variables) do table.insert(origination_variables, tostring(key) .. "='" .. tostring(value) .. "'"); -- cgit v1.2.3 From bb4ba3747de3f06970dddf4171305d473c11aa7f Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 12 Jun 2013 12:21:33 +0200 Subject: replacement on no_match fixed --- misc/freeswitch/scripts/dialplan/router.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 10551f1..50653d8 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -173,6 +173,9 @@ function Router.route_match(self, route) if element.action == 'not_match' then result = not result; + if result then + replacement = tostring(element.replacement); + end end if not result then -- cgit v1.2.3 From db8867ef5779e40b84da50870ddc6ecf2e52ac10 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 12 Jun 2013 13:57:29 +0200 Subject: gateway dependent caller_id handling --- misc/freeswitch/scripts/dialplan/sip_call.lua | 54 ++++++++++++++++++--------- 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index c8e40fc..7e3cddc 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -90,7 +90,7 @@ function SipCall.fork(self, destinations, arg ) for index, destination in ipairs(destinations) do local origination_variables = { 'gs_fork_index=' .. index } - self.log:info('FORK ', index, '/', #destinations, ' - ', destination.type, '=', destination.id, '/', destination.uuid, '@', destination.node_id, ', number: ', destination.number, ', caller_id: "', destination.caller_id_name, '" <', destination.caller_id_number, '>'); + self.log:info('FORK ', index, '/', #destinations, ' - ', destination.type, '=', destination.id, '/', destination.uuid, '@', destination.node_id, ', number: ', destination.number); if not common.str.to_b(arg.update_callee_display) then table.insert(origination_variables, 'ignore_display_updates=true'); @@ -125,6 +125,8 @@ function SipCall.fork(self, destinations, arg ) else local call_waiting = self:call_waiting_busy(sip_account); if not call_waiting then + local caller_id_number = destination.caller_id_number or self.caller.caller_id_number; + local caller_id_name = destination.caller_id_name or self.caller.caller_id_name; destinations[index].numbers = sip_account:phone_numbers(); if not arg.callee_id_name then @@ -148,10 +150,15 @@ function SipCall.fork(self, destinations, arg ) end if self.caller.clir then - table.insert(origination_variables, "origination_caller_id_number='anonymous'"); - table.insert(origination_variables, "origination_caller_id_name='" .. ( self.caller.anonymous_name or 'Anonymous') .. "'"); + caller_id_number = self.caller.anonymous_number or 'anonymous'; + caller_id_name = self.caller.anonymous_name or 'Anonymous'; + table.insert(origination_variables, "origination_caller_id_number='" .. caller_id_number .. "'"); + table.insert(origination_variables, "origination_caller_id_name='" .. caller_id_name .. "'"); + table.insert(origination_variables, "sip_h_Privacy='id'"); end + self.log:info('FORK ', index, '/', #destinations, ' - caller_id: "', caller_id_name, '" <', caller_id_number, '>, privacy: ', self.caller.clir); + table.insert(dial_strings, '[' .. table.concat(origination_variables , ',') .. ']sofia/' .. sip_account.record.profile_name .. '/' .. sip_account.record.auth_name .. '%' .. sip_account.record.sip_host); if destination.pickup_groups and #destination.pickup_groups > 0 then for key=1, #destination.pickup_groups do @@ -168,24 +175,25 @@ function SipCall.fork(self, destinations, arg ) local gateway = common.gateway.Gateway:new{ log = self.log, database = self.database}:find_by_id(destination.id); if gateway and gateway.outbound then - local caller_id_type = tostring(gateway.settings.caller_id_type); - - if caller_id_type == 'pid' or caller_id_type == '' or caller_id_type == 'nil' then - local identity = '"' .. (destination.caller_id_name or self.caller.caller_id_name) .. '" '; - - local account_uuid = common.array.try(self.caller, 'account.uuid'); - local auth_account_uuid = common.array.try(self.caller, 'auth_account.uuid'); + local asserted_identity = tostring(gateway.settings.asserted_identity); + local asserted_identity_clir = tostring(gateway.settings.asserted_identity); + local caller_id_number = destination.caller_id_number or self.caller.caller_id_number; + local caller_id_name = destination.caller_id_name or self.caller.caller_id_name; + local from_uri = common.array.expand_variables(gateway.settings.from, destination, self.caller, { gateway = gateway }); - if account_uuid and auth_account_uuid and account_uuid == auth_account_uuid then - table.insert(origination_variables, "sip_h_P-Asserted-Identity='" .. identity .. "'"); - else - table.insert(origination_variables, "sip_h_P-Preferred-Identity='" .. identity .. "'"); - end + self.log:devel('DESTINATION: ', destination); + if gateway.settings.asserted_identity then + local identity = common.array.expand_variables(gateway.settings.asserted_identity, destination, self.caller, { gateway = gateway }) + if self.caller.clir then - table.insert(origination_variables, "origination_caller_id_number='anonymous'"); - table.insert(origination_variables, "origination_caller_id_name='" .. ( self.caller.anonymous_name or 'Anonymous') .. "'"); - table.insert(origination_variables, "sip_h_P-Privacy='id'"); + caller_id_number = self.caller.anonymous_number or 'anonymous'; + caller_id_name = self.caller.anonymous_name or 'Anonymous'; + from_uri = common.array.expand_variables(gateway.settings.from_clir, destination, self.caller, { gateway = gateway }) or from_uri; + identity = common.array.expand_variables(gateway.settings.asserted_identity_clir, destination, self.caller, { gateway = gateway }) or identity; + table.insert(origination_variables, "origination_caller_id_number='" .. caller_id_number .. "'"); + table.insert(origination_variables, "origination_caller_id_name='" .. caller_id_name .. "'"); + table.insert(origination_variables, "sip_h_Privacy='id'"); else if destination.caller_id_number then table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'"); @@ -194,6 +202,16 @@ function SipCall.fork(self, destinations, arg ) table.insert(origination_variables, "origination_caller_id_name='" .. destination.caller_id_name .. "'"); end end + + if from_uri then + table.insert(origination_variables, "sip_from_uri='" .. from_uri .. "'"); + end + + if identity then + table.insert(origination_variables, "sip_h_P-Asserted-Identity='" .. identity .. "'"); + end + + self.log:info('FORK ', index, '/', #destinations, ' - from: ', from_uri, ', identity: ', identity, ', privacy: ', self.caller.clir); else if destination.caller_id_number then table.insert(origination_variables, "origination_caller_id_number='" .. destination.caller_id_number .. "'"); -- cgit v1.2.3 From d8dce422831675d0aca7b9a640b20bb5a5e947ab Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 12 Jun 2013 13:59:43 +0200 Subject: log line removed --- misc/freeswitch/scripts/dialplan/sip_call.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 7e3cddc..256508a 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -181,8 +181,6 @@ function SipCall.fork(self, destinations, arg ) local caller_id_name = destination.caller_id_name or self.caller.caller_id_name; local from_uri = common.array.expand_variables(gateway.settings.from, destination, self.caller, { gateway = gateway }); - self.log:devel('DESTINATION: ', destination); - if gateway.settings.asserted_identity then local identity = common.array.expand_variables(gateway.settings.asserted_identity, destination, self.caller, { gateway = gateway }) -- cgit v1.2.3 From 29eb5c09076e2966224d7653146ea06f066481b0 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Wed, 12 Jun 2013 18:27:14 +0200 Subject: settings can be nil --- misc/freeswitch/scripts/dialplan/sip_call.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/sip_call.lua b/misc/freeswitch/scripts/dialplan/sip_call.lua index 256508a..1966a41 100644 --- a/misc/freeswitch/scripts/dialplan/sip_call.lua +++ b/misc/freeswitch/scripts/dialplan/sip_call.lua @@ -179,16 +179,16 @@ function SipCall.fork(self, destinations, arg ) local asserted_identity_clir = tostring(gateway.settings.asserted_identity); local caller_id_number = destination.caller_id_number or self.caller.caller_id_number; local caller_id_name = destination.caller_id_name or self.caller.caller_id_name; - local from_uri = common.array.expand_variables(gateway.settings.from, destination, self.caller, { gateway = gateway }); + local from_uri = common.array.expand_variables(gateway.settings.from or '', destination, self.caller, { gateway = gateway }); if gateway.settings.asserted_identity then - local identity = common.array.expand_variables(gateway.settings.asserted_identity, destination, self.caller, { gateway = gateway }) + local identity = common.array.expand_variables(gateway.settings.asserted_identity or '', destination, self.caller, { gateway = gateway }) if self.caller.clir then caller_id_number = self.caller.anonymous_number or 'anonymous'; caller_id_name = self.caller.anonymous_name or 'Anonymous'; - from_uri = common.array.expand_variables(gateway.settings.from_clir, destination, self.caller, { gateway = gateway }) or from_uri; - identity = common.array.expand_variables(gateway.settings.asserted_identity_clir, destination, self.caller, { gateway = gateway }) or identity; + from_uri = common.array.expand_variables(gateway.settings.from_clir or '', destination, self.caller, { gateway = gateway }) or from_uri; + identity = common.array.expand_variables(gateway.settings.asserted_identity_clir or '', destination, self.caller, { gateway = gateway }) or identity; table.insert(origination_variables, "origination_caller_id_number='" .. caller_id_number .. "'"); table.insert(origination_variables, "origination_caller_id_name='" .. caller_id_name .. "'"); table.insert(origination_variables, "sip_h_Privacy='id'"); -- cgit v1.2.3 From 66ef95959eabf843832eeae4c844cbd05eabd5e3 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 14 Jun 2013 10:55:28 +0200 Subject: expression function added --- misc/freeswitch/scripts/dialplan/router.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 50653d8..c2b229d 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -160,13 +160,21 @@ function Router.route_match(self, route) table.insert(arguments, common.array.expand_variables(argument, destination, self.variables)); end result, replacement = self['fun_' .. variable_name](self, unpack(arguments)) - if self.log_details or true then + if not common.str.blank(element.pattern) then + if self.log_details then + self.log:debug('ELEMENT_FUNCTION - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); + end + result, replacement = self:element_match(tostring(element.pattern), tostring(replacement), tostring(replacement)); + end + if self.log_details then if result then self.log:debug('ELEMENT_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); else self.log:debug('ELEMENT_NO_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', tostring(replacement)); end end + else + self.log:error('ELEMENT_FUNCTION - function not found: ', 'fun_' .. variable_name); end end end @@ -267,3 +275,14 @@ function Router.fun_speeddial(self, number, name) end end end + + +function Router.fun_expression(self, expression_str) + expression_str = expression_str:gsub('[^%d%.%+%(%)%^%%%*%/-<>]', ''); + result = loadstring("return (" .. expression_str .. ")")(); + if result then + return true, result; + else + return false, result; + end +end -- cgit v1.2.3 From e48434bf0e1bac7687d08734578c01367b880562 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 14 Jun 2013 11:14:04 +0200 Subject: expression can be nil, empty or invalid --- misc/freeswitch/scripts/dialplan/router.lua | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index c2b229d..b762010 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -278,8 +278,24 @@ end function Router.fun_expression(self, expression_str) - expression_str = expression_str:gsub('[^%d%.%+%(%)%^%%%*%/-<>]', ''); - result = loadstring("return (" .. expression_str .. ")")(); + if common.str.blank(expression_str) then + self.log:error('EXPRESSION - no expression specified'); + return false; + end + + expression_str = expression_str:gsub('[^%d%.%+%(%)%^%%%*%/-<>=!|&]', ''); + expression_str = expression_str:gsub('&&', ' and '); + expression_str = expression_str:gsub('||', ' or '); + expression_str = expression_str:gsub('!=', '~='); + + local expression = loadstring("return (" .. expression_str .. ")") + + if not expression then + self.log:error('EXPRESSION - invalid expression: ', expression_str); + return false; + end + + result = expression(); if result then return true, result; else -- cgit v1.2.3 From 4f5c5e93fe01dec4eea933ab7cb805d95b0bd647 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Fri, 14 Jun 2013 11:59:15 +0200 Subject: action:set added --- misc/freeswitch/scripts/dialplan/router.lua | 72 ++++++++++++++++++----------- 1 file changed, 46 insertions(+), 26 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index b762010..4e6398e 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -109,6 +109,37 @@ function Router.element_match_group(self, pattern, groups, replacement, use_key, end +function Router.element_run_function(self, variable_name, element, destination) + local result = nil; + local replacement = nil; + + if self['fun_' .. variable_name] then + local arguments = {}; + for index, argument in ipairs(common.str.to_a(element.replacement, ',')) do + table.insert(arguments, common.array.expand_variables(argument, destination, self.variables)); + end + result, replacement = self['fun_' .. variable_name](self, unpack(arguments)) + if not common.str.blank(element.pattern) then + if self.log_details then + self.log:debug('ELEMENT_FUNCTION - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); + end + result, replacement = self:element_match(tostring(element.pattern), tostring(replacement), tostring(replacement)); + end + if self.log_details then + if result then + self.log:debug('ELEMENT_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); + else + self.log:debug('ELEMENT_NO_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', tostring(replacement)); + end + end + else + self.log:error('ELEMENT_FUNCTION - function not found: ', 'fun_' .. variable_name); + end + + return result, replacement; +end + + function Router.route_match(self, route) local destination = { gateway = 'gateway' .. route.endpoint_id, @@ -132,9 +163,19 @@ function Router.route_match(self, route) end if element.action ~= 'none' then - if common.str.blank(element.var_in) or common.str.blank(element.pattern) and element.action == 'set' then - result = true; - replacement = common.array.expand_variables(element.replacement, destination, self.variables); + if element.action == 'set' then + if common.str.blank(element.var_in) then + result = true; + replacement = common.array.expand_variables(element.replacement, destination, self.variables); + else + local command, variable_name = common.str.partition(element.var_in, ':'); + if command == 'fun' then + result, replacement = self:element_run_function(variable_name, element, destination); + else + result = true; + replacement = common.array.expand_variables(element.replacement, destination, self.variables); + end + end else local command, variable_name = common.str.partition(element.var_in, ':'); @@ -154,28 +195,7 @@ function Router.route_match(self, route) local search_string = self.caller:to_s('sip_h_' .. variable_name); result, replacement = self:element_match(tostring(element.pattern), search_string, tostring(element.replacement)); elseif command == 'fun' then - if self['fun_' .. variable_name] then - local arguments = {}; - for index, argument in ipairs(common.str.to_a(element.replacement, ',')) do - table.insert(arguments, common.array.expand_variables(argument, destination, self.variables)); - end - result, replacement = self['fun_' .. variable_name](self, unpack(arguments)) - if not common.str.blank(element.pattern) then - if self.log_details then - self.log:debug('ELEMENT_FUNCTION - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); - end - result, replacement = self:element_match(tostring(element.pattern), tostring(replacement), tostring(replacement)); - end - if self.log_details then - if result then - self.log:debug('ELEMENT_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', replacement); - else - self.log:debug('ELEMENT_NO_MATCH - function: ', variable_name, '(', table.concat(arguments, ', '), ') => ', tostring(replacement)); - end - end - else - self.log:error('ELEMENT_FUNCTION - function not found: ', 'fun_' .. variable_name); - end + result, replacement = self:element_run_function(variable_name, element, destination); end end @@ -282,7 +302,7 @@ function Router.fun_expression(self, expression_str) self.log:error('EXPRESSION - no expression specified'); return false; end - + expression_str = expression_str:gsub('[^%d%.%+%(%)%^%%%*%/-<>=!|&]', ''); expression_str = expression_str:gsub('&&', ' and '); expression_str = expression_str:gsub('||', ' or '); -- cgit v1.2.3 From b3a96040433edc2ee2a1d85cf989b6d6adb60ee2 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 20 Jun 2013 11:24:29 +0200 Subject: previous behavior of set action restored --- misc/freeswitch/scripts/dialplan/router.lua | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 4e6398e..24d2462 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -22,6 +22,7 @@ function Router.new(self, arg) self.variables = arg.variables or {}; self.log_details = arg.log_details; self.routing_tables = {}; + return object; end @@ -75,8 +76,9 @@ function Router.element_match(self, pattern, search_string, replacement, route_v local replace_by = common.array.expand_variables(replacement, route_variables, self.variables) result = search_string:gsub(pattern, replace_by); if self.log_details then - self.log:debug('ELEMENT_MATCH - ', search_string, ' ~= ', pattern, ' => ', replacement, ' => ', replace_by); + self.log:debug('ELEMENT_MATCH - ', search_string, ' ~= ', pattern, ' => ', replacement, ' => ', result); end + return true, result; end @@ -163,19 +165,9 @@ function Router.route_match(self, route) end if element.action ~= 'none' then - if element.action == 'set' then - if common.str.blank(element.var_in) then - result = true; - replacement = common.array.expand_variables(element.replacement, destination, self.variables); - else - local command, variable_name = common.str.partition(element.var_in, ':'); - if command == 'fun' then - result, replacement = self:element_run_function(variable_name, element, destination); - else - result = true; - replacement = common.array.expand_variables(element.replacement, destination, self.variables); - end - end + if common.str.blank(element.var_in) and common.str.blank(element.pattern) and element.action == 'set' then + result = true; + replacement = common.array.expand_variables(element.replacement, destination, self.variables); else local command, variable_name = common.str.partition(element.var_in, ':'); -- cgit v1.2.3 From 22c5ce2ab518a548428320ae38818fe1f16ce567 Mon Sep 17 00:00:00 2001 From: Peter Kozak Date: Thu, 20 Jun 2013 11:36:37 +0200 Subject: pattern can be ignored if action=set and var_in is blank --- misc/freeswitch/scripts/dialplan/router.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'misc/freeswitch/scripts/dialplan') diff --git a/misc/freeswitch/scripts/dialplan/router.lua b/misc/freeswitch/scripts/dialplan/router.lua index 24d2462..20b833b 100644 --- a/misc/freeswitch/scripts/dialplan/router.lua +++ b/misc/freeswitch/scripts/dialplan/router.lua @@ -165,7 +165,7 @@ function Router.route_match(self, route) end if element.action ~= 'none' then - if common.str.blank(element.var_in) and common.str.blank(element.pattern) and element.action == 'set' then + if common.str.blank(element.var_in) and element.action == 'set' then result = true; replacement = common.array.expand_variables(element.replacement, destination, self.variables); else -- cgit v1.2.3