Skip to content

feat: surface reply context and mentions in im.message.receive_v1#1798

Merged
YangJunzhou-01 merged 1 commit into
larksuite:mainfrom
91-enjoy:feat/im-message-receive-agent-fields
Jul 13, 2026
Merged

feat: surface reply context and mentions in im.message.receive_v1#1798
YangJunzhou-01 merged 1 commit into
larksuite:mainfrom
91-enjoy:feat/im-message-receive-agent-fields

Conversation

@91-enjoy

@91-enjoy 91-enjoy commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR improves the im.message.receive_v1 event output by exposing structural
metadata fields (reply context, sender type, mentions) that were previously only
available in the raw V2 envelope. It also syncs the same structural fields to the legacy
+subscribe --compact pipeline.

Changes

1. Event output enrichment (events/im/message_receive.go)

The ImMessageReceiveOutput struct is extended with seven new fields:

Field Source Description
sender_type event.sender.sender_type Sender type: user or bot
root_id event.message.root_id Root message of the reply/thread context
thread_id event.message.thread_id Thread ID, when present
reply_to event.message.parent_id Parent message of the direct reply context
mentions event.message.mentions Compact mentions with key, id, name
update_time event.message.update_time Message update time (only when ≠ create_time)
event_id header.event_id Event delivery ID (description updated to recommend message_id for dedup)

The redundant parent_id field is removed; reply_to serves as the canonical
parent message reference, aligned with im +messages-mget.

Helper functions compactMentions, stringField, and mentionOpenID are added
for safe mention extraction from the raw mentions array.

2. Old compact pipeline sync (shortcuts/event/)

The ImMessageProcessor.Transform compact mode for +subscribe --compact is
updated with the same seven fields (event_id, sender_type, root_id,
thread_id, reply_to, mentions, update_time). Existing behavior is
preserved — the interactive fallback to raw is unchanged, and the original
timestamp fallback logic (header → message create_time) is retained.

Shared helpers (stringField, mentionOpenID, compactMentions) are added to
shortcuts/event/helpers.go for reuse across processors.

Test Plan

Event output

  • go test ./events/im/...TestProcessImMessageReceive_Text verifies
    all new fields (sender_type, root_id, thread_id, reply_to, mentions,
    update_time) are present and correctly populated from raw payload.
  • TestProcessImMessageReceive_OmitsUnchangedUpdateTime verifies
    update_time is omitted when it equals create_time.
  • go test ./cmd/event/...TestRunSchema_ReceiveMessageAgentFieldsJSON
    verifies the reflected JSON schema includes root_id, thread_id, reply_to,
    sender_type, and mentions; confirms no parent_id.

Compact pipeline

  • go test ./shortcuts/event/... — all existing tests pass, including
    TestImMessageProcessor_CompactInteractiveFallsBackToRaw (unchanged behavior).

Related Issues

None

Summary by CodeRabbit

Summary

  • New Features

    • Enhanced im.message.receive_v1 output with reply/thread context, sender_type, conditional update_time, and structured mentions (key, id, name).
  • Bug Fixes

    • update_time is omitted when it matches create_time.
    • Mentions are more reliably compacted, excluding empty or malformed mention entries.
  • Tests

    • Added JSON-mode schema validation for im.message.receive_v1 resolved output fields.
    • Updated message receive and compact-output assertions, including more precise interactive fallback messaging.

@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 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
📝 Walkthrough

Walkthrough

This PR expands IM message receive handling with sender type, thread/reply context, update time, and structured mentions. It updates compact event processing, shared mention conversion helpers, resolved-schema assertions, and receive-event tests.

Changes

IM message metadata enrichment

Layer / File(s) Summary
Output schema and raw event parsing structs
events/im/message_receive.go
ImMessageReceiveOutput and MentionOutput gain sender type, thread/reply context, update time, and structured mentions; raw parsing captures the corresponding source fields.
Message transformation
events/im/message_receive.go
processImMessageReceive maps the new fields, conditionally emits UpdateTime, and compacts raw mentions into structured output.
Shared mention helper functions
shortcuts/event/helpers.go
Adds helpers for reading strings, normalizing mention IDs, and compacting raw mention data.
Compact event processor output wiring and tests
shortcuts/event/processor_im_message.go, shortcuts/event/processor_test.go
The processor emits new context fields and compact mentions, conditionally includes event_id and update_time, and strengthens fallback hint assertions.
Receive-event fixtures and assertions
events/im/message_receive_test.go
Fixtures and assertions cover mention rendering, relationship fields, timestamps, omitted update_time, and map-based output checks.
Resolved schema field test
cmd/event/schema_test.go
Adds JSON schema checks for new fields and selected message_id and event_id descriptions.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Event as im.message.receive_v1
  participant Receive as processImMessageReceive
  participant Mentions as compactMentions
  participant Output as ImMessageReceiveOutput
  Event->>Receive: Parse message, sender, and relationship fields
  Receive->>Mentions: Convert raw mentions
  Mentions-->>Receive: Return compact mention entries
  Receive-->>Output: Emit metadata, content, and mentions
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.41% 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 is concise and accurately summarizes the main change: exposing reply context and mentions for im.message.receive_v1.
Description check ✅ Passed The description follows the required template and includes summary, changes, test plan, and related issues with sufficient detail.
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.
✨ 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.

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

