This module lets you programmatically subscribe to updates from a pubsub node, even if the pubsub service is remote.
:depends("pubsub_subscription");
module:add_item("pubsub-subscription", {
module= "pubsub.example.com";
service = "otter_facts";
node
-- Callbacks:
= function()
on_subscribed :log("info", "Otter facts incoming!");
moduleend;
= function(event)
on_item :log("info", "Random Otter Fact: %s", event.payload:get_text());
moduleend;
});
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_subscribed
on_unsubscribed
on_error
type
, condition
, text
,
and extra
fields as argument.
on_item
payload
field in the table provided as argument. The ID of
the item can be found in item.attr.id
.
on_retract
item.attr.id
of the table argument..
on_purge
on_delete
= {
event_payload -- Common prosody event entries:
= util.stanza;
stanza = util.session;
origin
-- PubSub service details
= "pubsub.example.com";
service = "otter_facts";
node
-- The pubsub event itself
= util.stanza; -- <item/>
item = util.stanza; -- actual payload, child of <item/>
payload }
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