-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
The following code was copied to Slixfeed news bot from the atomtopubsub project (file: publishx.py).
def create_entry(xmpp_instance, jid, node, item_id, payload):
iq = xmpp_instance.Iq(stype="set", sto=jid)
iq['pubsub']['publish']['node'] = node
item = pubsub.Item()
item['id'] = item_id
item['payload'] = payload
iq['pubsub']['publish'].append(item)
return iq await iq.send(timeout=15)Instead, it is possible to use a Slixmpp function
async def publish_node_item(xmpp_instance, jid, node, item_id, payload):
try:
iq = await xmpp_instance.plugin['xep_0060'].publish(
jid, node, id=item_id, payload=payload)
# NOTE I suppose I want to make use of variable "iq" to read result and handle occurrences of issues.
print(iq)
return iq
except (IqError, IqTimeout) as e:
print(e)From Slixmpp (slixmpp/plugins/xep_0060/pubsub).
def publish(self, jid, node, id=None, payload=None, options=None,
ifrom=None, timeout_callback=None, callback=None,
timeout=None):
"""
Add a new item to a node, or edit an existing item.
For services that support it, you can use the publish command
as an event signal by not including an ID or payload.
When including a payload and you do not provide an ID then
the service will generally create an ID for you.
Publish options may be specified, and how those options
are processed is left to the service, such as treating
the options as preconditions that the node's settings
must match.
:param jid: The JID of the pubsub service.
:param node: The node to publish the item to.
:param id: Optionally specify the ID of the item.
:param payload: The item content to publish.
:param options: A form of publish options.
"""
iq = self.xmpp.Iq(sto=jid, sfrom=ifrom, stype='set')
iq['pubsub']['publish']['node'] = node
if id is not None:
iq['pubsub']['publish']['item']['id'] = id
if payload is not None:
iq['pubsub']['publish']['item']['payload'] = payload
iq['pubsub']['publish_options'] = options
return iq.send(callback=callback, timeout=timeout, timeout_callback=timeout_callback)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels