Skip to content

feat(matrix): add multi-room support with per-room config#18

Open
navsteruk wants to merge 1 commit intoopenagen:masterfrom
navsteruk:feat/matrix-multi-room
Open

feat(matrix): add multi-room support with per-room config#18
navsteruk wants to merge 1 commit intoopenagen:masterfrom
navsteruk:feat/matrix-multi-room

Conversation

@navsteruk
Copy link
Copy Markdown

Summary

  • Add multi-room Matrix support with per-room configuration (aligned with OpenClaw's approach)
  • Each room can be individually enabled/disabled and set to require mentions
  • Fix channel name lookup that prevented replies from being sent back to Matrix

Changes

  • schema.rs: New struct with and fields; optional on
  • matrix.rs: Activate dormant multi-room filter in event handler; add per-room mention detection using bot display name
  • mod.rs: Pass room configs to MatrixChannel constructor; fix channel name lookup to strip room ID suffix

Config example

[channels_config.matrix]
homeserver = "https://matrix.example.org"
access_token = "..."
room_id = "!main:matrix.org"  # default room for proactive messages
allowed_users = ["@user:matrix.org"]

[channels_config.matrix.rooms]
"!main:matrix.org" = { enabled = true, require_mention = false }
"!team:matrix.org" = { enabled = true, require_mention = true }

When rooms is absent, behavior is identical to the current single-room mode.

Bug fix included

The msg.channel field includes the room ID (e.g. matrix:!room:server) but channels_by_name is keyed by just the channel name (matrix). This caused target_channel to be None, silently dropping all replies. Fixed by stripping the room suffix before lookup.

Test plan

  • Tested with single room config (backward compatible, no rooms field)
  • Tested with multiple rooms, each with different require_mention settings
  • Verified replies land in the correct room
  • Verified mention-only rooms filter correctly
  • Tested on homelab with Synapse + Element

🤖 Generated with Claude Code

Add support for monitoring multiple Matrix rooms from a single channel
instance, aligned with OpenClaw's per-room configuration approach.

Changes:
- Add MatrixRoomConfig struct with enabled and require_mention fields
- Add optional rooms HashMap to MatrixConfig (backward compatible)
- Activate the dormant multi-room filter in the listen() event handler
- Add per-room mention detection using bot user ID and display name
- Resolve bot display name on startup for mention matching
- Fix channel name lookup to strip room ID suffix (was preventing
  replies from being sent back to Matrix)

Config example:
  [channels_config.matrix.rooms]
  "!room1:matrix.org" = { enabled = true, require_mention = false }
  "!room2:matrix.org" = { enabled = true, require_mention = true }

When rooms is absent, behavior is identical to before (single room_id).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant