[ejabberd] Modifying packet in offline_message_hook

Boris Okner boris.okner at gmail.com
Fri Feb 17 18:13:10 MSK 2012


Try:

NewPacket = xml:append_subtags(Packet, [XmlTo]),
.....

instead of :

NewPacket = xml:append_subtags(Packet, XmlTo),

xml:append_subtags/2 accepts the list of tags as a 2nd parameter as
opposed to a single tag.

Hope this helps,

Boris Okner

On Fri, Feb 17, 2012 at 3:19 AM, Saúl Ibarra Corretgé
<saul at ag-projects.com> wrote:
> Hi all,
>
> I'm trying to achieve something I believe it's quite simple, but my lack of knowledge of Erlang (just started) could be playing me here.
>
> I basically want to add a custom element to a message stanza when I get it in an offline_message hook. This is the simplest possible code that is failing for me:
>
> ...
> XmlTo = {xmlelement,"agp:foo", [{"value", "bar"}, {"xmlns:agp","ag-projects:xmpp"}], []},
> NewPacket = xml:append_subtags(Packet, XmlTo),
> ...
> ejabberd_router:route(_From, Destination, NewPacket),
>
> This gives me a badxml error:
>
> ** {{badxml,
>     {xmlelement,"message",
>      [{"from","saghul at gmail.com/Psi+4A1A4569"},
>       {"to","saghul at a.b.c.d"},
>       {"type","chat"},
>       {"id","a2298a"}],
>      [{xmlcdata,<<"\n">>},
>       {xmlelement,"body",[],[{xmlcdata,<<"t">>}]},
>       {xmlcdata,<<"\n">>},
>       {xmlelement,"active",
>        [{"xmlns","http://jabber.org/protocol/chatstates"}],
>        []},
>       {xmlcdata,<<"\n">>},
>       {xmlelement,"request",[{"xmlns","urn:xmpp:receipts"}],[]},
>       {xmlcdata,<<"\n">>},
>       {xmlelement,"nos:x",
>        [{"value","disabled"},{"xmlns:nos","google:nosave"}],
>        []},
>       {xmlelement,"arc:record",
>        [{"otr","false"},{"xmlns:arc","http://jabber.org/protocol/archive"}],
>        []}|
>       {xmlelement,"agp:foo",
>        [{"value","bar"},{"xmlns:agp","ag-projects:xmpp"}],
>        []}]},
>     {function_clause,
>      [{xml,'-element_to_string_nocatch/1-lc$^0/1-0-',
>        [{xmlelement,"agp:foo",
>          [{"value","bar"},{"xmlns:agp","ag-projects:xmpp"}],
>          []}]},
>       {xml,'-element_to_string_nocatch/1-lc$^0/1-0-',1},
>       {xml,element_to_string_nocatch,1},
>       {xml,element_to_string,1},
>       {xml,element_to_binary,1},
>       {ejabberd_service,handle_info,3},
>       {p1_fsm,handle_msg,10},
>       {proc_lib,init_p_do_apply,3}]}},
>    [{xml,element_to_string,1},
>     {xml,element_to_binary,1},
>     {ejabberd_service,handle_info,3},
>     {p1_fsm,handle_msg,10},
>     {proc_lib,init_p_do_apply,3}]}
>
> I guess it's a simple mistake, but I can't seem to find it :-S any help would be appreciated.
>
> In case it matters this is ejabberd 2.1.10.
>
>
> Thanks and regards,
>
> --
> Saúl Ibarra Corretgé
> AG Projects
>
>
>
> _______________________________________________
> ejabberd mailing list
> ejabberd at jabber.ru
> http://lists.jabber.ru/mailman/listinfo/ejabberd


More information about the ejabberd mailing list