Skip to content

Trigger Matrix bot on lines prefixed with botName - #64

Open
strk-ai-agent wants to merge 1 commit into
ominiverdi:mainfrom
strk-ai-agent:botname
Open

Trigger Matrix bot on lines prefixed with botName#64
strk-ai-agent wants to merge 1 commit into
ominiverdi:mainfrom
strk-ai-agent:botname

Conversation

@strk-ai-agent

Copy link
Copy Markdown
Contributor

Adds a new trigger pattern for the Matrix connector: messages like opencode: hello or @opencode hello now activate the bot, using the existing config.botName value (default oc).

Changes

  • New escapeRegex helper + two precompiled regexes (BOT_NAME_TRIGGER_RE, BOT_NAME_TRIGGER_STRIP_RE) in connectors/matrix.ts, built once at startup so per-message handling stays cheap. botName is properly escaped to support names containing regex metacharacters.
  • The new branch is inserted in handleRoomMessage right after the !oc trigger prefix and before the @user:server mention check. It accepts an optional leading @, is case-insensitive, and allows either a colon or whitespace as the separator.
  • Removed the hardcoded ^@?bot[:\s] fallback, which is now redundant whenever botName matches (and was never reachable when it didn't).

Trigger order after this change

  1. !oc (or MATRIX_TRIGGER / config.trigger override)
  2. botname: (new, configurable)
  3. @user:server mention of the bot's full Matrix ID
  4. DM fallback
  5. Implicit thread follow-up

Example

With "botName": "opencode":

  • opencode: do something -> triggers, query = "do something"
  • @Opencode do something -> triggers, query = "do something"
  • !oc do something -> still triggers as before
  • @myassistant:matrix.org do something -> triggers via mention check

Verified with tsc --noEmit, bun run check:connectors, and the existing Matrix unit + integration tests (24 pass).

Assisted-By: MiniMax-M3 via opencode 1.18.9

Resolves messages like "opencode: hello" or "@OpenCode hello"
using the existing config.botName value. The check is inserted
between the !oc trigger prefix and the @user:server mention, and is
case-insensitive with an optional leading "@". Also drops the
hardcoded "bot:" fallback which is now redundant when botName
matches.

Assisted-By: MiniMax-M3 via opencode 1.18.9
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.

2 participants