You will need a Facebook app and a Facebook page to connect you bot to messenger
To create a Facebook App, log in to your Facebook account and go to the Facebook for Developers website. Select My Apps from the top menu, and create a new app. For more details and assistance, visit the Facebook developer documentation
If you do not already have a Facebook page you will need to create one. You can find details on how to create a new Facebook page here
To link your chatbot to a pre-existing page, you must have an administrator or developer role
The messenger channel is made to interact with version 12.0 or higher of the Messenger API. It is not the default version so it must be changed in your app's settings
- Go to your Facebook App
- In the left sidebar, expand the Settings menu and select Advanced
- In the Upgrade API version section, select v12.0 or higher as the API version
- Click on Save changes
Messenger is not added by default in your Facebook App, so it must be added manually
- In the left sidebar, click on Add Product
- In the Facebook Messenger section click Set Up
The app id and secret are used to validate webhook requests
- In the left sidebar, expand the Settings menu and select Basic. Here you can find the App ID and App Secret
- Click on the Show button in the App Secret text box. Copy the appId and appSecret to your channel configuration
The page id and access token are used to send messages to the Messenger API
- In the left sidebar, expand the Messenger menu and select Settings
- In the Access Tokens section, click Add or remove Pages and add you facebook page
- Copy the number under you page name and paste it in you pageId channel configuration
- Click on Generate token. Copy this token and paste it in the accessToken channel configuration
The verify token is used by facebook to verify that you are the real owner of the provided webhook
You can generate any random alphanumerical string for this configuration. Paste it in your verifyToken channel configuration
Note: It is important you save your configuration before configuring the webhook, otherwise Messenger will be unable to validate the webhook url
- Edit your bot config
{
// ... other data
"messaging": {
"channels": {
"messenger": {
"version": "1.0.0",
"enabled": true,
"pageId": "page_id",
"accessToken": "your_access_token",
"appId": "app_id",
"appSecret": "your_app_secret",
"verifyToken": "your_verify_token"
}
// ... other channels can also be configured here
}
}
}
- Restart Botpress.
- You should see your webhook endpoint in the console on startup.
To receive messages from Messenger, you will need to setup a webhook
- Go to your Facebook App.
- In the left sidebar, expand the Messenger menu and select Settings
- In the Webhooks section, click Add Callback URL
- Set the webhook URL to:
<EXTERNAL_URL>/api/v1/messaging/webhooks/v1/<YOUR_BOT_ID/messenger
- Copy paste the verify token you generated earlier
- Click on Verify and save. Make sure your channel configuration was saved before doing this step, otherwise the webhook validation will fail
- Click on Add subscriptions and add
messages
andmessaging_postbacks
to your webhook