fabiang / xmpp

Library for XMPP protocol connections (Jabber) for PHP
Other
179 stars 82 forks source link

Example of echo bot #26

Open skobkin opened 8 years ago

skobkin commented 8 years ago

As said in #10 we need example of code for message receiving.

I tried to add event listener for {http://etherx.jabber.org/streams}message and for {jabber:client}message with no result. Callback just didn't calling.

Also I want to understand how client can be used in cycle for processing incoming messages in real-time.

skobkin commented 8 years ago

I was trying to debug EventManager::trigger() and found that only two events are fired on incoming messages: {jabber:client}message and {jabber:client}body. I was able to set event listener after small fix of my error.

But both events seems not to be usable for message processing.

{jabber:client}message contains unwanted data with message text.

{jabber:client}body does not.

But both have no information about sender or other helpful metadata.

bretterer commented 8 years ago

I Really Really Really need to see an example of Echo bot... I don't see anything that works here! @fabiang please help!

$client->getConnection()->getInputStream()->getEventManager()->attach('{http://etherx.jabber.org/streams}message', function() use ($client) {
        // send a message to the above channel
        $message = new Message;
        $message->setMessage('test')
            ->setTo($channel.'@'.$server)
            ->setType(Message::TYPE_GROUPCHAT);
        $client->send($message);

    });

This does not work!

SaturnTeam commented 7 years ago

I also don't understand how to implement echo bot