我使用Python Framework sleekxmpp创建了一个小型XMPP客户端。我使用followind代码创建连接类:
class Client(ClientXMPP):
def __init__(self, jid, password):
ClientXMPP.__init__(self, jid, password)
self.register_plugin('xep_0280')
self.add_event_handler("session_start", self.session_start)
self.add_event_handler("message", self.message)
self.add_event_handler("carbon_received", self.carbon_received)
self.add_event_handler("carbon_sent", self.carbon_sent)
我收到了回复消息或碳类的回复。在消息函数中,我可以使用msg [“body”]获取消息正文但是如何从碳消息中获取消息正文?
我尝试以与消息funktion相同的方式获取它,但它只返回一个空字符串。如果我做了一个类型的消息[“转发”]我得到了“”但我无法得到消息正文。
我使用的回调函数:
def message(self, msg):
sendMsg(msg["to"], msg["body"])
print msg["body"]
def carbon_received(self, msg):
print "carbon_received"
#print type(msg['forwarded'])
#print msg['forwarded']["stanza"]
#print msg
def carbon_sent(self, msg):
print "carbon_sent"
#print type(msg['forwarded'])
#print msg['forwarded']["stanza"]
#print msg