Skip to content

Commit 627b37e

Browse files
authored
Feishu: honor bot mentions by ID despite aliases (Fixes openclaw#36317) (openclaw#36333)
1 parent b9f3f8d commit 627b37e

2 files changed

Lines changed: 13 additions & 14 deletions

File tree

extensions/feishu/src/bot.checkBotMentioned.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ describe("parseFeishuMessageEvent – mentionedBot", () => {
7676
expect(ctx.mentionedBot).toBe(true);
7777
});
7878

79+
it("returns mentionedBot=true when bot mention name differs from configured botName", () => {
80+
const event = makeEvent("group", [
81+
{ key: "@_user_1", name: "OpenClaw Bot (Alias)", id: { open_id: BOT_OPEN_ID } },
82+
]);
83+
const ctx = parseFeishuMessageEvent(event as any, BOT_OPEN_ID, "OpenClaw Bot");
84+
expect(ctx.mentionedBot).toBe(true);
85+
});
86+
7987
it("returns mentionedBot=false when only other users are mentioned", () => {
8088
const event = makeEvent("group", [
8189
{ key: "@_user_1", name: "Alice", id: { open_id: "ou_alice" } },

extensions/feishu/src/bot.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -450,24 +450,15 @@ function formatSubMessageContent(content: string, contentType: string): string {
450450
}
451451
}
452452

453-
function checkBotMentioned(
454-
event: FeishuMessageEvent,
455-
botOpenId?: string,
456-
botName?: string,
457-
): boolean {
453+
function checkBotMentioned(event: FeishuMessageEvent, botOpenId?: string): boolean {
458454
if (!botOpenId) return false;
459455
// Check for @all (@_all in Feishu) — treat as mentioning every bot
460456
const rawContent = event.message.content ?? "";
461457
if (rawContent.includes("@_all")) return true;
462458
const mentions = event.message.mentions ?? [];
463459
if (mentions.length > 0) {
464-
return mentions.some((m) => {
465-
if (m.id.open_id !== botOpenId) return false;
466-
// Guard against Feishu WS open_id remapping in multi-app groups:
467-
// if botName is known and mention name differs, this is a false positive.
468-
if (botName && m.name && m.name !== botName) return false;
469-
return true;
470-
});
460+
// Rely on Feishu mention IDs; display names can vary by alias/context.
461+
return mentions.some((m) => m.id.open_id === botOpenId);
471462
}
472463
// Post (rich text) messages may have empty message.mentions when they contain docs/paste
473464
if (event.message.message_type === "post") {
@@ -768,10 +759,10 @@ export function buildBroadcastSessionKey(
768759
export function parseFeishuMessageEvent(
769760
event: FeishuMessageEvent,
770761
botOpenId?: string,
771-
botName?: string,
762+
_botName?: string,
772763
): FeishuMessageContext {
773764
const rawContent = parseMessageContent(event.message.content, event.message.message_type);
774-
const mentionedBot = checkBotMentioned(event, botOpenId, botName);
765+
const mentionedBot = checkBotMentioned(event, botOpenId);
775766
const hasAnyMention = (event.message.mentions?.length ?? 0) > 0;
776767
// In p2p, the bot mention is a pure addressing prefix with no semantic value;
777768
// strip it so slash commands like @Bot /help still have a leading /.

0 commit comments

Comments
 (0)