Marcus Pierson
Marcus Pierson

Reputation: 13

Sleekxmpp Managing Stanzas

I am currently using SleekXMPP to build a simple XMPP client in Python. I'm a beginner though, and while I've read about stanzas, presence, roster, etc. I'm not sure how to get XML from the stream or how to handle it. I can't find any documentation on this either.

So basically, what I'm wondering is, how do I make an event or a handler for something like a message? So I could call a function everytime a message is received or something.

Thanks for your help!

Upvotes: 1

Views: 1654

Answers (2)

user881288
user881288

Reputation:

If you want a quick tutorial on getting started with a simple echo bot for responding to messages, we have: http://sleekxmpp.com/getting_started/echobot.html

There are also several examples at http://github.com/fritzy/SleekXMPP/tree/develop/examples that you can see how to work with various plugins.

If you find you need any further help with understanding how to work with stanzas with Sleek, don't forget that you can join the [email protected] chat room.

-- Lance

Upvotes: 1

MattJ
MattJ

Reputation: 7924

The SleekXMPP quickstart guide should help you get started with things like this.

The relevant part for handling messages is this line:

self.add_event_handler('message', self.message)

With self.message implemented as:

def message(self, msg):
    if msg['type'] in ('normal', 'chat'):
        msg.reply("Thanks for sending:\n%s" % msg['body']).send()

Upvotes: 1

Related Questions