This module lets you programmatically subscribe to updates from a pubsub node, even if the pubsub service is remote.
module:depends("pubsub_subscription");
module:add_item("pubsub-subscription", {
service = "pubsub.example.com";
node = "otter_facts";
-- Callbacks:
on_subscribed = function()
module:log("info", "Otter facts incoming!");
end;
on_item = function(event)
module:log("info", "Random Otter Fact: %s", event.payload:get_text());
end;
});Ensure the module is loaded and add your subscription via the
:add_item API. The item table MUST have
service and node fields and SHOULD have one or
more on_<event> callbacks.
The JID of the pubsub service is given in service (could
also be the JID of an user for advanced PEP usage) and the node is given
in, unsurprisingly, the node field.
The various on_event callback functions, if present,
gets called when new events are received. The most interesting would be
on_item, which receives incoming items. Available events
are:
on_subscribedon_unsubscribedon_errortype, condition, text,
and extra fields as argument.
on_itempayload field in the table provided as argument. The ID of
the item can be found in item.attr.id.
on_retractitem.attr.id of the table argument..
on_purgeon_deleteevent_payload = {
-- Common prosody event entries:
stanza = util.stanza;
origin = util.session;
-- PubSub service details
service = "pubsub.example.com";
node = "otter_facts";
-- The pubsub event itself
item = util.stanza; -- <item/>
payload = util.stanza; -- actual payload, child of <item/>
}Should work with Prosody >= 0.11.x
With the plugin installer in Prosody 0.12 you can use:
sudo prosodyctl install --server=https://modules.prosody.im/rocks/ mod_pubsub_subscription
For earlier versions see the documentation for installing 3rd party modules