Skip to content

feat: add Mattermost and Matrix gateway adapters#1683

Merged
teknium1 merged 4 commits intomainfrom
feat/mattermost-matrix-adapters
Mar 17, 2026
Merged

feat: add Mattermost and Matrix gateway adapters#1683
teknium1 merged 4 commits intomainfrom
feat/mattermost-matrix-adapters

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Adds Mattermost and Matrix as supported messaging platforms. Both are self-hosted-first with real user bases (Mattermost: US DoD, NASA, CERN; Matrix: 180M users, French/German governments, UN).

Mattermost

  • REST API v4 + WebSocket for real-time events
  • Thread support, file upload/download, typing indicators
  • Dedup cache, exponential backoff reconnect
  • No new dependencies (uses aiohttp)
  • Env: MATTERMOST_URL, MATTERMOST_TOKEN, MATTERMOST_ALLOWED_USERS

Matrix

  • matrix-nio AsyncClient with continuous sync loop
  • Dual auth: access token or password login
  • Optional E2EE via matrix-nio[e2e] (libolm)
  • Thread support (m.thread/MSC3440), reply support, auto-join on invite
  • DM detection via m.direct account data
  • Install: pip install 'hermes-agent[matrix]'
  • Env: MATRIX_HOMESERVER, MATRIX_ACCESS_TOKEN, MATRIX_USER_ID, MATRIX_ALLOWED_USERS

Fixes over original PR #1225

  • Mattermost: timeout on file downloads, network error handling in API helpers, auth-aware file caching for incoming attachments
  • Matrix: authenticated media endpoint (v1.11+), robust m.direct cache with sync fallback, prefer aiohttp over httpx for downloads

Testing

  • 1020 gateway tests pass
  • Imports verified for both adapters
  • Clawdbot (competitor) has full support for both platforms — parity move

Salvaged from PR #1225 by @cyb0rgk1tty with fixes and doc verification against official API specs.

Add support for Mattermost (self-hosted Slack alternative) and Matrix
(federated messaging protocol) as messaging platforms.

Mattermost adapter:
- REST API v4 client for posts, files, channels, typing indicators
- WebSocket listener for real-time 'posted' events with reconnect backoff
- Thread support via root_id
- File upload/download with auth-aware caching
- Dedup cache (5min TTL, 2000 entries)
- Full self-hosted instance support

Matrix adapter:
- matrix-nio AsyncClient with sync loop
- Dual auth: access token or user_id + password
- Optional E2EE via matrix-nio[e2e] (libolm)
- Thread support via m.thread (MSC3440)
- Reply support via m.in_reply_to with fallback stripping
- Media upload/download via mxc:// URLs (authenticated v1.11+ endpoint)
- Auto-join on room invite
- DM detection via m.direct account data with sync fallback
- Markdown to HTML conversion

Fixes applied over original PR #1225 by @cyb0rgk1tty:
- Mattermost: add timeout to file downloads, wrap API helpers in
  try/except for network errors, download incoming files immediately
  with auth headers instead of passing auth-required URLs
- Matrix: use authenticated media endpoint (/_matrix/client/v1/media/),
  robust m.direct cache with sync fallback, prefer aiohttp over httpx

Install Matrix support: pip install 'hermes-agent[matrix]'
Mattermost needs no extra deps (uses aiohttp).

Salvaged from PR #1225 by @cyb0rgk1tty with fixes.
77 tests covering:

Mattermost (37 tests):
- Platform enum and config loading
- Message formatting (image markdown stripping)
- Message chunking at 4000 chars
- Send with mocked aiohttp (payload, threading, errors)
- WebSocket event parsing (double-encoded JSON!)
- File upload flow
- Post dedup cache (TTL, pruning)
- Requirements check

Matrix (40 tests):
- Platform enum and config loading (token + password auth, E2EE)
- mxc:// to HTTP URL conversion (authenticated v1.11+ endpoint)
- DM detection via m.direct cache
- Reply fallback stripping
- Thread detection from m.relates_to
- Message formatting and markdown to HTML
- Display name resolution
- Requirements check
Adds both platforms to the config system so hermes setup, hermes doctor,
and hermes config properly discover and manage their env vars.

- MATTERMOST_URL, MATTERMOST_TOKEN, MATTERMOST_ALLOWED_USERS
- MATRIX_HOMESERVER, MATRIX_ACCESS_TOKEN, MATRIX_USER_ID, MATRIX_ALLOWED_USERS
- Extra env keys for .env sanitizer: MATTERMOST_HOME_CHANNEL,
  MATTERMOST_REPLY_MODE, MATRIX_PASSWORD, MATRIX_ENCRYPTION, MATRIX_HOME_ROOM
Full Docusaurus docs following the Discord guide structure:

Mattermost (277 lines):
- Step-by-step: enable bot accounts, create bot, get token, add to channels
- All env vars documented with examples
- Reply mode (thread/off), home channel, troubleshooting

Matrix (354 lines):
- Step-by-step: create bot account, get access token (Element or API)
- Dual auth (token + password), E2EE section with libolm install
- Thread support, DM detection, home room, troubleshooting
- Works with any homeserver (Synapse, Conduit, Dendrite, matrix.org)
@teknium1 teknium1 force-pushed the feat/mattermost-matrix-adapters branch from 41b39fc to 1ae1e36 Compare March 17, 2026 10:18
@teknium1 teknium1 merged commit 3cb8340 into main Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant