Updated Tutorial: Build a Database-Driven Chatbot
3 min read
Use IBM Watson Assistant to build a Slackbot backed by a database app on IBM Cloud Code Engine, with data stored in Db2 on Cloud.
One of my favorite services on IBM Cloud is Watson Assistant, which allows you to easily build highly sophisticated chatbots. Even better, Watson Assistant has integrations with Slack, Facebook Messenger, WhatsApp, phone systems and more. Chatbots can become dynamic by leveraging data from backend systems, such as databases, customer relationship management (CRM) or enterprise resource planning (ERP) systems. The same way our (human) acceptance and interaction with chatbots have evolved, so have the capabilities and features of Watson Assistant. Therefore, it was time to update our popular tutorial on how to build a database-driven Slackbot. It shows how to build a chatbot to retrieve data about events and how to gather data for and then create a new database record.
The tutorial now makes use of action skills instead of dialog skills. And it shows how to reach out to a backend system with the new custom extensions in Watson Assistant. The updated tutorial demonstrates how such an extension is deployed to IBM Cloud Code Engine, the fully managed, serverless platform for containerized workloads. The backend app features a REST API to interact with data stored in an IBM Db2 on Cloud database. The following diagram shows the new overall architecture:
Watson Assistant and custom extensions
To deploy your chatbot to the (communication) channels your customers use, Watson Assistant offers a set of integrations. By adding them to your assistant, you can easily make the chatbot available to users on Slack or WhatsApp. The following screenshot shows the chatbot from the tutorial interacting on Slack:
To obtain data for a conversation from a database, web service, CRM or ERP system, Watson Assistant supports webhooks. The old version of the tutorial utilized webhooks to reach out to Cloud Functions to retrieve data from Db2 on Cloud. Custom extensions are a new feature in Watson Assistant. An extension is defined by importing an OpenAPI specification for a REST API. Thereby, the API functions with their input and output schemas are defined, so Watson Assistant knows about what functions are available, what data to pass to them and what result data to expect. This simplifies the conversation design because you are asked to map variables and user input to API parameters and you can reference result fields in assistant responses (see screenshot below).
In the updated tutorial, we use a REST API to manage data about events (conferences) stored in a Db2 on Cloud database. First, you import the API specification into Watson Assistant. Then, you configure server details for your deployed backend app (REST API) and tailor security settings:
The custom extension for the chatbot is a REST API. It is a Python database app that exposes operations on the Db2 on Cloud database as API functions. The source code for the app is available in a GitHub repository. For the tutorial, you can either use a pre-built container image with that app or build a container image on your own (with your modifications included). The image is deployed to IBM Cloud Code Engine as an app simply by first creating a Code Engine project, then creating the app.
Get started
Chatbots are an established tool for customer care. In the updated tutorial you learn how to work with a custom extension in Watson Assistant to create a database-driven chatbot integrated with Slack.
Are you ready to get started? Here are the relevant resources:
- The updated tutorial: Building a database-driven Slackbot
- Code on GitHub
If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@data_henrik) or LinkedIn.