10

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 get one running correctly. This is what I have tried so far:

  • Call some API and pass the servername and port number to connect to that server.
  • Call some API and pass the username, password to construct a JID object.
  • Authenticate with that JID.
  • Construct a Message object and call some API and pass that message obj in the argument.
  • Call some send API.

It seems easy enough in concept, but the devil is somewhere in the details. Please show a sample snippet if that's possible.

cathat
  • 389
  • 2
  • 6
  • 15

2 Answers2

40

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:

import xmpp

username = '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)
sorin
  • 161,544
  • 178
  • 535
  • 806
Nadia Alramli
  • 111,714
  • 37
  • 173
  • 152
  • 1
    Clearly something is wrong about these packages... I already had xmpp installed but it didn't have Client inside. I installed xmpppy and I still get the same error. Clearly a bad idea to release packages with the same name. – sorin Feb 18 '14 at 13:05
1

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.

cdleary
  • 69,512
  • 53
  • 163
  • 191