Skip to content

feat: add auto-pagination to messages search and update lark-im docs#30

Merged
liangshuo-1 merged 2 commits intolarksuite:mainfrom
YangJunzhou-01:feat/search_msg
Mar 30, 2026
Merged

feat: add auto-pagination to messages search and update lark-im docs#30
liangshuo-1 merged 2 commits intolarksuite:mainfrom
YangJunzhou-01:feat/search_msg

Conversation

@YangJunzhou-01
Copy link
Copy Markdown
Collaborator

Summary

This PR adds auto-pagination support to im +messages-search and updates the related lark-im docs to match the new behavior.

The change keeps the default behavior unchanged for existing users:

  • default remains single-page
  • users can opt into auto-pagination with --page-all
  • users can set an explicit cap with --page-limit <n>

Background

im +messages-search previously returned only a single page of results unless callers manually resumed with --page-token.

That was workable for simple lookups, but it was awkward for:

  • work summary / weekly report generation
  • broad keyword searches across active chats
  • cases where search results exceeded one page and callers needed a complete dataset

This PR addresses that gap while preserving backward compatibility.

What Changed

1. Add auto-pagination to im +messages-search

New flags:

  • --page-all
  • --page-limit <n>

Behavior:

  • default is still single-page
  • --page-all enables auto-pagination with a max cap of 40 pages
  • --page-limit <n> enables auto-pagination with an explicit cap
  • passing --page-limit without --page-all still enables auto-pagination
  • when pagination stops due to the configured cap, output still returns has_more / page_token so callers can resume manually

2. Keep large follow-up fetches batched

Search execution now:

  1. fetches message search pages
  2. batch-fetches message details via messages/mget in chunks of up to 50 IDs
  3. batch-fetches chat context via chats/batch_query in chunks of up to 50 chat IDs

This keeps the implementation aligned with downstream API limits and makes multi-page search results usable in practice.

3. Improve dry-run / help text

Dry-run output now reflects:

  • whether auto-pagination is enabled
  • the effective page cap
  • that message detail and chat-context enrichment happen in batches

Shortcut description and help text were also updated to mention:

  • auto-pagination support
  • batched mget / chat context enrichment

4. Update lark-im docs

Updated:

  • skills/lark-im/SKILL.md
  • skills/lark-im/references/lark-im-messages-search.md

Docs now cover:

  • --page-all / --page-limit
  • pagination behavior and resume strategy
  • report-generation guidance for multi-page search
  • actual p2p output fields

Also corrected the p2p field description to match current implementation:

  • chat_name is documented for group chats
  • chat_partner for p2p is documented as containing open_id

Compatibility / Behavior Notes

  • No breaking change to default behavior: single-page remains the default.
  • Existing manual pagination with --page-token continues to work.
  • --page-limit is validated as an integer in the range 1..40.
  • Pretty output shows a warning when results were truncated by the configured page cap.

Tests

Added / updated coverage for:

  • invalid --page-limit validation
  • pagination config behavior
  • dry-run output shape
  • execute path with multi-page search
  • batched mget calls
  • batched batch_query calls
  • explicit --page-limit without --page-all

Test command:

go test ./shortcuts/im/...

## Example Usage

# default: single page
lark-cli im +messages-search --query "incident"

# fetch automatically up to the default auto-pagination cap
lark-cli im +messages-search --query "incident" --page-all --format json

# fetch automatically with an explicit cap
lark-cli im +messages-search --query "incident" --page-limit 5 --format json

# resume manually if capped response still has_more=true
lark-cli im +messages-search --query "incident" --page-token <token> --format json

@YangJunzhou-01 YangJunzhou-01 changed the title feat(im): add auto-pagination to messages search and update lark-im docs feat: add auto-pagination to messages search and update lark-im docs Mar 28, 2026
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 30, 2026

CLA assistant check
All committers have signed the CLA.

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 87.73585% with 13 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@62ad335). Learn more about missing BASE report.

Files with missing lines Patch % Lines
shortcuts/im/im_messages_search.go 87.73% 6 Missing and 7 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #30   +/-   ##
=======================================
  Coverage        ?   48.31%           
=======================================
  Files           ?      280           
  Lines           ?    23056           
  Branches        ?        0           
=======================================
  Hits            ?    11139           
  Misses          ?    10921           
  Partials        ?      996           

☔ 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.

@liangshuo-1 liangshuo-1 merged commit 69bcdd9 into larksuite:main Mar 30, 2026
3 checks passed
tuxedomm pushed a commit that referenced this pull request Apr 3, 2026
…30)

Change-Id: Ic50e891d2385c2e3ac902cd89d95c3db99f94050
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants