Friday, January 12, 2007

Sametime bot finds zip code with @DBLookup

Based on Thomas Adrian's Swedish postcodes database, I've created a function for our company's Sametime bot which returns the post codes(zip codes) for a specified city or the city name by specified zip code. All you need to implement this functionality in the free evaluation version of Botstatiuon Bot is to create a "pattern answer" with @formula which makes lookup to the database. Similar formula can be used for any database lookup from bot. Later I will add bot function to lookup for phone area codes for cities in USA and Sweden.
With Sametime Widget (STWidget) AJAX-based tool you can make a live test of the function.
Commands you can type to bot:
postcode 18200
postcode Danderyd
zip 14700
zip tumba

And of course the most popular "joke" command which shows you a random joke every time you type it :)

TRY HERE: http://www.botstation.com/products/stweb/stwidget_zip.html


-------------------------------------
city:=@ReplaceSubstring(@Trim(@Right(@RequestText;" "));" ";"-");

tmp:=@DbLookup("":"NoCache";@Subset(@DBName;1):"bot\\pnr.nsf"; "By city";city;2);
@If(@IsError(tmp); @If(@Length(city)!=5;@Return("Postnumber not found for city "+city);"");@Return("Zip code(s) for "+city+": "+@Implode(@Sort(@Unique(tmp));", ")+"<br>--------------<br>You can also try reversed command:
postnumber "+@Subset(tmp;1)));

tmp1:=@DbLookup("":"NoCache";@Subset(@DBName;1):"bot\\pnr.nsf"; "By number";city;2);
@If(@IsError(tmp1);"City for postnumber "+city+" not found"; "City for postcode "+city+": "+@Implode(tmp1;", ")+"<br>--------------<br>You can also try reversed command:<br>postnumber "+@Subset(tmp1;1))

-------------------------------------

@RequestText function above is translated by Bot into the incoming command text, for example "zip 12345".

Screenshot of Bot's answer configuration page:
Sametime bot formula

An alternative way to find zip code is to make call to a Web Service, which is also possible with Botstation Sametime Bot, I'll show how to accomplish it in some of the posts later this month.


Related posts:
Sametime bot shows a random Bible quote
Merry Christmas from Sametime Bot




Tags:

No comments: