Skip to content

feat(im): support file input for message content#917

Open
Mycheers wants to merge 1 commit into
larksuite:mainfrom
Mycheers:feat/im-message-content-file-stdin
Open

feat(im): support file input for message content#917
Mycheers wants to merge 1 commit into
larksuite:mainfrom
Mycheers:feat/im-message-content-file-stdin

Conversation

@Mycheers
Copy link
Copy Markdown

@Mycheers Mycheers commented May 15, 2026

Summary

Support file and stdin input for im +messages-send --content, making scripted interactive-card sends safer and less brittle than passing large JSON through one shell argument.

Changes

  • Mark --content as a file/stdin-capable input flag, enabling --content @card.json and --content -
  • Update --content help text to document the new input modes
  • Add a dry-run E2E test covering both file-backed and stdin-backed interactive content

Test Plan

  • Unit tests pass
  • Manual local verification confirms the lark xxx command works as expected
  • Not run locally: Go toolchain is not installed in this WSL environment (gofmt: command not found)

Related Issues

Summary by CodeRabbit

  • New Features

    • The --content flag for sending instant messages now supports reading message content from local files and standard input.
  • Tests

    • Added end-to-end tests verifying file and stdin input support for message content delivery.

Review Change Stack

@CLAassistant
Copy link
Copy Markdown

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 15, 2026

📝 Walkthrough

Walkthrough

The PR enables the im +messages-send command to accept message content from local files and stdin by adding input source metadata to the --content flag, and validates the feature with e2e tests covering both input paths.

Changes

Message Content Input Sources

Layer / File(s) Summary
Content flag input support
shortcuts/im/im_messages_send.go
The --content flag metadata is extended with Input: []string{common.File, common.Stdin} to declare file and stdin as valid input sources for message content.
File and stdin content e2e tests
tests/cli_e2e/im/messages_send_content_input_test.go
E2e test validates im +messages-send --dry-run with content supplied via temporary JSON file and stdin, asserting exit code, expected dry-run output substrings, and absence of content source markers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Content now flows from many streams—
Files, stdin, whatever a script dreams!
The flag declares its sources bright,
While tests ensure both paths work right.
Messages send with easier might!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 'feat(im): support file input for message content' accurately summarizes the main change in the pull request.
Description check ✅ Passed The PR description covers all required template sections: Summary, Changes, Test Plan, and Related Issues with sufficient detail.
Linked Issues check ✅ Passed The PR directly addresses issue #916 by implementing file and stdin input support for --content flag as specified in the requirements [#916].
Out of Scope Changes check ✅ Passed All code changes are directly related to the stated objective of supporting file and stdin input for message content; no unrelated modifications detected.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 May 15, 2026
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 (2)
tests/cli_e2e/im/messages_send_content_input_test.go (2)

69-74: ⚡ Quick win

Consider adding config directory isolation.

As per coding guidelines, E2E tests should use t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) to isolate config state and prevent side effects. While dry-run tests may not write config files, adding this isolation improves test reliability and follows the established pattern.

🔒 Proposed addition for config isolation
 func setDryRunConfigEnv(t *testing.T) {
 	t.Helper()
+	t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir())
 	t.Setenv("LARKSUITE_CLI_APP_ID", "cli_dryrun_test")
 	t.Setenv("LARKSUITE_CLI_APP_SECRET", "secret_dryrun_test")
 	t.Setenv("LARKSUITE_CLI_BRAND", "feishu")
 }

As per coding guidelines for test isolation.

🤖 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 `@tests/cli_e2e/im/messages_send_content_input_test.go` around lines 69 - 74,
The helper setDryRunConfigEnv should also isolate config state by setting
LARKSUITE_CLI_CONFIG_DIR to a temporary folder; update setDryRunConfigEnv to
call t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir()) alongside the existing
t.Setenv calls so tests use an isolated config directory (refer to
setDryRunConfigEnv and its existing t.Setenv uses).

30-39: 💤 Low value

Consider removing redundant DefaultAs field.

Both test cases specify "--as", "bot" in Args (lines 32, 51) and also set DefaultAs: "bot" (lines 38, 57). The explicit --as flag makes DefaultAs redundant.

♻️ Simplify by removing DefaultAs
 		result, err := clie2e.RunCmd(ctx, clie2e.Request{
 			Args: []string{"im", "+messages-send",
 				"--as", "bot",
 				"--chat-id", "oc_dryrun_chat",
 				"--msg-type", "interactive",
 				"--content", "@" + cardPath,
 				"--dry-run",
 			},
-			DefaultAs: "bot",
 		})

Apply the same change to the stdin test case (lines 49-58).

Also applies to: 49-58

🤖 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 `@tests/cli_e2e/im/messages_send_content_input_test.go` around lines 30 - 39,
The test sets the --as flag explicitly in clie2e.Request Args so the DefaultAs
field is redundant; remove the DefaultAs: "bot" entries from both RunCmd calls
in tests (the Request literal where Args include "--as", "bot") so the tests
rely on the explicit flag only and apply the same removal in the stdin test case
as well.
🤖 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 `@tests/cli_e2e/im/messages_send_content_input_test.go`:
- Around line 69-74: The helper setDryRunConfigEnv should also isolate config
state by setting LARKSUITE_CLI_CONFIG_DIR to a temporary folder; update
setDryRunConfigEnv to call t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir())
alongside the existing t.Setenv calls so tests use an isolated config directory
(refer to setDryRunConfigEnv and its existing t.Setenv uses).
- Around line 30-39: The test sets the --as flag explicitly in clie2e.Request
Args so the DefaultAs field is redundant; remove the DefaultAs: "bot" entries
from both RunCmd calls in tests (the Request literal where Args include "--as",
"bot") so the tests rely on the explicit flag only and apply the same removal in
the stdin test case as well.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 40c60319-8c87-4661-a721-80ad87d1654e

📥 Commits

Reviewing files that changed from the base of the PR and between 5778adf and b1f9e6a.

📒 Files selected for processing (2)
  • shortcuts/im/im_messages_send.go
  • tests/cli_e2e/im/messages_send_content_input_test.go

@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.92%. Comparing base (5778adf) to head (b1f9e6a).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #917   +/-   ##
=======================================
  Coverage   65.92%   65.92%           
=======================================
  Files         523      523           
  Lines       49687    49687           
=======================================
  Hits        32757    32757           
  Misses      14131    14131           
  Partials     2799     2799           

☔ 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@b1f9e6aedf80d5e4833e4743b4f81d55944592e2

🧩 Skill update

npx skills add Mycheers/cli#feat/im-message-content-file-stdin -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.

Support file/stdin content for interactive card sends

2 participants