How-tos

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

Overview

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.

Conclusions

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 / Developer Advocate

More How-tos stories
December 13, 2018

Java Microservices with MicroProfile – API Documentation

To benefit from the reuse and consistency microservice APIs offer, other developers will need guidance to use your APIs correctly. With annotations defined in the MicroProfile OpenAPI specification from Java EE, it's easy to generate clear documentation.

Continue reading

December 13, 2018

Tutorial: Deploying the Jenkins Helm Community Chart on IBM Cloud Kubernetes Service

The IBM Hybrid Cloud Team has authored a tutorial that will guide you through the steps required to set up and install a Jenkins server and deploy a sample Node and React application on IBM Cloud Kubernetes Service.

Continue reading

December 12, 2018

Deploying to IBM Cloud Private 3.1 with IBM Cloud Developer Tools CLI

IBM Cloud Developer Tools CLI version 2.1.12 adds deployment support for IBM Cloud Private 3.1.

Continue reading