Re: [conversejs] AW: How to use Events
- Jc Brand
- 2014-06-02 @ 08:48
On Wed, May 28, 2014 at 10:50:43PM +0200, Patrick Schwarz wrote:
> 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,
> 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');