Persisting Data for a Smarter Chatbot

With Watson Conversation Service and Cloudant

Mark Watson
Dec 12, 2016 · 8 min read

In Review: Watson Recipe Bot

Before we start, let’s review how the Watson Recipe Bot works.

How It Works

Here is a high-level architecture diagram:

  1. Messages are immediately sent from Slack to the application over a WebSocket connection.
  2. The application forwards the message along with the current state of the conversation for the active user to Watson Conversation.
    Watson Conversation uses natural language processing to determine the intent of the message. For example, is the user asking to cook something? Did the user specify a cuisine?
  3. Watson Conversation returns a response to the application which includes the identified intent and any other information related to the current step in the conversation.
  4. The application uses the response to determine it’s next step. For example, if the user specifies a cuisine the application will query Spoonacular (a 3rd party API) for a list of recipes.
  5. Spoonacular returns a response to the application.
  6. The application formulates a message and sends it to Slack.
  7. Slack delivers the message to the user.

Adding Persistence with Cloudant

The new version of the application uses Cloudant to store users, ingredients, cuisines, and recipes.

  1. A document for each ingredient, cuisine, or recipe is also stored in Cloudant.
  2. The application looks for ingredients, cuisines, and recipes in Cloudant before querying Spoonacular.
    If one of these already exists in Cloudant, then it is returned immediately and there is no need for the application to query Spoonacular.
  3. Every request for an ingredient, cuisine, or recipe made by a user is stored in Cloudant.
  4. In addition, the number of times the user has requested a particular ingredient, cuisine, or recipe is stored in the user document.
  5. A new Watson Conversation intent has been created that allows a user to request their favorite recipes.
    The application queries Cloudant to find the recipes requested most by the user.

How It Works Now

Here is what the new architecture looks like:

  1. Provide a more personal experience for users (favorite recipes) using the data in Cloudant.
  2. Perform analysis on ingredients, cuisines, and recipes.

Reduce 3rd Party API Calls

Many 3rd Party APIs limit the number of times you can call them, or charge you based on the number of API calls you make. In our example
we make the following calls to Spoonacular:

  1. Request a list of recipes based on a cuisine.
  2. Request a specific recipe and the steps required to cook it.

Provide a More Personal Experience

As users request ingredients, cuisines, and recipes we can learn about each user’s habits. Do they cook Chinese food more than Italian food? Do they cook with chicken more than beef? What are their favorite recipes?

Analyzing the Data

Now that we are storing every user request for an ingredient, cuisine, and recipe, we can do some simple analytics on our data. The new application automatically creates views in Cloudant that allow you to find the most popular ingredients, cuisines, and recipes requested by all users. The views are a part of the by_popularity design doc and are named ingredients, cuisines, and recipes.

What’s Next?

In this blog we showed you how we could make simple, but valuable improvements to the Watson Recipe Bot by adding persistence with Cloudant and a little bit of code. We showed you how we could cut down on 3rd party API calls, personalize the user’s experience, and perform some basic analysis on the data.


Things we made with data at IBM’s Center for Open Source Data and AI Technologies.

Mark Watson

Written by

Tech Lead, HotSchedules


Things we made with data at IBM’s Center for Open Source Data and AI Technologies.