Monday, February 19, 2018

New tutorial: Db2-driven Slackbot

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 solution is based on IBM Cloud Functions and entirely serverless
Slackbot Architecture


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

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.

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.

(Based on