@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.
Usage
createMatrixAdapter() reads its config from environment variables when called without arguments.
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
Username/password
Defaults
- Persistence behavior is active whenever Chat provides a
stateadapter. - Redis or another durable state adapter is recommended for restart durability.
deviceIDis inferred from auth when possible, then reused from state, and only generated as a last resort.recoveryKeyenables E2EE.inviteAutoJoin: {}enables invite auto-join.
Common Options
Advanced tuning stays in code config:
Environment Variables
createMatrixAdapter() with no arguments uses only these env vars:
*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
Persistence
For production, pair the adapter with a durable Chat state adapter such as Redis.
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()returns501by 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
examples/bot.tsuses in-memory state for local development.examples/bot.redis.tsuses Redis-backed state for restart durability.examples/.env.examplelists the supported env vars for the examples.scripts/get-access-token.tshelps generate Beeper credentials interactively.
For release-specific changes, see CHANGELOG.md.
License
MIT