Tutorial: Facebook ChatBot

Facebook ChatBot
Establishing the Facebook Facilities

ChatBots, being of a programmatic origin, need to be registered with Facebook in much the same way as Facebook Apps are registered.  This is so that the application can consume and use its own key.  Similarly the ChatBot must be tied to a Facebook page so if you don’t already have a Facebook page you will need to create one.

Step 1 – Create A Facebook App

Facebook ChatBot CreationThe first thing we would want to do is head over to the Facebook Developers site and create an account if you don’t already have one.  After that is complete continue to add an App which will prompt you for details similar to that on the left.

Step 2 – Assign The Messenger Product To The App

Add Product To Facebook AppThe next stage looks similar to the image on the left.  Locate the “Messenger” product and click on the “Get Started” button to begin the process.



Step 3 – Assign The Messenger Product To The App

Facebook Page TokenA token is required from Facebook in order for the application to access the page and send and receive messages on its behalf.  Go ahead and select your Facebook page.  After obtaining permission from you this step will generate a Page Access Token.  Copy this access token to the config/default.json file of the tutorial application or place it somewhere for now.

Step 4 – Integrate The WebHook

Facebook WebHook IntegrationThe next step will require the tutorial application to be running on a publicly accessible IP address and port as Facebook will make a test call to it to ensure that the verification token is correctly set-up.  This endpoint will be called by Facebook to transmit message data to the application.

Using the image on the left configure the web hook as follows:

  • The callback URL should point to the IP or hostname of your application with a /webhook endpoint.  Only HTTPS is supported by Facebook
  • The verify token should match that which you have set in the config/default.json file in the verifyToken field of the ‘facebook’ connection
  • Ensure that both messages and messaging_postbacks are selected
Step 5 – Review And Very Visibility

Once Facebook has verified the connection to the ChatBot application and has verified the user-specified token (this is different to the page token we copied earlier) we need to ensure that the visibility of the ChatBot is not set to public.  To have the ChatBot operate publicly it needs to be reviewed and approved by Facebook and there is a number of information pieces to be supplied to Facebook.  Whilst the ChatBot operates outside of the public eye it is still available for testing and development.

Facebook ChatBot SettingsUsing the image on the left as a guide navigate to the “App Review” section of your App’s settings and ensure that the public visibility is set to NO.


Next Up:  Configuring OpenWeatherMap

Pages: 1 2 3 4 5 6

Written by YourAPIExpert