Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
520 views
in Technique[技术] by (71.8m points)

erlang - How to filter messages in Ejabberd

I have Ejabberd up and running with test users, and its working fine. I want to write a module that can intercept messages and modify them, as follows :

  1. intercept "messages"
  2. send them to a php file
  3. get the result from the same php file (immediate)
  4. Modify the message stanza and send it down the wire to the recipient

The ejabberd documentation is weak and tutorials are non-existent. Can you give me some sample code that does this. I can then figure how to configure it for my needs.

Thanks a bundle!

Adil

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here's the basic example of such module:

-module(packet_interceptor).
-behaviour(gen_mod).

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

-export([on_filter_packet/1]).


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

on_filter_packet({From, To, XML} = Packet) ->
    %% does something with a packet
    %% should return modified Packet or atom `drop` to drop the packet
    Packet.

And make sure to add this module into ejabberd's configuration into module section:

{modules,
 [...
  ...
  ...
  {packet_interceptor, []}
 ]}.

Just extend on_filter_packet/1 the way you want and return appropriately modified packet.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...