Frage

I am using ejabberd hook named "filter-packet" to make a module. Here I want to add an element to packet. How to do it? My Code is -

on_filter_packet({From, To, Packet}=Input) ->

Type = xml:get_tag_attr_s(list_to_binary("type"), Packet),

if (Type == <<"groupchat">>) ->
?INFO_MSG("type is group chat", []),
    NPacket={Packet, [{xmlelement, "time",
     [],
     [{xmlcdata, "testtime"}]}]},
    {From, To, NPacket};
  true ->
    Input
end.

This code is giving error of bad match. Any Help ?

War es hilfreich?

Lösung

13.12 uses different type for xmlelement.

Packet is a type of record #xmlel, so you need to insert new element to Packet#xmlel.children.

on_filter_packet({From, To, #xmlel{ children=OldChildren } = Packet}=Input) ->

...

TimeElem = #xmlel{ name = <<"time">>,
     children = 
     [{xmlcdata, <<"testtime">>}]},

NPacket = Packet#xmlel{ children = [TimeElem|OldChildren] },

...

Not tested, but will work.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top