How to Connect Facebook Messenger to AI Agent
Connect your Flametree AI agent to Facebook Messenger to automatically process and respond to messages sent to your Facebook Page. This integration uses the official Facebook Graph API and supports multi-account, round-robin outbound messaging.
Prerequisites
- Facebook Developer Account — Register at developers.facebook.com
- Facebook Page — The agent will respond as this page
- Facebook App — Created in the Facebook Developer Console
- Admin access to your Flametree account
Setting Up Facebook Messenger Integration
Step 1: Create Facebook App and Page
-
Create a Facebook Page
- Go to facebook.com/pages/create and follow the prompts
-
Create a Facebook App
- Go to developers.facebook.com/apps
- Click Create App
- Select Business as the app type
- Enter app name, contact email, and select your business account
- Go to App Settings > Basic and switch the app to Live mode to allow messages from real users
-
Add Messenger Product
- In your app dashboard, click Add Product
- Find Messenger and click Set Up
Step 2: Generate Access Tokens and IDs
-
Link Facebook Page to App
- In Messenger > Settings, add your Facebook Page to the app
-
Generate Page Access Token
- Go to Messenger > Settings
- Under Access Tokens, select your page and click Generate Token
- Save this token — you’ll need it for Flametree
-
Collect Required Parameters
- Page ID: In Messenger > Settings or from your page URL
- App ID: In Settings > Basic
- App Secret: In Settings > Basic
- Verify Token: Any value you make up yourself (for example,
my_fb_webhook_2026). It works like a shared password — the same value must be entered in the Meta App webhook settings and in the Flametree channel configuration so the two systems can verify each other
Step 3: Configure Webhook
-
Set up Webhook in Facebook App
- In Messenger > Settings, click Add Callback URL
- Enter the callback URL provided by Flametree (see below)
- Enter your Verify Token (must match the value you provide in Flametree )
- Subscribe to the following events:
messages,messaging_postbacks
-
Callback URL
- The callback URL will be provided in the Flametree channel setup screen after you create the integration
Step 4: Collect Integration Parameters
Save these values from the Facebook Developer Console:
| Parameter | Location in Meta Console |
|---|---|
| App ID | Settings > Basic |
| App Secret | Settings > Basic |
| Page ID | Messenger > API Settings |
| Access Token | Messenger > API Settings |
Configuring Flametree Integration
Step 1: Create Facebook Messenger Integration
-
Navigate to Settings
- Go to Settings > Channels
- Open Facebook Messenger
- Select Add +
-
Fill Configuration
Field Description Required Value Source Name Custom integration name ✅ Your choice Description Integration purpose ❌ Your choice App ID Default Meta app to subscribe webhook ✅ Meta Console App Secret Stored near the App ID in Meta console ✅ Meta Console Page ID Facebook page ID ✅ Meta Console Access token Facebook page API token ✅ Meta Console Field notes
-
You can connect multiple Facebook Pages by entering comma-separated values in Page ID and Access token. Example:
1234567890, 9876543210. Values must be provided in the same order across related fields. -
For outbound messages, Flametree uses connected accounts one by one in a fixed repeating sequence. After the first message, each recipient is handled by the same sender account.
-
-
Click Save to create the integration
-
Click Start in the upper-right corner to start the channel.
Step 2: Connect to AI Agent
-
Open Agent Configuration
- Navigate to your target AI agent's settings
- Go to Communication channels section
-
Assign Channel
- Select your Facebook Messenger integration from the list
- Save the agent configuration
-
Restart the agent: click Stop agent then Start agent to apply the changes.
You can use the same Facebook page for multiple agents only for outbound communication. For inbound messaging, every connected agent would reply to the same customer message, causing duplicate or conflicting answers. Best practice is to use a dedicated Facebook page per agent for reliable message handling.
Configuration Options
Configure additional features through Set Environment Variables:
| Variable | Description | Default |
|---|---|---|
FB_REGISTRATION_DELAY | Delay (seconds) between webhook registration attempts | 5.0 |
FB_REGISTRATION_COUNT | Number of webhook registration attempts | 20 |
Testing the Integration
-
Send a Message
- Go to your Facebook Page as a customer (not as an admin)
- Send a message to the page
-
Verify Response
- The AI agent should respond automatically
-
Test Carousel and Attachments
- Send a message with a list or media to test advanced features
Security Considerations
- Protect access tokens and rotate them regularly in Facebook console
- Enable two-factor authentication on your Facebook account
- Limit admin access to required team members only
- Monitor API usage and webhook activity for suspicious behavior
- Ensure message handling, data retention, and customer consent meet applicable privacy requirements