Skip to content

feat(im): resolve bot sender names in shortcuts#848

Open
os-zzw wants to merge 2 commits into
larksuite:mainfrom
os-zzw:feat_message_bot_name
Open

feat(im): resolve bot sender names in shortcuts#848
os-zzw wants to merge 2 commits into
larksuite:mainfrom
os-zzw:feat_message_bot_name

Conversation

@os-zzw
Copy link
Copy Markdown

@os-zzw os-zzw commented May 12, 2026

Summary

Enhance the bot sender name resolution for IM shortcuts and ensure the correct bot scope is applied.

Changes

  • Refactored bot sender name resolution to use the v3 /open-apis/bot/v3/bots/basic_batch API.
  • Unified the identity check by treating both "app" and "bot" as bot senders.
  • Added a fallback logic to extract the app's name from message content (e.g., welcome card).
  • Optimized resolution for the currently running bot using BotInfo() without making extra API calls.
  • Updated UserScopes and BotScopes in related IM shortcuts to include the required application:bot.basic_info:read scope.

Test Plan

  • Unit tests passed
  • Manual verification: Locally tested lark-cli im +chat-messages-list to ensure bot names are displayed correctly.

Related Issues

None

Summary by CodeRabbit

  • New Features

    • Improved resolution and display of bot/app sender names in messages, including extraction from welcome content and resolving the current runtime app’s sender.
  • Updates

    • Expanded authorization scopes to include bot basic info access for message search, retrieval, and thread listing, enabling accurate sender identification.
    • Feed-thread enrichment now resolves and attaches bot sender names before presenting messages.
  • Tests

    • Added tests validating bot/app sender resolution, batch resolution behavior, and scope declarations.
  • Documentation

    • Updated flag-list docs to note automatic enrichment with bot sender names.

Review Change Stack

@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 May 12, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 12, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7da00ae2-75b7-4d9a-bc84-dba6cdbeceda

📥 Commits

Reviewing files that changed from the base of the PR and between 1a2f157 and 2c496b9.

📒 Files selected for processing (4)
  • shortcuts/im/helpers.go
  • shortcuts/im/im_flag_list.go
  • shortcuts/im/im_flag_test.go
  • skills/lark-im/references/lark-im-flag-list.md

📝 Walkthrough

Walkthrough

Pre-resolves bot/app sender display names (from welcome HTML, bots/basic_batch, and runtime.BotInfo) before resolving users; adds the bot basic-info OAuth scope to IM shortcuts, tests bot/app resolution, attaches resolved sender names during feed-thread enrichment, and updates docs.

Changes

Bot/App Sender Resolution and Scope Declaration

Layer / File(s) Summary
Bot/App Sender Name Resolution Implementation
shortcuts/im/convert_lib/helpers.go
ResolveSenderNames now extracts app sender display names from message content via regex, collects bot/app IDs, batch-resolves them using the bots basic_batch endpoint in chunks, and falls back to runtime.BotInfo() for the current app bot. Adds helper predicates and utilities to populate the shared name cache.
Bot/App Sender Name Resolution Tests
shortcuts/im/convert_lib/helpers_test.go
Adds three tests validating: resolving the current runtime app's bot sender name while leaving unrelated app senders unresolved; batching bot open IDs through the bots basic_batch API and attaching returned names; and extracting an app sender name from welcome-card HTML content.
Bot Basic Info Scope Definition and Validation
shortcuts/im/helpers.go, shortcuts/im/helpers_test.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
Introduces botBasicInfoReadScope (application:bot.basic_info:read), appends it to flagMessageReadScopes, and adds it to affected IM shortcut UserScopes/BotScopes. Adds a test asserting the scope is declared across selected message/thread shortcuts for both identities.
Attach Resolved Sender Names in Flag List Enrichment
shortcuts/im/im_flag_list.go, shortcuts/im/im_flag_test.go
Imports convert_lib as convertlib, resolves sender names for collected byID messages with a cache via convertlib.ResolveSenderNames, applies names via convertlib.AttachSenderNames, updates dry-run scope messaging, and adds tests asserting enrichment resolves fetched bot sender names and mentions the new scope.
Docs: enrich-feed-thread behavior
skills/lark-im/references/lark-im-flag-list.md
Updates the --enrich-feed-thread parameter and response notes to document that feed-thread entries are enriched with bot sender names when possible and that enrichment calls im.messages.mget plus bot basic info resolution as needed.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ResolveSenderNames
  participant AppWelcomeExtractor
  participant BotBasicBatchAPI
  participant Runtime.BotInfo
  participant ContactBatchAPI
  Client->>ResolveSenderNames: provide messages with senders
  ResolveSenderNames->>AppWelcomeExtractor: parse welcome-card HTML for app display names
  AppWelcomeExtractor-->>ResolveSenderNames: update name cache for app senders
  ResolveSenderNames->>BotBasicBatchAPI: batch request display names for bot/app IDs
  BotBasicBatchAPI-->>ResolveSenderNames: return bot display names
  ResolveSenderNames->>Runtime.BotInfo: fetch current bot metadata
  Runtime.BotInfo-->>ResolveSenderNames: return current bot display name
  ResolveSenderNames->>ContactBatchAPI: batch request user display names for remaining IDs
  ContactBatchAPI-->>ResolveSenderNames: return user display names
  ResolveSenderNames-->>Client: messages with resolved sender names
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • larksuite/cli#770: Touches IM flag listing/enrichment flow that this PR extends with bot sender name resolution.

