Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Build Facebook Chatbots With IBM Watson

DZone's Guide to

How to Build Facebook Chatbots With IBM Watson

A simple bot built on Facebook Messenger that leverages the language capabilities of Watson.

· Web Dev Zone ·
Free Resource

Learn how error monitoring with Sentry closes the gap between the product team and your customers. With Sentry, you can focus on what you do best: building and scaling software that makes your users’ lives better.

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 give people some ideas about how to use cognitive Watson services and 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.

facebookbot5

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 tweets. 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>

What’s the best way to boost the efficiency of your product team and ship with confidence? Check out this ebook to learn how Sentry's real-time error monitoring helps developers stay in their workflow to fix bugs before the user even knows there’s a problem.

Topics:
chatbot ,ibm watson ,facebook

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}