-module(mod_bugbot).
-author('huangshiqiang@test').
-vsn('1.0').
%-define(EJABBERD_DEBUG, true).
-define(MYHOST, "test").
-define(BUGBOT, "bugbot").
-define(DEFAULTUSER, "master").
-behaviour(gen_mod).
-export([start/2, stop/1, process/2]).
-include("ejabberd.hrl").
-include("jlib.hrl").
-include("ejabberd_http.hrl").
start(_Host, _Opts) ->
ok.
stop(_Host) ->
ok.
process(_Path, R) ->
From = #jid{user = ?BUGBOT, server = ?MYHOST, resource = [],
luser = ?BUGBOT, lserver = ?MYHOST, lresource = []},
To = #jid{user = ?DEFAULTUSER, server = ?MYHOST, resource = ?MYHOST,
luser = ?DEFAULTUSER, lserver = ?MYHOST, lresource = ?MYHOST},
case R#request.q of
[{"user", User}, {"report", Report}] ->
To2 = To#jid{user = User, luser = User},
echo(From, To2, Report);
Other ->
Other
end,
"OK".
%% HELPER FUNCTIONS
%strip_bom([239,187,191|C]) -> C;
%strip_bom(C) -> C.
echo(From, To, Body) ->
send_message(From, To, "chat", Body).
send_message(From, To, TypeStr, BodyStr) ->
XmlBody = {xmlelement,
"message",
[{"type", TypeStr},
{"from", jlib:jid_to_string(From)},
{"to", jlib:jid_to_string(To)}],
[{xmlelement, "body", [], [{xmlcdata, BodyStr}]}]},
ejabberd_router:route(From, To, XmlBody).
|