Facebook

You can set up your bot to interact with users through Facebook Messenger. This section explains how to create a Facebook app on the Facebook for Developers site and connect it to your bot in the DRUID Portal.

Prerequisites

  • You built and published a DRUID chat bot.
  • You have one or more Facebook pages.
  • Open the Facebook Page's About page and then copy and save the Page ID.
  • For DRUID on premise deployments, make sure that you provide access to/from the necessary messaging endpoints as follows:
  • Outbound graph.facebook.com 
    Inbound DRUID.BotApp
Note:   In DRUID hybrid and cloud deployments Facebook channel uses the Microsoft Bot Framework, while in on premise deployments it uses direct DRUID Facebook integration.
Important!   The Facebook channel has a limitation on file transfer, it only supports common media files (images or video). Other file formats like .doc, .docx, .txt or .xslx (etc.) will be altered and corrupted both on file upload or when generated by chatbots.

Connect a bot to Facebook

Note:  The Facebook UI may appear slightly different depending on which version you are using.

To connect a bot with Facebook Messenger, follow these steps:

Step 1. Create a Facebook app

  1. In your browser, navigate to Facebook for Developers and log in.
  2. On the toolbar, click My Apps. Your Facebook apps page appears.
  3. Click the Create App button.
  4. Select the business portfolio (verified or unverified) that you want to connect to your app.

  5. Click Next.
  6. Select Other as the use case. You can customize how your app interacts with Meta later on the app Dashboard.

  7. Click Next.
  8. Select Business as the app type. Your app type determines which products and APIs are available to your app. For more information on the app type, see Facebook documentation.
  9. Click Next.
  10. Enter an app name and the email address to be used to contact you about this particular app.

  11. Optionally, you can link this app to an existing Business portfolio using the drop-down menu, or you can add this later.

  12. Click Create app.
  13. For security reasons, re-enter your password and click Submit.

The Add products to your app page appears. You can now customize the way you interact with people on Messenger. For more information, see the next step.

Step 2. Set up Messenger for your app

In this section you will enable Messenger. connect your app to a Facebook Page and generate an access token for the FB page:

  1. On the Add Products to Your App page, search for Messenger and click the Set Up button. The Messenger API Setup appears.
  2. Scroll-down to the Generate access tokens section and click Connect.
  3. Continue as logged in user or log in using another account.
  4. Select the target Facebook page and click Continue.
  5. When prompted to review the app's permission requests, click Save.
  6. A pop-up appears informing you that you linked your Facebook app to Facebook.

  7. Click Got it.
  8. The connected Facebook page appears on the Messenger API Setup.

  9. Click the Generate button to generate an access token for your FB page. The Token Generation pop-up appears.
  10. Tick I understand, then click the Copy button to copy the page access token and save it for use at Step 4.

  11. Click Done.

Step 3. Get your Facebook app details

  1. In Facebook for Developers Portal, go to your Facebook app settings.
  2. On the main menu, click App settings > Basic.
  3. Click Show and enter your FB password to reveal the App ID. Copy the App ID and App secret and save them for use in Step 4.
  4. Click Save changes.
  5. On the main menu, click Settings > Advanced.
  6. In the right pane, tap on Allow API Access to app settings.
  7. Click Save changes.

Step 4: Configure the DRUID chat bot

  1. Log in the DRUID Portal and go to your bot details page.
  2. Click on the Channels tab, then click Facebook. The Facebook channel section expands.
  3. Enter the Facebook App ID and the Facebook App Secret (the App ID and App Secret you copied when creating the Facebook app).
  4. Click the Add page button ().
  5. Enter the Facebook Page ID and Page Access Token and click the Save page button.
  6. Hint:  For information on how to get the Facebook Page ID, see Facebook documentation.

    If you host the bot (via Facebook app) in multiple Facebook pages, click the Add page button and enter the Page ID and access token for any subsequent Facebook pages.

  7. Channel activation may take up to 1 minute. Once activation is complete, the Callback URL and Verify Token fields will automatically populate.
  8. Click the Copy icon next to the Callback URL and Verify Token to copy the values and save them for use in Step 5.

After the channel’s activation, the following fields are available in DRUID:

  • [[ChatUser]].ChannelId = "facebook"
  • [[ChatUser]].UserId - Stores an unique identifier of the Facebook user account.

Step 5: Enable webhooks ans select webhooks subscriptions

In order to send messages and other events from your bot to Facebook Messenger, you must enable webhooks integration. To do so, follow these steps:

  1. In Facebook for Developers Portal, go to your Facebook app settings.
  2. On the main menu, click Messenger > API Settings.
  3. On the right pane, in the Configure webhooks section, click Configure. The Edit Callback URL pop-up appears.
  4. Enter the Callback URL and Verify Token you copied from the DRUID Portal.
  5. Enter the Callback URL and Verify Token automatically generated in DRUID on the bot Facebook channel and click Verify and save.
  6. The webhook appears in the Configure webhooks section, but no webhook events are selected. You need to select webhook fields for your FB app.
  7. Click the Manage button. The Webhook fields pop-up appears.
  8. Subscribe to the following webhook events: messages and messaging_postbacks. Select messaging_customer_information if you want DRUID to store the chat user's first name and last name (in [[ChatUser]].FirstName and [[ChatUser]].Lastname).
  9. Close the pop-up. The selected webhook fields appear in the section.
  10. Now you need to select webhook events for your FB page.

  11. In the Generate access tokens section, click the Add Subscriptions button. The Edit Page Subscription page appears.
  12. Select messages and messaging_postbacks. Select messaging_customer_information if you want DRUID to store the chat user's first name and last name (in [[ChatUser]].FirstName and [[ChatUser]].Lastname).
  13. Click Confirm. The selected webhook events appear in Generate access tokens section in line with your FB page.

The integration between the DRUID chatbot and the Facebook Page is complete.

Note:  The Facebook app is in Development Mode until you publish it. The plugin and API functionality will only work for admins, developers and testers.

Complete your Facebook app review, make the app public and publish the Facebook Page.

Step 6. Talk to your bot

To open the chatbot in the Facebook channel, in the DRUID Portal, go to the bot settings, click the Channels tab and click on the Facebook channel icon. You can start talking to the bot.

Note:  In DRUID 7.5 and higher, when a user initiates a conversation with the bot, the Welcome flow will be automatically triggered. Regardless of the user's subscription status to the bot channel, the welcome message will be promptly sent to the user, ensuring a seamless and engaging interaction experience.