Skip to content

fix(feishu): reply inside thread for P2P direct messages#64

Open
BingqingLyu wants to merge 1 commit intomainfrom
fork-pr-38808-fix-feishu-p2p-thread-reply
Open

fix(feishu): reply inside thread for P2P direct messages#64
BingqingLyu wants to merge 1 commit intomainfrom
fork-pr-38808-fix-feishu-p2p-thread-reply

Conversation

@BingqingLyu
Copy link
Copy Markdown
Owner

@BingqingLyu BingqingLyu commented Apr 27, 2026

Summary

  • Fix bot replying outside thread in P2P (direct message) chats when user sends a message inside a Feishu thread
  • Distinguish between thread messages (thread_id present) and plain quote replies (root_id only) per the Feishu API contract
  • Group chat behavior is completely unchanged — the new condition requires isDirect=true

Fixes openclaw#38806

Changes

Four targeted changes in extensions/feishu/src/bot.ts, all gated by directThreadMessage = isDirect && Boolean(ctx.threadId):

Parameter Before (P2P) After (P2P thread) After (P2P non-thread)
replyInThread false true false (unchanged)
replyTargetMessageId ctx.messageId ctx.rootId ctx.messageId (unchanged)
threadReply false true false (unchanged)
skipReplyToInMessages true false true (unchanged)

Test plan

  • Added test: P2P thread message (thread_id present) → replies to root with replyInThread=true
  • Added test: P2P plain reply (root_id only, no thread_id) → replies to triggering message with replyInThread=false
  • All 54 existing feishu bot tests pass
  • Manual verification: send message in P2P thread, confirm bot replies inside thread

When a user sends a message inside a Feishu thread (话题) in a P2P
chat, the bot's reply was incorrectly sent outside the thread as a
standalone message. This was caused by PR openclaw#33789 which fixed group
reply targeting (openclaw#32980) but inadvertently broke P2P thread replies
by gating all thread-aware logic behind isGroup checks.

The fix distinguishes between two P2P scenarios based on the Feishu
API contract (thread_id present = thread message, root_id only =
quote reply):

- P2P thread messages (thread_id present): reply to root_id with
  reply_in_thread=true so the response stays in the thread.
- P2P plain replies (root_id only, no thread_id): reply to the
  triggering message as before.

Group chat behavior is completely unchanged — the new condition
(directThreadMessage) requires isDirect=true, which is always false
for groups.

Changes:
- replyInThread: true for P2P thread messages (enables reply_in_thread API flag)
- replyTargetMessageId: use root_id for P2P thread messages
- threadReply: true for P2P thread messages (drives effectiveReplyInThread in dispatcher)
- skipReplyToInMessages: false for P2P thread messages (so send layer
  uses im.message.reply instead of im.message.create)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: bot replies outside thread in P2P direct message thread

2 participants