xmpp - Send message from ejabberd using Erlang -


i have simple ejabebrd plugin , need send message it.here posted code sample , error got. kindly give me 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",     = jlib:make_jid(luser, lserver, []),      tuser = "test2",     tserver = "localhost",     = 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 got error:

   d(<0.252.0>:ejabberd_router:313) : route     {jid,"test1","localhost",[],"test1",                   "localhost",[]}     {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 help.

my suggestion not create own xml. can use function catch packet , write error log

on_filter_packet({from, to, xml} = packet) ->     %% packet     %% should return modified packet or atom `drop` drop packet      error_logger:info_msg(xml, [a_module]),      %% or use error_logger:info_msg(xml:get_subtag(xml, <<"body">>), [a_module]),     %% take body     packet. 

then can use same xml, changed xmlcdata


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -