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

@msgly/messenger

v0.2.2

Published

Facebook Messenger adapter for Msgly

Readme

@msgly/messenger

Facebook Messenger adapter for Msgly. Send and receive Messenger messages through the unified hub — text, all media types, buttons, quick replies, typing indicators. Zero classes, runs in Node, Next.js, and Edge runtimes.

Install

npm install @msgly/core @msgly/messenger

Quick start

import express from 'express';
import { createHub } from '@msgly/core';
import { createMessengerAdapter } from '@msgly/messenger';

const hub = createHub();

hub.register(
  createMessengerAdapter({
    pageAccessToken: process.env.MESSENGER_PAGE_TOKEN!,
    appSecret: process.env.META_APP_SECRET!,
    verifyToken: process.env.META_VERIFY_TOKEN!,
  }),
);

await hub.connect({ throwOnFailure: true });

hub.on('message', async (msg) => {
  if (msg.channel === 'messenger' && msg.content.type === 'text') {
    await hub.send({
      channel: 'messenger',
      account: msg.account,
      contact: msg.contact,
      content: { type: 'text', text: `You said: ${msg.content.text}` },
    });
  }
});

const app = express();
app.use(express.json({ verify: (req, _r, buf) => ((req as any).rawBody = new Uint8Array(buf)) }));

const handlers = hub.createWebhookHandler();
app.get('/webhook/:channel', handlers.get);
app.post('/webhook/:channel', handlers.post);

app.listen(3000);

Config

interface MessengerConfig {
  /** Page access token from Messenger → Generate Tokens. */
  pageAccessToken: string;

  /** App secret — used for X-Hub-Signature-256 verification. */
  appSecret: string;

  /** Your chosen string for the webhook GET handshake. */
  verifyToken: string;

  /** Override for tests. Defaults to https://graph.facebook.com. */
  apiBase?: string;

  /** Graph API version. Defaults to v20.0. */
  apiVersion?: string;
}

Setup (15 minutes)

Prerequisite: a Facebook Page. Create one at facebook.com/pages/create if needed.

  1. Create a Meta App at developers.facebook.com → Create App → Business type.
  2. App Secret. Settings → Basic → Show next to App Secret → META_APP_SECRET.
  3. Verify token. Any random string → META_VERIFY_TOKEN. Same value must be configured in Meta's webhook form.
  4. Add the Messenger product → Set up.
  5. Generate a Page token. Messenger → Settings → "Generate Tokens" → select your Page → Generate Token. Copy immediately — shown only once. Set as MESSENGER_PAGE_TOKEN.
  6. Webhook subscription. Same Settings page → "Webhooks":
    • Callback URL: <PUBLIC_URL>/webhook/messenger
    • Verify token: same as META_VERIFY_TOKEN
    • Click Verify and Save (server must be running)
    • Subscription fields: tick messages and messaging_postbacks
  7. Subscribe the Page. Same Webhooks section → next to your Page → Subscribe.
  8. Test. Open Messenger, find your Page, send a message.

Token expiry

Page tokens generated in the dashboard are short-lived in Development mode (~60 days). Two production paths:

  • Exchange for long-lived:
    GET /oauth/access_token
      ?grant_type=fb_exchange_token
      &client_id={app-id}
      &client_secret={app-secret}
      &fb_exchange_token={short-lived-token}
  • Switch the app to Live mode and use a System User token from Business Settings → Users → System Users. System User tokens don't expire.

Capabilities

| Feature | Supported | | ------------- | --------- | | text | ✓ | | image | ✓ | | video | ✓ | | audio | ✓ | | file | ✓ | | location | ✓ | | buttons | ✓ | | quick replies | ✓ (max 13, 20-char labels) | | templates | — | | reactions | — | | typing | ✓ |

Sending examples

Image

await hub.send({
  channel: 'messenger',
  account, contact,
  content: {
    type: 'image',
    mediaRef: { kind: 'url', value: 'https://example.com/cat.png' },
  },
});

Quick replies

await hub.send({
  channel: 'messenger',
  account, contact,
  content: {
    type: 'interactive',
    text: 'Pick one:',
    buttons: [
      { id: 'a', label: 'Option A' },
      { id: 'b', label: 'Option B' },
    ],
  },
});

User taps → your message event fires with content.text equal to the button's id.

Common pitfalls

  • Webhook verify fails in console: META_VERIFY_TOKEN in code must match the value typed into the Meta form byte-for-byte. Server must be reachable at the public URL the moment you click Verify.
  • Bot replies arrive but user doesn't see them: the App must be subscribed to the Page. Webhooks section → Subscribe next to the Page.
  • InvalidSignature: wrong appSecret, or your Express app isn't capturing the raw body. The verify callback in express.json() is essential.
  • (#10) Application does not have permission for this action: in Development mode, only Page admins/devs/testers can message the bot. Add the user under App Roles, or switch the App to Live mode.
  • Page token suddenly invalid: short-lived tokens expire (~60 days in dev mode). See Token expiry.

Documentation

Full setup walkthrough and multi-channel usage: https://github.com/AyushJain070401/msgly

License

MIT