Matrix command handling — receive and dispatch @mosaic commands #381

Closed
opened 2026-02-15 07:01:07 +00:00 by jason.woltje · 1 comment
Owner

Summary

Wire MatrixService to receive messages from Matrix rooms, parse commands via the shared CommandParser, and dispatch to StitcherService — identical flow to Discord bridge.

Implementation

Message Reception

MatrixService sync loop receives m.room.message events. Filter for:

  • Messages in mapped workspace rooms
  • Messages mentioning the bot (or starting with !mosaic)
  • Ignore bot's own messages

Command Flow

Matrix room message
  → MatrixService.onMessage()
  → CommandParser.parse(content)   // Shared with Discord
  → StitcherService.dispatch(command, workspaceId)
  → Job created in BullMQ

Command Prefix

  • Discord uses @mosaic (mention-based)
  • Matrix should support both @mosaic:homeserver (mention) and !mosaic (text prefix)
  • CommandParser already handles the parsing — just strip the prefix before passing

Thread Handling

Matrix supports threads (MSC3440, stable since Synapse 1.67). When a job is created:

  1. Bot replies to the command message (creating a thread)
  2. All job updates go into that thread
  3. Maps to existing createThread() / sendThreadMessage() in IChatProvider

Acceptance Criteria

  • Bot receives and processes commands from Matrix rooms
  • Commands dispatched to Stitcher (same path as Discord)
  • Thread created per job for status updates
  • !mosaic help returns command list
  • Unknown commands return helpful error
  • Integration tests with mocked Matrix client + real CommandParser

Refs

## Summary Wire MatrixService to receive messages from Matrix rooms, parse commands via the shared CommandParser, and dispatch to StitcherService — identical flow to Discord bridge. ## Implementation ### Message Reception MatrixService sync loop receives `m.room.message` events. Filter for: - Messages in mapped workspace rooms - Messages mentioning the bot (or starting with `!mosaic`) - Ignore bot's own messages ### Command Flow ``` Matrix room message → MatrixService.onMessage() → CommandParser.parse(content) // Shared with Discord → StitcherService.dispatch(command, workspaceId) → Job created in BullMQ ``` ### Command Prefix - Discord uses `@mosaic` (mention-based) - Matrix should support both `@mosaic:homeserver` (mention) and `!mosaic` (text prefix) - CommandParser already handles the parsing — just strip the prefix before passing ### Thread Handling Matrix supports threads (MSC3440, stable since Synapse 1.67). When a job is created: 1. Bot replies to the command message (creating a thread) 2. All job updates go into that thread 3. Maps to existing `createThread()` / `sendThreadMessage()` in IChatProvider ## Acceptance Criteria - [ ] Bot receives and processes commands from Matrix rooms - [ ] Commands dispatched to Stitcher (same path as Discord) - [ ] Thread created per job for status updates - [ ] `!mosaic help` returns command list - [ ] Unknown commands return helpful error - [ ] Integration tests with mocked Matrix client + real CommandParser ## Refs - CommandParser: `apps/api/src/bridge/parser/command-parser.service.ts` - Discord flow: `apps/api/src/bridge/discord/discord.service.ts` (line 59+) - EPIC: #377 - Depends on: #378, #380
jason.woltje added the apiapi labels 2026-02-15 07:01:07 +00:00
jason.woltje added this to the M12-MatrixBridge (0.0.12) milestone 2026-02-15 07:01:51 +00:00
Author
Owner

Completed in commit ad24720 on branch feature/m12-matrix-bridge.

  • MatrixService uses shared CommandParserService for platform-agnostic parsing
  • MatrixRoomService for dynamic room-to-workspace lookup
  • Dispatches to StitcherService for job execution
  • Added getWorkspaceForRoom reverse lookup
  • 49 Matrix tests passing, 112 total bridge tests
Completed in commit ad24720 on branch feature/m12-matrix-bridge. - MatrixService uses shared CommandParserService for platform-agnostic parsing - MatrixRoomService for dynamic room-to-workspace lookup - Dispatches to StitcherService for job execution - Added getWorkspaceForRoom reverse lookup - 49 Matrix tests passing, 112 total bridge tests
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: mosaic/stack#381