Thursday, July 09, 2009

Twitter bots

We wrote already about our Twitter mashup – Twitter 411 service. It is a web application lets you easily create your own Twitter bots. Bot here is an application that receives some requests via Twitter and responds with your own data. You define a form for the request as well as the content for the response. Here is an example for such a bot (stock market).

As a response for the bot within t411 service you can provide any CGI script (e.g. jsp, java servlet, php etc.) on your own site. See again here a complete example (JSP) for stock market bot.

And now let us see a yet another example. Now it is a weather bot.
How does it work? The source data provided by the site This site contains weather forecast around the world. And what is important, you can pickup weather data in XML or RSS format. So it is a quick deal to build some automation processing. We create a new bot for t411 service – code for the request is w

As a reaction for this bot we've set a JSP file that obtains RSS data from, presents them in mobile ready form and responds back with a link to the requested forecast. Here is a part of that file:

<div class="content">

<%@ taglib uri="/WEB-INF/taglib374.tld" prefix="w" %>

<w:setLocation url="" ttl="36000" id="A"/>

<w:forEachDay feedId="A">

<img src="<%=itemImage%>" style="border:0;float:left;padding-right:5px" alt=''/>

<br/>&copy; <w:getChannelCopyright feedId="A"/>
<w:getChannelLink feedId="A" id="url"/>
<br/><a href="<%=url%>">Original data</a><br/>


code uses the Weather taglib from Coldtags suite. Tag setLocation requests rss feed (and caches it for 10 hours. Tag forEachDay outputs data. And finally we prints a copyright information as well as the back link (as it is required by

The rest of the deal is standard. Follow to user @t411 and send him a direct message for the weather forecast you are interested in.

Here are examples (what the bot recognizes and what you have to send as direct message to @t411):

w london get forecast for London
w paris get forecast for Paris
w msk get forecast for Moscow
w spb get forecast for Sankt-Petersburg

And the result (you will get a direct message back) is a link to the mobile site with the forecast. Because it is a mobile site you will be able to open it right from your mobile phone.

The direct messages from Twitter could be delivered by SMS to user's mobile. And so – the mobile link will be delivered too. That was the original idea for t411 service – Twitter could be used as an alternative model for SMS services programming. Twitter is a transport here.

No comments: