filter_packet hook

I am wondering if the filter_packet hook signature was changed, I was following this article[1] to create a simple hook in Elixir, but the code seems that doesn't work anymore.

Can anyone help me?

    defmodule PacketFilter do
      import Ejabberd.Logger
      @behaviour :gen_mod

      def start(_host, _opts) do
        info('Starting ejabberd module Filter Packet Demo')
        Ejabberd.Hooks.add(:filter_packet, :global, __ENV__.module, :on_filter_packet, 50)
        :ok
      end

      def stop(_host) do
        info('Stopping ejabberd module Filter Packet Demo')
        Ejabberd.Hooks.delete(:filter_packet, :global, __ENV__.module, :on_filter_packet, 50)
        :ok
      end

      def on_filter_packet({from, to, xml={:xmlel, "message", attributes, children}} = packet) do
         # This hook is never called.
        # What I want only packets of type `message` here.

        info("on_filter_packet [1] #{inspect packet}")
        packet
      end

      def on_filter_packet(packet) do
        # Always called, without this hook, the ejabberd throws a lot of erros.
        info("on_filter_packet [2] #{inspect packet}")
        packet
      end
     
    end

1 - https://blog.process-one.net/ejabberd-with-elixir-packet-filters/

Tracked here:

Syndicate content