Manage and Test Your Chatbot from the Command Line
By Henrik Loeser
New features for your Watson Assistant chatbot
Some time ago, when the IBM Watson Assistant service still was named Watson Conversation, I wrote a command line tool for it. In this blog post, I want to point you to some useful features that were added since then. They allow you to test client and server-side actions for your Watson Assistant chatbot.
Watson Conversation Tool with client action
Programmatic calls in Watson Assistant
With Watson Assistant, you can build chatbots—solutions that understand natural language and respond to the user input. In order to not just return hard-coded answers, it is pretty common to integrate database systems and other services into the solution. Watson Assistant allows you to directly execute actions coded with IBM Cloud Functions (server actions). Another option is client actions that are run by the application. In that case, Watson Assistant signals the client to perform the action and send the result back.
The Watson Assistant documentation for making programmatic calls lists these sample use cases:
You can use an external service to validate information that you collected from the user, or perform calculations or string manipulations on the input which are too complex to be handled by using supported SpEL expressions and methods. Or you can interact with an external web service to get information, such as an air traffic service to check on a flight’s expected arrival time or a weather service to get a forecast. You can even interact with an external application, such as a restaurant reservation site, to complete a simple transaction on the user’s behalf.
In a tutorial with a chatbot for Slack, the actions perform searches in Db2 databases and validate data. Testing server actions is easy because only the credentials for executing the embedded IBM Cloud Functions are needed. The action itself runs on the server and, therefore, can be utilized by any client app. On the other hand, client actions are executed by the app—the client application. I wanted to be able to easily test them during the development process, so I extended my Watson Conversation Tool.
Testing chatbot actions
As stated, Watson Assistant needs credentials for IBM Cloud Functions to invoke server actions. Typically, they would be passed in by the app layer. In the tool, they can be included into the configuration file. If present, they are added to the message context and then passed to Watson Assistant. See the sample configuration file included in the GitHub repository.
Client actions require a different approach. Using the Python-based tool, they can be tested in two ways:
Manually modify the session context: The tool saves the entire session context to a file session_context.json after receiving the response from Watson Assistant. It reads that file before sending the next message request. By using an editor, you could modify the session context and add, change, or delete values. The new request would pick up those values and send them to Watson Assistant. The process works well in general but does not strictly follow the protocol for the client actions.
Provide code for/to simulate client action: As a new feature, the tool now accepts a parameter “-actionmodule name.” That module or single Python file is then dynamically loaded and a function handleClientActions is called. That function either provides the regular logic for the client action or could be some code to simulate the action by assigning test values. I have successfully used it to test some client actions with a Watson Assistant workspace. This way, you could test Watson Assistant independently of the actual client application.
Here is a sample invocation of how I use the Watson Conversation Tool to test the dialog flow. The handling of a client action is in handleClientAction.py and I am only interested in the regular output (“-outputonly”):
python wctool.py -dialog -id e5e9781f-xxxx-xxxx-9xx9-d9xxx405a0e4 -actionmodule handleClientAction -outputonly
Let me know if you have questions or feature requests by opening an issue against my GitHub “watson-conversation-tool” repositoryor reaching out to me directly. Please note that the tool is provided “as-is,” and it not an official IBM project and is unsupported. I hope that you find it useful nonetheless. To get started, check out these links:
Watson Conversation Tool on GitHub
IBM Cloud solution tutorial featuring a Slackbot and using server actions
For feature requests, defects, or suggestions, open an issue or a pull request against the repository. If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@data_henrik) or LinkedIn.