Introduction
Matrix is an open, decentralized instant messaging protocol, and Element is its most popular client. By connecting OpenClaw to the Matrix network, you can chat with your AI assistant from any Matrix client while enjoying the privacy protection and decentralization benefits that the Matrix protocol provides.
This tutorial will walk you through the entire process of integrating OpenClaw with Matrix from scratch.
Prerequisites
Before getting started, make sure the following requirements are met:
| Dependency | Minimum Version | Description |
|---|---|---|
| Node.js | 22+ | OpenClaw runtime environment |
| OpenClaw | Latest | npm install -g openclaw@latest |
| Matrix Homeserver | Any | Can be matrix.org or a self-hosted Synapse |
| Element Client | Any | For testing and daily use |
If you haven't installed OpenClaw yet, run:
npm install -g openclaw@latest
openclaw onboard
Step 1: Create a Matrix Bot Account
You need to create a dedicated Matrix account for OpenClaw. It's recommended to register using the Element client.
Register on matrix.org
- Visit Element Web and click "Create Account"
- Select
matrix.orgas the Homeserver (or use your self-hosted Homeserver address) - Choose a username — something like
openclaw-botis recommended - Set a strong password and complete the registration
Register on a Self-Hosted Synapse
If you're running your own Synapse server, you can register via the command line:
# Run on the Synapse server
register_new_matrix_user -c /etc/synapse/homeserver.yaml http://localhost:8008
# Follow the prompts to enter a username and password, select no for admin
Step 2: Obtain an Access Token
OpenClaw requires an Access Token to authenticate with the Matrix account. There are two ways to obtain one.
Option 1: Via the Element Client
- Log in to Element with the bot account
- Click the avatar in the top-left corner → "All settings"
- Navigate to the "Help & About" tab
- Expand the "Advanced" section at the bottom
- Find the "Access token" field and click to copy
Option 2: Via the API
curl -X POST "https://matrix.org/_matrix/client/v3/login" \
-H "Content-Type: application/json" \
-d '{
"type": "m.login.password",
"user": "@openclaw-bot:matrix.org",
"password": "your-password-here"
}'
The response will contain an access_token field:
{
"user_id": "@openclaw-bot:matrix.org",
"access_token": "syt_b3BlbmNsYXctYm90_xxxxxxxxxxxxx_xxxxxx",
"device_id": "ABCDEFGHIJ"
}
Keep this token safe and do not share it with anyone.
Step 3: Configure OpenClaw
Edit the OpenClaw configuration file at ~/.config/openclaw/openclaw.json5:
{
// Other settings...
channels: {
matrix: {
enabled: true,
// Matrix Homeserver URL
homeserverUrl: "https://matrix.org",
// Bot's full Matrix ID
userId: "@openclaw-bot:matrix.org",
// Access Token obtained in the previous step
accessToken: "syt_b3BlbmNsYXctYm90_xxxxxxxxxxxxx_xxxxxx",
// Automatically join rooms when invited
autoJoin: true,
// Response mode: all responds to all messages, mention responds only when @mentioned
responseMode: "mention",
// Allowed rooms list (empty means all rooms are allowed)
allowedRooms: [],
// Display name
displayName: "OpenClaw AI",
// Avatar URL (optional)
avatarUrl: ""
}
}
}
Configuration Reference
| Option | Type | Default | Description |
|---|---|---|---|
homeserverUrl |
string | Required | Full URL of the Homeserver |
userId |
string | Required | Bot's Matrix user ID |
accessToken |
string | Required | Authentication token |
autoJoin |
boolean | true |
Whether to automatically accept room invitations |
responseMode |
string | "mention" |
all or mention |
allowedRooms |
array | [] |
List of room IDs where the bot is allowed to respond |
displayName |
string | Username | Bot's display name |
Step 4: Start and Verify
After saving the configuration, restart OpenClaw:
openclaw restart
Check the logs to confirm the Matrix channel is connected:
openclaw logs
You should see output similar to:
[INFO] Matrix channel initializing...
[INFO] Connected to homeserver: https://matrix.org
[INFO] Logged in as @openclaw-bot:matrix.org
[INFO] Matrix channel ready, listening for messages
Step 5: Create a Room and Invite the Bot
Create a Dedicated Room
- In Element, click "+" to create a new room
- Set the room name to something like "AI Assistant"
- Choose whether to enable encryption based on your needs (see the encryption section below)
- After creating the room, invite the bot account to join
Invite the Bot
Invite the bot by entering this command in the room:
/invite @openclaw-bot:matrix.org
If you configured autoJoin: true, the bot will automatically accept the invitation and join the room.
Test the Conversation
Send a message in the room to test:
@openclaw-bot Hello, please introduce yourself
If responseMode is set to all, the bot will respond without needing to be @mentioned.
End-to-End Encryption Considerations
Matrix's end-to-end encryption (E2EE) is a powerful privacy feature, but it requires extra attention when integrating with bots.
Current Limitations
OpenClaw's Matrix integration supports E2EE, but keep the following in mind:
- Device Verification: On first launch, the bot needs to complete device verification. It's recommended to manually verify the bot's device in Element
- Key Backup: Enabling key backup is recommended; otherwise, OpenClaw may not be able to read older encrypted messages after a restart
- Performance Overhead: E2EE adds latency to message processing
Enabling Encrypted Room Support
Add E2EE-related settings to your configuration:
{
channels: {
matrix: {
// ...base configuration...
encryption: {
enabled: true,
// Path for storing encryption keys
storePath: "~/.openclaw/matrix-crypto-store",
// Whether to automatically verify new devices
autoVerify: false
}
}
}
}
Verifying the Bot's Device
Complete device verification in Element:
- Open a direct chat with the bot
- Click the bot's avatar → "Security"
- Select "Manually verify by text" or use emoji verification
- Follow the prompts to complete the verification process
Restricting Room Access
For security purposes, it's recommended to restrict the bot to respond only in specific rooms:
{
channels: {
matrix: {
// Only respond to messages in these rooms
allowedRooms: [
"!abcdefg:matrix.org", // AI Assistant room
"!hijklmn:matrix.org" // Team discussion room
]
}
}
}
To find a room ID: go to room settings in Element → "Advanced" → copy the "Internal room ID".
Using Bridges to Connect Other Platforms
One of Matrix's most powerful features is the ability to connect to other platforms via bridges. When used with OpenClaw, a single bot account can serve multiple platforms simultaneously.
Common bridges include:
| Bridge | Connected Platform | Project URL |
|---|---|---|
| mautrix-telegram | Telegram | github.com/mautrix/telegram |
| mautrix-whatsapp | github.com/mautrix/whatsapp | |
| mautrix-discord | Discord | github.com/mautrix/discord |
| mautrix-signal | Signal | github.com/mautrix/signal |
Through bridges, messages are automatically synced between Matrix and the target platform, so OpenClaw only needs to connect to Matrix.
Troubleshooting
Bot Cannot Connect to the Homeserver
# Check if the Homeserver is reachable
curl -s https://matrix.org/_matrix/client/versions
# Verify the Access Token is valid
curl -s -H "Authorization: Bearer YOUR_TOKEN" \
"https://matrix.org/_matrix/client/v3/account/whoami"
Bot Doesn't Respond to Messages
- Confirm that
responseModeis set correctly - Check that
allowedRoomsincludes the current room - Look for error messages in the OpenClaw logs:
openclaw logs
Cannot Decrypt Messages in Encrypted Rooms
- Confirm that
encryption.enabledis set totrue - Check that the crypto-store path is correct and has write permissions
- Redo the device verification process
Summary
Through this tutorial, you've successfully connected OpenClaw to the Matrix network. Matrix's decentralized architecture and end-to-end encryption capabilities make it an ideal choice for privacy-conscious users. Combined with OpenClaw's AI capabilities, you can enjoy intelligent assistant services in Element or any Matrix-compatible client.
Next steps:
- Refer to the "Connecting OpenClaw to Multiple Chat Channels" tutorial to set up multi-platform access
- Explore the ClawHub skill marketplace to add more capabilities to your bot