获取模块中的数据包类型(ejabberd 15.02)

Get packet type in module (ejabberd 15.02)

我有一个 ejabberd 模块的代码。我正在尝试过滤消息以便在其中一些消息中添加元标记,但是当我尝试获取数据包类型以仅过滤 'message' 个数据包时出现错误。

到目前为止,这是我的代码:

-module(mod_test).
-behaviour(gen_mod).

-include("ejabberd.hrl").
-include("logger.hrl").

-export([start/2,
         stop/1]).

-export([on_filter_packet/1]).


start(Host, _Opts) ->
    ejabberd_hooks:add(filter_packet, global, ?MODULE, on_filter_packet, 0).

stop(_Host) ->
    %?DEBUG("Bye bye, ejabberd world!", []),
    ok.

on_filter_packet({From, To, XML} = Packet) ->
    %% does something with a packet
    %% should return modified Packet or atom `drop` to drop the packet
    ?INFO_MSG("filtering packet :D", []),

    Packet_Type = xml:get_tag_attr_s("type", Packet),

    case Packet_Type of
        "message" ->
            ?INFO_MSG("Its a message...", []);
        _Other ->
            ?INFO_MSG("Other kind of presence~n~p", [Packet])
    end,

    %xml:get_tag_attr_s(list_to_binary("type"),Packet),

    % case Packet_Type of
    %   "message" ->
    %       process_received_message(Packet);
    %   _ ->
    %       Packet
    % end.

    Packet.

我遇到了这个错误。

16:21:53.627 [error] {function_clause,[{xml,get_tag_attr_s,[<<"type">>,{{jid,<<"leo">>,<<"localhost">>,...

我已经尝试了所有方法,但似乎无法解决问题。如何获取数据包类型?

我猜你想做 Packet_Type = xml:get_tag_attr_s("type", XML),而不是 Packet_Type = xml:get_tag_attr_s("type", Packet)