Facebook Messenger

How to create a bot and connect it to Facebook Messenger and Integromat

The Facebook Messenger app supports a connection of a bot that can then be used to receive and send messages on behalf of a designated page that belongs to the bot.

Scenario

The following steps are necessary for the correct setup.

  1. Log into Facebook, navigate to Facebook developer portal and click the Add a New App button to create a new app.

    2019-08-16_16_52_40-All_Apps_-_Facebook_for_Developers.png

  2. Once you create the app, you will be shown the Product Setup page. Select Messenger and click Set up.

    fWvpPZmBOM.gif

  3. Scroll down until you see the Webhooks section. Click on Add Callback URL button. You will be prompted to fill in an Edit Callback URL dialog. The required values can be generated through Integromat.

    2019-08-16_17_11_31-IMTbot_-_Messenger_-_Facebook_for_Developers.png

  4. Open a new tab and log into your Integromat account and create a new scenario. Add the module Facebook messenger > Watch messages as the first module to your scenario. Click the Add button to create a new webhook.
    Enter a webhook name and a verification token of your choice into the respective field. You will need this verification token later. Click the Save button.

    5dHhPVciwh.gif

  5. Clicking the save button will generate an URL of the webhook. Copy this URL to your clipboard.

    Copy address

  6. Go back to the Edit Callback URL dialog. In the Callback URL field enter the URL from your clipboard and in the Verify token field enter the same token that you entered in step 4. Click Verify and Save to save the dialog.

    2019-08-16_17_20_55-IMTbot_-_Messenger_-_Facebook_for_Developers.png

  7. Select and grant access to the page you want to use with the Facebook bot and select permissions the app should be granted for that page.
    – Click the Add or Remove Pages button.
    2019-08-16_17_28_25-IMTbot_-_Messenger_-_Facebook_for_Developers.png
    – Grant access to the selected page.
    Rn3hyOMtXO.gif
    – Click the Add Subscriptions button and add messages and messages_postbacks subscription fields.
    EKv859uU2q.gif
  8. Now you have to generate an access token for the bot. Go to the Access Tokens section (just above the Webhooks section) and generate a token for the desired page by clicking the Generate Token button next to the corresponding page.

    2019-08-16_17_42_31-IMTbot_-_Messenger_-_Facebook_for_Developers.png
    – Check the I understand checkbox and copy the token to the clipboard.
    2019-08-16_17_44_20-IMTbot_-_Messenger_-_Facebook_for_Developers.png

  9. To create a connection between Integromat and Facebook messenger, go to the settings of the Send a message module and click the Add button. Enter the access token from the previous step into the respective field and click Continue.
    2020-08-19_13_22_55-Window.png
  10. Map the Sender ID to the ID field and specify the Message Content in the Send a message module.
    mceclip2.png
  11. Set up the Send a message module and run the scenario to test your bot.

Completed

Testing the Facebook Messenger Bot

To test the bot application you need to:

  1. Set up test developer role
  2. Run the scenario
  3. Send a test message to the test page (created by the app administrator) when logged in as a test developer to trigger the Watch messages module in your scenario.

Setting up developer roles

In order to test your application before publishing it, you need to set up roles for developers who will test it. For non-developer accounts, the app does not respond until it is officially released.

You need two Facebook accounts to test the app:
The First account that creates the app (bot) and is the owner of the Facebook page.

Navigate to Roles > Add Developers button and add the developer that can test your Facebook Messenger bot. 

To add someone you aren't friends with on Facebook, enter their fbid or username.

2019-09-20_10_27_07-Window.png
Second account that is set up as verified Facebook developer account (How do I verify my developer account on Facebook?) and sends the test message to the Facebook page.

Log in with your second developer (test) account and confirm the request on the https://developers.facebook.com/requests page.

2020-08-19_13_17_32-Window.png

After the test developer account is set, run your Integromat scenario, login to Facebook (with your test developer account credentials), and open the public page you want to test the bot with.
Send the message (mceclip1.png) to the page to test your bot.


Conditions that have to be met while testing:

  • The Facebook account you write a message to the Facebook page must be set as the developer of the app.
  • The bot cannot send the message first (anti-spam policy). The conversation must be initiated by the app test user with the developer role, your second account. 

For more information on how to set up the roles, see the official Facebook documentation.

 

Popular use cases from our blog

automated-data-collection-crm-illustration

How to Automate Data Collection - Part 5: CRM Systems

automated-data-collection-chatbot-marketing-illustration

How to Automate Data Collection - Part 4: Chatbot Marketing

automated-data-collection-paid-ads-illustration

How to Automate Data Collection - Part 3: Paid Ads

automated-data-collection-email-illustration

How to Automate Data Collection - Part 2: Email Marketing Segmentation

personalized-customer-experience-illustration-integromat

5 Automated Solutions to Personalize Customer Experience

data-collection-automation-forms-pt-1

How to Automate Data Collection - Part 1: Online Forms

Didn’t find what you were looking for?

Expert

Find an expert

We feature a network of 450+ certified partners across the globe who are ready to help

Find an expert

Automate any workflow in your business

Sign up for a free account today. No credit card required, no time limits on free plan.