feat: resolve @user name and open_id from mentions in card format#1218
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughInteractive card rendering now resolves ChangesMention-aware interactive card rendering
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/im/convert_lib/card_test.go (1)
28-42: ⚡ Quick winAdd one end-to-end card-conversion case for mention resolution.
These tests cover
convertAtdirectly, but the new feature also depends onconvertCardforwardingmentionsand on the newjson_attachmentobject branch. A regression in either layer would still pass here. Please add a case that callsconvertCard(raw, mentions)with an object-valuedjson_attachmentand asserts the rendered@...output.Also applies to: 246-313
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@shortcuts/im/convert_lib/card_test.go` around lines 28 - 42, Add an end-to-end test that verifies convertCard forwards mentions and handles object-valued json_attachment: construct a rawCard string that includes a json_card (with body text or element that will reference a mention id) and a json_attachment object mapping that id to a person name, then call convertCard(rawCard, mentions) where mentions is the map you expect convertCard to forward (or nil if convertCard should use json_attachment), and assert the output contains the rendered `@Name` (use the same pattern as existing assertions in TestConvertCard). Reference convertCard, convertAt, json_attachment and mentions to ensure the test exercises the mention-resolution path through convertCard.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@shortcuts/im/convert_lib/card_test.go`:
- Around line 28-42: Add an end-to-end test that verifies convertCard forwards
mentions and handles object-valued json_attachment: construct a rawCard string
that includes a json_card (with body text or element that will reference a
mention id) and a json_attachment object mapping that id to a person name, then
call convertCard(rawCard, mentions) where mentions is the map you expect
convertCard to forward (or nil if convertCard should use json_attachment), and
assert the output contains the rendered `@Name` (use the same pattern as existing
assertions in TestConvertCard). Reference convertCard, convertAt,
json_attachment and mentions to ensure the test exercises the mention-resolution
path through convertCard.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b66da286-0d1b-4c56-b425-ef83f19ac220
📒 Files selected for processing (3)
shortcuts/im/convert_lib/card.goshortcuts/im/convert_lib/card_test.goshortcuts/im/convert_lib/content_convert.go
0a0caff to
c8ddaf6
Compare
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@b9e6a08535635e411ab0c9433cb92a27b7805945🧩 Skill updatenpx skills add 91-enjoy/cli#feat/card_message_format -y -g |
Change-Id: I00f846d76482adba315d07361c35909b71ca74c7
c8ddaf6 to
b9e6a08
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1218 +/- ##
==========================================
+ Coverage 69.19% 69.21% +0.01%
==========================================
Files 634 634
Lines 59482 59517 +35
==========================================
+ Hits 41161 41194 +33
- Misses 15007 15009 +2
Partials 3314 3314 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Interactive card messages (msg_type: interactive) can contain @user elements in their card body. The json_attachment.at_users field stores resolved user info, but the user_id there is the sender-side platform user_id — not the reading app's canonical open_id. When the backend populates a mention_key on each at_users entry, it signals that the API-level mentions[] array carries a more authoritative open_id and display name for the reading context. This PR adds support for this two-level lookup: it threads the raw mentions[] array into the card converter, indexes it by mention_key for O(1) access, and renders the canonical open_id + display name whenever the link is resolvable. All existing fallback paths (no mention_key, nil mentions) are preserved without behavioral change. Change-Id: I00f846d76482adba315d07361c35909b71ca74c7
Change-Id: I00f846d76482adba315d07361c35909b71ca74c7
Summary
Interactive card messages (
msg_type: interactive) can contain@userelements in their cardbody. The
json_attachment.at_usersfield stores resolved user info, but theuser_idthere isthe sender-side platform user_id — not the reading app's canonical
open_id. When the backendpopulates a
mention_keyon eachat_usersentry, it signals that the API-levelmentions[]array carries a more authoritative
open_idand display name for the reading context. This PR addssupport for this two-level lookup: it threads the raw
mentions[]array into the card converter,indexes it by
mention_keyfor O(1) access, and renders the canonicalopen_id+ display namewhenever the link is resolvable. All existing fallback paths (no
mention_key, nil mentions) arepreserved without behavioral change.
Changes
content_convert.goMentions []interface{}field toConvertContextFormatEventMessageandFormatMessageItemso the card converter can access theraw API mentions array alongside the existing
MentionMapcard.goconvertCard(raw)→convertCard(raw, mentions []interface{})and passmentionswhen the message contains ajson_cardbuildMentionsByKey(mentions)helper: produces amap[string]map[string]interface{}keyedby
mention.keyfor O(1) lookup insideconvertAtmentionsByKeyfield tocardConverter; populate it before rendering beginsconvertAt: whenat_users[key].mention_keyis non-empty, look up the mention and usemention.nameas the display name andmention.id(extracted viaextractMentionOpenId) as theopen_id@userrender output:@Name(no ID shown)@Name(ou_xxx)— shows canonical open_idmention_key, fallback):@Name(origKey)— shows the card element's at keyjson_attachmenthandling inconvertCard: previously only accepted a JSONstring; nowalso handles a pre-parsed
cardObjvalue via a type switchcard_test.goTestConvertCardcall sites to passnilas the newmentionsargumentTestConvertAtWithMentionswith four cases:@Name(ou_xxx)mention_key→@Name(user_id:xxx)(legacy path, unchanged)mention_keypresent butmentionsByKeynil → graceful degradation toat_usersdataTest Plan
make unit-testpassedTestConvertAtWithMentionscovers the four resolution paths above@user, confirmlark im chat historyrenders@Name(ou_xxx)with the correct open_idRelated Issues
N/A
Summary by CodeRabbit
Release Notes
New Features
@mentionsusing provided mention data to display canonical user information, including names and IDs.Tests