ejabberd-18.12:解析包在挂钩内

时间:2019-02-01 18:10:51

标签: ejabberd ejabberd-module ejabberd-api ejabberd-hooks

挂钩代码:

user_receive_packet({Packet, #{jid := JID} = C2SState}) ->
    ?INFO_MSG("~p.", [Packet]),
    {Packet, C2SState}.

输出:

{message,<<"49a85099-6fa6-4aa5-84ab-bced89adf847">>,groupchat,<<"en">>,{jid,<<"sgj279_59f990094dd64c4846cc38c5_59fa99bbfdbd1ab22e59df29">>,<<"conference.localhost">>,<<"localhost">>,<<"sgj279_59f990094dd64c4846cc38c5_59fa99bbfdbd1ab22e59df29">>,<<"conference.localhost">>,<<"localhost">>},{jid,<<"test1">>,<<"localhost">>,<<"49921480726720246332274">>,<<"test1">>,<<"localhost">>,<<"49921480726720246332274">>},[],[{text,<<>>,<<"{\"type\":\"text\",\"payload\":{\"body\":\"a beautiful\"}}">>}],undefined,[{mam_archived,{jid,<<"sgj279_59f990094dd64c4846cc38c5_59fa99bbfdbd1ab22e59df29">>,<<"conference.localhost">>,<<>>,<<"sgj279_59f990094dd64c4846cc38c5_59fa99bbfdbd1ab22e59df29">>,<<"conference.localhost">>,<<>>},<<"1549043294480251">>},{stanza_id,{jid,<<"sgj279_59f990094dd64c4846cc38c5_59fa99bbfdbd1ab22e59df29">>,<<"conference.localhost">>,<<>>,<<"sgj279_59f990094dd64c4846cc38c5_59fa99bbfdbd1ab22e59df29">>,<<"conference.localhost">>,<<>>},<<"1549043294480251">>}],#{ip => {0,0,0,0,0,0,0,1},mam_archived => true,muc_sender_real_jid => {jid,<<"test1">>,<<"localhost">>,<<"49921480726720246332274">>,<<"test1">>,<<"localhost">>,<<"49921480726720246332274">>},stanza_id => 1549043294480251}}.

我想同时读取stanza_id字段值和mam_archived下列出的时间戳记

解析任何字段的语法是什么?

1 个答案:

答案 0 :(得分:0)

尝试:

?INFO_MSG("Stanza ID: ~p", [ maps:get(stanza_id, Packet#message.meta) ]),