@chat-adapter/messenger
Facebook Messenger adapter for Chat SDK, using the Messenger Platform API.
Installation
Usage
When using createMessengerAdapter() without arguments, credentials are auto-detected from environment variables.
Facebook Messenger setup
1. Create a Meta app
- Go to developers.facebook.com/apps
- Click Create App
- Select the use case "Engage with customers on Messenger from Meta"
- Enter your app name and contact email, then create the app
- Go to App > App Settings > Basic and copy your App Secret — this becomes
FACEBOOK_APP_SECRET
2. Create a Facebook Page
Your Messenger bot needs a Facebook Page to send and receive messages. If you don't have one:
- The easiest approach is to create a Facebook Business profile first
- Then create a Page under that business profile
- Note the Page name — users will message this Page to interact with your bot
3. Configure Messenger API
- In your Meta app dashboard, go to Use Cases
- Find "Engage with customers on Messenger from Meta" and click Customize
- Then open Messenger API Settings
Configure webhooks
- Under Configure webhooks, click Add Callback URL
- Enter your webhook URL:
https://your-domain.com/api/webhooks/messenger - Enter a Verify Token — this is a secret string you create (this becomes
FACEBOOK_VERIFY_TOKEN) - Click Verify and Save
- After verification, click Add Subscriptions and enable:
messagesmessaging_postbacksmessaging_reactionsmessage_deliveriesmessage_reads
Generate a Page Access Token
- Under Generate access tokens, click Add or remove Pages
- Your Pages should populate — select the Page you created
- Assign the standard permissions when prompted
- Click Generate Token
- Copy the token — this becomes
FACEBOOK_PAGE_ACCESS_TOKEN
Environment variables
Webhook setup
Messenger uses two webhook mechanisms:
- Verification handshake (GET) — Meta sends a
hub.verify_tokenchallenge that must match yourFACEBOOK_VERIFY_TOKEN. - Event delivery (POST) — incoming messages, reactions, and postbacks, verified via
X-Hub-Signature-256.
Features
Messaging
Rich content
Conversations
Message history
Interactive messages
Card elements are automatically converted to Messenger templates:
- Generic Template — Used when the card has a
titleorimageUrl. Supports up to 3 buttons. - Button Template — Used when the card has text content and buttons but no title/image. Max 640 characters.
- Text Fallback — Used when the card contains unsupported elements (tables, select menus) or exceeds constraints.
Template constraints:
- Maximum 3 buttons per template
- Button titles limited to 20 characters (truncated with ellipsis)
- Subtitles limited to 80 characters
- Button Template text limited to 640 characters
Thread ID format
Example: messenger:27161130920158013
License
MIT