Connect a bot to Facebook
Your bot can be connected to both Facebook Messenger and Facebook Workplace, so that it can communicate with users on both platforms. The following tutorial shows how to connect a bot to these two channels.
The Facebook UI may appear slightly different depending on which version you are using.
Connect a bot to Facebook Messenger
To configure a bot to communicate using Facebook Messenger, enable Facebook Messenger on a Facebook page and then connect the bot.
Copy the Page ID
The bot is accessed through a Facebook Page.
Create a new Facebook Page or go to an existing Page.
Open the Facebook Page's About page and then copy and save the Page ID.
Create a Facebook app
In your browser, navigate to Create a new Facebook App.
Enter the name of your app and click the Create New Facebook App ID button.
In the displayed dialog, enter your email address and click the Create App ID button.
Go through the wizard steps.
Enter the required check information, then click the Skip Quick Start button in the upper right.
In the left pane of the next displayed window, expand Settings and click Basic.
In the right pane, copy and save the App ID and App Secret.
In the left pane, under Settings, click Advanced.
In the right pane, set Allow API Access to App Settings slider to Yes.
In the page bottom right, click the Save Changes button.
In the left pane, click Dashboard.
In the right pane, scroll down and in the Messenger box, click the Set Up button. The Messenger entry is displayed under the PRODUCTS section in the left pane.
Generate a Page Access Token
In the left pane, under the Messenger entry, click Settings.
In the right pane, scroll down and in the Token Generation section, select the target page.
Click the Edit Permissions button to grant the app pages_messaging in order to generate an access token.
Follow the wizard steps. In the last step accept the default settings and click the Done button. At the end a page access token is generated.
Copy and save the Page Access Token.
In order to send messages and other events from your bot to Facebook Messenger, you must enable webhooks integration. At this point, let's leave the Facebook setting steps pending; will come back to them.
In your browser open a new window and navigate to the Azure portal.
In the Resource list, click on the bot resource registration and in the related blade click Channels.
In the right pane, click the Facebook icon.
In the wizard enter the Facebook information stored in the previous steps. If the information is correct, at the bottom of the wizard, you should see the callback URL and the verify token. Copy and store them.
Click the Save button.
Let's go back to the Facebook settings. In the right pane, scroll down and in the Webhooks section, click the Subscribe To Events button. This is to forward messaging events from Facebook Messenger to the bot.
In the displayed dialog, enter the Callback URL and Verify Token values stored previously. Under Subscription Fields, select message_deliveries, messages, messaging_optins, and messaging_postbacks.
Click the Verify and Save button.
Select the Facebook page to subscribe the webhook. Click the Subscribe button.
Submit for review
Make the App public and publish the Page
Until an app is published, it is in Development Mode. Plugin and API functionality will only work for admins, developers, and testers.
After the review is successful, in the App Dashboard under App Review, set the app to Public. Ensure that the Facebook Page associated with this bot is published. Status appears in Pages settings.
Connect a bot to Facebook Workplace
Facebook Workplace is a business-oriented version of Facebook, which allows employees to easily connect and collaborate. It contains live videos, news feeds, groups, messenger, reactions, search, and trending posts. It also supports:
- Analytics and integrations. A dashboard with analytics, integration, single sign-on, and identity providers that companies use to integrate Workplace with their existing IT systems.
- Multi-company groups. Shared spaces in which employees from different organizations can work together and collaborate.
To use Facebook Workplace with your bot, you must create a Workplace account and a custom integration to connect the bot.
Create a Workplace Premium account
- Submit an application to workplace on behalf of your company.
- Once your application has been approved, you will receive an email inviting you to join. The response may take a while.
- From the e-mail invitation, click Get Started.
- Enter your profile information.
Set yourself as the system administrator. Remember that only system administrators can create custom integrations.
- Click Preview Profile and verify the information is correct.
- Access Free Trial.
- Create password.
- Click Invite Coworkers to invite employees to sign-in. The employees you invited will become members as soon as they sign. They will go through a similar sign-in process as described in these steps.
Create a custom integration
Create a custom integration for your Workplace following the steps described below. When you create a custom integration, an app with defined permissions and a page of type 'Bot' only visible within your Workplace community are created.
In the Admin Panel, open the Integrations tab.
Click on the Create your own custom App button.
Choose a display name and a profile picture for the app. Such information will be shared with the page of type 'Bot'.
Set the Allow API Access to App Settings to "Yes".
Copy and safely store the App ID, App Secret and App Token that's shown to you.
Now you have finished creating a custom integration. You can find the page of type 'Bot' in your Workplace community,as shown below.
Provide Facebook credentials
In Azure portal, paste the Facebook App ID, Facebook App Secret and Page Access Token values copied from the Facebook Workplace previously. Instead of a traditional pageID, use the numbers following the integrations name on its About page. Similar to connecting a bot to Facebook Messenger, the webhooks can be connected with the credentials shown in Azure.
Submit for review
Please refer to the Connect a bot to Facebook Messenger section and Workplace Developer Documentation for details.
Make the App public and publish the Page
Please refer to the Connect a bot to Facebook Messenger section for details.
Setting the API version
If you receive a notification from Facebook about deprecation of a certain version of the Graph API, go to Facebook developers page. Navigate to your bot’s App Settings and go to Settings > Advanced > Upgrade API version, then switch Upgrade All Calls to 3.0.