I am trying to implement a custom module to log all the messages to a webhook. I've found a good reference to do that, https://github.com/PH-F/mod_offline_http_post/blob/master/src/mod_offline_http_post.erl.
I have some custom tag in the message stanza, and I want to pass this to the webhook too.
But I couldn't figure out how to read the custom field out. Please help and tell me which API I should use to read the text in the "extra" tag, showing below.
Thanks in advance.
The Ejabber Server is latest v18.04.
The Xml format of the message:
<message type="chat" to="dichen@123.123.123.123" id="7521387E-D6D1-41B4-A909-E9AD3251FB84">
<body>Image</body>
<thread>dichen@123.123.123.123</thread>
<x xmlns="jabber:x:event"><offline/></x>
<extra xmlns="ocp:extra"><extra type="image" thumbnail="thumbnailUrl" url="url"></extra></extra>
</message>
The Packet format I got from Ejabberd log:
{message,
<<"7521387E-D6D1-41B4-A909-E9AD3251FB84">>,
chat,
<<"en">>,
{jid,<<"dichen">>,<<"123.123.123.123">>,<<>>,<<"dichen">>,<<"123.123.123.123">>,<<>>},
{jid,<<"johndoe">>,<<"123.123.123.123">>,<<>>,<<"johndoe">>,<<"123.123.123.123">>,<<>>},
[],
[{text,<<>>,<<"Image">>}],
{message_thread,<<>>,<<"johndoe@52.160.83.11">>},
[
{xmlel,<<"x">>,[{<<"xmlns">>,<<"jabber:x:event">>}],[{xmlel,<<"offline">>,[],[]}]},
{xmlel,<<"extra">>, [{<<"xmlns">>,<<"ocp:extra">>}], [{xmlcdata,<<"<extra type=\"image\" thumbnail=\"thumbnailUrl\" url=\"url\"></extra>">>}]}
]
...
}
The easiest way I can think:
fxml:get_tag_cdata(fxml:get_subtag_with_xmlns(xmpp:encode(Packet), <<"extra">>, <<"ocp:extra">>))
That will return:
<<"<extra type=\"image\" thumbnail=\"thumbnailUrl\" url=\"url\"></extra>">>