Skip to content

[codex] support bot menu events#1765

Merged
sang-neo03 merged 3 commits into
larksuite:mainfrom
LXJ0000:codex/support-bot-menu-event
Jul 20, 2026
Merged

[codex] support bot menu events#1765
sang-neo03 merged 3 commits into
larksuite:mainfrom
LXJ0000:codex/support-bot-menu-event

Conversation

@LXJ0000

@LXJ0000 LXJ0000 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds application.bot.menu_v6 support to lark-cli event so bots can consume custom menu push events over the existing event pipeline. The output is flattened around the menu event_key and operator identifiers so callers can filter events such as start_eval with --jq.

Changes

  • Add a new Application event domain with application.bot.menu_v6 registration and processed output schema.
  • Flatten bot menu payload fields including event_key, header metadata, menu timestamp, and operator open/union/user IDs.
  • Register the Application event domain in the global event registry.
  • Add unit coverage for metadata, registration, payload parsing, timestamp fallback, and malformed payload passthrough.
  • Document the new EventKey in the lark-event skill reference with a --jq filtering example.

Test Plan

  • Unit tests pass: go test ./events/application ./events
  • Manual local verification confirms the lark-cli event consume application.bot.menu_v6 --as bot --jq 'select(.event_key == "start_eval")' flow receives a real bot menu click event.

Related Issues

  • None

Summary by CodeRabbit

  • New Features
    • Added support for the application.bot.menu_v6 Application event, producing flattened output with event/header identifiers, menu metadata, operator details, and normalized timestamps.
    • Registered the new event in the global event key registry.
  • Bug Fixes
    • If an incoming payload can’t be parsed, event processing now returns the original payload unchanged.
  • Tests
    • Added unit tests for payload variants, timestamp normalization, and event registry wiring.
  • Documentation
    • Updated the event catalog and added a new reference page with consume examples and a flattened field guide.

@CLAassistant

CLAassistant commented Jul 6, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a7de11ae-a4e0-4fb5-9291-0b5c15f7d259

📥 Commits

Reviewing files that changed from the base of the PR and between a43410c and 3ba85ed.

📒 Files selected for processing (1)
  • events/register.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • events/register.go

📝 Walkthrough

Walkthrough

Adds processing and registration for application.bot.menu_v6. Payloads are flattened into BotMenuOutput, timestamps are normalized, registry and authentication metadata are wired, tests cover processing behavior, and event usage is documented.

Changes

Bot menu v6 event support

Layer / File(s) Summary
BotMenuOutput schema and processing
events/application/menu.go
Defines BotMenuOutput and processBotMenu, including scalar normalization, timestamp fallback and conversion, field extraction, and malformed-payload passthrough.
Event registration and global wiring
events/application/register.go, events/register.go
Registers application.bot.menu_v6 with its schema, handler, bot authentication, console event linkage, and global registry inclusion.
Processing and registration tests
events/application/menu_test.go
Tests metadata, registry presence, field mapping, timestamp fallbacks, event type handling, malformed payload behavior, and the processing helper.
Reference documentation
skills/lark-event/SKILL.md, skills/lark-event/references/lark-event-application.md
Documents the event trigger, consume commands, flattened fields, jq filtering, and topic-index entry.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant EventConsumer
  participant GlobalRegistry
  participant processBotMenu
  participant BotMenuOutput

  EventConsumer->>GlobalRegistry: lookup application.bot.menu_v6
  GlobalRegistry->>processBotMenu: process raw event payload
  processBotMenu->>BotMenuOutput: flatten and normalize fields
  processBotMenu-->>EventConsumer: marshaled output
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and clearly describes the main change: support for bot menu events.
Description check ✅ Passed The description matches the required template and includes summary, changes, test plan, and related issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

@github-actions github-actions Bot added the size/M Single-domain feat or fix with limited business impact label Jul 6, 2026
@LXJ0000
LXJ0000 force-pushed the codex/support-bot-menu-event branch from 3795f41 to 0d8576b Compare July 6, 2026 11:00
@LXJ0000
LXJ0000 marked this pull request as ready for review July 6, 2026 11:02
Copilot AI review requested due to automatic review settings July 6, 2026 11:02

Copilot AI 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.

Pull request overview

This PR extends the lark-cli event pipeline by adding a new Application-domain event key (application.bot.menu_v6) so bots can consume custom menu push events with a flattened, jq-friendly output shape.

Changes:

  • Added a new events/application domain and registered application.bot.menu_v6 with a processed (flattened) output schema.
  • Implemented payload processing to surface event_key, header metadata, menu timestamp, and operator identifiers at the top level (with timestamp fallback behavior).
  • Added unit tests for registration/metadata and for payload parsing + malformed-payload passthrough, and documented the new EventKey in the lark-event skill docs.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
skills/lark-event/SKILL.md Adds the Application topic entry pointing to the new Application EventKey reference.
skills/lark-event/references/lark-event-application.md Documents application.bot.menu_v6, flattened fields, and jq filtering examples.
events/register.go Registers the new Application event domain in the global event registry.
events/application/register.go Defines the application.bot.menu_v6 KeyDefinition (schema + auth + required console events).
events/application/menu.go Implements payload flattening + timestamp fallback and tolerant timestamp parsing.
events/application/menu_test.go Adds unit coverage for definition metadata, registry integration, parsing, fallback behavior, and malformed passthrough.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@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/application/menu.go (1)

