How to Write Your Own IM Bot in Less Than 5 Minutes

Write IM bot This quick tutorial will show you how to develop your own functional IM bot that works with Google Talk, Yahoo! Messenger, Windows Live and all other popular instant messaging clients.

To get started, all you need to know are some very basic programming skills (any language would do) and web space to host your “bot”.

For this example, I have created a dummy bot called “labnol” that listens to your IM messages and return related search phrases based on Google Suggest. To see this live, add  labnol@bot.im to your GTalk buddy list and start chatting.

google-talk-bot

If you like to write a personal IM bot, just follow these simple steps:

Step 1: Go to imified.com and request an invite. You should also give your bot a decent name because you can have just one bot per email address.

Step 2. An email with a secret key should arrive in your Inbox the next minute. Copy that key to the clipboard and go here to redeem that key.

Step 3. Now it’s time to create a bot which is actually a simple script that resides on your public web server. It could be in PHP, Perl, Python or any other language. More here.

This is the source of the PHP script I wrote for the labnol IM bot – pretty self explanatory – it reads your message, gets the relevant data from Google Suggest and echoes it back to the IM window.

<?php
  // Get all the related keywords from Google Suggest
  $u = "http://google.com/complete/search?output=toolbar";
  $u = $u . "&q=" . $_REQUEST['msg'];

  // Using the curl library since dreamhost doesn't allow fopen
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $u);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  $xml = simplexml_load_string(curl_exec($ch));
  curl_close($ch);

  // Parse the keywords and echo them out to the IM window
  $result = $xml->xpath('//@data');
  while (list($key, $value) = each($result)) {
    echo $value ."<br>";
  }
?>

Step 4: Once your script is ready, put it somewhere on your web server and copy the full URI to the clipboard.

web-url Now login to your imified account, paste the script URL and add that im bot your friends list. That’s it.

This was a very basic bot but the possibilities are endless.

For instance, you could write a bot that will send an email to all your close friends via a simple IM message. Or you could write one that will does currency conversion. See stuff that is already implemented in this list of most useful Google Talk bots.

Find this article at: http://www.labnol.org/internet/tutorial-create-bot-for-gtalk-yahoo-messenger/4354/

Tags: , , , , , , , Internet

Reader Comments

wow that seems to be a excellent post because now you can program your own bots! Wooh the technology is growing huge guys!

that’s great,Excellent tutorial, I think I will try to write a bot,thanks

amit, this has got to be one of the most clearest and useful imified bot scripts i’ve seen yet. nice job!

Well…I need to sharp my programming skills to write my own bots.

I need to know if there is any AIML implementation present in PHP. So that we can create Artifically Intelligent bots that can talk with us.

Yea that’s cool, but you can do more complicated things with that structure fyi ;)

A very interesting, and very cool development I must say. I could see this being useful for web hosting companies and ISPs where commonly asked questions and requests for information can be answered with a chat bot

Jesus christ this gave me a heart attack. I got linked here from Digg ( link ) and when I saw the name Amit in the .png file I thought it had somehow already managed to decipher my own name!!

Stick a fork in me, I’m done!

Greetings from Sydney, Australia :)

Very neat work, I’ve tried adding a bot, but it doesnt show online. Do we need to do something to make that happen?

nice article. Maybe I’ll make the bot soon. I think I can get many things in this blog. thanks

you have all noticed that imified.com plan to make the developers pay for this when it comes out of beta ?
but do not worry “You’ll have plenty of upgrade options when our Beta period ends”

I was able to use fopen on dreamhost using a custom php.ini, they have instructions in their wiki on creating one.

Is it possible to make a bot which pushes messages to its subscribers ?

As far as i can see the bot can only reply on questions.

If it is posible i would like to use it on my new site link

I’m kinda lost here. after pasting the script url, how will I add the bot on my friendlist? and where is that? Am I going to add the link on my gmail chat, yahoo msgr? is that it?

Great tutorial! Having the same problem as Abhimanyu invited the bot however it has not accepted my request! I knew I should not of called it Hal 9000…
“This mission is too important for me to allow you to jeopardize it”

I have the same problem, my bot is offline, i don’t know how to activate it.

Thanks. This was really helpful. Now I can make a bot that gives information of all my company products.

Thanks a lot !

Actually, this post is about how to link a custom PHP script to IMified. It is not about writing “your own IM Bot”.

Amit..this is great. But i dont know why my bot isn’t alive as i add my bot just now? How long do i have to wait?

me having the same problem :( bot is invisible. Anyone know what to do?

Cool! The script is very straight forward too, good job!

I feel like whole imified.com bot network is down. I can’t even access regular imified bot.

Amit, congrats for reaching on delicious and digg’s homepage ;)

I have the same problem, my bot appears offline.

I tried link but it is also offline :(

imified.com has big troubles !!!

I dont think the bot will work until the Digg Rush is over =)

The IMified bot has been down since a couple of months now. I just created this bot, and well quite obviously, it’s offline.

We’re currently experiencing some difficulty bringing your new bot online due to an appearance on the Digg home page resulting in an unexpected high load.

Please bare with us while we get things back online. You can check our blog link for the latest status.

Great post. Thanks for sharing this tip. Tinh

Lol. as if I’d give my IM login data to imified. Next thing you know: They sell it… or “lose” it… Haha.

Besides: I have my own IM libs in Java on my server.

Seriously, if you’re smart enough to write PHP, Perl, or whatever, you should be smart enough to write a bot to connect to Jabber or any other protocols.

The primary benefit here is that they host the bot process for you so you don’t need a VPS or the like.

The negative is obviously that this is event based and can’t actually initiate a conversation or push content.

Barefoot: put the tin foil hat away and just create a new SN that you’d use for the bot…

Andrew: You can push content using IMified. See the developer docs at link for details on our APIs.

Barefoot: you don’t need to give us any login info. We create a Jabber account for each bot on our servers and your bot runs as link .

Wow this is what Ive always wanted, just didn’t know how to setup one. Thx

Thanks for creating this tutorial, it’s been very informative. I’ve kind of started to play with it and mash it up but I was wondering why the “output=toolbar” parameter? Thanks in advance!

We followed this and with a little twist we were able to create a bot to use in our company intranet.
Thanks!

Thanks, I always wondered how to create my own bot. I’ve been slightly envious of one of my friends who created a fairly complex one over the last 15 years, and I doubt I’ll stay motivated enough to make anything even comparable to his, but at least I can have a fun little bot to tool around with now.

Insted of simplexml you can use PHP version of jQuery and simply do AJAX request.

It’s called phpQuery and can be found here:
link

Hi

I created a bot on imified. But the bot is offline. Trying to add it as a gtalk buddy does not seem to have any effect. Can anybody help?

the form has changed a bit from what you are showing in the blog post.

how long does it take for a new bot to come online ?


Comment

Google Custom Search