From 2c0c376caf1f6361aaa264a4cc7a0e2bcce345a9 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Wed, 6 Oct 2010 15:02:17 +0000 Subject: Changed callback_url to callback_command to give user better configurability --- vmail-model.lua | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/vmail-model.lua b/vmail-model.lua index f8f3ae3..81f943a 100644 --- a/vmail-model.lua +++ b/vmail-model.lua @@ -18,7 +18,8 @@ config.domain = config.domain or "voicemail" config.event_socket_ip = config.event_socket_ip or "127.0.0.1" config.event_socket_port = config.event_socket_port or "8021" config.event_socket_password = config.event_socket_password or "ClueCon" -config.callback_url = config.callback_url or "sofia/gateway/asterlink.com/$1" +config.callback_command = config.callback_command or "originate {ignore_early_media=true,origination_caller_id_name='Voicemail',origination_caller_id_number='Voicemail'}sofia/gateway/asterlink.com/$1 &playback($2)" + local env local con @@ -70,10 +71,13 @@ local function voicemail_inject(user, domain, sound_file, cid_num, cid_name) return result end -local function voicemail_callback(extension, sound_file, cid_num, cid_name) - local cmd = "echo -e 'auth "..escape_quotes(config.event_socket_password).."\n\n" - cmd = cmd.."bgapi originate {ignore_early_media=true,origination_caller_id_name='\\''"..string.gsub(cid_name or "Voicemail", "'", "").."'\\'',origination_caller_id_number='\\''" - cmd = cmd..string.gsub(cid_num or "", "'", "").."'\\''}"..escape_quotes(string.gsub(config.callback_url, "$1", extension)).." &playback("..escape_quotes(sound_file)..")" +local function voicemail_callback(extension, sound_file, username) + local cmd = "echo -e 'auth "..escape_quotes(config.event_socket_password).."\n\nbgapi " + local c = config.callback_command + c = c:gsub("%$1", extension) + c = c:gsub("%$2", sound_file) + c = c:gsub("%$3", username) + cmd = cmd..escape_quotes(c) cmd = cmd.."\n\nexit\n\n' | nc "..format.escapespecialcharacters(config.event_socket_ip).." "..format.escapespecialcharacters(config.event_socket_port).." 2>&1" local f = io.popen( cmd ) local result = f:read("*a") or "" @@ -323,8 +327,8 @@ local function validateconfig(newconfig) newconfig.value.event_socket_password.errtxt = "Cannot be blank" success = false end - if newconfig.value.callback_url.value == "" then - newconfig.value.callback_url.errtxt = "Cannot be blank" + if newconfig.value.callback_command.value == "" then + newconfig.value.callback_command.errtxt = "Cannot be blank" success = false end return success, newconfig @@ -340,7 +344,7 @@ get_config = function() result.event_socket_ip = cfe({ value=config.event_socket_ip, label="FS Event Socket IP" }) result.event_socket_port = cfe({ value=config.event_socket_port, label="FS Event Socket Port" }) result.event_socket_password = cfe({ value=config.event_socket_password, label="FS Event Socket Password" }) - result.callback_url = cfe({ value=config.callback_url, label="FS SIP URL for Callback", desc="Use $1 for extension. No other parameters allowed." }) + result.callback_command = cfe({ value=config.callback_command, label="FS API Command for Callback", desc="Use $1 for extension, $2 for wav filename, and $3 for originating user. No other parameters allowed." }) return cfe({ type="group", value=result, label="Voicemail Config" }) end -- cgit v1.2.3