[ejabberd] mod_msg_filter - block/allow message delivery over HTTP

Hisham Mardam Bey hisham.mardambey at gmail.com
Thu Apr 26 04:58:46 MSK 2012

Hi folks,

One of the requirements we have for our chat service where I work is
the ability to decide whether users are allowed to chat based on
business logic that we execute in our permission system. This means
that we need to ask the permissions system every time people start to
exchange messages. To that effect we've implemented mod_msg_filter and
figured we'd share it in case anyone else on the list has similar use

Here's the blurb:

mod_msg_filter allows the filtering of "message"
stanzas across an HTTP service. The URL of the
service must be passed as part of the module's
configuration. Both JIDs and their resources are
passed as part of the query string and the result
is expected to be one of:

<status value="denied">


<status value="allowed">

The values of the <error> tags or <noop> tags will
be cached in mnesia using 2 keys that look like:

{bare_jid1, bare_jid2, resource1, resource2}
{bare_jid2, bare_jid1, resource2, resource1}

The <error> tags will then be sent over to both JIDs
if the <status> has a "value" of "denied", otherwise
the original message is let through.

The mnesia cache can be flushed if the ejabberd
server is hit on a request handler that maps to this
module (for example: /mod_msg_filter/). A stanza must
be POSTed that looks like:

<flush jid="user at domain.com"/>

Note that no resource is included at all. This can be
used if ejabberd is part of a system that has billing
restrictions on chatting but allows presence to go
through all the time.

And you can find the code here:




Hisham Mardam-Bey

More information about the ejabberd mailing list