Messenger and Facebook
Add your bot to Messenger and Facebook using the official integration
The official Messenger and Facebook integration allows users to chat with your bot by messaging a Facebook page.
Setup
You will need:
- In Botpress Studio, select Explore Hub in the upper-right corner.
- Search for the Messenger integration, then select Install Integration.
- In the Configuration menu, select Authorize Messenger.
- Follow the instructions to connect Botpress to your Messenger account.
For advanced use cases, you can use your own Meta app with our integration.
You will need:
- A published bot
- A Facebook page
- A Meta developer app. Check out the Meta developer documentation to learn more about the setup process.
Get your Meta app ready
Before setting up the integration in Botpress, you need to get your Meta app ready:
Add the Messenger API
To configure your integration, you need to access the Messenger API:
- Log in to your Meta developer account.
- Select the app you want to use with the integration.
- Scroll to Add products to your app.
- Under the Messenger section, select Set up.
Set up the integration in Botpress
Once your Meta app is ready, you can set up the integration in Botpress:
Install the integration
- In Botpress Studio, select Explore Hub in the upper-right corner.
- Search for the Messenger and Facebook integration, then select Install Integration.
- In the Configuration menu, select the drop-down menu, then select Configure by manually supplying the Meta app details.
Configure the integration
To configure the integration, you need to create a webhook endpoint for the Messenger integration. To do this, fill in the integration’s configuration fields using information from your Meta app:
Client ID
Client ID
To get your Meta app’s client ID:
- In your Meta app’s left sidebar, go to App settings > Basic.
- Copy the App ID, then paste it in the Client ID field in Botpress.
Client Secret (Optional)
Client Secret (Optional)
The client secret is used to check the webhook’s signature. You can leave this field empty to disable signature check.
To get your Meta app’s client secret:
- In your Meta app’s left sidebar, go to App settings > Basic.
- Copy the App secret, then paste it in the Client Secret field in Botpress.
Verify Token
Verify Token
Used by Meta to verify that you’re the real owner of the provided webhook. Can be any alphanumeric string.
Access Token
Access Token
To get your Meta app’s access token:
- In your Meta app’s left sidebar, go to Messenger > Messenger API Settings.
- Scroll to Generate access tokens, then find your Facebook page.
- Select Generate, then copy the token.
- Paste it into the Access Token field in Botpress.
Page ID
Page ID
To get your Meta app’s page ID:
- In your Meta app’s left sidebar, go to Messenger > Messenger API Settings.
- Scroll to Generate access tokens, then find your Facebook page.
- Copy the number under your page’s name, then paste it into the Page ID field in Botpress.
When you’ve filled in all the fields, select Save Configuration. This will automatically enable your integration.
Finalize the integration
Now that your Botpress webhook endpoint is ready, you can add it to your Meta app:
Get the webhook URL and Verify Token
In Botpress, copy:
- The integration’s webhook URL. It should start with
https://webhook.botpress.cloud/ - The Verify Token you created
Configure the webhook in Meta
- Go back to your Meta app. In the left sidebar, go to Messenger > Messenger API Settings.
- Scroll to Configure webhooks
- Paste:
- Your webhook URL into the Callback URL field.
- Your Verify Token into the Verify token field.
- Select Verify and save.
Make sure you saved your integration’s configuration after configuring it in Botpress—otherwise, the webhook validation will fail.
Submit app for review
The integration is configured, but will only work for admins, developers, and testers. To make it available for public use, make sure you submit it for review by Meta.
You’ve manually configured your Messenger integration.
If you want to test your bot’s behaviour in Messenger before going through the actual setup process, you can use the Messenger integration playground.
You will need:
- In Botpress Studio, select Explore Hub in the upper-right corner.
- Search for the Messenger integration, then select Install Integration.
- Select Test your agent on Messenger.
- Follow the instructions to set up the playground.
Options
The Messenger integration’s Configuration menu offers a few additional options:
Get user profile
When this option is enabled (default), the integration will update the Botpress user’s name and picture URL with data from Messenger.
Download media
When enabled, this option automatically downloads media files using the Files API. When disabled, media files are displayed using their Messenger media URL.
Downloaded media expiry
Expiry time (in hours) for downloaded media files. An expiry time of 0 means the files will never expire. Defaults to 24 hours.
Replying to comments in DM
You can configure your bot to reply to user comments in a direct message (DM).
Step 1: Check where the conversation started
First, add a router Node that checks whether the conversation originated from a user’s comment.
In Botpress Studio, enter your Main Workflow.
Add a new Node to the Workflow.
Rename the Node to Router, then move it between the Start Node and any other existing Nodes:
Add two Expression Cards to the Router Node.
Open the second Expression Card’s inspector. Next to the Condition field, toggle to disable generative AI.
Configure this Card for conversations started normally:
- In the Label field, paste in:
Conversation started - In the Condition field, paste in:
{{event.channel == 'channel'}}
Open the first Expression Card’s inspector. Next to the Condition field, toggle to disable generative AI.
Step 2: Reply to the user’s comment
Next, add logic to reply to the user’s comment. This lets them know that the bot will continue the conversation in a DM.
Add a Text Card to the new Node.
Step 3: Start a DM conversation from the comment
Finally, add logic to start a DM conversation whenever a user leaves a comment.
Add the Start DM Conversation from Comment Card to the new Node.
Open the Start DM Conversation from Comment Card’s inspector.
- In the Comment ID field, paste in:
{{event.payload.commentId}} - In the Message field, enter the first message you want to send the user in a DM. For example:
Hey! Received your comment.
If you want to send the user’s original comment back to them, you can add {{event.payload.text}} to the Message field.
Attach the Reply_to_comment Node to the DM_reply Node. Then, attach the DM_reply Node to the End Node:
When a user comments on a post, your bot will now:
- Reply to their comment, letting them know to check their DMs
- Continue the conversation in a DM
You can further modify your Workflow depending on your desired behaviour.
Cards
Get or Create a Conversation
Proactively create a conversation from a bot
inputobjectoutputobjectGet or Create a User
Proactively create a user from a bot
inputobjectoutputobjectStart DM Conversation from Comment
Start a DM conversation from a comment
inputobjectstartTypingIndicator
inputobjectstopTypingIndicator
inputobjectTriggers
Tags
You can read event tags to get information about an active Messenger conversation:
Message ID
To get the Messenger ID of a message:
event.tags.message['messenger:id']
Recipient ID
To get the Messenger ID of the recipient:
event.tags.message['messenger:recipientId']
Sender ID
To get the Messenger ID of the sender:
event.tags.message['messenger:senderId']
Conversation ID
To get the Messenger ID of the conversation:
event.tags.conversation['messenger:id']
User ID
To get the Messenger ID of the user:
event.tags.user['messenger:id']