Last active
October 18, 2017 14:51
-
-
Save javipalanca/d17222430cee165892ef53af8a469c4a to your computer and use it in GitHub Desktop.
aioxmpp example to insert a custom attribute into a <message/>
This file contains 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
import asyncio | |
import aioxmpp | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
class Fipa(aioxmpp.xso.XSO): | |
TAG = ("fipa:x:acl", "fipa-envelope") | |
performative = aioxmpp.xso.Attr(tag="performative", type_=aioxmpp.xso.String(), default="QUERY") | |
async def connect(c): | |
async with c.connected() as stream: | |
aioxmpp.stanza.Message.fipa = aioxmpp.xso.Child([Fipa]) | |
msg = aioxmpp.stanza.Message( | |
to=aioxmpp.JID.fromstr("jpalanca@localhost"), | |
from_=aioxmpp.JID.fromstr("jpalanca@localhost"), | |
type_=aioxmpp.MessageType.CHAT, | |
) | |
msg.body[None] = "Hello World!" | |
msg.fipa = Fipa() | |
msg.fipa.performative = "INFORM" | |
await stream.send(msg) | |
await asyncio.sleep(5) | |
jid = aioxmpp.JID.fromstr("jpalanca@localhost") | |
client = aioxmpp.PresenceManagedClient(jid, aioxmpp.make_security_layer("********")) | |
loop = asyncio.get_event_loop() | |
try: | |
loop.run_until_complete(connect(client)) | |
except Exception as e: | |
print(e) | |
finally: | |
loop.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment