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.

Technical Offering Manager / Developer Advocate

More How-tos stories
April 23, 2019

Announcing the Deprecation of the Watson Machine Learning JSON Token Authentication Service

We’d like to inform you about the deprecation of the Watson Machine Learning JSON Token Authentication service. This method of authentication will be retired on May 30, 2019.

Continue reading

April 2, 2019

Data Refinery and Profiling Changes in Watson Studio and Watson Knowledge Catalog

We'd like to announce data refinery and profiling changes related to Watson Studio and Watson Knowledge Catalog that will take effect on May 17, 2019.

Continue reading

March 26, 2019

Announcement for the IBM Watson Discovery Community

Starting April 2, 2019, we will be upgrading the infrastructure of the IBM Watson Discovery service to improve reliability and quality of results.

Continue reading