Skip to content

feat: support user access token for im file and image upload#474

Merged
YangJunzhou-01 merged 1 commit intolarksuite:mainfrom
chenxingtong-bytedance:feat/support_uat_upload_file
Apr 16, 2026
Merged

feat: support user access token for im file and image upload#474
YangJunzhou-01 merged 1 commit intolarksuite:mainfrom
chenxingtong-bytedance:feat/support_uat_upload_file

Conversation

@chenxingtong-bytedance
Copy link
Copy Markdown
Contributor

@chenxingtong-bytedance chenxingtong-bytedance commented Apr 14, 2026

Summary

The /open-apis/im/v1/images and /open-apis/im/v1/files APIs now support User Access Token (UAT) in addition to Tenant Access Token (TAT). Previously the upload helpers forced bot identity unconditionally; this PR aligns them with the surrounding shortcut's --as flag so uploads and sends share the same identity.

Changes

  • shortcuts/im/helpers.go: replace DoAPIAsBot with DoAPI in all four upload helpers (uploadImageToIM, uploadFileToIM, uploadImageFromReader, uploadFileFromReader) so they respect the runtime identity instead of always using TAT
  • shortcuts/common/runner.go: remove the stale "e.g. image/file upload" example from the DoAPIAsBot doc comment
  • skills/lark-im/references/lark-im-messages-send.md: update note to reflect that upload and send now use the same identity
  • skills/lark-im/references/lark-im-messages-reply.md: same doc fix as above

Test Plan

  • make unit-test passed
  • Manual verification with --as user:
    • lark-cli im +messages-send --user-id ou_xxx --image ./photo.png --as user
    • lark-cli im +messages-send --user-id ou_xxx --file ./doc.pdf --as user
    • Confirmed upload and send both use UAT
  • Existing --as bot behavior unchanged (still uses TAT)

Related Issues

Closes #

Summary by CodeRabbit

  • Bug Fixes

    • Lark IM media uploads (images, files, video, audio) now use consistent authentication identity for both upload and send operations.
  • Documentation

    • Updated media upload behavior documentation in Lark IM references.

@github-actions github-actions Bot added domain/im PR touches the im domain size/L Large or sensitive change across domains or core paths labels Apr 14, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

The pull request updates Feishu IM media upload requests to use runtime identity instead of bot identity, with corresponding documentation updates clarifying that upload and send operations now use consistent identity throughout the shortcut execution.

Changes

Cohort / File(s) Summary
Identity handling in media uploads
shortcuts/im/helpers.go
Switched media upload execution from DoAPIAsBot() to DoAPI() in four helper functions (uploadImageToIM, uploadFileToIM, uploadImageFromReader, uploadFileFromReader), changing uploads to use runtime identity instead of bot identity.
DoAPIAsBot documentation
shortcuts/common/runner.go
Updated documentation comment for DoAPIAsBot to broaden use case description from "bot-only APIs" to "APIs that must always be called with TAT".
Media upload identity documentation
skills/lark-im/references/lark-im-messages-reply.md, skills/lark-im/references/lark-im-messages-send.md
Clarified that media uploads and send operations now use the same identity throughout (UAT for --as user, TAT for --as bot), replacing prior description of identity split between upload and send steps.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • sammi-bytedance
  • YangJunzhou-01

Poem

🐰 A rabbit hops through code with glee,
Identity flows consistently—
Bot or user, now they know,
Same throughout, the uploads go!
Documentation shines so bright,
API calls now get it right! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: enabling user access token support for IM file and image upload operations, which aligns with the core objective of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The PR description is comprehensive and well-structured, covering all required template sections with clear details about motivation, specific code changes, and test verification.

✏️ 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.

@chenxingtong-bytedance chenxingtong-bytedance force-pushed the feat/support_uat_upload_file branch from 14155c0 to 30ea80e Compare April 14, 2026 13:03
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.

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

1134-1138: Please add explicit --as user upload-path tests.

Given this behavior change, it would be good to add coverage that asserts image/file upload requests use user identity in user mode (not bot-forced), alongside existing bot-path tests.

