Ruby to MSN

Posted in ruby by elisehuard on September 20, 2008

So for work i’m looking into making a chatbot for an application.  Apparently these days teenagers like MSN, so if that’s your market, that’s where you go.  Anyhow, it turns out it’s pretty easy to do !

First off, make a Jabber account on an existing jabber server, which also has an MSN transport plugin.  Jabber is the nice name for XMPP (Extensible Messaging and Presence Protocol), an IETF recognized standard.

The good thing about Jabber is that people made a bunch of plugins to Jabber servers so these servers can connect to a lot of different kinds of proprietary chat stuff.  Talking to MSN directly is doable, but not something i want to spend time implementing.

Examples of Jabber servers speaking MSN: jabber.no, jabber.me.uk, net.jabber.cz.

It’s easy to make an account with one of them using a jabber client (i used Adium). You then make a Windows Live account, to login to the MSN network.  Using the Jabber client again,  you browse the services of the jabber server (services, discovery browser, or whatever it’s called).  You set up the MSN transport for your account to point to that windows live account (using your Windows Live Id and password).

It’s possible to do at least part of this in Ruby, but why bother ? It’s a one-time operation to create your jabber account.

Then, you’re in.  There’s this ruby library, written by Blaine Cook, called Jabber::Simple, which encapsulates all the complexities of XMPP4R, itself the XMPP ruby library.

Using this library, you talk to the jabber server, which then talks to MSN.


require 'rubygems'
require 'xmpp4r-simple'

jabber = Jabber::Simple.new 'test@jabber.no','password'
jabber.status(nil,"coffee time") # show online status

Signal.trap("INT") {
exit } # disconnect when ctrl-c

loop do
jabber.received_messages do |msg|
puts "#{msg.body}"
jabber.deliver(msg.from,'yes, you\'re right')

If you wanted to deliver a message to an MSN id in particular: for test@hotmail.com use test%hotmail.com@msn.jabber.no (in case of the jabber.no MSN transport – adapt to server you’re using).
Using this same principle, it should be child’s play to make a bot for ICQ, Yahoo, … because the nice Jabber server developers also developed bridges for those !

Tagged with: , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: