[ejabberd] Sen message from ejabberd plugin

CGS cgsmcmlxxv at gmail.com
Thu Nov 3 16:24:02 MSK 2011


Sorry for delay, I was a bit busy.

Here is how I send messages using exmpp:
_________________________________________________

%% Defining the internet address of the server:
Server = "myserver",

%% Create session
MySession = exmpp_session:start(),

%% Create sender JID (= MyJID);
%% XMPP client ID (user resources) = exmpp (use random if not filtered 
packets);
%% USER = user nick
MyJID = exmpp_jid:make(User, Server, "exmpp"),

%% Create a new session with basic (digest) authentication,
%% with Password = your account password
exmpp_session:auth_basic_digest(MySession, MyJID, Password),

%% Connect in standard TCP:
{ok, _StreamId} = exmpp_session:connect_TCP(MySession, Server, 5222),

%% Login with defined JID / Authentication:
try exmpp_session:login(MySession)
catch
throw:{auth_error, 'not-authorized'} ->
    %% Throw a message to the prompter line:
    io:format("Error: not authorized attempt in ~p.~n",[MySession])
end,

%% If login OK, explicitly send presence:
  exmpp_session:send_packet(MySession,exmpp_presence:set_status(exmpp_presence:available(), "transmitting")),

%% Creating the packet needed to be sent
%% with To = nick at server
%% and Body = "a string message"
Packet = 
exmpp_stanza:set_sender(exmpp_stanza:set_recipient(exmpp_message:chat(Body), 
To), From),

%% Sending the packet:
exmpp_session:send_packet(MySession, Packet),
__________________________________________________

I hope it will help you.

CGS


On 11/03/2011 08:30 AM, Alexander Kuleshov wrote:
> Hello,
>
> I have simple ejabebrd plugin and i need to esn message from it.
>
> My code:
>
> send_message(TypeStr, BodyStr) ->
>     LUser = "test1",
>     LServer = "localhost",
>     From1 = jlib:make_jid(LUser, LServer, "fb"),
>
>     TUser = "test2",
>     TServer = "localhost",
>     To1 = jlib:make_jid(TUser, TServer, "fb"),
>
>     FromAddress = jlib:jid_to_string(From1),
>     ToAddress = jlib:jid_to_string(To1),
>
>     XmlBody = {xmlelement, "message", [{"type", TypeStr}, {"from", 
> FromAddress}, {"to", ToAddress}], [{xmlelement, "body", [], 
> [{xmlcdata, BodyStr}]}]},
>    ejabberd_router:route(From, To, XmlBody).
>
> But i get error:
>
> =ERROR REPORT==== 2011-11-03 13:27:12 ===
> E(<0.494.0>:ejabberd_router:70) : {{badrecord,jid},
>                                                   
> [{ejabberd_router,do_route,3},
>                                                   
> {ejabberd_router,route,3},
>                                                   
> {mod_poker,on_register,3},
>                                                   {ejabberd_hooks,run1,3},
>                                                   
> {ejabberd_c2s,wait_for_auth,2},
>                                                  {p1_fsm,handle_msg,10},
>                                                 
>  {proc_lib,init_p_do_apply,3}]}
> when processing: {"test1 at localhost","test2 at localhost",
> {xmlelement,"message",
> [{"type","chat"},
>   {"from","test1 at localhost/fb"},
>   {"to","test2 at localhost/fb"}],
>   [{xmlelement,"body",[],[{xmlcdata,"test test"}]}]}}
>
> How can i fix it? How can i send message from ejabberd plugin?
>
> Thank you.
>
>
> _______________________________________________
> ejabberd mailing list
> ejabberd at jabber.ru
> http://lists.jabber.ru/mailman/listinfo/ejabberd

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.jabber.ru/pipermail/ejabberd/attachments/20111103/34732a37/attachment.html>


More information about the ejabberd mailing list