Echo bot using XMPPPY in a MUC

148 Views Asked by At

so here is my problem I have an Ejabberd server running and I try to implement my own XMPP API using xmpppy but at the moment I can't figure why my echo bot on a MUC isn't working. I have already made an echo bot on private message/offline queue and it is working but here it seems to connect but can't read the messages here is the code for the 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)

When I run this the message is sent without any problem and it is waiting for new messages to print it, but nothing happens even if I try to send a message while the bot is running with another python script, and when it seems to be connected in the terminal and still running, on the web interface of ejabberd this is what is shown Ejabberd web page.

So it seems on the web page that the echo bot isn't connected on the MUC.

Thanks in advance for help !

1

There are 1 best solutions below

0
On

Ok I find the solution it was simply by adding a username when I send presence like this:

cl.send(xmpp.Presence(to="%s %s" % (room + "/username", self.jid)))