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

@beeper/chat-adapter-matrix

v0.2.0

Published

Matrix adapter for chat

Downloads

2,408

Readme

@beeper/chat-adapter-matrix

Matrix adapter for Chat SDK. It runs over Matrix sync instead of webhooks and works with Beeper conversations and bridged networks such as WhatsApp, Telegram, Instagram, and Signal.

Installation

Requires Node.js >=22.

pnpm add chat @beeper/chat-adapter-matrix

Usage

createMatrixAdapter() reads its config from environment variables when called without arguments.

import { Chat } from "chat";
import { createMemoryState } from "@chat-adapter/state-memory";
import { createMatrixAdapter } from "@beeper/chat-adapter-matrix";

const matrix = createMatrixAdapter();

const bot = new Chat({
  userName: process.env.MATRIX_BOT_USERNAME ?? "beeper-bot",
  state: createMemoryState(),
  adapters: { matrix },
});

bot.onNewMention(async (thread, message) => {
  await thread.subscribe();
  await thread.post(`Hi ${message.author.userName}. Mention me or run /ping.`);
});

bot.onSlashCommand("/ping", async (event) => {
  await event.channel.post("pong");
});

await bot.initialize();

Chat SDK concepts such as Chat, Thread, Message, subscriptions, and handlers work the same here. See the upstream docs for the core API:

Authentication

Access token

createMatrixAdapter({
  baseURL: process.env.MATRIX_BASE_URL!,
  auth: {
    type: "accessToken",
    accessToken: process.env.MATRIX_ACCESS_TOKEN!,
    userID: process.env.MATRIX_USER_ID,
  },
});

Username/password

createMatrixAdapter({
  baseURL: process.env.MATRIX_BASE_URL!,
  auth: {
    type: "password",
    username: process.env.MATRIX_USERNAME!,
    password: process.env.MATRIX_PASSWORD!,
    userID: process.env.MATRIX_USER_ID,
  },
});

Defaults

  • Persistence behavior is active whenever Chat provides a state adapter.
  • Redis or another durable state adapter is recommended for restart durability.
  • deviceID is inferred from auth when possible, then reused from state, and only generated as a last resort.
  • recoveryKey enables E2EE.
  • inviteAutoJoin: {} enables invite auto-join.

Common Options

createMatrixAdapter({
  baseURL: process.env.MATRIX_BASE_URL!,
  auth: {
    type: "accessToken",
    accessToken: process.env.MATRIX_ACCESS_TOKEN!,
    userID: process.env.MATRIX_USER_ID,
  },
  recoveryKey: process.env.MATRIX_RECOVERY_KEY,
  commandPrefix: "/",
  roomAllowlist: ["!room:beeper.com"],
  inviteAutoJoin: {
    inviterAllowlist: ["@alice:beeper.com", "@ops:beeper.com"],
  },
  matrixSDKLogLevel: "error",
});

Advanced tuning stays in code config:

createMatrixAdapter({
  baseURL: process.env.MATRIX_BASE_URL!,
  auth: {
    type: "accessToken",
    accessToken: process.env.MATRIX_ACCESS_TOKEN!,
    userID: process.env.MATRIX_USER_ID,
  },
  e2ee: {
    useIndexedDB: false,
    cryptoDatabasePrefix: "beeper-matrix-bot",
  },
  persistence: {
    keyPrefix: "my-bot",
    session: {
      ttlMs: 86_400_000,
    },
    sync: {
      persistIntervalMs: 10_000,
    },
  },
});

Environment Variables

createMatrixAdapter() with no arguments uses only these env vars:

| Variable | Required | Description | |----------|----------|-------------| | MATRIX_BASE_URL | Yes | Matrix homeserver base URL | | MATRIX_ACCESS_TOKEN | Yes* | Access token for access-token auth | | MATRIX_USERNAME | Yes* | Username for password auth | | MATRIX_PASSWORD | Yes* | Password for password auth | | MATRIX_USER_ID | No | User ID hint | | MATRIX_DEVICE_ID | No | Explicit device ID override | | MATRIX_RECOVERY_KEY | No | Enables E2EE and key-backup bootstrap | | MATRIX_BOT_USERNAME | No | Mention-detection username | | MATRIX_COMMAND_PREFIX | No | Slash command prefix. Defaults to / | | MATRIX_INVITE_AUTOJOIN | No | Enable invite auto-join | | MATRIX_INVITE_AUTOJOIN_ALLOWLIST | No | Comma-separated Matrix user IDs allowed to invite the bot | | MATRIX_SDK_LOG_LEVEL | No | Matrix SDK log level |

*Use either MATRIX_ACCESS_TOKEN, or MATRIX_USERNAME plus MATRIX_PASSWORD.

Thread Model

  • A Matrix room is a Chat SDK channel.
  • Top-level room messages belong to the channel timeline.
  • Matrix threaded replies map to Chat SDK threads using roomID + rootEventID.
  • openDM(userId) reuses existing direct rooms when possible and creates one when needed.

Features

| Feature | Supported | |---------|-----------| | Mentions | Yes | | Rich text | Yes, via Matrix formatted_body and m.mentions | | Thread replies | Yes | | Reactions (add/remove) | Yes | | Message edits | Yes | | Message deletes | Yes | | Typing indicator | Yes | | Direct messages | Yes | | File uploads | Yes | | Message history | Yes | | Channel and thread metadata | Yes | | E2EE | Yes | | Invite auto-join | Yes | | Slash commands | Prefix-parsed from message text | | Webhooks | No, this adapter uses sync polling | | Cards | No | | Modals | No | | Ephemeral messages | No | | Native streaming | No |

Persistence

For production, pair the adapter with a durable Chat state adapter such as Redis.

import { Chat } from "chat";
import { createRedisState } from "@chat-adapter/state-redis";
import { createMatrixAdapter } from "@beeper/chat-adapter-matrix";

const matrix = createMatrixAdapter({
  baseURL: process.env.MATRIX_BASE_URL!,
  auth: {
    type: "accessToken",
    accessToken: process.env.MATRIX_ACCESS_TOKEN!,
    userID: process.env.MATRIX_USER_ID,
  },
  recoveryKey: process.env.MATRIX_RECOVERY_KEY,
});

const bot = new Chat({
  userName: process.env.MATRIX_BOT_USERNAME ?? "beeper-bot",
  state: createRedisState({ url: process.env.REDIS_URL! }),
  adapters: { matrix },
});

Persistence covers:

  • generated or inferred device IDs
  • password login sessions
  • DM room mappings
  • Matrix sync snapshots
  • E2EE secrets bundles when E2EE is enabled

Message and History APIs

The adapter supports:

  • fetchMessage(threadId, messageId)
  • fetchMessages(threadId, options)
  • fetchChannelMessages(channelId, options)
  • fetchThread(threadId)
  • fetchChannelInfo(channelId)
  • listThreads(channelId, options)
  • openDM(userId)

Limitations

  • handleWebhook() returns 501 by design because Matrix uses sync polling here.
  • Cards, modals, and ephemeral messages are not implemented.
  • Native streaming is not implemented at the adapter layer.
  • Slash commands are parsed from plain text messages; Matrix does not provide native slash command events.

Examples

For release-specific changes, see CHANGELOG.md.

License

MIT