0
votes

I am trying to create a simple echo bot in ejabberd. I cam get the mod_echo working ok and i'm fairly certain I had my own version working at one point (debugging has played tricks with my head). I am getting the error below but i can't figure out what to do next to debug it. There seems to be an issue routing but not quite sure why. Any tips?

2016-03-31 16:49:38.350 [debug] <0.448.0>@ejabberd_router:do_route:324 route
    from {jid,<<"user1">>,<<"alchemy.local">>,<<"alchemy">>,<<"user1">>,<<"alchemy.local">>,<<"alchemy">>}
    to {jid,<<>>,<<"echo.alchemy.local">>,<<>>,<<>>,<<"echo.alchemy.local">>,<<>>}
    packet {xmlel,<<"message">>,[{<<"xml:lang">>,<<"en">>},{<<"to">>,<<"echo.alchemy.local">>},{<<"id">>,<<"aacca">>}],[{xmlcdata,<<"\n">>},{xmlel,<<"subject">>,[],[]},{xmlcdata,<<"\n">>},{xmlel,<<"body">>,[],[{xmlcdata,<<"testme">>}]},{xmlcdata,<<"\n">>},{xmlel,<<"nick">>,[{<<"xmlns">>,<<"http://jabber.org/protocol/nick">>}],[{xmlcdata,<<"user1">>}]},{xmlcdata,<<"\n">>}]}
2016-03-31 16:49:38.351 [error] <0.448.0>@ejabberd_router:route:77 {function_clause,[{mod_echobot,route,[{jid,<<"user1">>,<<"alchemy.local">>,<<"alchemy">>,<<"user1">>,<<"alchemy.local">>,<<"alchemy">>},{jid,<<>>,<<"echo.alchemy.local">>,<<>>,<<>>,<<"echo.alchemy.local">>,<<>>},{xmlel,<<"message">>,[{<<"xml:lang">>,<<"en">>},{<<"to">>,<<"echo.alchemy.local">>},{<<"id">>,<<"aacca">>}],[{xmlcdata,<<"\n">>},{xmlel,<<"subject">>,[],[]},{xmlcdata,<<"\n">>},{xmlel,<<"body">>,[],[{xmlcdata,<<"testme">>}]},{xmlcdata,<<"\n">>},{xmlel,<<"nick">>,[{<<"xmlns">>,<<"http://jabber.org/protocol/nick">>}],[{xmlcdata,<<"user1">>}]},{xmlcdata,<<"\n">>}]}],[{file,"mod_echobot.erl"},{line,86}]},{ejabberd_router,route,3,[{file,"src/ejabberd_router.erl"},{line,75}]},{ejabberd_c2s,check_privacy_route,5,[{file,"src/ejabberd_c2s.erl"},{line,2121}]},{ejabberd_c2s,session_established2,2,[{file,"src/ejabberd_c2s.erl"},{line,1288}]},{p1_fsm,handle_msg,10,[{file,"src/p1_fsm.erl"},{line,582}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,237}]}]}
when processing: {{jid,<<"user1">>,<<"alchemy.local">>,<<"alchemy">>,<<"user1">>,<<"alchemy.local">>,<<"alchemy">>},{jid,<<>>,<<"echo.alchemy.local">>,<<>>,<<>>,<<"echo.alchemy.local">>,<<>>},{xmlel,<<"message">>,[{<<"xml:lang">>,<<"en">>},{<<"to">>,<<"echo.alchemy.local">>},{<<"id">>,<<"aacca">>}],[{xmlcdata,<<"\n">>},{xmlel,<<"subject">>,[],[]},{xmlcdata,<<"\n">>},{xmlel,<<"body">>,[],[{xmlcdata,<<"testme">>}]},{xmlcdata,<<"\n">>},{xmlel,<<"nick">>,[{<<"xmlns">>,<<"http://jabber.org/protocol/nick">>}],[{xmlcdata,<<"user1">>}]},{xmlcdata,<<"\n">>}]}}
2016-03-31 16:50:16.356 [debug] <0.447.0>@ejabberd_receiver:process_data:282 Received XML on stream = <<"\n">>
1
This is a function_clause error in the function mod_echobot:route. That means that this function is being called with the arguments shown in the error message, but these arguments cannot match the argument list in any of the clauses of this function. Seeing the source of mod_echobot:route should make it simple to spot the error.legoscia
Thanks @legoscia - I created a gist here gist.github.com/stevenlivz/d666200595a23c42b2a662fef87bf281stevenlivz
Hmm, it seems that in my code i need to use <<"message">> in the clauses to actually match, whereas the sample code i used did not do that, using just "message" and so on - was this something that was added to the language or am i missing something obvious [new to erlang]? Working now. Also, also worth noting that xmlelement is now xmlel.stevenlivz
The representation of XML elements in ejabberd changed some years ago, I forgot which version. As a result, a fair amount of sample code is outdated.legoscia
Btw, it might help other people if you post your findings as an answer to your own question. You'll probably get an upvote or two :)legoscia

1 Answers

0
votes

It seems that in the code sample (which was from an older sample i found online) https://gist.github.com/stevenlivz/d666200595a23c42b2a662fef87bf281 i need to use <<"message">> in the clauses to actually match, whereas the sample code i used did not do that, using just "message" and so on. Also, also worth noting that xmlelement is now xmlel and so clauses also need to be updated. E.g.

route(From, To, {xmlel, <<"message">>, _, _} = Packet) ->