Build Watson Powered Facebook Messenger Chatbot
Build Watson Powered Facebook Messenger Chatbot
Have you ever wanted to quickly build conversations for chatbots and virtual agents? Read this tutorial in order to find out how.
Join the DZone community and get the full member experience.
Join For FreeThe most visionary programmers today dream of what a robot could do, just like their counterparts in 1976 dreamed of what personal computers could do. Read more on MistyRobotics.com and enter to win your own Misty.
In this blog, we will demonstrate how to build a Facebook messenger chatbot using the Watson Assistant service and Botkit middleware. The Watson Assistant service allows you to quickly build conversations for chatbots and virtual agents. Botkit is designed to ease the process of designing and running useful, creative bots that live inside messaging platforms such as Slack, Facebook, and Twilio. The Botkit middleware we use is created by the Watson Developer Cloud team as a plugin to Botkit. It allows developers to easily integrate a Watson Assistant workspace with the messaging platforms supported by Botkit.
Prerequisites
Configure Watson Assistant Service and Create a Conversation
The first step is to create a Watson Assistant service in IBM Cloud. Then, create a new Watson Assistant workspace and begin to define Intents, Entities, and the Dialog. Finally, let's build a simple chabot by following this getting started guide. This conversation forms the basis for our integration with Facebook messenger.
Take note of the Watson Assistant credentials when creating the service. We will need the USERNAME
, PASSWORD
and WORKSPACE ID
in later steps.
Create a Facebook Page and Configure Facebook Messenger
- Create a Facebook page to deploy the Facebook messenger bot. If additional help is needed, refer to Facebook's How do I create a Page? documentation.
- Go to Facebook for Developers, click on My Apps, and select the Add a new app option.
- Create a new app ID by entering a Display Name and Email.
- Once the app is created, go to your app's Settings and under PRODUCTS, click Add Product. Select Messenger and choose to Set up the messenger product.
- Create a page access token to start using Facebook APIs. This page token has all messenger permissions regardless of whether your app is approved to use them or not. Select your page and choose to generate a token. Make note of the token, as it is required in a few steps. Note that these tokens do not expire.
Configure Botkit Middleware
- Fork and clone the Botkit middleware repository.
git clone https://github.com/watson-developer-cloud/botkit-middleware.git cd botkit-middleware
- Navigate to the folder
examples/multi-bot
within the repository. You can choose to either deploy your bot to a single platform (Slack, Facebook, or Twilio) or choose multiple platforms. For this exercise, choose to deploy to Facebook Messenger only.cd examples/multi-bot
- Edit the
.env
file by updating the Watson AssistantUSERNAME
,PASSWORD
andWORKSPACE ID
. - Still in the
.env
file, specify the Facebook related variablesFB_ACCESS_TOKEN
,FB_VERIFY_TOKEN
,FB_APP_SECRET
andUSE_FACEBOOK
.FB_ACCESS_TOKEN=<token you had generated in the token generation step> FB_VERIFY_TOKEN=<random token that you can generate> FB_APP_SECRET=<secret key which Facebook provides available in the facebook developer dashboard> USE_FACEBOOK=true
- Upload your application to IBM Cloud from your working directory (examples/multi-bot). Follow the steps for Uploading your application to push your application to IBM Cloud through the CLI.
- You can check your IBM Cloud dashboard to view the application after it starts running successfully. Take note of the application URL as that is required in a few steps.
- Go to the Facebook apps page, configure the Webhook with your IBM Cloud application URL, and verify the token.
Ensure theCallback URL: https://<your_unique_url>.mybluemix.net/facebook/receive Verify Token: random token that you specified in step 4
messages
andmessaging_postbacks
options are selected. Click Verify and Save. - In order for your webhook to receive events for a specific page, you must subscribe your app to your page. You can do this in the Webhooks section under the Messenger tab.
Your Facebook messenger chatbot is now ready! You can test it by using Facebook messenger!
Robot Development Platforms: What the heck is ROS and are there any frameworks to make coding a robot easier? Read more on MistyRobotics.com
Published at DZone with permission of Riya Roy , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}