Skip to content

feat(im): show bot sender display names when reading messages#1829

Merged
YangJunzhou-01 merged 1 commit into
larksuite:mainfrom
sammi-bytedance:feat/im-bot-sender-name
Jul 13, 2026
Merged

feat(im): show bot sender display names when reading messages#1829
YangJunzhou-01 merged 1 commit into
larksuite:mainfrom
sammi-bytedance:feat/im-bot-sender-name

Conversation

@sammi-bytedance

@sammi-bytedance sammi-bytedance commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

When reading messages, the CLI now shows a display name for bot senders as well as users (previously only users resolved). Names come solely from the server: the CLI opts in with with_sender_name=true and reads the returned sender_name / sender_i18n_names for both users and bots, with open_bot_id passthrough and a graceful fallback to the sender id. There is no contact/mention fallback and no new permission scope.

Changes

  • convert_lib: read the server-provided sender_name / sender_i18n_names for both user and bot senders (pickSenderName, i18n by locale); open_bot_id passes through the whole sender object. The previous contact-batch and mention-based resolution is removed — a sender the server does not name falls back to its id.
  • with_sender_name=true opt-in: added to chat-messages-list / messages-mget / messages-search / threads-messages-list, and to the inline fetches that render nested senders — merge_forward sub-messages and auto-expanded thread replies — so senders that appear only inside those nested views also get named.
  • Read commands: fall back to the sender id when no name is available (shared senderDisplay helper). System messages (msg_type: system) show no sender name, as expected.
  • Docs: rewrite the "Sender Name Resolution" section in the lark-im skill (template + generated) and add a CHANGELOG entry.

Test Plan

  • Unit tests pass: go test ./shortcuts/im ./shortcuts/im/convert_lib (user+bot display, id fallback, system messages, i18n selection, open_bot_id passthrough, with_sender_name on all four commands + merge_forward / thread-reply inline fetches)
  • go build ./... / go vet / gofmt clean
  • Manual local verification against a real conversation containing bot messages

Related Issues

  • None

Summary by CodeRabbit

  • New Features
    • Message lists, search, and fetch results now show sender display names directly when provided by the server.
    • Bot messages can include an optional bot identifier in JSON output.
  • Bug Fixes
    • Sender names now fall back to a sender ID when no display name is available.
    • System messages no longer appear as missing-name errors.
  • Documentation
    • Updated message-handling docs and changelog to reflect the latest sender-name behavior.

@github-actions github-actions Bot added domain/im PR touches the im domain size/M Single-domain feat or fix with limited business impact labels Jul 9, 2026
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds server-side sender-name resolution to Lark IM shortcuts: query parameters request with_sender_name, a new senderDisplay helper renders sender fields, pickSenderName prefers producer-supplied sender_name/sender_i18n_names over contact-API lookups, and documentation/tests are updated accordingly.

Changes

Sender name resolution feature

Layer / File(s) Summary
Producer name picking and resolution logic
shortcuts/im/convert_lib/helpers.go, shortcuts/im/convert_lib/helpers_test.go
Adds pickSenderName with locale-priority (zh_cn, en_us) and sorted fallback; updates ResolveSenderNames (signature changed to require cache map[string]string) to harvest producer-provided names before batch contact resolution; updates AttachSenderNames to prefer producer names; adds tests covering precedence, contact-skip behavior, and system-message handling.
senderDisplay helper and command wiring
shortcuts/im/sender_display.go, shortcuts/im/sender_display_test.go, shortcuts/im/helpers.go, shortcuts/im/im_chat_messages_list.go, shortcuts/im/im_messages_mget.go, shortcuts/im/im_messages_search.go, shortcuts/im/im_threads_messages_list.go, shortcuts/im/builders_test.go, shortcuts/im/coverage_additional_test.go, shortcuts/im/with_sender_name_test.go
Adds senderDisplay (name-then-id fallback) and wires it into row rendering for chat-messages-list, mget, search, and threads-messages-list; adds with_sender_name=true query parameter to chat-messages-list, threads-messages-list, and mget URL builder; updates and adds tests validating URL/query param behavior.
Changelog and skill documentation updates
CHANGELOG.md, skill-template/domains/im.md, skills/lark-im/SKILL.md
Documents server-provided sender-name resolution, removed bot scope requirement, id fallback, optional open_bot_id in JSON output, and system-message exceptions.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Command as IM Shortcut Command
  participant LarkAPI as Lark Server API
  participant ResolveSenderNames
  participant ContactAPI as Contact API
  participant senderDisplay

  Command->>LarkAPI: request messages with with_sender_name=true
  LarkAPI-->>Command: messages with sender_name/sender_i18n_names
  Command->>ResolveSenderNames: harvest sender names from messages
  ResolveSenderNames->>ResolveSenderNames: pickSenderName (producer names)
  alt name missing for user sender
    ResolveSenderNames->>ContactAPI: batch resolve remaining ou_ ids
    ContactAPI-->>ResolveSenderNames: resolved names
  end
  ResolveSenderNames-->>Command: nameMap
  Command->>senderDisplay: render sender (name or id fallback)
  senderDisplay-->>Command: display string
  Command-->>Command: render output row
