skip navigation
Previous Tutorial

Web Services

Now that your chatbots can remember what you tell them, wouldn't it be great if they could also tell you something you didn't know? Perhaps, your chatbot could make a comment on the weather, suggest a recipe to make or tell you the latest breaking news. All this can be done by having your chatbot browse through handy web services called RSS feeds.

RSS feeds

Similar to a radio stations, RSS feeds are meant for broadcasting information that frequently changes and updates. Each entry in a RSS feed has a title, a link and a description. Programs go and collect information and bring it back to the user. For our purposes, we will simply call a method to get the information we want.

Using Provided Web Services

Getting the weather

Let's start off with getting the weather for today. To do so we can call a method named User.RSSWeatherToday. This method has two parameters: the city and the state in which you want the weather from. To use it, just give it the parameters for the location you want and store the answer in a variable. For example, if you wanted the chatbot to check the weather in Baltimore, Maryland you might code something like this:

string weather = User.RSSWeatherToday("Baltimore", "Maryland");
return weather;

Notice that "Baltimore", the city, came before "Maryland", the state. This ordering is important because if you flipped these two around the poor chatbot will go off looking for a city named Maryland in Baltimore state which doesn't exist!

Browsing the news

Aside from getting the weather, you can also search on Google News for interesting news related to a given topic. The methods for doing this are the following:

User.RSSGoogleNewsTitle( string searchTerm )
Gets the title of the news item.
User.RSSGoogleNewsLink( string searchTerm )
Gets the link to the full article.
User.RSSGoogleNewsDescription( string searchTerm )
Gets a brief description of the news.

The parameter named searchTerm is a string that contains the keywords to perform the search by. For example, the following code makes a handy bot that will give you a link the top headline related to what you just said to it:

string link = User.RSSGoogleNewsLink( message );
string title = User.RSSGoogleNewsTitle( message );
return "I've heard some news about that. It was called: "+ title +". Check it out at: " + link;

So if I say "I like smoothies" to this bot, It might reply with the following:

I've heard some news about that. It was called:
Beat the Heat With Refreshing Summer Treats - Korea Times. 
Check it out at:

Customizing your own Services

If you wish to go far and beyond the world of weather and Google News, you can get information from an RSS feed of your choice. First you need to find the url to a RSS feed you wish to use. These can be found online at sites similar to Top 100 Most-Subscribed-To RSS Feeds. Once you get a RSS feed url, you can call the functions User.RSSgetTitle, User.RSSgetLink and User.RSSgetDescription with the url as the first parameter and get the information you would like.

If you would like to know what other methods you can call to get specific RSS information, check out the RSS Reference.

Extra Bots

Now that you have completed the tutorial, go and make your own bots! You can find additional bot ideas on this page.

Previous Tutorial
This work is supported by the following National Science Foundation Grants: CNS-087508, CNS-0549481, IIS-0811884, IIS-0415273
Send comments to Richard Ladner