我遇到的问题是我定义的钩子没有被事件“user_send_packet”调用。我确实假设正在发送的任何节(包括消息)都会触发此事件。
我已经通过将钩子设置为“0”来考虑如何调用钩子的优先级。在日志中,我已验证模块已启动(“mod_stanza_ack 启动”)。erl 文件确实编译了,它只收到警告“gen_mod”未定义,但我在 ejabberd 邮件列表上读到这是无害的,并且变量“Host”在第 12 行中未使用。也许这有关系有了它,但我无法确定是否是这种情况。
-module(mod_stanza_ack).
-behaviour(gen_mod).
-include("ejabberd.hrl").
-export([start/2,
stop/1]).
-export([on_user_send_packet/3]).
start(Host, _Opts) ->
?INFO_MSG("mod_stanza_ack starting", []),
ejabberd_hooks:add(user_send_packet, global, ?MODULE, on_user_send_packet, 0),
ok.
stop(Host) ->
?INFO_MSG("mod_stanza_ack stopping", []),
ejabberd_hooks:delete(user_send_packet, global, ?MODULE, on_user_send_packet, 0),
ok.
on_user_send_packet(From, To, Packet) ->
?INFO_MSG("mod_stanza_ack a package has been sent coming from: ~p", [From]),
?INFO_MSG("mod_stanza_ack a package has been sent to: ~p", [To]),
?INFO_MSG("mod_stanza_ack a package has been sent with the following packet: ~p", [Packet]),
Packet.