Jabber bot

Just a quick update today – been spending some time writing a little Jabber bot.

It’s also my first real excursion into local::lib – initially, I wasn’t sure about pulling down CPAN packages, but the package I wanted to use to write bot wanted some fresh stuff. Rather than risk breaking other parts of the system by installing packages into the system lib directories, local::lib lets me keep whatever I need “local” to the project.

Debian doesn’t (yet) ship local::lib as a package in its stable repo, but the package for squeeze installs cleanly. This Work For MeΓ’β€žΒ’, as it’s installed system-wide and when the new release is made I know I’ll get any updates.

So, local::lib installed, I grabbed the Net::Jabber::Bot package from CPAN. For some reason, the CPAN install run failed a load of tests, but when I re-ran it, it pulled down some more packages and worked. So it goes…

The documentation for Net::Jabber::Bot is…not that great (yes, yes, I know – submit a patch). The HTML version on CPAN has formatting issues with example code, but the POD version is fine.

The Jabber server I was going to post to uses the Google servers for connection, and runs as a separate conference server, so my initial problem was connecting to the Google server. It would connect, but fail to authenticate, and not return any error messages.

A bit of searching different mailing lists, and I’d found the culprit – authenticating to the Google servers requires version 1.23 of the XML::Stream package, and I’d only got version 1.22 installed. XML::Stream is a dependency of Net::XMPP (which is a dependency of Net::Jabber, which is a understandably a dependency of Net::Jabber::Bot), and although that particular version is not required per-se, I personally think it might be a good idea for Net::Jabber::Bot to specifically require that version (or later) of that package – it should harm no other Jabber server, and would prevent other people having to follow exactly the investigation I did.

More local::lib-fu, and I was in!

For the record, my Net::Jabber::Bot object was created like this:

my $bot = Net::Jabber::Bot->new( {
 server => 'talk.google.com',
 server_host => 'gmail.com',
 tls => 1,
 conference_server => $conf_server,
 username => $username,
 password => $password,
 alias => $alias,
 message_function => \&new_bot_message,
 forums_and_responses => \%f_and_r,
} );

I pulled some more code from the example bot, created a simple learn/forget/is system (backed by an SQLite database), and my bot is up and running (and learning all kinds of junk as I haven’t put in any kind of access control yet). I’m still having problems getting it to send direct messages, but as a general announce bot it’s working well.


  1. todd_rinaldo

    Thanks for the post.

    1. What don’t you like about the docs you don’t necessarily have to submit a patch if you don’t want to. Open a ticket.

    2. Questions are always welcome on the mailing list. There are a couple of successful implementations I know of that have a presence on it.

    3. The XML::Stream thing has only been fixed a month ago. I agree that I should update my dependencies even though technically I don’t directly use XML::Stream so typically this is a bug for Jabber::Bot and/or Net::XMPP, which are both owned by the XML::Stream author. I’d encourage you to submit an RT to him to fix things.


  2. Post

    1: I think some of my problems were due to the fact that I’d never tried connecting to a Jabber server before (with my own code, at least). One thing that does need documenting is the %bot_message_hash passed to the message_function sub – I don’t remember seeing any docs for that, and it’s probably of quite a lot of interest to people using N::J::Bot. πŸ™‚ It’s just a question of (lack of) time regarding submitting patches – so much to do, so few hours in the day (and night…)

    2: I only started hacking at it last night (bit of a side project). From never having looked at Jabber to getting a bot working in only a couple of hours is pretty good going. I like to do a bit of my own leg-work before asking on lists. πŸ™‚

    3: Yes, the direct dependency isn’t really your “problem”. I guess it could be covered by adding something to the docs along the lines of “If you want to connect to Google servers, you need XML::Stream 1.23 or later”. There’s also the bot in the examples (gtalk_RSSbot.pl) which obviously isn’t going to work if the right version isn’t installed – a note/dep in the sources there would clue people in as well.

    Thanks for creating this package – I wouldn’t have been able to get a bot up so quickly and easily without it. πŸ™‚

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.