Setting up a Facebook messenger chat bot

Shreya Sinha
3 min readNov 21, 2020

This article is a guide on how to set-up a Facebook messenger chat-bot.

Note: For explanation purposes this article will quote examples from the sample Python bot built as a part of this post. This bot is deployed on Nimbella.

Facebook Page

Create a Facebook page with name same as what you would want your bot to be named. This page will be the point of contact with your bot.

Facebook App

  • Create an App by going to the Facebook Developers Page
  • Click on Skip and Create App ID. Choose the appropriate app type.
  • Provide the necessary app details as required (App Display Name, App Contact Email etc.) and click on Create App.
  • Choose the Messenger product to integrate with your App. Click on Set Up.
  • Click on Add or Remove Pages and select the Page that you had initially created. Once chosen you will also get an option to Generate Token for the page that you had created. Copy this token as you will need to configure it in your application to make calls to your messenger bot. For our sample Python application, the TOKEN environment variable mentioned there is this same token which needs to be passed as an “access_token” to the calls made to Facebook.
  • Set up the webhook for your bot. The Callback URL is the URL which will perform the challenge-response auth for your messages and process the messages sent to your bot. Also, provide the value of the Verify Token that should be processed by our app. In our sample app, the parameter verify_token is this same value. Also, in our implementation the environment variable WEBHOOK_VERIFY_TOKEN should have this same value.
  • Click on Verify and Save. If your webhook endpoint is up and running this should happen successfully. Else, check if the Callback URL that you have provided is correct or not and also check that the value of the Verify Token that you have provided is what you expect in your code.
  • Choose the following subscription fields for your bot/page: messages, messaging_postbacks, messaging_referrals

Testing the integration

  • Go to the Page that you created and send a message to your bot to test out the functionality
  • Alternatively, you can try to search for your bot in messenger and directly send a message from there.

--

--