Skip to content Skip to sidebar Skip to footer

Send An Xmpp Message Using A Python Library

How can I send an XMPP message using one of the following Python libraries: wokkel, xmpppy, or jabber.py ? I think I am aware of the pseudo-code, but so far have not been able to g

Solution 1:

This is the simplest possible xmpp client. It will send a 'hello :)' message. I'm using xmpppy in the example. And connecting to gtalk server. I think the example is self-explanatory:

importxmppusername='username'
passwd = 'password'
to='name@example.com'
msg='hello :)'


client = xmpp.Client('gmail.com')
client.connect(server=('talk.google.com',5223))
client.auth(username, passwd, 'botty')
client.sendInitPresence()
message = xmpp.Message(to, msg)
message.setAttr('type', 'chat')
client.send(message)

Solution 2:

xmpppy has a number of examples listed on its main page (under "examples"), the most basic of which sends a single test message. They make the examples progressively more interesting -- they introduce the callback-oriented API via a chat bot program.

Post a Comment for "Send An Xmpp Message Using A Python Library"