I’ve been playing a little more with the Slots feature in IBM Watson Conversations and hit a few issues that at first seemed like they could be a problem. One scenario in particular that took me a while to solve, was how to build conditional logic into a node with Slots.
Let’s say that we are walking the user through a process and in the middle of that process a decision needs to be made based on a value collected earlier in the process. This is a common feature of a workflow, it’s obvious how it is done using multiple nodes but how do we do it in a single node using Slots?
I’m going to stick with the example process (Open Account) I’ve used before and extend the completed workspace from this previous post (Read that post first for background). When you’ve worked through the steps in this post it should look something like this completed workspace.
The diagram below details the workflow we are going to follow to implement our process.
So our process is the same as in previous posts with the addition that if the @Subscription_Type is Annual we’re giving away a free t-shirt and need to collect the size. Our challenge is to be able to complete this process in a single node using slots so that we only ask for @TShirtSize when the @Subscription_Type equals Annual.
To perform this kind of condition slot we need to understand two things about the way slots work.
- Using the Slot editor on the slot we can use the JSON editor of the Found/Not Found conditions to update the context
- A slot is fulfilled when the context variable in the “save as” field has a value
With these insights in mind our solution will
- Update the definition of the @Subscription_Type slot so that it updates context with
- Add a slot with the “Check for” condition set to
@TShirtSizeand the “Save as” field set to
Start by adding an entity called @TShirtSize to the workspace and add values for Small, Medium and Large.
Next, select the #Open_Account node and click the icon for the @SubscriptionType slot to open the editor.
Find the section that says “When user responds, if @Subscription_Type is…”, select the “Not found” option and add a condition for @Subscription_Type:Monthly.
Click the icon, select Open JSON editor and add a statement to set the context variable TShirtSize to “NA”.
Save the @Subscription_Type slot and add a new slot with a “Check for” value of @TShirtSize, “Save as” value of $TShirtSize and “Would you like a Small, Medium or Large t-shirt?” in the “If not present, ask” field as shown below.
To finish off our conditional slot we’ll add a conditional response to demonstrate that the final responses can also be tailored to our process and business rules. To do this, open the #Open_Account node, right at the bottom of that node you will see a section for “Then respond with:” which can have conditions attached to responses.
Click the add condition link above the current response and add a condition of
$TShirtSize=="NA" then click “Add another response” and enter the text as “Okay, I’ll open your $Account_Type with $Subscription_Type payments and send your $TShirtSize t-shirt right now.”
Go ahead and test the workspace, in particular try out both Monthly and Annual subscription types to verify conditional t-shirt size question only gets asked when it should.
Using this approach you can build really quite complex decision trees without having to create trees at all, moreover your decision trees will allow users to provide information in a flexible manner, one at a time or all at once.
In my next post on using Slots in IBM Watson I will discuss how to add slots for non Entity conditions and how to deal with numbers where zero (0) is a valid entry.