Loading

Suggested labels: feature

Suggested reviewers: YangJunzhou-01

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly matches the main change: showing bot sender display names when reading IM messages.
Description check ✅ Passed The description follows the required template with Summary, Changes, Test Plan, and Related Issues sections filled in.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
shortcuts/im/im_messages_mget.go (1)

114-118: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting the sender-row logic into a shared helper.

This exact block (sender type-assert → senderDisplay → conditional row["sender"] assignment) is duplicated verbatim in im_messages_search.go (lines 220-224) and im_threads_messages_list.go (lines 144-148). Consider adding a small helper alongside senderDisplay (e.g. attachSenderRow(row, msg)) in sender_display.go and calling it from all three sites to avoid triplicated logic.

♻️ Proposed helper (add to sender_display.go, then call from each shortcut)
// attachSenderRow sets row["sender"] from msg's sender field using senderDisplay,
// leaving it unset when neither a name nor an id is available.
func attachSenderRow(row, msg map[string]interface{}) {
	if sender, ok := msg["sender"].(map[string]interface{}); ok {
		if disp := senderDisplay(sender); disp != "" {
			row["sender"] = disp
		}
	}
}
-				if sender, ok := msg["sender"].(map[string]interface{}); ok {
-					if disp := senderDisplay(sender); disp != "" {
-						row["sender"] = disp
-					}
-				}
+				attachSenderRow(row, msg)
🤖 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/im_messages_mget.go` around lines 114 - 118, The sender-to-row
mapping block is duplicated across multiple IM shortcut files, so extract it
into a shared helper near senderDisplay. Add a small helper such as
attachSenderRow(row, msg) in sender_display.go that performs the sender type
assertion, calls senderDisplay, and conditionally sets row["sender"], then
replace the repeated inline block in im_messages_mget.go, im_messages_search.go,
and im_threads_messages_list.go with calls to that helper.
🤖 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/im_messages_mget.go`:
- Around line 114-118: The sender-to-row mapping block is duplicated across
multiple IM shortcut files, so extract it into a shared helper near
senderDisplay. Add a small helper such as attachSenderRow(row, msg) in
sender_display.go that performs the sender type assertion, calls senderDisplay,
and conditionally sets row["sender"], then replace the repeated inline block in
im_messages_mget.go, im_messages_search.go, and im_threads_messages_list.go with
calls to that helper.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0f4f23df-a31f-444b-a53c-f9c16c467600

📥 Commits

Reviewing files that changed from the base of the PR and between 74d8458 and 314ed67.

📒 Files selected for processing (15)
  • CHANGELOG.md
  • shortcuts/im/builders_test.go
  • shortcuts/im/convert_lib/helpers.go
  • shortcuts/im/convert_lib/helpers_test.go
  • shortcuts/im/coverage_additional_test.go
  • shortcuts/im/helpers.go
  • shortcuts/im/im_chat_messages_list.go
  • shortcuts/im/im_messages_mget.go
  • shortcuts/im/im_messages_search.go
  • shortcuts/im/im_threads_messages_list.go
  • shortcuts/im/sender_display.go
  • shortcuts/im/sender_display_test.go
  • shortcuts/im/with_sender_name_test.go
  • skill-template/domains/im.md
  • skills/lark-im/SKILL.md

@sammi-bytedance
sammi-bytedance force-pushed the feat/im-bot-sender-name branch 6 times, most recently from d50c988 to 227ab62 Compare July 13, 2026 08:14
@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@f5e47c7ad5a63bb2b91181933de67db74edb8893

🧩 Skill update

npx skills add sammi-bytedance/larksuite-cli#feat/im-bot-sender-name -y -g

Read the server-provided sender_name for both user and bot senders (previously
only users resolved) so message-read commands display bot names instead of raw
ids. The CLI opts into server-side name filling by sending with_sender_name=true
on chat-messages-list, threads-messages-list, messages-mget and messages-search,
as well as on the inline fetches that render nested senders: merge_forward
sub-messages and auto-expanded thread replies. Without it those nested-only
senders carry no sender_name and, with no fallback, render as raw ids.

Names come solely from the server (single source of truth): there is no contact
or mention fallback, so the contact scope is dropped from these four commands and
the contact/mention resolution code is removed. A sender the server does not name
falls back to its id; system messages show no name. The resolved name is exposed
in the existing `name` field (backward compatible); the duplicate raw
`sender_name` is stripped while the full `sender_i18n_names` map and `open_bot_id`
are preserved for consumers. No new permission scope is required. Updates the
lark-im skill docs.
@sammi-bytedance
sammi-bytedance force-pushed the feat/im-bot-sender-name branch from 227ab62 to f5e47c7 Compare July 13, 2026 08:38
@YangJunzhou-01
YangJunzhou-01 merged commit 7675185 into larksuite:main Jul 13, 2026
33 checks passed
@liangshuo-1 liangshuo-1 mentioned this pull request Jul 13, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/im PR touches the im domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants