docs: add config comments to example, update README with ignoreRooms/ignoreUsers
- Add inline comments to matrix.json.example - Add ignoreRooms and ignoreUsers to config table - Add config priority section - Add example config usage instructions
This commit is contained in:
parent
267f60a55c
commit
cae866fec6
|
|
@ -1,17 +1,55 @@
|
||||||
{
|
{
|
||||||
|
// Matrix homeserver URL
|
||||||
"homeserver": "https://matrix.org",
|
"homeserver": "https://matrix.org",
|
||||||
|
|
||||||
|
// Bot user ID (e.g., @bot:server.org)
|
||||||
"userId": "@opencode-bot:matrix.org",
|
"userId": "@opencode-bot:matrix.org",
|
||||||
|
|
||||||
|
// Bot password for login (preferred over accessToken)
|
||||||
"password": "",
|
"password": "",
|
||||||
|
|
||||||
|
// Static access token (alternative to password)
|
||||||
|
"accessToken": "",
|
||||||
|
|
||||||
|
// Device ID for login
|
||||||
"deviceId": "opencode-matrix-plugin",
|
"deviceId": "opencode-matrix-plugin",
|
||||||
|
|
||||||
|
// Auto-join rooms the bot is invited to
|
||||||
"autoJoin": true,
|
"autoJoin": true,
|
||||||
|
|
||||||
|
// Message prefixes to trigger the bot.
|
||||||
|
// Empty array = all messages are processed.
|
||||||
|
// Configured = only messages with trigger/mention/thread-reply are processed.
|
||||||
"triggerPatterns": ["!oc "],
|
"triggerPatterns": ["!oc "],
|
||||||
|
|
||||||
|
// Room IDs to completely ignore (messages not processed)
|
||||||
"ignoreRooms": [],
|
"ignoreRooms": [],
|
||||||
|
|
||||||
|
// User IDs to completely ignore (messages not processed)
|
||||||
"ignoreUsers": [],
|
"ignoreUsers": [],
|
||||||
|
|
||||||
|
// Allowlist of users who can interact with the bot.
|
||||||
|
// Empty = everyone allowed (subject to ignoreUsers).
|
||||||
"allowedUsers": [],
|
"allowedUsers": [],
|
||||||
|
|
||||||
|
// Send HTML-formatted responses (requires marked package)
|
||||||
"formatHtml": false,
|
"formatHtml": false,
|
||||||
|
|
||||||
|
// Each Matrix thread gets its own isolated session
|
||||||
"threadIsolation": true,
|
"threadIsolation": true,
|
||||||
|
|
||||||
|
// Reply to plain messages in active threads (follow-up mode)
|
||||||
"respondToThreadReplies": true,
|
"respondToThreadReplies": true,
|
||||||
|
|
||||||
|
// Per-user cooldown between messages (seconds)
|
||||||
"rateLimitSeconds": 5,
|
"rateLimitSeconds": 5,
|
||||||
|
|
||||||
|
// Bot display name for @mentions
|
||||||
"botName": "opencode",
|
"botName": "opencode",
|
||||||
|
|
||||||
|
// Storage directory for bot state and crypto keys
|
||||||
|
"storagePath": "",
|
||||||
|
|
||||||
|
// Enable/disable the plugin
|
||||||
"enabled": true
|
"enabled": true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,8 @@ ln -s /path/to/your/project/plugins/matrix-plugin ~/.config/opencode/plugins/mat
|
||||||
| `deviceId` | string | `opencode-matrix-plugin` | Device ID for login |
|
| `deviceId` | string | `opencode-matrix-plugin` | Device ID for login |
|
||||||
| `autoJoin` | boolean | `true` | Auto-join rooms the bot is invited to |
|
| `autoJoin` | boolean | `true` | Auto-join rooms the bot is invited to |
|
||||||
| `triggerPatterns` | string[] | `[]` | Message prefixes to trigger the bot. Empty = all messages. |
|
| `triggerPatterns` | string[] | `[]` | Message prefixes to trigger the bot. Empty = all messages. |
|
||||||
|
| `ignoreRooms` | string[] | `[]` | Room IDs to completely ignore |
|
||||||
|
| `ignoreUsers` | string[] | `[]` | User IDs to completely ignore |
|
||||||
| `allowedUsers` | string[] | `[]` | Allowlist (empty = everyone) |
|
| `allowedUsers` | string[] | `[]` | Allowlist (empty = everyone) |
|
||||||
| `formatHtml` | boolean | `false` | Send HTML-formatted responses |
|
| `formatHtml` | boolean | `false` | Send HTML-formatted responses |
|
||||||
| `threadIsolation` | boolean | `true` | Per-thread sessions |
|
| `threadIsolation` | boolean | `true` | Per-thread sessions |
|
||||||
|
|
@ -124,6 +126,28 @@ ln -s /path/to/your/project/plugins/matrix-plugin ~/.config/opencode/plugins/mat
|
||||||
| `storagePath` | string | auto | Directory for bot state and crypto keys |
|
| `storagePath` | string | auto | Directory for bot state and crypto keys |
|
||||||
| `enabled` | boolean | `true` | Enable/disable the plugin |
|
| `enabled` | boolean | `true` | Enable/disable the plugin |
|
||||||
|
|
||||||
|
### Config Priority
|
||||||
|
|
||||||
|
Configuration is loaded in this order (highest priority first):
|
||||||
|
|
||||||
|
1. **Plugin options** from `opencode.jsonc` (`plugins[].options`)
|
||||||
|
2. **Config file** — `matrix.json` or `matrix.jsonc` in:
|
||||||
|
- Project level: `.opencode/matrix.json` (next to `opencode.jsonc`)
|
||||||
|
- Global level: `~/.config/opencode/matrix.json`
|
||||||
|
3. **Environment variables** — `MATRIX_*`
|
||||||
|
|
||||||
|
> **Auto-create**: If no config is found, the plugin auto-creates `~/.config/opencode/matrix.json` with defaults (permissions `0o600`).
|
||||||
|
|
||||||
|
### Example Config
|
||||||
|
|
||||||
|
Copy `matrix.json.example` from the project root and customize:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp matrix.json.example ~/.config/opencode/matrix.json
|
||||||
|
```
|
||||||
|
|
||||||
|
See the example file for fully commented configuration with all options.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Triggering the Bot
|
### Triggering the Bot
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ export interface MatrixOptions {
|
||||||
deviceId?: string
|
deviceId?: string
|
||||||
autoJoin?: boolean
|
autoJoin?: boolean
|
||||||
triggerPatterns?: string[]
|
triggerPatterns?: string[]
|
||||||
|
ignoreRooms?: string[]
|
||||||
|
ignoreUsers?: string[]
|
||||||
allowedUsers?: string[]
|
allowedUsers?: string[]
|
||||||
formatHtml?: boolean
|
formatHtml?: boolean
|
||||||
threadIsolation?: boolean
|
threadIsolation?: boolean
|
||||||
|
|
@ -232,6 +234,8 @@ export class MatrixBotClient {
|
||||||
private readonly threadIsolation: boolean
|
private readonly threadIsolation: boolean
|
||||||
private readonly respondToThreadReplies: boolean
|
private readonly respondToThreadReplies: boolean
|
||||||
private readonly allowedUsers: string[]
|
private readonly allowedUsers: string[]
|
||||||
|
private readonly ignoreRooms: string[]
|
||||||
|
private readonly ignoreUsers: string[]
|
||||||
private readonly formatHtml: boolean
|
private readonly formatHtml: boolean
|
||||||
|
|
||||||
constructor(options: MatrixOptions) {
|
constructor(options: MatrixOptions) {
|
||||||
|
|
@ -242,6 +246,8 @@ export class MatrixBotClient {
|
||||||
this.threadIsolation = options.threadIsolation !== false
|
this.threadIsolation = options.threadIsolation !== false
|
||||||
this.respondToThreadReplies = options.respondToThreadReplies !== false
|
this.respondToThreadReplies = options.respondToThreadReplies !== false
|
||||||
this.allowedUsers = options.allowedUsers || []
|
this.allowedUsers = options.allowedUsers || []
|
||||||
|
this.ignoreRooms = options.ignoreRooms || []
|
||||||
|
this.ignoreUsers = options.ignoreUsers || []
|
||||||
this.formatHtml = options.formatHtml || false
|
this.formatHtml = options.formatHtml || false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -348,6 +354,16 @@ export class MatrixBotClient {
|
||||||
|
|
||||||
if (message.sender === this.userId) return
|
if (message.sender === this.userId) return
|
||||||
|
|
||||||
|
// Check ignored rooms
|
||||||
|
if (this.ignoreRooms.length > 0 && this.ignoreRooms.includes(roomId)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check ignored users
|
||||||
|
if (this.ignoreUsers.length > 0 && this.ignoreUsers.includes(message.sender)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Check allowed users
|
// Check allowed users
|
||||||
if (this.allowedUsers.length > 0 && !this.allowedUsers.includes(message.sender)) {
|
if (this.allowedUsers.length > 0 && !this.allowedUsers.includes(message.sender)) {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue