processone / xmpp

Erlang/Elixir XMPP parsing and serialization library on top of Fast XML

Home Page:http://process-one.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question - How to read custom Tag in Message.

heigong opened this issue · comments

Sorry to report an issue here, I need help and don't know where to go.

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.

There is a custom tag in the message xml, 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">&lt;extra type="image" thumbnail="thumbnailUrl" url="url"&gt;&lt;/extra&gt;</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>">>}]}
]
...
}

Right, I asked on SO too. Thanks for your help! You can close the issue now.