16-16: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Consider hardcoding Type instead of trusting the payload.

The Type field doc says it's "always application.bot.menu_v6", but the value is copied from envelope.Header.EventType (payload-controlled) rather than the local eventTypeBotMenuV6 constant. If the header ever arrives empty/mismatched, downstream --jq filters on .type would silently break the documented guarantee.

♻️ Proposed fix
 	out := &BotMenuOutput{
-		Type:            envelope.Header.EventType,
+		Type:            eventTypeBotMenuV6,
 		EventID:         envelope.Header.EventID,

Also applies to: 64-64

🤖 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/application/menu.go` at line 16, The menu event Type is currently
being populated from envelope.Header.EventType instead of the local
eventTypeBotMenuV6 constant, which makes the documented “always
application.bot.menu_v6” guarantee depend on payload data. Update the
application menu event construction in menu.go so Type is set directly from
eventTypeBotMenuV6 (and not copied from the envelope header), ensuring the
emitted JSON always matches the documented value even when the incoming header
is empty or mismatched.
🤖 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/application/menu.go`:
- Line 16: The menu event Type is currently being populated from
envelope.Header.EventType instead of the local eventTypeBotMenuV6 constant,
which makes the documented “always application.bot.menu_v6” guarantee depend on
payload data. Update the application menu event construction in menu.go so Type
is set directly from eventTypeBotMenuV6 (and not copied from the envelope
header), ensuring the emitted JSON always matches the documented value even when
the incoming header is empty or mismatched.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4d874fd5-a12c-4282-920c-f3cd5c41877b

📥 Commits

Reviewing files that changed from the base of the PR and between ee46e22 and 0d8576b.

📒 Files selected for processing (6)
  • events/application/menu.go
  • events/application/menu_test.go
  • events/application/register.go
  • events/register.go
  • skills/lark-event/SKILL.md
  • skills/lark-event/references/lark-event-application.md

@LXJ0000
LXJ0000 force-pushed the codex/support-bot-menu-event branch from 0d8576b to 7ddd654 Compare July 6, 2026 11:26
@sang-neo03

Copy link
Copy Markdown
Collaborator

@LXJ0000 The feature direction is reasonable, and the overall implementation fits the existing event consume framework. The relevant package tests have passed.

The main issue is the time unit handling for event.timestamp. In real Feishu callbacks, header.create_time is usually a millisecond string, while event.timestamp may be a 10-digit Unix timestamp in seconds. The current implementation marks menu_timestamp as timestamp_ms, and when header.create_time is empty, it falls back to event.timestamp for the top-level timestamp. This may cause downstream scripts or agents to parse a seconds-level value as milliseconds, resulting in incorrect time comparisons.

Please fix this before merging: normalize event.timestamp to a millisecond string in processBotMenu. A 10-digit seconds-level value should be multiplied by 1000, while a 13-digit millisecond value should be kept as is. Please also add a test with a real-world sample, for example 1694592375 -> 1694592375000.

Also, the current GitHub Checks only show CodeRabbit and sync-pr-labels. Please run the regular CI checks as well.

@LXJ0000

LXJ0000 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@sang-neo03

Thanks for the review. Fixed in a43410c.

Changes made:

  • Normalize event.timestamp through processBotMenu before exposing it as menu_timestamp or as the top-level timestamp fallback.
  • A 10-digit seconds timestamp is converted to a millisecond string, e.g. 1694592375 -> 1694592375000.
  • A 13-digit millisecond timestamp is kept as-is.
  • Added TestProcessBotMenuSecondsTimestampFallback with the real-world seconds sample.

Local verification:

  • go test ./events/application ./events passed.
  • go test -race ./events/application ./events passed.
  • python3 scripts/fetch_meta.py passed.
  • go build ./... passed.
  • go vet ./... passed.
  • gofmt -l . returned no files.
  • go mod tidy && git diff --exit-code go.mod go.sum passed.

I also tried the regular CI unit-test command locally:

go test -v -race -count=1 -timeout=5m ./cmd/... ./internal/... ./shortcuts/... ./extension/...

It ran through the suite but exits non-zero because of an unrelated existing cmd package failure after fetching current remote meta:

TestIntegration_StrictModeUser_ProfileOverride_ServiceBotOnlyMethodReturnsEnvelope
exit code = 0, want 2 (ExitValidation)

This failure is outside the changed events/application package and is not caused by the timestamp normalization change.

@LXJ0000
LXJ0000 marked this pull request as draft July 13, 2026 15:18
@LXJ0000
LXJ0000 marked this pull request as ready for review July 13, 2026 15:18
@LXJ0000

LXJ0000 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

@sang-neo03 辛苦帮忙再 review 一下~~

@github-actions

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add LXJ0000/cli#codex/support-bot-menu-event -y -g

@sang-neo03
sang-neo03 merged commit b526772 into larksuite:main Jul 20, 2026
31 of 36 checks passed
@liangshuo-1 liangshuo-1 mentioned this pull request Jul 20, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants