【发布时间】:2023-03-09 21:27:01
【问题描述】:
所以这是我的问题,我有一个 Ejabberd 服务器正在运行,我尝试使用 xmpppy 实现我自己的 XMPP API,但目前我无法弄清楚为什么我在 MUC 上的 echo bot 不起作用。我已经在私人消息/离线队列上创建了一个 echo bot,它正在工作,但在这里它似乎连接但无法读取消息这里是 MUC Echo bot 的代码:
def messageCB(self,conn,msg):
print(msg.getType())
if msg.getType() == "groupchat":
print(str(msg.getFrom()) +": "+ str(msg.getBody()))
if msg.getType() == "chat":
print("private: " + str(msg.getFrom()) + ":" +str(msg.getBody()))
def StepOn(self,conn):
try:
conn.Process(1)
except KeyboardInterrupt:
return 0
return 1
def GoOn(self,conn):
while self.StepOn(conn):
pass
def receive_muc(self, muc_room):
client=xmpp.protocol.JID(self.jid)
cl = xmpp.Client(client.getDomain(), debug=[])
cl.connect()
cl.auth(client.getNode(),self.passw)
cl.sendInitPresence()
cl.RegisterHandler('message', self.messageCB)
room = muc_room
print("Joining " + room)
cl.send(xmpp.Presence(to="%s %s" % (room, self.jid)))
self.send_muc("I'm online !", room)
self.GoOn(cl)
当我运行此消息时,消息发送没有任何问题,它正在等待新消息打印它,但即使我尝试在机器人使用另一个 python 脚本运行时发送消息,也没有任何反应。要在终端中连接并仍在运行,在 ejabberd 的 Web 界面上显示的是 Ejabberd web page。
所以在网页上似乎没有在 MUC 上连接 echo bot。
提前感谢您的帮助!
【问题讨论】:
标签: python xmpp ejabberd xmpppy