Database-driven Slack chatbot with Conversation service

Share this post:

Ever wanted to build a Slackbot, a chatbot integrated into Slack, on your own? I am going to show you how easy it is to integrate Slack or Facebook Messenger with the IBM Watson Conversation service. As a bonus, the bot is going to access a Db2 database to store and retrieve data. The code in the tutorial uses a serverless fashion with IBM Cloud Functions.

Henrik’s Slackbot


Today, more and more people use messenging services like Slack, Facebook Messenger, WhatsApp or Skype to collaborate. Some services offer APIs to integrate outside systems. This allows notifications about events on Github or alerts about upcoming inclement weather conditions. Especially interesting to enterprises, the APIs enable interaction with business systems in the backend. Thus, it may be interesting to try out a new tutorial that shows how a database-driven chatbot can be built with the Conversation service and then deployed as Slack app. Query a Db2 database using natural language instead of SQL. Gather all the required data in a step-by-step dialog and then insert a new record into the database.

The tutorial utilizes the Conversation connector. It is a set of components that mediate communication between a Conversation workspace and a Slack or Facebook app. The connector builds on IBM Cloud Functions and Cloudant NoSQL DB and, hence, implements a serverless approach. For the tutorial I am using the scenario of a database with event data (conferences, meetings).

Chatbot Details

Slack Chatbot Architecture

Slack Chatbot Architecture

Using Cloud Functions, it would have been possible to directly connect Slack with the Db2 database. You might wonder why I use the Conversation service. The answer is quite simple, to improve the user experience and to allow really natural language for input. To give an example, with a programmatic interface users would need to stick to a certain command syntax. Using Conversation, input can be provided in a step-by-step approach using dialog slots. Moreover, users can enter regular sentences with the required information

“Show me conferences in March”. For this input, the Conversation service recognizes the intent to query for event data. Next, it understands that the search is by date. Furthermore, it translates “March” into a date range from 2018-03-01 to 2018-03-31. Utilizing Conversation dialog actions, the search request is routed to Db2 as a parameterized query. The result data is postprocessed and a text answer is returned to the Slack user.

The Conversation service automatically detects entities like date and time. All kinds of variations are possible, e.g., “tomorrow”, “next Wednesday” or “2018-02-22”. When enabled, the service extracts city and location information. Intents and entity values are available for processing within dialog nodes and to apps or middleware calling into the Conversation service.


Using services offered by IBM Cloud and following the instructions in the new tutorial, it is really easy to create a chatbot integration to Slack. If you are new to chatbots, check out my previous posts on that topic:

Moreover, check out all of the existing IBM Cloud tutorials in the documentation. If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@data_henrik) or LinkedIn.

Technical Offering Manager

More How-tos stories
September 18, 2018

How To Convert CSV Objects to Parquet in Cloud Object Storage

If you're looking to lower storage costs by compressing your data and get better query performance when querying the data in Cloud Object Storage, you may want to click to learn how to convert CSV objects to Parquet.

Continue reading

September 17, 2018

How To Consolidate PostgreSQL Data to IBM Cloud Object Storage for IBM Cloud SQL Query

Consolidating PostgreSQL data into a durable and highly reliable data storage service like IBM Cloud Object Storage will not only reduce costs, but it provides a flexible, durable, and scalable solution for storing all sorts of unstructured data.

Continue reading

August 30, 2018

Querying Your Distributed Application Data Using IBM Cloud Object Storage and IBM SQL Query

In this third part of a four-part series on Operationalizing SQL Query, we'll bring together the microservices we deployed in Part 1 to query data in IBM Cloud Object Storage (COS) using the techniques we developed in Part 2 using IBM SQL Query with the goal of connecting our application's data to Business Intelligence (BI) tools.

Continue reading