feat: add Mattermost and Matrix gateway adapters#1683
Merged
Conversation
5bad257 to
0e165d3
Compare
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)
41b39fc to
1ae1e36
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
MATTERMOST_URL,MATTERMOST_TOKEN,MATTERMOST_ALLOWED_USERSMatrix
matrix-nio[e2e](libolm)pip install 'hermes-agent[matrix]'MATRIX_HOMESERVER,MATRIX_ACCESS_TOKEN,MATRIX_USER_ID,MATRIX_ALLOWED_USERSFixes over original PR #1225
Testing
Salvaged from PR #1225 by @cyb0rgk1tty with fixes and doc verification against official API specs.