Skip to content

feat(im/convert): support content_v2 blocks in post message conversion - #1411

Merged
liujiashu-shiro merged 1 commit into
mainfrom
feat/content-v2-support
Jun 18, 2026
Merged

feat(im/convert): support content_v2 blocks in post message conversion#1411
liujiashu-shiro merged 1 commit into
mainfrom
feat/content-v2-support

Conversation

@liujiashu-shiro

@liujiashu-shiro liujiashu-shiro commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Support content_v2 post message conversion in IM shortcuts so newer post payloads render with the expected markdown, mention, and image formats while preserving fallback compatibility with legacy content.

Changes

  • Prefer non-empty content_v2 blocks when converting post messages, with fallback to legacy content.
  • Add rendering support for md post elements.
  • Update mention rendering to preserve <at user_id="...">...</at> format when user IDs are available.
  • Update image rendering to markdown image syntax.
  • Add unit coverage for content_v2 selection, fallback behavior, md, mention, and image rendering.

Test Plan

  • go test ./shortcuts/im/convert_lib
  • make unit-test
  • Manual local verification confirms the lark-cli im <command> flow works as expected

Related Issues

  • None

Summary by CodeRabbit

  • New Features
    • Rich-text message rendering now prefers newer content blocks when available, falling back to the original content when needed.
    • Mentions rendering was refined: @all is rendered via an explicit <at user_id="all"></at> token, and ou*/name combinations follow consistent <at ...></at> output rules (with name-only and id-only handled distinctly).
    • Image placeholders now render as Markdown (![Image](img_xxx)), with a separate fallback when no image key exists.
    • Inline Markdown is preserved verbatim, including embedded <at ...></at> markup.
  • Documentation
    • Updated image placeholder examples across message list, search, threads, enrichment, and resource download guidance.
  • Tests
    • Updated and expanded tests for mention/image rendering and for selecting content_v2 vs content.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 40474dab-1357-4b65-8988-772b7c8b638d

📥 Commits

Reviewing files that changed from the base of the PR and between da5df0b and 6b0ec80.

📒 Files selected for processing (8)
  • shortcuts/im/convert_lib/helpers_test.go
  • shortcuts/im/convert_lib/text.go
  • shortcuts/im/convert_lib/text_test.go
  • skills/lark-im/references/lark-im-chat-messages-list.md
  • skills/lark-im/references/lark-im-message-enrichment.md
  • skills/lark-im/references/lark-im-messages-mget.md
  • skills/lark-im/references/lark-im-messages-search.md
  • skills/lark-im/references/lark-im-threads-messages-list.md
✅ Files skipped from review due to trivial changes (2)
  • skills/lark-im/references/lark-im-messages-mget.md
  • skills/lark-im/references/lark-im-messages-search.md
🚧 Files skipped from review as they are similar to previous changes (6)
  • skills/lark-im/references/lark-im-message-enrichment.md
  • skills/lark-im/references/lark-im-chat-messages-list.md
  • skills/lark-im/references/lark-im-threads-messages-list.md
  • shortcuts/im/convert_lib/helpers_test.go
  • shortcuts/im/convert_lib/text.go
  • shortcuts/im/convert_lib/text_test.go

📝 Walkthrough

Walkthrough

Updated post rendering to prefer content_v2 blocks via new selectContentBlocks helper, and changed rich-text element output: mentions emit <at> tags with user IDs (special-casing @_all), images use Markdown syntax ![Image](...), and markdown elements pass through their text. Tests and documentation updated throughout.

Changes

Post Rendering with Content Block Selection

Layer / File(s) Summary
Element rendering format updates
shortcuts/im/convert_lib/text.go, shortcuts/im/convert_lib/text_test.go, shortcuts/im/convert_lib/helpers_test.go
renderPostElem changes output format for "at" mentions (emits <at user_id="all"> for @_all/all, <at user_id="...">name</at> when both id and name exist, otherwise @user_id), "img" elements (Markdown ![Image](<key>) instead of [Image: ...]), and adds explicit "md" element case that returns text content. TestRenderPostElem and TestExtractPostBlocksText expectations updated for consistency.
Content block selection helper
shortcuts/im/convert_lib/text.go
New selectContentBlocks function prefers content_v2 blocks when present and non-empty, otherwise falls back to content blocks.
PostConverter integration
shortcuts/im/convert_lib/text.go, shortcuts/im/convert_lib/text_test.go
postConverter rich-text assembly loop now uses selectContentBlocks to choose blocks. TestSelectContentBlocks validates selection logic across presence/emptiness scenarios. TestPostConverterConvertContentV2 validates full conversion flow including content_v2 preference, fallback to content, and correct element rendering in both paths.
Documentation updates
skills/lark-im/references/lark-im-chat-messages-list.md, skills/lark-im/references/lark-im-message-enrichment.md, skills/lark-im/references/lark-im-messages-mget.md, skills/lark-im/references/lark-im-messages-search.md, skills/lark-im/references/lark-im-threads-messages-list.md
User-facing documentation for IM endpoints updated to reflect Markdown image syntax ![Image](img_xxx) in rendered content examples.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • larksuite/cli#893: Both PRs adjust the IM post content pipeline to represent inline images as Markdown (![Image](...))—the main PR changes convert_lib's img/rich-text rendering and tests, while the retrieved PR updates Markdown-to-post helpers to produce/handle that Markdown image rendering format.
  • larksuite/cli#1245: Both PRs modify IM post rendering in shortcuts/im/convert_lib/text.go—specifically renderPostElem behavior for post elements like "at" mention/markup rendering—so the main PR's at/img output changes connect directly to the retrieved PR's text-rendering updates.

