Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/add-facebook-adapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chat-adapter/facebook": minor
---

Add Facebook Messenger adapter with support for messages, reactions, postbacks, typing indicators, and webhook verification
5 changes: 5 additions & 0 deletions examples/nextjs-chat/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ BOT_USERNAME=mybot
# DISCORD_BOT_TOKEN=your-bot-token
# DISCORD_PUBLIC_KEY=your-public-key

# Facebook Messenger (optional)
# FACEBOOK_APP_SECRET=your-app-secret
# FACEBOOK_PAGE_ACCESS_TOKEN=your-page-access-token
# FACEBOOK_VERIFY_TOKEN=your-verify-token

# GitHub (optional) - use PAT OR GitHub App, not both
# PAT authentication:
# GITHUB_TOKEN=ghp_xxxxxxxxxxxx
Expand Down
3 changes: 2 additions & 1 deletion examples/nextjs-chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
},
"dependencies": {
"@chat-adapter/discord": "workspace:*",
"@chat-adapter/facebook": "workspace:*",
"@chat-adapter/gchat": "workspace:*",
"@chat-adapter/github": "workspace:*",
"@chat-adapter/linear": "workspace:*",
"@chat-adapter/slack": "workspace:*",
"@chat-adapter/state-memory": "workspace:*",
"@chat-adapter/state-redis": "workspace:*",
"@chat-adapter/telegram": "workspace:*",
"@chat-adapter/teams": "workspace:*",
"@chat-adapter/telegram": "workspace:*",
"ai": "^6.0.5",
"chat": "workspace:*",
"next": "^16.1.5",
Expand Down
14 changes: 5 additions & 9 deletions examples/nextjs-chat/src/app/api/webhooks/[platform]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,16 @@ export async function POST(
});
}

// Health check endpoint
export async function GET(
_request: Request,
request: Request,
{ params }: { params: Promise<{ platform: string }> }
): Promise<Response> {
const { platform } = await params;

const hasAdapter = bot.webhooks[platform as Platform] !== undefined;

if (hasAdapter) {
return new Response(`${platform} webhook endpoint is active`, {
status: 200,
});
const webhookHandler = bot.webhooks[platform as Platform];
if (!webhookHandler) {
return new Response(`${platform} adapter not configured`, { status: 404 });
}

return new Response(`${platform} adapter not configured`, { status: 404 });
return webhookHandler(request);
}
23 changes: 23 additions & 0 deletions examples/nextjs-chat/src/lib/adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import {
createDiscordAdapter,
type DiscordAdapter,
} from "@chat-adapter/discord";
import {
createFacebookAdapter,
type FacebookAdapter,
} from "@chat-adapter/facebook";
import {
createGoogleChatAdapter,
type GoogleChatAdapter,
Expand All @@ -22,6 +26,7 @@ const logger = new ConsoleLogger("info");

export interface Adapters {
discord?: DiscordAdapter;
facebook?: FacebookAdapter;
gchat?: GoogleChatAdapter;
github?: GitHubAdapter;
linear?: LinearAdapter;
Expand Down Expand Up @@ -86,6 +91,12 @@ const LINEAR_METHODS = [
"addReaction",
"fetchMessages",
];
const FACEBOOK_METHODS = [
"postMessage",
"startTyping",
"openDM",
"fetchMessages",
];
const TELEGRAM_METHODS = [
"postMessage",
"editMessage",
Expand Down Expand Up @@ -122,6 +133,18 @@ export function buildAdapters(): Adapters {
);
}

// Facebook Messenger adapter (optional) - env vars: FACEBOOK_APP_SECRET, FACEBOOK_PAGE_ACCESS_TOKEN, FACEBOOK_VERIFY_TOKEN
if (process.env.FACEBOOK_APP_SECRET) {
adapters.facebook = withRecording(
createFacebookAdapter({
userName: "Chat SDK Bot",
logger: logger.child("facebook"),
}),
"facebook",
FACEBOOK_METHODS
);
}

// Slack adapter (optional) - env vars: SLACK_SIGNING_SECRET + (SLACK_BOT_TOKEN or SLACK_CLIENT_ID/SECRET)
if (process.env.SLACK_SIGNING_SECRET) {
adapters.slack = withRecording(
Expand Down
56 changes: 56 additions & 0 deletions packages/adapter-facebook/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "@chat-adapter/facebook",
"version": "4.15.0",
"description": "Facebook Messenger adapter for chat",
"type": "module",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"files": [
"dist"
],
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"test": "vitest run --coverage",
"test:watch": "vitest",
"typecheck": "tsc --noEmit",
"clean": "rm -rf dist"
},
"dependencies": {
"@chat-adapter/shared": "workspace:*",
"chat": "workspace:*"
},
"devDependencies": {
"@types/node": "^25.3.2",
"tsup": "^8.3.5",
"typescript": "^5.7.2",
"vitest": "^4.0.18"
},
"repository": {
"type": "git",
"url": "git+https://github.com/vercel/chat.git",
"directory": "packages/adapter-facebook"
},
"homepage": "https://github.com/vercel/chat#readme",
"bugs": {
"url": "https://github.com/vercel/chat/issues"
},
"publishConfig": {
"access": "public"
},
"keywords": [
"chat",
"facebook",
"messenger",
"bot",
"adapter"
],
"license": "MIT"
}
Loading