While i was going through Redmine’s source code, trying to fix some email notification bugs, I felt it would be good if instant messenger notification was also available.So i decided to give it a try. I was sure it would be cool if i could write my own programs to communicate with my IM friends, even though it may not be very ‘useful’
1. How to connect and communicate with IM servers.
XMPP/Jabber protocol is used for interaction with IM servers. Ruby has a xmpp4r library. I also found a xmpp4r-simple library which was built on top of xmpp4r, very easy to use and would serve my purpose. So i chose xmpp4r-simple.
sudo gem install xmpp4r
sudo gem install xmpp4r-simple
2. Connecting to GoogleTalk
Since Gtalk supports Jabber, i decided to do my experiments using Gtalk servers.
I started off with a program that connects to google talk, authenticates and sends “Hello” to a predefined user.
(Replace the username, password and destination_username in the code with with actual ones. Login to destination_username’ in an IM to see our code running)
3. My first chat program - autoreply
A program that will simply send a predefined message in reply to every message it receives from any user. May be when you are busy, instead of setting status as “busy”, you can simply run this program, so that it sends some appropriate reply automatically.
4. Echo Chat
Program that will simply send back whatever message it receives. Sure this will baffle your IM buddies
5. Normal Chat
User1 sends a message,user2 responds, again user1, then user2 and so on. But if user1 wants to send a message before user2 responds, its not possible here since its a single threaded program, which will block,waiting for user2’s response.
Using 2 separate threads for listening and sending solves this issue.
6. A remote shell
Well, my next idea was to simulate a remote shell over IM. ie To run commands on a remote machine and get the results through IM.
How good it be, if you could say “geyser ON” on your IM, on your way home, which turns on the geyser at your home, so that you have warm water ready by the time you reach home?
Theoretically, we can do it like this:
i. Connect the geyser to your parallel port (ofcourse not directly, there should be some relay/switching device in between), so that a TTL HIGH on one of the parallel port pins, turns on the Geyser.
ii. Write a simple C program named “geyser”(or might be in Ruby itself, i am not sure if we can do it in Ruby), which talks to the parallel port. On running this program with argument ON, it should produce HIGH on one of the parallel port pins, and OFF should make that pin LOW, so that we can use this program to turn the geyser ON and OFF.
iii. Now we can run this “geyser” program through our “IM remote shell”. So you say “geyser ON” in your IM, it turns the geyser ON.
7. IM based dictionary service
You wanted to know the French equivalent for the word ‘yesterday’. You have an IM called ‘french-bot’ , you just send him the word “yesteday” through your IM and he (or she - as you wish) immediately sends you back the French word for “yesterday”. Wont it be cool?
Here is your French-Bot
Thats all for now. Playing with IM was really fun.
6 responses so far ↓
1 Vamsee // Jan 14, 2008 at 12:14 pm
Very nice and detailed
2 Tessy // Jan 16, 2008 at 8:21 am
Too good Unni.. Great thoughts and great work…
3 The Viamentis Blog » Blog Archive » Some more fun with Ruby and Instant messaging // Jan 22, 2008 at 1:02 pm
[…] i already had some ruby programs which could talk to IM servers, an interface to Eliza was just what i needed. I visted the Eliza’s webpage, one of the […]
4 The Viamentis Blog » Blog Archive » Listening and Talking to your Linux Box // Jan 25, 2008 at 1:48 pm
[…] I couldn’t stop before i tried using Festival with my Instant messenger programs […]
5 Don Park // Mar 21, 2008 at 5:04 am
my jabber id is @gmail.com yet gmail.com is not the server. talk.google.com is the server.
(see http://www.google.com/support/talk/bin/answer.py?hl=en&answer=24076)
there are magic DNS records supposedly to translate this but xmpp4r doesnt appear to follow them.
6 Pat // Apr 1, 2008 at 4:54 am
I use chat0.rb and I have got error like this.
C:\Documents and Settings\Heath\Desktop\IM in Ruby>chat0
C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.2/lib/xmpp4r/connection.
rb:60:in `initialize’: Bad file descriptor - connect(2) (Errno::EBADF)
from C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.2/lib/xmpp4
r/connection.rb:60:in `new’
from C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.2/lib/xmpp4
r/connection.rb:60:in `connect’
from C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.2/lib/xmpp4
r/client.rb:71:in `connect’
from C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.7/li
b/xmpp4r-simple.rb:390:in `connect!’
from C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.7/li
b/xmpp4r-simple.rb:322:in `client’
from C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.7/li
b/xmpp4r-simple.rb:331:in `send!’
from C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.7/li
b/xmpp4r-simple.rb:147:in `status’
from C:/Program Files/Ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.7/li
b/xmpp4r-simple.rb:90:in `initialize’
from C:/Documents and Settings/Heath/Desktop/IM in Ruby/chat0.rb:29:in `
new’
from C:/Documents and Settings/Heath/Desktop/IM in Ruby/chat0.rb:29
C:\Documents and Settings\Heath\Desktop\IM in Ruby>
I install xmpp4r and xmpp4r-simple completely and then run this code. I change code to
jabber = Jabber::Simple.new(”hb.pat87@hotmail.com”, “***mypass***”)
jabber.deliver(”.pat87@hotmail.com”, “Hey! Dang if you recieve this message please answer me! this’s not virus na don’t worry”)
and It’s not respond message. it can use woth hotmail?? or can I do something wrong??
Leave a Comment