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 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 informations
  • It will ask you to add products to your app. Add Messenger
  • Create a page if you have none as the bot will be used on the page
  • Get 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.

Sarufi Dashboard provide a quick way to deploy your bot. You can deploy your bot in just a few clicks. You can also use it to manage your bot. You can view your bot logs and many 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 Save button. Then click Deploy button.

    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 simple steps at setting messenger webhook.

    Messenger webhook url

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

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

Finalize Messenger Setup

We are going to finalize the setup by setting up webhook and subscribe to 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 facebook developer account. On 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 url section. Copy the VERIFY_TOKEN, paste it into verify token 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 shall subscribe to messages and messaging_postback topic. Just scroll down to webhook section of messenger, click Add subscriptions. Then select messages and messaging_postback >> Save.

Test Your Messenger ChatBot

With a bot deployed in messenger, here is a sample of a pizza bot.

Bot deployed in messenger