DIY Chatbot with IBM Watson

Yesterday IBM announced that they are rolling out an integration between their IBM Watson artificial intelligence platform and Slack’s built in chat bot “Slackbot”. If you are unfamiliar with Slack, then you are not yet part of the nearly 3 million users that use the chat platform to collaborate and communicate in groups and teams. Slackbot is Slack’s built-in service bot, where you can ask for help by typing “help” and other simple questions about how Slack works. This upcoming integration with IBM Watson’s Conversation technology is exciting because Conversation lets you add Natural Language Processing to any app with relative ease, and adding this ability to Slack will allow developers to build tools that will let teams control things using natural speech. Users will be able to request information and control things simply by asking questions in real language. Software developers can ask things like “check the build status for the last deployment I pushed”. Business people can setup meetings by telling Slackbot to “schedule a meeting with Mark Zuckerberg when it is convenient for both of us”. Even ordering food is possible, by saying “Order a ham and pineapple pizza from Domino’s, for 6pm tonight”.

For anyone keen on trying out IBM’s Conversation tech, it is possible to do for free. All you need are some coding skills, something to integrate with Conversation (I used Facebook Messenger) and a free account on IBM’s Bluemix infrastructure.

I’ve implemented the Conversation technology in a couple of prototypes, and I thought I’d share some of my experiences with you here.

ABE – A simple advertising report chat bot

My most recent full time work has been developing software for online advertising to make it better. It made sense for me to think about a solution in the digital marketing space, so I thought I’d build a chatbot that could help you with your online advertising needs. You can see the working prototype of that chatbot, ABE, on his Facebook page, just send him a message. Remember, this is a prototype, so the ad reporting integration isn’t working. But you can talk to him and ask him to do a small set of reporting tasks, like ask for a time based report for AdWords or Facebook Ads.

For this example, I won’t go into the specifics of code, but I will show you how things are hooked up at a high level, and my experience with setting up IBM Watson Conversation to add natural language processing to drive the dialog behind my chatbot.

First thing I did was to create a new Facebook Developer App. This gets you credentials so you can use the Facebook Messenger API, and setup the webhook to use when someone chats with your bot. You do have to setup a Facebook Page to associate with your bot, so there is an actual entity for people to chat to. Once you’ve done that, you are ready to start coding.

I used Node.js to hook everything up, specifically the Sails framework. Yes, it can be a little bit of overkill for a mostly server-side project like this, but I like Sails because it takes care of a lot of the underlying connections I need when building a web app. This lets me deploy and test an idea that I might have within a few hours. Because I’ve spent a good amount of time building multiple projects with Sails, I now have my own library of custom tools that I can choose to reuse for new projects, reducing my time to implementation.

IBM has a Watson SDK that lets you use all of their Watson services in your Node app. It’s pretty good, and there are also good examples of everything, including one for Conversation, which I used as an example to follow for my build.

If you have ever used Google Cloud Platform or Amazon Web Services, then you will have an idea of how IBM’s Bluemix works. Part of the Bluemix offering is the Watson analytics services, which give you Watson powered analytics for images, text and video. This is actually pretty exciting since Watson is pretty powerful and you can do this all for free.

Once I setup a Bluemix account, I setup the Conversation service for my chatbot. This involved a few steps.


First thing to setup is the intents that I wanted to capture, along with examples of user inputs that are valid signals of those intents. One of my intents that I want ABE to understand is that I want to get a new report. In the Conversation console, I create a new intent called “#getnewreport” and then I add at least 5 different natural ways a person could ask for that intent. For example someone might say “Can you get me a new report” or “new report please” or “how did Facebook do last month?”. These all contain the intent that I am asking for a new report of some kind to be generated.

I do this for all the different intents that I want ABE to understand, everything from asking for “#help” or asking for best performing ads to “#saygoodbye”. I specifically wanted to capture intents that were related to reporting for digital ad performance, which very simply is “#getnewreport”.

Screenshot from 2016-10-27 14-45-03.png
Setting up Intents on Conversation.


