Reputation: 10588
I have this code for an ejabberd module. I am trying to filter messages in order to add meta-tags inside some of them but I am getting an error when I try to get the type of the Packet to filter only 'message' packets.
This is my code so far:
-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.
I am getting this error.
16:21:53.627 [error] {function_clause,[{xml,get_tag_attr_s,[<<"type">>,{{jid,<<"leo">>,<<"localhost">>,...
I have tried everything and nothing seems to solve the problem. How can I get the packet type?
Upvotes: 0
Views: 394
Reputation: 14042
I guess that you want to do Packet_Type = xml:get_tag_attr_s("type", XML)
, not Packet_Type = xml:get_tag_attr_s("type", Packet)
Upvotes: 1