Fix Matrix bracketed display-name mentions (#83156) · openclaw/openclaw@37636ac
wdx-agent-io
·
2026-06-16
·
via Recent Commits to openclaw:main
File tree
extensions/matrix/src/matrix/monitor
| Original file line number | Diff line number | Diff line change |
|---|
@@ -40,6 +40,15 @@ describe("stripMatrixMentionPrefix", () => {
|
40 | 40 | expect(result).toBe("/model"); |
41 | 41 | }); |
42 | 42 | |
| 43 | +it("strips bracketed @display name syntax", () => { |
| 44 | +const result = stripMatrixMentionPrefix({ |
| 45 | +text: "@[OpenClaw Bot] /model", |
| 46 | +displayName: "OpenClaw Bot", |
| 47 | +mentionRegexes: [], |
| 48 | +}); |
| 49 | +expect(result).toBe("/model"); |
| 50 | +}); |
| 51 | + |
43 | 52 | it("returns original text when text is empty", () => { |
44 | 53 | const result = stripMatrixMentionPrefix({ |
45 | 54 | text: "", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -913,6 +913,31 @@ describe("matrix monitor handler pairing account scope", () => {
|
913 | 913 | expect(recordInboundSession).toHaveBeenCalled(); |
914 | 914 | }); |
915 | 915 | |
| 916 | +it("processes room messages mentioned via bracketed @displayName in formatted_body", async () => { |
| 917 | +const recordInboundSession = vi.fn(async () => {}); |
| 918 | +const { handler } = createMatrixHandlerTestHarness({ |
| 919 | +isDirectMessage: false, |
| 920 | +getMemberDisplayName: async () => "Display Name", |
| 921 | + recordInboundSession, |
| 922 | +}); |
| 923 | + |
| 924 | +await handler( |
| 925 | +"!room:example.org", |
| 926 | +createMatrixRoomMessageEvent({ |
| 927 | +eventId: "$bracketed-display-name-mention", |
| 928 | +content: { |
| 929 | +msgtype: "m.text", |
| 930 | +body: "@[Display Name] please reply", |
| 931 | +formatted_body: |
| 932 | +'<a href="https://matrix.to/#/@bot:example.org">@[Display Name]</a> please reply', |
| 933 | +"m.mentions": { user_ids: ["@bot:example.org"] }, |
| 934 | +}, |
| 935 | +}), |
| 936 | +); |
| 937 | + |
| 938 | +expect(recordInboundSession).toHaveBeenCalled(); |
| 939 | +}); |
| 940 | + |
916 | 941 | it("does not fetch self displayName for plain-text room mentions", async () => { |
917 | 942 | const getMemberDisplayName = vi.fn(async () => "Tom Servo"); |
918 | 943 | const { handler, recordInboundSession } = createMatrixHandlerTestHarness({ |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -228,6 +228,24 @@ describe("resolveMentions", () => {
|
228 | 228 | expect(result.hasExplicitMention).toBe(true); |
229 | 229 | }); |
230 | 230 | |
| 231 | +it("detects mention when the visible label is bracketed @displayName text", () => { |
| 232 | +const result = resolveMentions({ |
| 233 | +content: { |
| 234 | +msgtype: "m.text", |
| 235 | +body: "@[Display Name] please reply", |
| 236 | +formatted_body: |
| 237 | +'<a href="https://matrix.to/#/@bot:matrix.org">@[Display Name]</a> please reply', |
| 238 | +"m.mentions": { user_ids: ["@bot:matrix.org"] }, |
| 239 | +}, |
| 240 | + userId, |
| 241 | +displayName: "Display Name", |
| 242 | +text: "@[Display Name] please reply", |
| 243 | +mentionRegexes: [], |
| 244 | +}); |
| 245 | +expect(result.wasMentioned).toBe(true); |
| 246 | +expect(result.hasExplicitMention).toBe(true); |
| 247 | +}); |
| 248 | + |
231 | 249 | it("ignores out-of-range hexadecimal HTML entities in visible labels", () => { |
232 | 250 | expect( |
233 | 251 | resolveMentions({ |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -89,6 +89,7 @@ function resolveMatrixMentionPrefixCandidates(params: {
|
89 | 89 | append(localpart ? `@${localpart}` : null); |
90 | 90 | append(params.displayName); |
91 | 91 | append(params.displayName ? `@${params.displayName}` : null); |
| 92 | +append(params.displayName ? `@[${params.displayName}]` : null); |
92 | 93 | |
93 | 94 | return candidates; |
94 | 95 | } |
@@ -158,6 +159,7 @@ function isVisibleMentionLabel(params: {
|
158 | 159 | localpart ? extractVisibleMentionText(`@${localpart}`) : null, |
159 | 160 | params.displayName ? extractVisibleMentionText(params.displayName) : null, |
160 | 161 | params.displayName ? extractVisibleMentionText(`@${params.displayName}`) : null, |
| 162 | +params.displayName ? extractVisibleMentionText(`@[${params.displayName}]`) : null, |
161 | 163 | ].filter((value): value is string => Boolean(value)); |
162 | 164 | return candidates.includes(cleaned); |
163 | 165 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。