Skip to main content

Messenger

Messenger is a messaging app and platform developed by Facebook, Inc. It allows users to send text messages and voice messages, make voice and video calls, and share images, documents, user locations, and other media.

Messenger is one of the most popular messaging apps in the world. It has over 2 billion active users and is available in 120 different languages.

How to connect to Messenger

To get started using this blueprint, you will need credentials which you can get from the Facebook Developer Portal after creating an app. Note that the bot will be used on a page so you will need to create a page.

Here are steps to follow for you to get started:

  • Go to your apps.
  • Create an app.
  • On Which use case do you want to add to your app?, select Other >> Next.
  • Select Business >> Business (it will prompt you to enter basic app information)
  • It will ask you to add products to your app. Add Messenger.
  • Create a page if you do not already have a page.
  • Get an access token.

Getting Started

Deploying your Messenger bot can be either done using either Sarufi Dashboard or your own server. We are going to cover both ways.

The Sarufi Dashboard provides a quick way to deploy your bot. You can deploy your bot in just a few clicks. You can also use it for bot management, viewing bot logs and much more. To get started, you will need to have a Sarufi account.

Steps:

  • Log in into your Sarufi account.

    Go to your Dashboard to create a bot. Click Create Bot button. Enter your bot name and click Create Bot button

  • Add messenger credentials

    Navigate to Settings >> Integrations >> Facebook Messenger. Enter your page access token and Verify token. Click the Save button. Then click Deploy.

    Adding Messenger credentials in Sarufi dashboard

  • Wait for your job to finish. Once done, you will have a webhook URL presented to you. Copy the URL and follow the steps about setting up a messenger webhook here.

    Messenger webhook URL

  • In case you want to change some of your credentials, just update your credentials in your dashboard and click Update. Then Re-deploy again.

  • You can view your bot logs by clicking View Logs.

Finalize Messenger Setup

We are going to finalize our setup process by setting up the webhook and subscribing to the messages and messaging_postback.

  1. Setting webhook

    After starting ngrok, you will have a public URL to access the local server. The url looks like https://xxxxxxxxxxx.ngrok.io. Navigate into your Meta developer account. In the webhooks section, click Messenger >> Settings.

    Messenger Settings section

    Scroll down to webhook section of messenger, click Add Callback URL. Then paste the provided URL into the URL section. Copy the VERIFY_TOKEN and paste it into the verify token field in messenger >> Verify and save.

    Messenger webhook setup

  2. Webhook field subscription

    We have to subscribe to webhook fields in order to receive messages sent by user. We will subscribe to the messages and messaging_postback topics. Scroll down to webhook section and click Add subscriptions. Then select messages and messaging_postback >> Save.

Test Your Messenger ChatBot

Here is a demonstration of the PizzaBot deployed in Messenger.

Bot deployed in Messenger