Yoan Blanc’s weblog

Another swiss guy lost in Paris

A IM bot as an user interface (kind of)

Yoan BlancSun, 11 Nov 2007, , , , , ,

A while ago, I’ve already played with this kind of tool that looks to be magical. A remote bot that will do some action for you, to communicate with him, you just have to fire up your favorite Instant Messaging software talk with him. How many times a day you do so with your work mates asking little things? I’ll present a bot for Tumblr (yes it already exists, but it’s closed source and for AOL only), it enables you to post easily 4 of the 7 items you can post on Tumblr (mainly due to my laziness). The result is on my temporary Tumblr.

First of all, I’ve chosen Twisted instead of XMPPPy (like Thomas Perl’s Jabberbot) because Twisted contains support for many other protocols like IRC, OSCAR (ICQ) or MSN which could be useful if you need them as well.

Let’s do a very simple bot (the same I did before):

from jabberbot import JabberBot

class DumbBot(JabberBot):
 def gotMessage(self, jid, msg, resource):
  words = msg.split(" ")
  words.reverse()
  self.sendMessage(jid, " ".join(words))

print "DumbBot running, hit Ctrl+C to quit"
DumbBot("greutly@swissjabber.ch", PASSWORD).run()
		

This bot only handle message type of data, feel free to extend it.

To Post on Tumblr, it was required to create a Tumblr client that will take advantage of their REST API which is very simple.

A simple usage of it:

from tumblr import Tumblr, Regular

hello_world = Regular("Hello World!")
blog = Tumblr("greut", EMAIL, PASSWORD)
blog.post(hello_world)

You can also post Quotes, Conversations and Links at the moment.

Now mix the Jabber and the Tumblr things together:

from tumblr import Tumblr, Regular
from jabberbot import JabberBot

class TumblrBot(JabberBot):
 def __init__(self, jid, password, tumblr):
  super(TumblrBot, self).__init__(jid, password)
  self.tumblr = tumblr

 def gotMessage(self, jid, msg, resource):
  post = Regular(msg)
  self.tumblr.post(post)
  self.sendMessage(jid, "posted %s" % \
   self.tumblr.get_url(post))

blog = Tumblr("greut", EMAIL, PASSWORD)

print "TumblrBot running, hit Ctrl+C to quit"
TumblrBot("greutly@swissjabber.ch", PASSWORD, blog).run()

Et voilà, you’ve just posted on Tumblr via Jabber. The above code is the minimal code to achieve this kind of sweetness. The bot (tumblr.tgz) supports more actions and format types.

Going further: you can have a Jabber client on your Blackberry, your iPhone, simple and lightweight that is already heavily used by applications like Remember the Milk or Twitter. The SwissJabber guy made some bots for: the meteo, for asking a phone number, a whois, etc. Most of the time, web applications offer a IM interface, Tumblr does, but internal tools don’t, internal entities to your company for example or relative to your datas you may not want external companies look at. Their is a field of exploration here. Unwanted IM are more disruptive than unwanted emails, but the cool thing with a IM bot is that it knows if you’re either online, away or not and can acting accordingly to this.

A Doodle like that is IM powered for simple and very important things like: “where are we eating today?” One of the most recurrent question inside a company before lunch time. Many things are doable in this area and it’s easy.

J’ai ressorti un vieux bout de code servant à faire un bot Jabber très simple pour tenter d’aller plus loin et en faire une interface à Tumblr, un système de blogging minimaliste (le résultat). Un (ro)bot se greffant sur un système de messagerie instantanée est là pour ces petites actions qui doivent prendre 10 secondes, Remember the Milk et Twitter en font déjà un précieux usage.

Parti sur Twisted Matrix plutôt que XMPPPy (à l’instar de Thomas Perl et son très élégant Jabberbot) car Twisted intègre le support d’autres protocoles comme OSCAR (AOL et ICQ), IRC ou MSN qui peuvent s’avérer utile le besoin venant.

Pour commencer, j’ai réécrit un bot Jabber vide permettant de refaire le bot précédant encore plus simplement, le code source se trouvant dans la partie en anglais (mes excuses).

Puis une couche d’abstraction à l’API REST de Tumblr. Qui est plutôt triviale, toute bonne API se devant de l’être. À l’heure actuelle, seul 4 des 7 types de posts sont supportés (libre à vous).

En enfin, en combinant les deux on obtient un bot permettant qui va faire le pont entre les messages reçu et ceux qu’il va créer sur votre Tumblr personnel (télécharger tumblr.tgz). Différentes syntax suivant le type de message désiré sont comprises, ça n’est pas forcément toujours simple de trouver la syntaxe adéquate aux besoins qu’on va en faire (le grand avantage d’avoir un contrôle sur lui est qu’on peut choisir ce genre de détails là).

Aller plus loin: Monsieur Swissjabber a créé différents bots pour différents usages comme la météo, un whois, la recherche de prix sur toppreise, etc. pas forcément très sexy, mais tout aussi inutile que l’application ci-dessus. Si vous pouvez questionner un bot, il peut également en plus de vous répondre vous parler directement, vous tenir informé d’informations pouvant vous être intéressantes. Son plus grand atout est de savoir si vous êtes connecté ou pas. Si à l’heure actuelle bon nombre de services Web (2.0 pour la plupart) offrent l’option messagerie instantanée ou sont supportés par un autre service Web 2.0 imified (qui en a fait son business model), toutes les applications qui concernent vos données, celles de votre entreprise doivent rester entre vos mains d’où la nécessité de gérer ce service-là vous même.

Des services comme Doodle ou PollDaddy fonctionnant uniquement via messagerie instantanée seraient assez fun, la question universelle et récurrante étant : « où va-t-on manger ce midi? » Il faudra toujours des moyens inventifs pour y répondre.

About

meYoan Blanc is a web developer that lives in Paris (19, rue Bichat75010France) works for Yahoo! and comes from Switzerland ( La Chaux-de-Fonds). This web site is for this weblog, a playground for random stuffs and can help keepingconnected with some friends out there.

Get my vCard or contact me by phone (+33 1 74 30 12 92) or email ().

Misc

RSS, list.blogug.ch

This site reflects only my opinion and is not affiliated with my employer.

copyright 2006-2007 — doSimple.ch