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 to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

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>

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:
chatbot ,ibm watson ,facebook

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}