Skip to content

fix(feishu): restore private chat pairing replies in Lark/Feishu#31403

Merged
Takhoffman merged 2 commits intoopenclaw:mainfrom
stakeswky:fix-31351-feishu-dm-pairing-chatid
Mar 2, 2026
Merged

fix(feishu): restore private chat pairing replies in Lark/Feishu#31403
Takhoffman merged 2 commits intoopenclaw:mainfrom
stakeswky:fix-31351-feishu-dm-pairing-chatid

Conversation

@stakeswky
Copy link

Summary

Fixes a regression where Feishu/Lark private chat (p2p) users could not receive pairing replies.

In p2p events, the sender identity may be user_id (mobile delivery) while outbound message send targeting for DMs should use the conversation chat_id (or a valid open_id). After recent sender-id fallback changes, pairing reply routing used user:${ctx.senderOpenId} and could become user:<user_id>, which is not a valid open_id receive target in this flow.

This made DM onboarding/pairing appear broken while group @mention flows still worked.

Root Cause

In handleFeishuMessage() unauthorized DM pairing path, the reply target was built from sender id:

  • before: to: \user:${ctx.senderOpenId}``

With the open_id -> user_id fallback introduced for inbound sender identity, this path can now pass a user_id under the user: prefix, causing Feishu send failures and no DM response.

Fix

  • Send pairing reply back to the DM conversation itself:
    • now: to: \chat:${ctx.chatId}``

This is stable for p2p regardless of whether inbound sender id is open_id or user_id.

Tests

Added/updated tests in extensions/feishu/src/bot.test.ts:

  • replies pairing challenge to DM chat_id instead of user:sender id
  • ✅ updated existing pairing regression assertion to expect chat:oc-dm

Ran:

  • pnpm vitest run --config vitest.extensions.config.ts extensions/feishu/src/bot.test.ts extensions/feishu/src/bot.checkBotMentioned.test.ts

Closes #31351

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0cd9a780a0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

await sendMessageFeishu({
cfg,
to: `user:${ctx.senderOpenId}`,
to: `chat:${ctx.chatId}`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep pairing reply target valid for synthetic p2p events

Using chat:${ctx.chatId} here breaks the reaction fallback path when Feishu omits chat_id: resolveReactionSyntheticEvent synthesizes chat_id as p2p:${senderId} (extensions/feishu/src/monitor.account.ts:95), so this code now sends to chat:p2p:..., which normalizes to an invalid receive id and causes sendMessageFeishu to fail in pairing mode. Before this change, the same path replied via user:${ctx.senderOpenId}, which remains valid for these synthetic DM events.

Useful? React with 👍 / 👎.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

This PR fixes a regression where Feishu/Lark private chat pairing replies failed for mobile users.

After commit e0b1b48be added fallback from open_id to user_id for sender identity (to support mobile app deliveries), the pairing reply flow broke because it was sending to user:${ctx.senderOpenId}, which could now contain a user_id instead of an open_id - an invalid target for Feishu's messaging API in DM contexts.

Key changes:

  • Changed pairing reply target from user:${ctx.senderOpenId} to chat:${ctx.chatId} (line 909)
  • The chat_id is stable for p2p chats regardless of whether the sender identity is open_id or user_id
  • Added comprehensive test coverage for mobile-only user scenario
  • Main message flow was not affected - it already uses chatId for replies via the dispatcher

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • The fix is minimal, surgical, and directly addresses the root cause. The chat_id is a required field in Feishu events, so the new approach is safe. Tests cover both scenarios (mobile user_id and standard open_id). The change is isolated to the pairing reply path and doesn't affect other flows.
  • No files require special attention

Last reviewed commit: 0cd9a78

@Takhoffman Takhoffman force-pushed the fix-31351-feishu-dm-pairing-chatid branch from 0cd9a78 to 1ee4e24 Compare March 2, 2026 23:27
@Takhoffman Takhoffman merged commit 66397c2 into openclaw:main Mar 2, 2026
9 checks passed
@Takhoffman
Copy link
Contributor

PR #31403 - fix(feishu): restore private chat pairing replies in Lark/Feishu (#31403)

Merged after verification.

  • Merge commit: 66397c2
  • Verified: pnpm test -- extensions/feishu/src/bot.test.ts; pnpm build
  • Autoland updates:
    M CHANGELOG.md
  • Changelog: CHANGELOG.md updated=true required=true opt_out=false

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1ee4e24f31

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

await sendMessageFeishu({
cfg,
to: `user:${ctx.senderOpenId}`,
to: `chat:${ctx.chatId}`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid chat targeting for synthetic p2p fallback IDs

When pairing is required in DMs, this now always sends the challenge to chat:${ctx.chatId}; however, resolveReactionSyntheticEvent can synthesize chat_id as p2p:<sender> when Feishu omits chat_id (extensions/feishu/src/monitor.account.ts), so this path produces chat:p2p:..., which is normalized as a chat_id target and fails delivery. In that reaction fallback scenario, unauthorized users never receive the pairing reply, whereas the prior user:${ctx.senderOpenId} target remained valid for these synthetic DM events.

Useful? React with 👍 / 👎.

dawi369 pushed a commit to dawi369/davis that referenced this pull request Mar 3, 2026
…nclaw#31403) thanks @stakeswky

Verified:
- pnpm test -- extensions/feishu/src/bot.test.ts
- pnpm build

Co-authored-by: stakeswky <64798754+stakeswky@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
OWALabuy pushed a commit to kcinzgg/openclaw that referenced this pull request Mar 4, 2026
…nclaw#31403) thanks @stakeswky

Verified:
- pnpm test -- extensions/feishu/src/bot.test.ts
- pnpm build

Co-authored-by: stakeswky <64798754+stakeswky@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 2026
…nclaw#31403) thanks @stakeswky

Verified:
- pnpm test -- extensions/feishu/src/bot.test.ts
- pnpm build

Co-authored-by: stakeswky <64798754+stakeswky@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: In Lark, communication is only possible through group chat @ mentions and bots; private chat is not supported.

2 participants