I have simple ejabebrd plugin and i need to send message from it.Here i posted my code sample and error which i got. Kindly give me your feedback on this.
My code:
-module(mod_final).
-on_load(send_message/0).
-behaviour(gen_mod).
-export([start/2, stop/1]).
-include("ejabberd.hrl").
-include("logger.hrl").
-include("jlib.hrl").
start(_Host, _Opt) ->
?INFO_MSG("mod_final starting", []),
ok.
stop(_Host) ->
?INFO_MSG("mod_final stoping", []),
ok.
send_message() ->
LUser = "test1",
LServer = "localhost",
From = jlib:make_jid(LUser, LServer, []),
TUser = "test2",
TServer = "localhost",
To = jlib:make_jid(TUser, TServer, []),
FromAddress = jlib:jid_to_string(From),
ToAddress = jlib:jid_to_string(To),
?INFO_MSG("send message starting", []),
XmlBody = {xmlelement, "message", [{"id", []},{"type", "chat"}, {"from", FromAddress}, {"to", ToAddress}], [{xmlelement, "body", [], [{xmlcdata, <<"Test Message">>}]}]},
ejabberd_router:route(From, To, XmlBody).
But i got this error:
D(<0.252.0>:ejabberd_router:313) : route
from {jid,"test1","localhost",[],"test1",
"localhost",[]}
to {jid,"test2","localhost",[],"test2",
"localhost",[]}
packet {xmlelement,"message",
[{"type","error"},
{"to","test2@localhost"},
{"from","test1@localhost"},
{"id",[]}],
[{xmlelement,"body",[],[{xmlcdata,<<"Test Message">>}]},
{xmlelement,"error",
[{"code","503"},{"type","cancel"}],
[{xmlelement,"service-unavailable",
[{"xmlns","urn:ietf:params:xml:ns:xmpp-stanzas"}],
[]}]}]}
Appreciate your help.