Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (43 sloc) 1.91 KB
-- original source:
-- mod_textpresence is a module for Prosody IM ( to publish your xmpp status through http
-- installation: copy mod_textpresence.lua to your modules directory, then add "textpresence" to your modules_enabled list
-- usage: once loaded, simply browse to http://your.prosody.server:5280/status-text/JID_YOU_WANT_TO_SEE
local httpserver = require "net.httpserver";
local jid_split = require "util.jid".prepped_split;
local check_user_exists = require "core.usermanager".user_exists;
local response_404 = { status = "404 Not Found", body = "<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :(" };
local function handle_request(method, body, request)
local jid = request.url.path:match("[^/]+$");
if not jid then return response_404; end
local user, host = jid_split(jid);
if host and not user and then
user, host = host,;
if host then host = host:gsub(":%d+$", ""); end
if not host or not user then return response_404; end
if not check_user_exists(user, host) then return response_404; end
local user_sessions = hosts[host] and hosts[host].sessions[user];
if not user_sessions then return "offline"; end
local status = user_sessions.top_resources[1];
if not status or not status.presence then return "offline"; end
status = status.presence:child_with_name("show");
if not status then
status = "online";
status = status:get_text();
return {
status = "200 OK",
headers = { ["Content-Type"] = "text/plain" },
body = status
local function setup()
local ports = module:get_option("http_ports") or { 5280 };
httpserver.new_from_config(ports, handle_request, { base = "status-text" });
if prosody.start_time then -- already started
else"server-started", setup);