Chatbots: Some tricks with slots in conversations

Share this post:

If you follow my private blog you might remember that I have been using the IBM Watson Conversation service and DB2. My goal was to write a database-driven Slackbot, a Slack app that serves as chat interface to data stored in Db2. I will write more about that entire Slackbot soon, but today I wanted to share some chatbot tricks I learned. How to gather input data, perform checks and clean up the processing environment.

Henrik’s Slackbot


With my chatbot interface to Db2 I want to both query the database and insert new records. Thus, I need to collect input data of various kind. The Conversation service has a neat feature named input slots that simplifies that process. Within a dialog node (a logical step within the chat flow) I can specify a list of items the Conversation service should check for. I can tell in which variable to save that input and what question to ask if that data was not provided yet. Optional slots, i.e., optional data, can be enabled.

Cancel or exit the input process

When several items need to be collected, e.g., for a new database record, it could be that it takes too long or the user has second thoughts. It is a good practices to provide an escape route by allowing magic words or phrases. So-called handlers can be used in the Conversation service. There are different ways of how to process such an exit route. I wanted to jump back to the upper dialog level and discard all the collected input. For that I needed the following two features.

Existence Check

The Conversation service offers some variables and checks that help to determine if all slots were processed. One of these is all_slots_filled which evaluates to true or false. What I utilized is an existence check on the last required slot-defined variable. If it was present, all data was collected and I could return a related response. Else I could return a message acknowledging the cancelation. The following is the syntax. It checks whether myVariable exists and either returns what is before the colon or after it.

<? context.myVariable? 'Great. I have the following: '+context.myVariable+'.' : 'No information present' ?>"

Cleanup of Context Variables

Something to do in both a successful collection of all data or cancelation is to clean up the processing environment. It could be to simply set the context variables to an empty or null value. However, I found it more effective to delete (remove) the context variables:


The above should be put into an expression and embedded into the output section. An example can be found in this Github repository with tips & tricks on using variables in the Conversation service.

Closing Remarks

So much for today in processing variables and what I learned in building a Slack-based interface to Db2. More on that in an upcoming post. If you are new to chatbots, check out my previous posts on that topic:

If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@data_henrik) or LinkedIn.

Add Comment
No Comments

Leave a Reply

Your email address will not be published.Required fields are marked *

More Watson stories

A predictive Machine Learning model from Build to Retrain

This post is an excerpt from our solution tutorial that walks you through the process of building a predictive machine learning model, deploying it as an API to be used in applications, testing the model and retraining the model with feedback data. All of this happening in an integrated and unified self-service experience on IBM Cloud.

Continue reading

How to organize users, teams and applications in IBM Cloud

Learn how to organize your project with multiple deployment environments

Continue reading

How to build a cloud native app in 30 minutes

I’m one of the IBM Cloud App Service architects and have been involved in leading the team in the engineering and delivery of this tool for accelerating development of cloud native apps. After giving an overview of app architecture and stating the game plan,  I’ll take you through video demos of creating two microservices and an iOS […]

Continue reading