🧹 Nitpick comments (1)
events/im/message_receive.go (1)

114-151: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider extracting shared mention helpers to avoid duplication.

The compactMentions, stringField, and mentionOpenID helpers defined here appear to be duplicated in shortcuts/event/helpers.go per the PR stack context. Since these are unexported in events/im, the shortcuts/event package can't import them, but a shared internal package (e.g., internal/mention or similar) would eliminate the copy and ensure both call sites stay in sync.

This is deferred-able if there's a circular-dependency concern or if the two packages intentionally maintain separate copies.

🤖 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 `@events/im/message_receive.go` around lines 114 - 151, The mention-compaction
helpers are duplicated across packages, so move the shared logic from
compactMentions, stringField, and mentionOpenID into a common internal helper
package that both events/im/message_receive.go and shortcuts/event can use. Keep
the existing behavior the same, but have the local call sites delegate to the
shared helper functions so future changes stay in sync and the duplication is
removed.
🤖 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 `@events/im/message_receive.go`:
- Around line 114-151: The mention-compaction helpers are duplicated across
packages, so move the shared logic from compactMentions, stringField, and
mentionOpenID into a common internal helper package that both
events/im/message_receive.go and shortcuts/event can use. Keep the existing
behavior the same, but have the local call sites delegate to the shared helper
functions so future changes stay in sync and the duplication is removed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 783f42ae-93ea-4266-aea1-8cec8fbbc002

📥 Commits

Reviewing files that changed from the base of the PR and between 1a9f637 and ab90667.

📒 Files selected for processing (6)
  • cmd/event/schema_test.go
  • events/im/message_receive.go
  • events/im/message_receive_test.go
  • shortcuts/event/helpers.go
  • shortcuts/event/processor_im_message.go
  • shortcuts/event/processor_test.go
💤 Files with no reviewable changes (1)
  • shortcuts/event/processor_test.go

@91-enjoy
91-enjoy force-pushed the feat/im-message-receive-agent-fields branch from ab90667 to b11ca86 Compare July 8, 2026 07:44
@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add 91-enjoy/cli#feat/im-message-receive-agent-fields -y -g

@91-enjoy
91-enjoy force-pushed the feat/im-message-receive-agent-fields branch from b11ca86 to 3e132eb Compare July 13, 2026 03:48

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

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

37-83: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Helpers are correct and nil-safe; consider sharing duplicated utilities.

All three functions handle nil maps and unexpected types gracefully — failed type assertions produce zero values that flow through the empty-string guards correctly. The conditional field inclusion and nil-on-empty return contract in compactMentions matches the downstream consumer's expectations (key/id/name per context snippet 2).

stringField and mentionOpenID are byte-for-byte identical to the same-named functions in events/im/message_receive.go (context snippet 1). If both packages will continue evolving these mention-extraction rules together, extracting the two pure helpers into a shared internal package would prevent silent divergence. For now this is acceptable given the small surface area and different package boundaries.

Per coding guidelines, every behavior change needs a test alongside the change. These helpers are likely exercised indirectly via processor_test.go, but dedicated unit tests for mentionOpenID's three branches (nested map, plain string, unsupported type) and compactMentions's nil/empty paths would lock in the contract at the helper level.

🤖 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/event/helpers.go` around lines 37 - 83, Keep the existing helper
behavior, but add dedicated unit tests for mentionOpenID covering nested-map,
plain-string, and unsupported-type inputs, and for compactMentions covering
nil/empty inputs and its nil-on-empty result contract. Place the tests alongside
these helpers and avoid changing production logic or duplicating shared
utilities.

Source: Coding guidelines

🤖 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 `@shortcuts/event/helpers.go`:
- Around line 37-83: Keep the existing helper behavior, but add dedicated unit
tests for mentionOpenID covering nested-map, plain-string, and unsupported-type
inputs, and for compactMentions covering nil/empty inputs and its nil-on-empty
result contract. Place the tests alongside these helpers and avoid changing
production logic or duplicating shared utilities.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a06cf34d-75de-47d4-96cf-843928a5a014

📥 Commits

Reviewing files that changed from the base of the PR and between b11ca86 and 3e132eb.

📒 Files selected for processing (6)
  • cmd/event/schema_test.go
  • events/im/message_receive.go
  • events/im/message_receive_test.go
  • shortcuts/event/helpers.go
  • shortcuts/event/processor_im_message.go
  • shortcuts/event/processor_test.go
💤 Files with no reviewable changes (1)
  • shortcuts/event/processor_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • cmd/event/schema_test.go
  • events/im/message_receive_test.go
  • events/im/message_receive.go
  • shortcuts/event/processor_im_message.go

@91-enjoy
91-enjoy force-pushed the feat/im-message-receive-agent-fields branch 2 times, most recently from b6edba4 to 30881f2 Compare July 13, 2026 12:07
@91-enjoy
91-enjoy force-pushed the feat/im-message-receive-agent-fields branch from 30881f2 to db6f851 Compare July 13, 2026 12:10
@YangJunzhou-01
YangJunzhou-01 merged commit 83352fe into larksuite:main Jul 13, 2026
19 checks passed
@liangshuo-1 liangshuo-1 mentioned this pull request Jul 13, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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