Commit c5846a91 authored by Ted Trask's avatar Ted Trask

Added callbackmessage function. Uses new config parameter callback_uri.

parent 53930987
......@@ -70,6 +70,14 @@ movemymessage = function( self )
return self:redirect_to_referrer(self.model.move_message(self.clientdata.message, self.clientdata.newfolder, self.sessiondata.userinfo.userid))
end
callbackmessage = function( self )
return self:redirect_to_referrer(self.model.callback_message(self.clientdata.message, self.clientdata.extension))
end
callbackmymessage = function( self )
return self:redirect_to_referrer(self.model.callback_message(self.clientdata.message, self.clientdata.extension, self.sessiondata.userinfo.userid))
end
editusersettings = function( self )
return controllerfunctions.handle_form(self, function() return self.model.get_usersettings(self.clientdata.username) end, self.model.update_usersettings, self.clientdata, "Save", "Edit Settings", "Settings Saved")
end
......
......@@ -67,11 +67,14 @@ end
<% end %>
<% if viewlibrary.check_permission("movemessage") or viewlibrary.check_permission("movemymessage") then %>
$("#multimove").click(HandleMulti);
<% end %>
<% if viewlibrary.check_permission("callbackmessage") or viewlibrary.check_permission("callbackmymessage") then %>
$("#multicallback").click(HandleMulti);
<% end %>
});
</script>
<% displaycommandresults({"deletemessage", "deletemymessage", "forwardmessage", "forwardmymessage", "emailmessage", "emailmymessage", "movemessage", "movemymessage"}, session) %>
<% displaycommandresults({"deletemessage", "deletemymessage", "forwardmessage", "forwardmymessage", "emailmessage", "emailmymessage", "movemessage", "movemymessage", "callbackmessage", "callbackmymessage"}, session) %>
<h1>Messages</h1>
<DL>
......@@ -117,6 +120,16 @@ end
</form>
<% end %>
<% end %>
<% if viewlibrary.check_permission("callbackmessage") or viewlibrary.check_permission("callbackmymessage") then %>
<form id="multicallback" action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller) %>/
<% if viewlibrary.check_permission("callbackmessage") then io.write("callbackmessage") else io.write("callbackmymessage") end %>
" method="POST">
<input class="hidden" type="hidden" name="redir" value="<%= html.html_escape(page_info.orig_action) %>" >
<input class="hidden" type="hidden" name="message" value="" >
<input class="submit" type="submit" value="Callback">
<input class="text" type="text" name="extension" value="" style="width:auto;">
</form>
<% end %>
</TD></TR></TABLE>
<table><tr><td>
<small>select: </small>
......
......@@ -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 = {}
......
GUEST=vmail:processdialplanxml,vmail:processdirectoryxml
USER=vmail:listfolders,vmail:listusers,vmail:listmymessages,vmail:downloadmymessage,vmail:deletemymessage,vmail:editmyusersettings,vmail:forwardmymessage,vmail:movemymessage,vmail:emailmymessage
USER=vmail:listfolders,vmail:listusers,vmail:listmymessages,vmail:downloadmymessage,vmail:deletemymessage,vmail:editmyusersettings,vmail:forwardmymessage,vmail:movemymessage,vmail:emailmymessage,vmail:callbackmymessage
EDITOR=vmail:editusers,vmail:createuser,vmail:deleteuser,vmail:editusersettings
EXPERT=vmail:editconfig,vmail:listmessages,vmail:downloadmessage,vmail:deletemessage,vmail:forwardmessage,vmail:movemessage,vmail:emailmessage
ADMIN=vmail:listmessages,vmail:downloadmessage,vmail:deletemessage,vmail:forwardmessage,vmail:movemessage,vmail:emailmessage,vmail:editusersettings,vmail:listfolders,vmail:listusers,vmail:editusers,vmail:createuser,vmail:deleteuser,vmail:editconfig
EXPERT=vmail:editconfig,vmail:listmessages,vmail:downloadmessage,vmail:deletemessage,vmail:forwardmessage,vmail:movemessage,vmail:emailmessage,vmail:callbackmessage
ADMIN=vmail:listmessages,vmail:downloadmessage,vmail:deletemessage,vmail:forwardmessage,vmail:movemessage,vmail:emailmessage,vmail:callbackmessage,vmail:editusersettings,vmail:listfolders,vmail:listusers,vmail:editusers,vmail:createuser,vmail:deleteuser,vmail:editconfig
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment