[ejabberd] Altering message body in a module

Hisham Mardam Bey hisham.mardambey at gmail.com
Sun Apr 1 02:54:22 MSK 2012

>> On Fri, Mar 30, 2012 at 7:54 PM, Hisham Mardam Bey
>> <hisham.mardambey at gmail.com> wrote:
>> Hi folks,
>> I'm working on a module for ejabberd 2.1.x that needs to alter the
>> contents of the body in a message stanza. I'm to the point where I
>> have my altered body as a string and I want to put it back into the
>> cdata entry in the message. exmpp offers convenience functions to do
>> these kinds of operations but I am not sure how to do it on my own
>> being new to Erlang. Any recommendations?
>> Thanks,
>> hmb.

>On Sat, Mar 31, 2012 at 1:02 AM, Daniel Dormont <dan at greywallsoftware.com> wrote:
> You'll have to construct the appropriate tuple representing your new message
> stanza yourself. If it's just the content of the body you want to set, and
> you don't need any additional elements, then a simple:
> {xmlelement, "message", OrigAttrs, [{xmlelement, "body", [], [{xmlcdata,
> NewBodyText}]}]}
> ought to work. This is assuming you kept the attributes for the original
> message in a variable.
> dan

Hi Dan,

Thanks for your response. I've put together something similar to what
you suggested using "lists:keyreplace" so I can simply alter the body
cdata and maintain other attributes untouched. This is part of a
module that uses erlang_js to process stanzas. I've put the prototype
source on Gist and dubbed it mod_js. It can be found here if anyone
wants to have a look or implement something similar:


Happy ejabberd'ing! (=


Hisham Mardam-Bey

More information about the ejabberd mailing list