Reputation: 11
I was reading this book Oreilly XMPP The definitive Guide
Theres and example code in chapter 2 for an EchoBot
I want to know how i can test this code...
def main():
bot = EchoBot("[email protected]/HelloWorld", "mypass")
bot.run()
class EchoBot(object):
def __init__(self, jid, password):
self.xmpp = sleekxmpp.ClientXMPP(jid, password)
self.xmpp.add_event_handler("session_start", self.handleXMPPConnected)
self.xmpp.add_event_handler("message", self.handleIncomingMessage)
def run(self):
self.xmpp.connect()
self.xmpp.process(threaded=False)
def handleXMPPConnected(self, event):
self.xmpp.sendPresence(pstatus="Send me a message")
def handleIncomingMessage(self, message):
self.xmpp.sendMessage(message["jid"], message["message"])
ive installed sleekxmpp, created an account on jabber.org and replaced [email protected]/HelloWorld with [email protected]/HelloWorld and mypass with mypassword
But when i run this code... it doesnt seem to do anything. it jus terminates. Is there anything im missing?
Upvotes: 1
Views: 701
Reputation: 501
In order to test the echo bot, you can open another Jabber Client (Psi or Kopete for example), add the echo bot to your roster and then you can chat with it like you would in any other IM scenario, only the echo bot will respond with the message that you sent it.
But be sure to visit https://github.com/fritzy/SleekXMPP/wiki/XMPP%3A-The-Definitive-Guide to see the most update version of the the books examples.
Upvotes: 0
Reputation: 111
This example code does not work with new version of SleekXMPP library, because API has been changed.
Last line of your bot should be:
self.xmpp.sendMessage(message["from"], message["body"])
The author of SleekXMPP library explains changes required in example code here: https://github.com/fritzy/SleekXMPP/wiki/XMPP%3A-The-Definitive-Guide
Upvotes: 1