Jabberwocky

snicker-snack!

Ruby to MSN

| Comments

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/ruby
require 'rubygems'
require 'xmpp4r-simple'

jabber = Jabber::Simple.new 'test@jabber.no','password'
jabber.status(nil,"coffee time") # show online status
Signal.trap("INT") {
  jabber.disconnect
exit } # disconnect when ctrl-c
loop do
  jabber.received_messages do |msg|
    puts "#{msg.body}"
    jabber.deliver(msg.from,'yes, you\'re right')
  end
end

ruby to msn

Comments