Suggested reviewers

  • sammi-bytedance
  • YangJunzhou-01

🐰 Bot names now bloom in sender lists bright,
I sniffed the HTML, pulled out the light,
Batched little bots, fetched names in a breeze,
Scopes set in shortcuts with elegant ease,
Hooray — senders sing clear on the message trees.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 48.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: enhancing bot sender name resolution in IM shortcuts, which is the primary objective of the PR.
Description check ✅ Passed The description includes all required template sections: Summary, Changes, Test Plan, and Related Issues. All sections are adequately filled with relevant details about the implementation and testing.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
shortcuts/im/convert_lib/helpers.go (1)

158-158: 💤 Low value

Locale-specific regex pattern.

The regex 我是\s+\*\*([^*\n]+)\*\* is hardcoded for Chinese welcome messages and won't extract bot names from messages in other locales. This is acceptable since the batch API fallback (lines 282-308) will still resolve bot names when regex extraction fails. Consider documenting this limitation if welcome card formats vary by locale.

🤖 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/helpers.go` at line 158, The regex stored in
appWelcomeNameRe (var appWelcomeNameRe =
regexp.MustCompile(`我是\s+\*\*([^*\n]+)\*\*`)) is Chinese‑locale specific; add a
concise inline comment near appWelcomeNameRe noting this limitation and that bot
name extraction will fail for other locales, and reference the fallback behavior
that resolves names via the batch API (the existing fallback block) so future
maintainers understand why the pattern is narrow and where name resolution
occurs if the regex doesn't match.
🤖 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.

Inline comments:
In `@shortcuts/im/convert_lib/helpers.go`:
- Around line 282-308: The batchResolveBots function calls a possibly incorrect
endpoint "/open-apis/bot/v3/bots/basic_batch" via runtime.DoAPIJSON; verify the
correct Lark API path or whether this is an internal/undocumented API and
replace the endpoint string and any query parameter keys (e.g., "bot_ids") with
the documented ones, or implement a safe fallback (per-ID lookup using the
documented bot info endpoint) and add proper error handling/logging around
runtime.DoAPIJSON to avoid silent failures; update only the endpoint/query usage
and error path in batchResolveBots to use the confirmed API or the fallback.

---

Nitpick comments:
In `@shortcuts/im/convert_lib/helpers.go`:
- Line 158: The regex stored in appWelcomeNameRe (var appWelcomeNameRe =
regexp.MustCompile(`我是\s+\*\*([^*\n]+)\*\*`)) is Chinese‑locale specific; add a
concise inline comment near appWelcomeNameRe noting this limitation and that bot
name extraction will fail for other locales, and reference the fallback behavior
that resolves names via the batch API (the existing fallback block) so future
maintainers understand why the pattern is narrow and where name resolution
occurs if the regex doesn't match.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ee247f48-381b-4d5d-89a3-18cf39cddfa1

📥 Commits

Reviewing files that changed from the base of the PR and between 6a8fd92 and 968b8c9.

📒 Files selected for processing (1)
  • shortcuts/im/convert_lib/helpers.go

Comment thread shortcuts/im/convert_lib/helpers.go Outdated
@os-zzw os-zzw force-pushed the feat_message_bot_name branch from 1a2f157 to 2c496b9 Compare May 13, 2026 06:09
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

❌ Patch coverage is 88.67925% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.92%. Comparing base (25c72ce) to head (2c496b9).
⚠️ Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/im/convert_lib/helpers.go 87.23% 6 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #848      +/-   ##
==========================================
+ Coverage   65.67%   65.92%   +0.25%     
==========================================
  Files         513      518       +5     
  Lines       47655    48919    +1264     
==========================================
+ Hits        31297    32250     +953     
- Misses      13652    13896     +244     
- Partials     2706     2773      +67     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add os-zzw/cli#feat_message_bot_name -y -g

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