Overview
Matrix is a decentralized, encrypted communication protocol used by:- Element (official client)
- Government organizations
- Privacy-focused communities
- Federated chat systems
- End-to-end encryption (E2EE)
- Decentralized architecture
- Room-based messaging
- User allowlists
- Mention-only mode
Configuration
Basic Setup
With Allowlist
Getting Access Token
Create Matrix Account
Sign up at https://app.element.io or your homeserver
Get Access Token
Element Web:
- Settings → Help & About
- Scroll to “Advanced”
- Click “Access Token”
- Copy the token
Features
End-to-End Encryption
Matrix channel automatically handles E2EE rooms using the matrix-sdk library:First message in encrypted room may take a few seconds while keys are exchanged.
Session Persistence
Matrix sessions are stored in~/.zeroclaw/matrix/ directory:
- Crypto store: Encryption keys
- Session data: Login session
- State sync: Room membership
Mention-Only Mode
Only respond when bot is mentioned:User Allowlist
Restrict who can interact:Room Types
Public Rooms
Private Rooms
Encrypted Rooms
Message Features
Send Messages
Receive Messages
Automatically processes:- Text messages
- Encrypted messages (auto-decrypted)
- Mentions
- Room invites
Implementation Details
Matrix SDK:- Uses
matrix-sdkcrate - Full E2EE support via Olm/Megolm
- Automatic key backup
- Device verification
- Long-polling sync
- Real-time message delivery
- Encrypted room support
- Automatic reconnection
src/channels/matrix.rs
Troubleshooting
Messages not decrypting
Messages not decrypting
Solutions:
- Delete crypto store and re-login:
- Verify bot has been invited to encrypted room
- Check logs for key exchange errors:
Bot not responding
Bot not responding
Solutions:
- Check allowlist:
- Verify room ID format:
- Check mention_only mode:
Connection errors
Connection errors
Solutions:
- Verify homeserver URL:
- Check access token validity:
- Test with fresh token
Performance
Sync Latency:- Real-time: <1 second (long-polling)
- Encrypted rooms: +500ms (decryption overhead)
- Send: 10 messages/second
- Receive: Limited by sync rate
Security
- E2EE: All messages in encrypted rooms use Olm/Megolm
- Access Control: User allowlists enforced
- Token Storage: Access token stored in config (use environment variable in production)
- Device Trust: Automatic device verification