How to build Facebook Chatbots with IBM Watson

Update November 2016: The dialog service has been deprecated and replaced with the Conversation service.

I’ve open sourced a simple sample of a chatbot for Facebook that leverages IBM Watson Dialog and IBM Watson Natural Language Classifier for conversations with users.

Get the code from GitHub.

The GitHub project contains a sample of a Facebook bot built on the Facebook Messenger Platform which is currently available as beta. The sample bot is pretty simple but might people give some ideas how to use cognitive Watson services and how to host the bot on Bluemix.

The sample bot shows recent tweets with a positive or negative sentiment about a specific topic via the Insights for Twitter service. Check out the screenshots folder for more information.

The left screenshot shows the usage of the Dialog service. The right column shows additionally the Natural Language Classifier. In this example users can type in ‘awesome’ which is a word that is not hardcoded anywhere.


I’ve implemented the bot via Node.js. In order to invoke the action that reads the tweets I’ve extended the dialog definition with the JavaScript code which is supposed to be invoked.

<item>Alright. Here are the {Sentiment} tweets about {Topic}:$ExecCode$showTweets(sender, "{Topic}", "{Sentiment}")</item>

In order to use buttons in the chat I’ve extended the dialog definition with the button data.

Rather than clicking on buttons users can also type in text like ‘awesome’. Rather than hardcoding all alternatives the Watson classifier is used to determine whether users are interested in positive or negative tweet. The id of the classifier is defined as part of the dialog definition.

<item>Are you interested in positive or negative tweets?$ShowButtons$[{"type":"postback","title":"Positive","payload":"positive"},{"type":"postback","title":"Negative","payload":"negative"}]#3a84cfx63-nlc-5285</item>