Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #echobot.py
- from twisted.words.xish import domish
- from wokkel.xmppim import MessageProtocol, AvailablePresence
- from twisted.web import xmlrpc
- class EchoBotProtocol(MessageProtocol):
- def connectionMade(self):
- print "Connected!"
- # send initial presence
- self.send(AvailablePresence())
- def connectionLost(self, reason):
- print "Disconnected!"
- def onMessage(self, msg):
- print str(msg)
- if msg["type"] == 'chat' and hasattr(msg, "body"):
- reply = domish.Element((None, "message"))
- reply["to"] = msg["from"]
- reply["from"] = msg["to"]
- reply["type"] = 'chat'
- reply.addElement("body", content="echo: " + str(msg.body))
- self.send(reply)
- def mycall(self, msg):
- print "ooppss= "+(msg)
- reply = domish.Element((None, "message"))
- reply["type"] = 'chat'
- reply.addElement("body", content='Some body sent this : ' + str((msg)))
- xmppclient.send(reply)
- return 'your msg is : '+ msg
- class MyRPC(xmlrpc.XMLRPC):
- def __init__(self):
- self.allowNone = True
- self.useDateTime = False
- self.fc = EchoBotProtocol()
- #self.fc = echobot()
- def xmlrpc_dispatch(self, m):
- return self.fc.mycall(m)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement