[ejabberd] Start bot with exmpp

Alexander Kuleshov kuleshovmail at gmail.com
Tue Aug 2 12:17:23 MSD 2011


Hello,

I try to run bit with exmpp library. I run ejabberd. My bot code:


start(JID, Password) ->
    spawn(?MODULE, init, [JID, Password]).

init(JID, Password) ->
    MySession = exmpp_session:start(),
    [User, Server] = string:tokens(JID, "@"),
    MyJID = exmpp_jid:make(User, Server, random),
    exmpp_session:auth_basic_digest(MySession, MyJID, Password),
    exmpp_session:connect_TCP(MySession, Server, 5222),
    Manager = #state{host = Server},
    session(MySession, MyJID, Password, Manager).

session(MySession, _MyJID, Password, Manager) ->
    try exmpp_session:login(MySession)
    catch
	throw:{auth_error, 'not-authorized'} ->
	    io:format("Register~n",[]),
	    exmpp_session:register_account(MySession, Password),
	    exmpp_session:login(MySession)
    end,
    %% We explicitely send presence:
    exmpp_session:send_packet(MySession,
			      exmpp_presence:set_status(
				exmpp_presence:available(), "")),

    loop(MySession, Manager).

But in exmpp_session:connect_TCP(MySession, Server, 5222), string i get error:

=ERROR REPORT==== 2011-08-02 14:16:01 ===
** State machine <0.411.0> terminating
** Last message in was {'$gen_sync_event',
                           {<0.406.0>,#Ref<0.0.0.10247>},
                           {connect_socket,"localhost",5222,[]}}
** When State == setup
**      Data  == {state,digest,
                        {{jid,<<"manager at localhost/exmpp#1312294561459425">>,
                              <<"manager">>,<<"localhost">>,
                              <<"exmpp#1312294561459425">>},
                         "localhost"},
                        {0,0},
                        false,false,false,undefined,undefined,undefined,
                        <0.406.0>,exmpp_socket,undefined,undefined,false,
                        undefined,undefined,undefined,undefined}
** Reason for termination =
** {badarg,[{ets,member,[exmpp_xml_engines_registry,expat]},
            {exmpp_xml,is_engine_available,1},
            {exmpp_xml,get_engine_from_options,1},
            {exmpp_xml,start_parser,1},
            {exmpp_session,start_parser,0},
            {exmpp_session,connect,5},
            {gen_fsm,handle_msg,7},
            {proc_lib,init_p_do_apply,3}]}

How can i fix it?

Thank you.


More information about the ejabberd mailing list