diff --git a/extensions/feishu/src/bot.ts b/extensions/feishu/src/bot.ts index c10f3f518..94d16257e 100644 --- a/extensions/feishu/src/bot.ts +++ b/extensions/feishu/src/bot.ts @@ -846,65 +846,13 @@ export async function handleFeishuMessage(params: { const envelopeFrom = isGroup ? `${ctx.chatId}:${ctx.senderOpenId}` : ctx.senderOpenId; - // If there's a permission error, dispatch a separate notification first + // Append permission error notice to the main message body instead of dispatching + // a separate agent turn. A separate dispatch caused the bot to reply twice — once + // for the permission notification and once for the actual user message (#27372). if (permissionErrorForAgent) { const grantUrl = permissionErrorForAgent.grantUrl ?? ""; - const permissionNotifyBody = `[System: The bot encountered a Feishu API permission error. Please inform the user about this issue and provide the permission grant URL for the admin to authorize. Permission grant URL: ${grantUrl}]`; - - const permissionBody = core.channel.reply.formatAgentEnvelope({ - channel: "Feishu", - from: envelopeFrom, - timestamp: new Date(), - envelope: envelopeOptions, - body: permissionNotifyBody, - }); - - const permissionCtx = core.channel.reply.finalizeInboundContext({ - Body: permissionBody, - BodyForAgent: permissionNotifyBody, - RawBody: permissionNotifyBody, - CommandBody: permissionNotifyBody, - From: feishuFrom, - To: feishuTo, - SessionKey: route.sessionKey, - AccountId: route.accountId, - ChatType: isGroup ? "group" : "direct", - GroupSubject: isGroup ? ctx.chatId : undefined, - SenderName: "system", - SenderId: "system", - Provider: "feishu" as const, - Surface: "feishu" as const, - MessageSid: `${ctx.messageId}:permission-error`, - Timestamp: Date.now(), - WasMentioned: false, - CommandAuthorized: commandAuthorized, - OriginatingChannel: "feishu" as const, - OriginatingTo: feishuTo, - }); - - const { - dispatcher: permDispatcher, - replyOptions: permReplyOptions, - markDispatchIdle: markPermIdle, - } = createFeishuReplyDispatcher({ - cfg, - agentId: route.agentId, - runtime: runtime as RuntimeEnv, - chatId: ctx.chatId, - replyToMessageId: ctx.messageId, - accountId: account.accountId, - }); - - log(`feishu[${account.accountId}]: dispatching permission error notification to agent`); - - await core.channel.reply.dispatchReplyFromConfig({ - ctx: permissionCtx, - cfg, - dispatcher: permDispatcher, - replyOptions: permReplyOptions, - }); - - markPermIdle(); + messageBody += `\n\n[System: The bot encountered a Feishu API permission error. Please inform the user about this issue and provide the permission grant URL for the admin to authorize. Permission grant URL: ${grantUrl}]`; + log(`feishu[${account.accountId}]: appending permission error notice to message body`); } const body = core.channel.reply.formatAgentEnvelope({