Also applies to: 1175-1179, 1203-1207, 1235-1239

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@shortcuts/im/helpers.go` around lines 1134 - 1138, Add explicit tests
asserting that upload requests use the user identity when running in "user"
mode: for each runtime.DoAPI call that uploads files (the ApiReq with ApiPath
"/open-apis/im/v1/images" and other similar calls at the other locations using
larkcore.WithFileUpload()), create a test that invokes the command with "--as
user" and asserts the outgoing request path/headers reflect user identity (not
bot-forced). Locate the calls to runtime.DoAPI/ApiReq and WithFileUpload() in
shortcuts/im/helpers.go (lines around the shown diffs and the other groups at
~1175-1179, ~1203-1207, ~1235-1239), add corresponding upload-path tests (naming
them e.g. TestUpload_AsUser_UsesUserPath) that mirror existing bot-path tests
but pass "--as user" and verify the request target/identity accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@shortcuts/im/helpers.go`:
- Around line 1134-1138: Add explicit tests asserting that upload requests use
the user identity when running in "user" mode: for each runtime.DoAPI call that
uploads files (the ApiReq with ApiPath "/open-apis/im/v1/images" and other
similar calls at the other locations using larkcore.WithFileUpload()), create a
test that invokes the command with "--as user" and asserts the outgoing request
path/headers reflect user identity (not bot-forced). Locate the calls to
runtime.DoAPI/ApiReq and WithFileUpload() in shortcuts/im/helpers.go (lines
around the shown diffs and the other groups at ~1175-1179, ~1203-1207,
~1235-1239), add corresponding upload-path tests (naming them e.g.
TestUpload_AsUser_UsesUserPath) that mirror existing bot-path tests but pass
"--as user" and verify the request target/identity accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9d375c91-efe6-43f4-a8fa-b8ba0a80cd39

📥 Commits

Reviewing files that changed from the base of the PR and between fe41234 and 14155c0.

📒 Files selected for processing (4)
  • shortcuts/common/runner.go
  • shortcuts/im/helpers.go
  • skills/lark-im/references/lark-im-messages-reply.md
  • skills/lark-im/references/lark-im-messages-send.md

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)
cmd/root.go (1)

328-331: Use centralized endpoint resolution here to prevent host drift.

This local brand/host branch duplicates endpoint selection logic. Consider deriving the host from the shared endpoint resolver so future domain transitions only need one change point.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/root.go` around lines 328 - 331, The host selection currently duplicates
logic via the local branch using host and cfg.Brand; replace this with the
centralized endpoint resolver: remove the host := ... / if cfg.Brand == "lark"
... block and obtain the host by calling the shared resolver function (e.g.,
endpointResolver.Resolve(cfg.Brand) or GetHostForBrand(cfg.Brand)) so host is
derived from the single source of truth; ensure any error or fallback handling
used by the resolver is preserved when assigning host.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/root.go`:
- Line 328: Update the test expectations that still assert the old domain
"open.feishu.cn" to match the new default host "open.feishu-pre.cn" introduced
by changing host in cmd/root.go; specifically update assertions in the tests
referenced (e.g., those in root_integration_test.go and types_test.go) to expect
"open.feishu-pre.cn" wherever they compare against the console host or default
endpoint string (search for "open.feishu.cn" in tests and replace with
"open.feishu-pre.cn").

---

Nitpick comments:
In `@cmd/root.go`:
- Around line 328-331: The host selection currently duplicates logic via the
local branch using host and cfg.Brand; replace this with the centralized
endpoint resolver: remove the host := ... / if cfg.Brand == "lark" ... block and
obtain the host by calling the shared resolver function (e.g.,
endpointResolver.Resolve(cfg.Brand) or GetHostForBrand(cfg.Brand)) so host is
derived from the single source of truth; ensure any error or fallback handling
used by the resolver is preserved when assigning host.
🪄 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: 9d9bd82f-1388-4a7b-a9f8-ed4b14ba2498

📥 Commits

Reviewing files that changed from the base of the PR and between 14155c0 and 30ea80e.

📒 Files selected for processing (6)
  • cmd/root.go
  • internal/core/types.go
  • shortcuts/common/runner.go
  • shortcuts/im/helpers.go
  • skills/lark-im/references/lark-im-messages-reply.md
  • skills/lark-im/references/lark-im-messages-send.md
✅ Files skipped from review due to trivial changes (3)
  • skills/lark-im/references/lark-im-messages-send.md
  • internal/core/types.go
  • shortcuts/common/runner.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • skills/lark-im/references/lark-im-messages-reply.md
  • shortcuts/im/helpers.go

Comment thread cmd/root.go Outdated
@chenxingtong-bytedance chenxingtong-bytedance force-pushed the feat/support_uat_upload_file branch from 30ea80e to 7a62872 Compare April 15, 2026 10:01
… send the resource message

Change-Id: I3d7fd528dd30fef9aea2d88100ceb03db4c7c3ac
@chenxingtong-bytedance chenxingtong-bytedance force-pushed the feat/support_uat_upload_file branch from 7a62872 to e8c3637 Compare April 15, 2026 12:06
@github-actions
Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add chenxingtong-bytedance/cli#feat/support_uat_upload_file -y -g

@YangJunzhou-01 YangJunzhou-01 merged commit 656c16a into larksuite:main Apr 16, 2026
14 checks passed
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/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants