← Back to PRs

#7842: Fix Matrix mention detection for Element client (formatted_body links)

by emadomedher open 2026-02-03 07:38 View on GitHub →
channel: matrix stale
Fixes #7840 ## Summary Adds support for detecting mentions in `formatted_body` with `matrix.to` links, enabling mention detection from Element and other clients that don't use the newer `m.mentions` field. ## Problem Element (the official Matrix client) doesn't send `m.mentions` in message events. Instead, it uses `formatted_body` with HTML links: ```html <a href="https://matrix.to/#/@bot:server">@bot:server</a> hello ``` OpenClaw only checked `m.mentions`, causing it to miss all mentions from Element users. ## Solution Added fallback logic to parse `formatted_body` and extract user IDs from `matrix.to` mention links: ```typescript // Check formatted_body for matrix.to mention links (Element compatibility) const formatted = content.formatted_body; if (formatted && content.format === 'org.matrix.custom.html') { const regex = /https?:\/\/matrix\.to\/#\/@([^"'<>\s]+)/g; let match; while ((match = regex.exec(formatted)) !== null) { mentionedUserIds.add('@' + match[1]); } } ``` ## Compatibility - ✅ Works with Element (web, desktop, mobile) - ✅ Maintains compatibility with clients using `m.mentions` - ✅ Handles both old and new mention formats ## Testing Tested with: - Element Web sending mentions - Direct mentions: `@bot:server test` - Inline mentions: `hey @bot:server how are you` - Multiple mentions in one message ## References - Matrix spec: https://spec.matrix.org/v1.11/client-server-api/#mentions - Element behavior: Uses `formatted_body` with HTML links - OpenClaw issue: #7840 <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR updates Matrix mention detection to support clients (notably Element) that don’t send `m.mentions` by also checking `formatted_body` for `matrix.to` mention links. The change is localized to `extensions/matrix/src/matrix/monitor/mentions.ts`, and the resolved `wasMentioned` flag now includes the formatted-body fallback in addition to room mentions, explicit user_ids, and text-pattern matching. <h3>Confidence Score: 4/5</h3> - This PR is generally safe to merge, but the formatted_body matching is strict enough that it may still miss common matrix.to mention link variants. - Change is small and scoped, with low regression risk because it only adds an additional OR condition. Main concern is correctness coverage: exact-string `href` matching likely fails for URL-encoded fragments and links with query params, meaning the reported fix may be incomplete for some Element/server combinations. - extensions/matrix/src/matrix/monitor/mentions.ts <!-- greptile_other_comments_section --> <sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub> <!-- /greptile_comment -->

Most Similar PRs