Tuesday, February 6, 2018

Chatbots: Some tricks with slots in IBM Watson Conversation

As you might remember, 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.

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.
 
<? 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:

context.remove('myVariable')

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.

So much for today in processing variables and what I learned in building a Slack-based interface to Db2. More on that in a future post. If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@data_henrik) or LinkedIn.

A slightly extended version is published in the IBM Cloud blog.

No comments:

LinkWithin

Related Posts with Thumbnails