views:

2109

answers:

4

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.

+1  A: 

For your own good it would be best to gain experience by facing the devil by yourself. It's not that hard, you have to do it one step at a time. I'm sorry, but your question sounds a bit like if you had a homework assignment you didn't feel like doing and simply wanted to have someone hand you a complete solution on a silver platter.

For each subtask try to find appropriate methods from the libraries' APIs to move one step forward. Some of them have at least a tutorial on writing a simplest script sending a message to a given recipient.

Try it, get your hands dirty. Maybe you'll enjoy it after all. ;)

macbirdie
A: 

Are you familiar with twisted? I've got several apps written to use wokkel on github.

Dustin
+13  A: 

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

import xmpp

username = 'username'
passwd = 'password'
to='[email protected]'
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)
Nadia Alramli
A: 

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