mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
fix(feishu): stop automatic mention cascades (#71396)
Fix Feishu inbound mention targets being carried into outbound replies, with regression coverage for text, card, and streaming-card paths.\n\nThanks @MonkeyLeeT and @AxelHu.
This commit is contained in:
@@ -292,6 +292,21 @@ export function parseFeishuMessageEvent(
|
||||
return ctx;
|
||||
}
|
||||
|
||||
const MAX_MENTION_CONTEXT_NAME_LENGTH = 80;
|
||||
|
||||
function formatMentionNameForAgentContext(name: string): string {
|
||||
const stripped = Array.from(name, (char) => {
|
||||
const code = char.charCodeAt(0);
|
||||
return code < 0x20 || char === "[" || char === "]" ? " " : char;
|
||||
}).join("");
|
||||
const normalized = stripped.replace(/\s+/g, " ").trim();
|
||||
const bounded =
|
||||
normalized.length > MAX_MENTION_CONTEXT_NAME_LENGTH
|
||||
? `${normalized.slice(0, MAX_MENTION_CONTEXT_NAME_LENGTH - 3)}...`
|
||||
: normalized;
|
||||
return JSON.stringify(bounded || "unknown");
|
||||
}
|
||||
|
||||
export function buildFeishuAgentBody(params: {
|
||||
ctx: Pick<
|
||||
FeishuMessageContext,
|
||||
@@ -322,8 +337,10 @@ export function buildFeishuAgentBody(params: {
|
||||
}
|
||||
|
||||
if (ctx.mentionTargets && ctx.mentionTargets.length > 0) {
|
||||
const targetNames = ctx.mentionTargets.map((t) => t.name).join(", ");
|
||||
messageBody += `\n\n[System: Your reply will automatically @mention: ${targetNames}. Do not write @xxx yourself.]`;
|
||||
const targetNames = ctx.mentionTargets
|
||||
.map((t) => formatMentionNameForAgentContext(t.name))
|
||||
.join(", ");
|
||||
messageBody += `\n\n[System: Feishu users mentioned in the incoming message, for context only: ${targetNames}. Do not notify or mention these users solely because they are listed here.]`;
|
||||
}
|
||||
|
||||
// Keep message_id on its own line so shared message-id hint stripping can parse it reliably.
|
||||
@@ -1383,7 +1400,6 @@ export async function handleFeishuMessage(params: {
|
||||
replyInThread,
|
||||
rootId: ctx.rootId,
|
||||
threadReply,
|
||||
mentionTargets: ctx.mentionTargets,
|
||||
accountId: account.accountId,
|
||||
identity,
|
||||
messageCreateTimeMs,
|
||||
@@ -1550,7 +1566,6 @@ export async function handleFeishuMessage(params: {
|
||||
replyInThread,
|
||||
rootId: ctx.rootId,
|
||||
threadReply,
|
||||
mentionTargets: ctx.mentionTargets,
|
||||
accountId: account.accountId,
|
||||
identity,
|
||||
messageCreateTimeMs,
|
||||
|
||||
Reference in New Issue
Block a user