Suggested labels

feature

Suggested reviewers

  • YangJunzhou-01

Poem

🐰 A clever rabbit hops through posts with glee,
Choosing v2 blocks when they be,
Images now markdown, mentions with care,
At-tags and md elements everywhere!
Content flows true with a fallback so fair. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% 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 accurately describes the main change: adding support for content_v2 blocks in post message conversion, which is the primary focus of the changeset.
Description check ✅ Passed The description follows the template structure with all required sections: Summary, Changes, Test Plan, and Related Issues. It provides clear details about the motivation and specific implementation changes.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/content-v2-support

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.

@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 Jun 11, 2026
@liujiashu-shiro
liujiashu-shiro force-pushed the feat/content-v2-support branch from 06004af to 721f1b9 Compare June 17, 2026 03:16
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add larksuite/cli#feat/content-v2-support -y -g

@liujiashu-shiro
liujiashu-shiro force-pushed the feat/content-v2-support branch from 721f1b9 to d0bfce5 Compare June 17, 2026 03:38

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

Actionable comments posted: 1

🤖 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/text.go`:
- Around line 131-135: The condition that checks if userId starts with "ou"
using strings.HasPrefix(userId, "ou") is too restrictive and prevents the
correct at-mention format from being rendered for valid user IDs that don't
start with "ou". Remove the strings.HasPrefix(userId, "ou") check and instead
render the <at user_id="...">...</at> format whenever userId is non-empty,
moving the else branch logic to handle only the case where userId is empty. This
ensures that any non-empty userId value will produce the proper at-mention XML
format rather than just the `@name` fallback.
🪄 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: 9b1cf6ef-d8b2-49a1-8114-37721c9540fd

📥 Commits

Reviewing files that changed from the base of the PR and between 721f1b9 and d0bfce5.

📒 Files selected for processing (8)
  • shortcuts/im/convert_lib/helpers_test.go
  • shortcuts/im/convert_lib/text.go
  • shortcuts/im/convert_lib/text_test.go
  • skills/lark-im/references/lark-im-chat-messages-list.md
  • skills/lark-im/references/lark-im-message-enrichment.md
  • skills/lark-im/references/lark-im-messages-mget.md
  • skills/lark-im/references/lark-im-messages-search.md
  • skills/lark-im/references/lark-im-threads-messages-list.md
✅ Files skipped from review due to trivial changes (6)
  • skills/lark-im/references/lark-im-threads-messages-list.md
  • skills/lark-im/references/lark-im-message-enrichment.md
  • skills/lark-im/references/lark-im-messages-search.md
  • skills/lark-im/references/lark-im-chat-messages-list.md
  • skills/lark-im/references/lark-im-messages-mget.md
  • shortcuts/im/convert_lib/helpers_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • shortcuts/im/convert_lib/text_test.go

Comment thread shortcuts/im/convert_lib/text.go
@liujiashu-shiro
liujiashu-shiro force-pushed the feat/content-v2-support branch 2 times, most recently from 1b1064d to da5df0b Compare June 17, 2026 03:52
# Conflicts:
#	shortcuts/im/convert_lib/text.go
#	shortcuts/im/convert_lib/text_test.go
@liujiashu-shiro
liujiashu-shiro force-pushed the feat/content-v2-support branch from da5df0b to 6b0ec80 Compare June 17, 2026 03:58
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.43%. Comparing base (714da97) to head (6b0ec80).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1411      +/-   ##
==========================================
+ Coverage   73.42%   73.43%   +0.01%     
==========================================
  Files         753      753              
  Lines       70111    70119       +8     
==========================================
+ Hits        51476    51489      +13     
+ Misses      14826    14823       -3     
+ Partials     3809     3807       -2     

☔ View full report in Codecov by Harness.
📢 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.

@liujiashu-shiro
liujiashu-shiro merged commit 815cdb8 into main Jun 18, 2026
22 checks passed
@liujiashu-shiro
liujiashu-shiro deleted the feat/content-v2-support branch June 18, 2026 09:53
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