Skip to content

Instantly share code, notes, and snippets.

@nchapman
Created January 27, 2011 19:08
Show Gist options
  • Save nchapman/799006 to your computer and use it in GitHub Desktop.
Save nchapman/799006 to your computer and use it in GitHub Desktop.
local http = require "socket.http"
local function url_encode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
local function on_message(data)
if data.stanza:child_with_name("body") then
module:log("info", url_encode(tostring(data.stanza)))
http.request("http://127.0.0.1:7379/", "RPUSH/messages" .. url_encode(tostring(data.stanza)))
end
return nil
end
module:hook("message/bare", on_message, 20)
module:hook("message/full", on_message, 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment