summaryrefslogtreecommitdiffstats
path: root/vmail-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'vmail-model.lua')
-rw-r--r--vmail-model.lua46
1 files changed, 46 insertions, 0 deletions
diff --git a/vmail-model.lua b/vmail-model.lua
index 39b6041..8c627a1 100644
--- a/vmail-model.lua
+++ b/vmail-model.lua
@@ -18,6 +18,7 @@ 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"
local env
local con
@@ -67,6 +68,17 @@ 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)..")"
+ 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 ""
+ f:close()
+ return result
+end
+
local function assert (v, m)
if not v then
m = m or "Assertion failed!"
@@ -293,6 +305,10 @@ 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"
+ success = false
+ end
return success, newconfig
end
@@ -306,6 +322,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." })
return cfe({ type="group", value=result, label="Voicemail Config" })
end
@@ -518,6 +535,35 @@ move_message = function(message, newfolder, username)
return retval
end
+callback_message = function(message, extension, username)
+ local retval = cfe({ label="Callback message result" })
+ if string.find(message, ",") then
+ retval.errtxt = "Failed to callback message - can only callback one message at a time"
+ elseif extension == "" or string.find(extension, "[%s@]") then
+ retval.errtxt = "Failed to callback message - invalid extension"
+ else
+ local res, err = pcall(function()
+ local connected = databaseconnect()
+ -- Check if message exists
+ local sql = "SELECT * FROM voicemail_msgs" .. generatewhereclause(username, message)
+ local mess = getselectresponse(sql)
+ if #mess == 1 then
+ -- Initiate the call to the extension
+ voicemail_callback(extension, mess[1].file_path, username)
+ retval.value = "Initiated callback"
+ else
+ retval.errtxt = "Failed to callback message - message not found"
+ end
+ if connected then databasedisconnect() end
+ end)
+ if not res and err then
+ retval.errtxt = err
+ end
+ end
+
+ return retval
+end
+
list_folders = function()
local errtxt
local folders = {}