How-tos

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

Slots

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.

[code]<? context.myVariable? ‘Great. I have the following: ‘+context.myVariable+’.’ : ‘No information present’ ?>"[/code]

 

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:

[code]context.remove(‘myVariable’)[/code]

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

More How-tos stories
September 19, 2018

How To Estimate Costs for Serverless Functions, Virtual Machines, and Other Runtime Models

Explore relevant costs, performance, and availability issues for a Total Cost of Ownership comparison of virtual machine and serverless functions.

Continue reading

September 19, 2018

Tutorial: Apply End-to-End Security to Cloud Applications

A new tutorial will show you how to use IBM Cloud services to secure your cloud application. Capture and review security-related events, encrypt storage, integrate authentication, and more.

Continue reading

September 18, 2018

How To Convert CSV Objects to Parquet in Cloud Object Storage

If you're looking to lower storage costs by compressing your data and get better query performance when querying the data in Cloud Object Storage, you may want to click to learn how to convert CSV objects to Parquet.

Continue reading