xmpp icon indicating copy to clipboard operation
xmpp copied to clipboard

Example of echo bot

Open skobkin opened this issue 9 years ago • 3 comments

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 avatar Nov 04 '15 17:11 skobkin

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.

skobkin avatar Nov 04 '15 18:11 skobkin

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!

bretterer avatar Dec 06 '15 04:12 bretterer

I also don't understand how to implement echo bot

SaturnTeam avatar Apr 16 '17 11:04 SaturnTeam