Managing Watson Assistant Response - Part 2 (Slots)
Hickmat 100000QA3T Visits (136)
Following on from my previous post I've been working to extent my approach to allow me to support the "Slots" facility within Watson Assistant. Given approach was focused on getting a single response object I needed to find a way that I could return a collection of items which can then be mapped into the Slots settings.
Looking at the flow of my code the answer was actually pretty simple and fairly obvious... Return a JSON Object holding the multiple details. So this meant I needed to introduce the concept of a "type" of content item (currently just two text and json) so that I could handle the response flow correctly. In both cases I still needed to support the mustache templating but in the case of JSON I would get a rich object rather than the single 'message' element. Applying this the format of my Cloudant documents changed to:
In the above you can see that for the "loans" area I have defined two elements (newLoan and status) one of type json the other of type text. In the json block I also show how the mustache substitution can be used (in this case I am simply showing a maximum loan value which I have stored in the context). With the document structure defined I needed to update my NodeRED flow to support the new type. To do this I simply extended the retrieve content path to "switch" based on the content type. The text path follows what I had before but in the case of the JSON path I convert the content JSON into a string which I then pass to the Mustache node and have that return a parsed JSON payload.
The final step was to set up my Watson Assistant Dialog flow to use this. In this case I will just show the "loanRequest" flow as that uses the added JSON feature.
Skipping the initial setup parts for the flow lets start with the "Get Content" node.
So here I set up my webhook call to get my content and assuming it all works my Context is updated with the Content context variable containing the JSON object returned from the NodeRED flow. Based on this the 1st thing I do is to return the message to check if the user will provide permission for me to collect addition information. Assuming they agree I flow to the following node.
Here you can see that I used the elements in the content JSON to populate the the "prompts" and so this allows me the ability to flex they way I engage with the customer when driving the slots to collect information.
I've not experimented with it yet but this approach should work equally well for the "Option" response type.
Well that concludes this brief post, I plan to continue to experiment with my approach and if I come up with anything else that is post worth I will add it to my blog,