Skip to content

fix: 支持 Schema 2 card callback 中 operator.user_id 嵌套格式#505

Merged
evandance merged 1 commit into
larksuite:mainfrom
easonlh:fix/schema2-card-callback-operator
May 16, 2026
Merged

fix: 支持 Schema 2 card callback 中 operator.user_id 嵌套格式#505
evandance merged 1 commit into
larksuite:mainfrom
easonlh:fix/schema2-card-callback-operator

Conversation

@easonlh
Copy link
Copy Markdown
Contributor

@easonlh easonlh commented May 12, 2026

问题

Schema 2 的 card callback 中,operator identity 可能嵌套在 operator.user_id 下而非 operator.open_id。当前代码只读取 operator.open_id,导致 Schema 2 格式的 card button action 被静默丢弃。

对应 OpenClaw issue: openclaw/openclaw#71670

修改内容

  • src/channel/interactive-dispatch.ts:
    • FeishuCardActionTriggerEvent 接口增加 user_id 可选字段
    • extractBasics()senderOpenId 增加 operator.user_id 作为 fallback

适配背景

此修改适配 OpenClaw v2026.5.10-beta.5 中的 Feishu 相关修复。

Copy link
Copy Markdown
Collaborator

@evandance evandance left a comment

Choose a reason for hiding this comment

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

Thanks for finding this. Schema 2 card callbacks do have a different identity shape here, and the fallback direction is consistent with openclaw/openclaw#71670.

The PR is not ready as-is though: it fixes only the plugin interactive dispatch path. The same operator?.open_id callback identity read still exists in at least:

  • src/tools/ask-user-question.ts:221
  • src/tools/auto-auth.ts:757

Both are card callback handlers reached before dispatchFeishuPluginInteractiveHandler(). Under the same Schema 2 payload shape, they will still lose the operator identity. For ask-user-question, that can bypass the intended "only the asked user may answer" check when senderOpenId is missing.

Could you sweep all card callback operator identity reads and apply the fix consistently, preferably through a small shared helper? Please also add a regression test with a Schema 2 payload where the operator identity is available through operator.user_id but operator.open_id is absent.

@easonlh
Copy link
Copy Markdown
Contributor Author

easonlh commented May 15, 2026

@evandance 感谢建议,之前确实没考虑周全。
新增文件:

src/core/card-action-operator.ts — 共享 helper 函数 resolveCardCallbackOperatorId(),优先取 open_id,回退到 user_id
tests/card-action-operator.test.ts — 8 个回归测试用例
修改文件:

src/channel/interactive-dispatch.ts — 改用 helper(原有修复)
src/tools/ask-user-question.ts — 改用 helper,修复安全隐患
src/tools/auto-auth.ts — 改用 helper

@easonlh easonlh requested a review from evandance May 15, 2026 00:43
Copy link
Copy Markdown
Collaborator

@evandance evandance left a comment

Choose a reason for hiding this comment

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

Thanks for the thorough rework — the shared helper, all three sibling sites swept, and the eight test cases land exactly the asks from the prior review. The helper's location in src/core/ and the upstream-issue reference in the docstring are also right.

One adjustment before this is mergeable: the commit currently carries a Co-Authored-By: Claude Opus 4.7 <[email protected]> trailer. That doesn't match the repo's standard commit-message style — none of the recent merged commits, including AI-assisted contributions from other contributors, include Co-Authored-By trailers. Please amend the commit to drop the trailer and force-push.

Non-blocking nit: tests #6 and #8 document that {open_id: '', user_id: 'real'} returns ''. Since ask-user-question.ts:287's authorization check short-circuits on falsy senderOpenId, switching ?? to || in the helper would close that edge defensively. Up to you whether to fold that in now or as a follow-up.

@easonlh easonlh force-pushed the fix/schema2-card-callback-operator branch from 6715f8a to db44b77 Compare May 15, 2026 12:43
Schema 2 的 card callback 中,operator identity 可能嵌套在
operator.user_id 下而非 operator.open_id(openclaw/openclaw#71670)。

提取共享 helper 函数 resolveCardCallbackOperatorId(),统一处理
所有 card callback handler 中的 operator identity 解析:

- src/core/card-action-operator.ts — 共享 helper(新增)
- src/channel/interactive-dispatch.ts — 使用 helper
- src/tools/ask-user-question.ts — 使用 helper(修复安全隐患)
- src/tools/auto-auth.ts — 使用 helper

Fixes #71670
@easonlh easonlh force-pushed the fix/schema2-card-callback-operator branch from db44b77 to 526c211 Compare May 15, 2026 12:50
@easonlh easonlh requested a review from evandance May 15, 2026 12:52
Copy link
Copy Markdown
Collaborator

@evandance evandance left a comment

Choose a reason for hiding this comment

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

Thanks for the thorough rework — the shared helper, all three sibling sites covered, the eight test cases, and the proactive ??|| adoption all land cleanly. One detail isn't quite right but doesn't block this merge: test #6's title says "returns undefined" but the assertion is .toBe('') (the inline comment is correct, just the title). Approving.

@evandance evandance added bug Something isn't working channel src/channel/ — WebSocket, events, monitor, reconnection labels May 16, 2026
@evandance evandance merged commit eef7835 into larksuite:main May 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working channel src/channel/ — WebSocket, events, monitor, reconnection

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants