Skip to content

Instantly share code, notes, and snippets.

@allan-simon
Created January 31, 2014 09:28
Show Gist options
  • Save allan-simon/8728954 to your computer and use it in GitHub Desktop.
Save allan-simon/8728954 to your computer and use it in GitHub Desktop.
import logging
from sleekxmpp import ClientXMPP
from sleekxmpp.exceptions import IqError, IqTimeout
JID = 'your_test_jid@example.com'
PASSWORD = "your_password"
ROOM_JID = "testroom@conference.example.com";
class EchoBot(ClientXMPP):
def __init__(self, jid, password, nick):
ClientXMPP.__init__(self, jid, password)
self.nick = nick
self.add_event_handler("session_start", self.session_start)
self.add_event_handler("message", self.message)
self.add_event_handler("groupchat_message", self.muc_message)
def session_start(self, event):
self.get_roster()
self.send_presence()
# note: the send message without joining is made on purpose
# so that we will receive a <message type="error"> back
self.send_message(
mto=ROOM_JID,
mbody="Echo, from " + self.nick,
mtype='groupchat'
)
def message(self, msg):
print("we should arrive here")
def muc_message(self, msg):
print("and certainly here too")
if __name__ == '__main__':
logging.basicConfig(
level=logging.DEBUG,
format='%(levelname)-8s %(message)s'
)
#bot_1 is simply a nick for the room
xmpp = EchoBot(JID, PASSWORD, "bot_1")
xmpp.register_plugin('xep_0045')
xmpp.connect()
xmpp.process(block=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment