Created
January 27, 2011 19:08
-
-
Save nchapman/799006 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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