Having a good old Natter

I've been thinking about an XMPP chat-bot based interface - something similar to the XMPP bot I created in May '08 - for a project that I've started playing with recently. This project is still very new so it doesn't have much code yet. A perfect time for experimenting. My recent foray into the world of ActiveCouch reminded me of a library called Doodle that I've been meaning to get to grips with. Can you see where this is going?

Doodle is a Ruby library and gem for simplifying the definition of Ruby classes by making attributes and their properties more declarative

Doodle has a number of advantages over the ActiveCouch approach, but this isn't a post about Doodle so I'll save that for another time.

I used Doodle to create something DSL-like that can describe, in Ruby, a chat-bot that talks XMPP. It doesn't do anything fancy yet - it doesn't deal with subscription requests for example - but it can login, send and receive messages, and it has the beginnings of a basic roster so it can track who it's seen and talked to and when.

Natter.bot do
  channel do
    username "username@domain.com"
    password "sekrit"
  end
  on :message_received do |message|
    puts Time.now.to_s + "> " + message.body
    reply_to message, "Thanks for your message!"
  end
end

If you'd like to play with it, the code can be retrieved using Git.

git clone http://barkingiguana.com/~craig/code/natter.git

You'll need to install xmpp4r-simple and doodle to get it to run.

sudo gem install xmpp4r-simple doodle

There's very little documentation at the moment, but there are a few simple examples in the examples/ subdirectory and there's a quick example in the README file too.

Leave feedback...

Commenting is closed for this article.

About the boy

A picture of Craig in grayscale

Craig Webster is a software engineer living in London. He usually works with Ruby although sometimes he sneaks in some Erlang or JavaScript. He's into rock climbing, snowboarding, skating, photography and fencing. Yes, this does mean he has a sword.

Near here you'll find Craig's homepage, contact details, PGP key and keysigning policy, and talks.

Licence

The entire content of this blog is public domain. Use it however you fancy. You don't even need to attribute it to me, although it would be nice if you did. Just don't sue me and we'll all be happy.

I Work With Rails

Recommend Me

My Travels

I go places. Do you go places too? Let's meet up!.