librelist archives

« back to archive

Re: How to use Events

Re: How to use Events

From:
Patrick Schwarz
Date:
2014-05-28 @ 20:50
Hi,

 

can someone tell me a short example how to use the converse.on('onMessage')
event? I want to call a function with the buddy name and the message text
from the current event. E.g.  example(buddy, message);

 

Maybe a short example can be added to the documentation.

 

Thanks,

Patrick

Re: [conversejs] AW: How to use Events

From:
Jc Brand
Date:
2014-06-02 @ 08:48
On Wed, May 28, 2014 at 10:50:43PM +0200, Patrick Schwarz wrote:
>    Hi,
> 
>    can someone tell me a short example how to use the
>    converse.on('onMessage‘) event? I want to call a function with the buddy
>    name and the message text from the current event. E.g.  example(buddy,
>    message);
> 
>    Maybe a short example can be added to the documentation.

The parameter passed to the event handler is the message XML that was received
from the XMPP server.

You can pass that to jQuery to get a jquery object that you can query just as
you would with a DOM element.

You can get the message text like this:

    var $body = $(message).children('body');
    var text = ($body.length > 0 ? $body.text() : undefined);

And the sender JID like this:

    message_from = $(message).attr('from');