Next I had to setup a couple of entities.  Entities are things that are contained in a body of text, like a person’s name or a place. Conversation can be setup to capture a few system entities like percentage numbers, currency values and numbers. The entities that my chatbot needed to be interested in are the platform a report should be generated for, Google AdWords or Facebook Ads, as well as the type of report (for now just date range types) like last month, last week, or yesterday.

For entities, you add the entity name, in my case I added “@REPORT_TYPE” and added all the different report types I wanted to include: today, last month, last week, and yesterday. Then for each report type, I added synonyms for each, ie. last week could also be expressed as “last 7 days”. I did this for “@AD_PLATFORM” as well.

Two entities and synonyms for report types.

Still with me? Well those were the easy steps. The next step – well, that is an easy one too, but it is the more complicated step of the Conversation setup process.


The Dialog is the path a conversation takes, defined by the combination of intents and entities that are understood from the user input. A dialog is made up of different nodes, and the nodes are defined by intents or entities or combinations of both. At the top level of the dialog for my chatbot, I have all the main intents that I want to understand right from the start of a chat session. Things like saying hello, getting a report or replying with a help message.

Screenshot from 2016-10-27 14-53-51.png
Top level of my Dialog tree.

From here I add child nodes to each of the nodes that might lead to a conversation path that requires more information. The “#getnewreport” node is one of those – I know the user wants a new report, but in order to fill that request we need the type of report and a platform to generate that report on. It looks a little more complicated here because I wanted to be able to capture cases where the user might just say the platform on its own, without the report type. This node path captures and handles cases for “get me an AdWords report for the last 7 days” as well as “get me an AdWords report”. In the latter case, it asks for the user to provide the report type since it is missing. If a user wants to start over, this path also recognises that intent and sends the user back to the dialog start.

The branches of the dialog tree for getting a new report.

IBM’s Conversation Dialog tool let me test the dialog that I’d setup, so I could see that everything is being recognised as I expect. The tool also shows the intents it recognised using the example text I provided. Remember, Conversation is letting us leverage Watson’s natural language processing ability, so we can ask questions in plain English and have intents and entities recognised to take the dialog along a specific path.

Screenshot from 2016-10-27 15-03-47.png
Testing out Watson Conversation in the tool window.

The Bluemix infrastructure is relatively new and as a result is constantly changing. The interface changed a couple of times while I have been using it over the past year, mostly resulting in an improvement each time. New in the current version of the Conversation tool is “Improve”. This was  not yet implemented  when I first built this bot, but at a quick glance it looks like an archive of conversations that have been had with my app. Training is an important part of natural language processing, and this tool lets you do that using conversation history. I’ll report back once I’ve used it a bit more.

Screenshot from 2016-10-27 15-06-56.png
Improve conversations with training.

Now that I had Watson Conversation set up, I hooked up to it and Facebook Messenger in Node.js using Sails. The connections are pretty simple, I take any messages that come from a user in Facebook Messenger and send them through to the Watson Conversation API. That API replies back with an object that contains information about the recognised intent, the response text that is contained in the Conversation dialog, any found entities in the text body, and a few more details related to the conversation node.

For the most part I just let Conversation handle the responses without any intervention, though at the end of the “#getNewReport” intent  dialog branch, I would do the fetch for the AdWords report.

Screenshot from 2016-10-27 15-24-00.png
Abe in action. He doesn’t actually pull reports yet. Maybe one day…

Overall my experience with Watson has been pretty positive. You can even define dialogs using a JSON schema and upload them to the tool, and there is an Enterprise level service that I am sure is much more sophisticated. There were a few little things, like top level intents not carrying through to the dialog branch – every piece of text a user sends is parsed for intent, but this is a minor problem since I store initial intent in the app state, then maintain it as I progress down the same dialog path, resetting it only when the conversation starts over.

Any questions? Ask below. Or suggestions on other chatbot dialog frameworks to try out? There are a couple out there that I’ve been meaning to try, like Chatfuel. I’ll post a review once I’ve gotten my hands dirty. Bye for now!



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s