← Back to PRs

#20744: fix(feishu): reply under topic instead of creating new topic in topic groups [Enhanced]

by paceyw open 2026-02-19 08:14 View on GitHub →
channel: discord agents channel: feishu size: S
# PR Description ## Summary Fixes an issue where bot replies in Feishu/Lark topic groups create new topics instead of appearing as replies under the original topic. ## Problem In Feishu topic groups (话题群), when users mention the bot within an existing topic thread, the bot's response was created as a new standalone topic rather than appearing as a comment under the original topic where it was mentioned. ### Root Cause The bot used `ctx.messageId` as the `replyToMessageId` parameter when calling the Feishu message reply API. In topic groups, messages have a `root_id` field that identifies the root message of the topic thread. To reply within a topic, the API call must target the root message ID, not the specific message that triggered the response. ## Solution Use `ctx.rootId ?? ctx.messageId` instead of just `ctx.messageId` when setting `replyToMessageId`. This ensures: - When in a topic (`rootId` exists): Reply targets the topic root → appears under the topic - When not in a topic: Falls back to normal message reply behavior ## Changes ### Core Fix (Original) ```diff // extensions/feishu/src/bot.ts - replyToMessageId: ctx.messageId, + replyToMessageId: ctx.rootId ?? ctx.messageId, ``` Applied to both: 1. Normal reply dispatcher (line ~935) 2. Permission error notification dispatcher (line ~850) ### Enhanced Features (Added) - **Debug Logging**: Added `rootId` and `msgId` to message reception logs for easier debugging - **Context Enhancement**: Added `MessageThreadId` to the context payload for better thread tracking ```diff // extensions/feishu/src/bot.ts - `feishu[${account.accountId}]: received message from ${ctx.senderOpenId} in ${ctx.chatId} (${ctx.chatType})` + `feishu[${account.accountId}]: received message from ${ctx.senderOpenId} in ${ctx.chatId} (${ctx.chatType}) rootId=${ctx.rootId ?? "null"} msgId=${ctx.messageId}` // In context payload MessageSid: ctx.messageId, + MessageThreadId: ctx.rootId ?? undefined, ``` ### Streaming Card Support Updated `FeishuStreamingSession` to support reply mode: - Constructor accepts `replyToMessageId` parameter - Streaming cards now use `message.reply()` API when replying to topics - Falls back to `message.create()` for non-topic messages ## Testing - [x] Tested in Feishu topic group: Verified bot replies appear under the original topic - [x] Verified normal group behavior remains unchanged - [x] No regression in DM handling - [x] Debug logs correctly show rootId/msgId values - [x] Streaming card mode works correctly with topic replies ## Related - Fixes: Topic group replies creating new topics instead of replying under original topic - Enhanced with: Debug logging and MessageThreadId context for better observability ## Local Deployment Status ✅ **Successfully deployed and tested** on production OpenClaw instance (v2026.2.17) - Running in production since 2026-02-19 - Verified in actual Feishu topic groups - No issues reported ## Checklist - [x] Code follows project style guidelines - [x] Changes are minimal and focused - [x] No sensitive information exposed - [x] Tested locally - [x] Enhanced with debugging capabilities - [x] Production-ready --- **Example Behavior:** Before fix: ``` User: @Bot (in Topic A) → "Hello" Bot: (creates new Topic B) → "Hi there!" ``` After fix: ``` User: @Bot (in Topic A) → "Hello" Bot: (replies under Topic A) → "Hi there!" ``` **Debug Log Example:** ``` feishu[main]: received message from ou_xxx in chat:oc_xxx (group) rootId=om_x100b565xxx msgId=om_x100b5648xxx ```

Most Similar PRs