npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@chat-adapter/messenger

v4.29.0

Published

Messenger adapter for chat

Readme

@chat-adapter/messenger

npm version npm downloads

Facebook Messenger adapter for Chat SDK, using the Messenger Platform API.

Installation

pnpm add @chat-adapter/messenger

Usage

import { Chat } from "chat";
import { createMessengerAdapter } from "@chat-adapter/messenger";

const bot = new Chat({
  userName: "mybot",
  adapters: {
    messenger: createMessengerAdapter(),
  },
});

bot.onDirectMessage(async (thread, message) => {
  await thread.post("Hello from Messenger!");
});

When using createMessengerAdapter() without arguments, credentials are auto-detected from environment variables.

Facebook Messenger setup

1. Create a Meta app

  1. Go to developers.facebook.com/apps
  2. Click Create App
  3. Select the use case "Engage with customers on Messenger from Meta"
  4. Enter your app name and contact email, then create the app
  5. 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:

  1. The easiest approach is to create a Facebook Business profile first
  2. Then create a Page under that business profile
  3. Note the Page name — users will message this Page to interact with your bot

3. Configure Messenger API

  1. In your Meta app dashboard, go to Use Cases
  2. Find "Engage with customers on Messenger from Meta" and click Customize
  3. Then open Messenger API Settings

Configure webhooks

  1. Under Configure webhooks, click Add Callback URL
  2. Enter your webhook URL: https://your-domain.com/api/webhooks/messenger
  3. Enter a Verify Token — this is a secret string you create (this becomes FACEBOOK_VERIFY_TOKEN)
  4. Click Verify and Save
  5. After verification, click Add Subscriptions and enable:
    • messages
    • messaging_postbacks
    • messaging_reactions
    • message_deliveries
    • message_reads

Generate a Page Access Token

  1. Under Generate access tokens, click Add or remove Pages
  2. Your Pages should populate — select the Page you created
  3. Assign the standard permissions when prompted
  4. Click Generate Token
  5. Copy the token — this becomes FACEBOOK_PAGE_ACCESS_TOKEN

Environment variables

FACEBOOK_APP_SECRET=...              # App secret from App Settings > Basic
FACEBOOK_PAGE_ACCESS_TOKEN=...       # Generated Page access token
FACEBOOK_VERIFY_TOKEN=...            # User-defined webhook verification secret
FACEBOOK_BOT_USERNAME=...            # Optional, defaults to "messenger-bot"
FACEBOOK_API_URL=...                 # Optional, override the Meta Graph API base URL

Webhook setup

Messenger uses two webhook mechanisms:

  1. Verification handshake (GET) — Meta sends a hub.verify_token challenge that must match your FACEBOOK_VERIFY_TOKEN.
  2. Event delivery (POST) — incoming messages, reactions, and postbacks, verified via X-Hub-Signature-256.
// Next.js App Router example
import { bot } from "@/lib/bot";

export async function GET(request: Request) {
  return bot.webhooks.messenger(request);
}

export async function POST(request: Request) {
  return bot.webhooks.messenger(request);
}

Features

Messaging

| Feature | Supported | |---------|-----------| | Post message | Yes | | Edit message | No (Messenger limitation) | | Delete message | No (Messenger limitation) | | Streaming | Buffered (accumulates then sends) | | Typing indicator | Yes |

Rich content

| Feature | Supported | |---------|-----------| | Card format | Generic/Button Templates | | Buttons | Yes (max 3 per message) | | Link buttons | Yes (web_url) | | Select menus | No | | Tables | Text fallback | | Fields | Text fallback | | Images in cards | Yes (Generic Template) | | Modals | No |

Conversations

| Feature | Supported | |---------|-----------| | Reactions | Receive only | | Typing indicator | Yes | | DMs | Yes (DM-only platform) | | Postbacks | Yes |

Message history

| Feature | Supported | |---------|-----------| | Fetch messages | Cached sent messages only | | Fetch thread info | Yes |

Interactive messages

Card elements are automatically converted to Messenger templates:

  • Generic Template — Used when the card has a title or imageUrl. 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

messenger:{recipientId}

Example: messenger:27161130920158013

License

MIT