lark-event

作者: larksuite

Lark/Feishu real-time event listening / subscribing / consuming: stream events as NDJSON via `lark-cli event consume ` (covers IM messages/reactions/chat changes, VC meeting ended, Minutes generated, etc.). Use for Lark bots, real-time message processing, long-running subscribers, streaming webhook/push handlers. Supports `--max-events` / `--timeout` bounded runs and a stderr ready-marker contract — designed for AI agents running as subprocesses.

npx skills add https://github.com/larksuite/cli --skill lark-event

Lark Events

Prerequisite: Read ../lark-shared/SKILL.md first for authentication, --as user/bot switching, Permission denied handling, and safety rules.

Core commands

CommandPurpose
lark-cli event list [--json]List all subscribable EventKeys
lark-cli event schema <EventKey> [--json]Show an EventKey's params and output schema
lark-cli event consume <EventKey> [flags]Blocking consume; events → stdout NDJSON
lark-cli event status [--json] [--fail-on-orphan]Inspect the local bus daemon status
lark-cli event stop [--all] [--force]Stop the bus daemon

Common flags

FlagDescription
--param key=value / -pBusiness params (repeatable; comma-separated for multi-value). Unknown keys fail with valid names listed inline
--jq <expr>jq expression to filter / transform each event; empty output skips the event
--max-events NExit after N events. Default 0 = unlimited
--timeout DExit after duration D (e.g. 30s, 2m). Default 0 = no timeout. Whichever of --max-events / --timeout fires first wins
--output-dir <dir>Write each event as a file (relative paths only; prevents traversal)
--quietSuppress stderr diagnostics. AI should not use this — it silences the ready marker
--as user|bot|autoIdentity for the session (see lark-shared)

Examples

# Default: stream every event for the key (no filter, no projection)
lark-cli event consume im.message.receive_v1 --as bot

# Grab one sample event to inspect payload shape
lark-cli event consume im.message.receive_v1 --max-events 1 --timeout 30s --as bot

# Run for 10 minutes then auto-exit
lark-cli event consume im.message.receive_v1 --timeout 10m --as bot

# Consume multiple EventKeys concurrently (one shape per process, no dispatcher)
lark-cli event consume im.message.receive_v1          --as bot > receive.ndjson &
lark-cli event consume im.message.reaction.created_v1 --as bot > reaction.ndjson &
wait

Call flow

  1. lark-cli event list --json → pick a legal key
  2. lark-cli event schema <key> --json → read resolved_output_schema + jq_root_path to determine field paths
  3. lark-cli event consume <key> [--jq '<expr>'] → consume

Subprocess contract

Ready marker

event consume's stderr emits a fixed line [event] ready event_key=<key>. Parent processes should block on stderr until this line appears, then start reading stdout. Do not fall back to sleep.

stdin EOF = graceful exit

event consume treats stdin close as a shutdown signal (wired for AI subprocess callers). Bounded runs are exempt: when --max-events or --timeout is set (> 0), stdin EOF is ignored and the run exits only via its own bound, timeout, or SIGTERM. For unbounded runs, < /dev/null / nohup / systemd's default StandardInput=null will cause an immediate graceful exit (stderr reason: signal). To keep an unbounded run alive:

  • Feed stdin a source that never EOFs: < <(tail -f /dev/null)
  • Or run bounded: --max-events N / --timeout D

Exit codes & reason

On exit, the last stderr line is [event] exited — received N event(s) in Xs (reason: ...).

exit codereasonTrigger
0reason: limit--max-events reached
0reason: timeout--timeout reached
0reason: signalCtrl+C / SIGTERM / stdin EOF (stdin EOF applies to unbounded runs only)
1JSON error envelope on stderrLark API business failure during pre-consume setup (for example subscription create/delete)
2JSON error envelope on stderr (no exited line)Validation failure (unknown EventKey, bad --param / --jq, another bus already connected)
3JSON error envelope on stderrAuth failure (missing token, missing scopes)
4 / 5JSON error envelope on stderrNetwork / internal failure (bus startup, handshake, file I/O)

Startup and runtime failures emit a structured JSON envelope on stderr: {"ok":false,"error":{"type","subtype","param","message","hint",...}} (the envelope may also carry top-level identity / _notice siblings). Parse error.type / error.subtype to branch (e.g. missing_scope carries a missing_scopes list), error.param to find the offending flag, and error.hint for the recovery action — do not regex-match message text.

Orchestrators should treat reason: limit/timeout/signal (all exit 0) as "business completion" and non-zero as "failure".

Never kill -9

Avoid kill -9 on consume processes: for EventKeys with a PreConsume hook (those that register server-side subscriptions via OAPI), kill -9 skips the OAPI unsubscribe and leaks server-side subscriptions (symptoms: "subscription already exists" on restart, duplicate event delivery). Prefer SIGTERM or closing stdin.

One consume, one EventKey (multi-key = multi-shell)

The command takes exactly one positional argument; k1,k2 and wildcards are unsupported. Listening to N keys means N subprocesses — this is intentional:

  • One shape per process stdout; no dispatcher logic required in the AI
  • Fault isolation (one key failing doesn't affect others)
  • Independent --as / --jq / --max-events / --timeout per key

All N consumers share a single bus daemon (UDS local IPC), so the overhead is small

Writing jq via schema

event schema <key> --json is the source of truth for writing --jq. Four things to look at:

(1) Where fields start — see jq_root_path

  • Value "." → fields are at the top level, write .chat_id
  • Value ".event" → fields are inside a V2 envelope, write .event.chat_id

(2) Field list and types — see resolved_output_schema.properties.<name>

Each field carries type / description, and some also have format. Snippet (from event schema im.message.receive_v1 --json):

{
  "chat_id":     {"type":"string", "format":"chat_id",      "description":"Chat ID, prefixed with oc_"},
  "sender_id":   {"type":"string", "format":"open_id",      "description":"Sender open_id, prefixed with ou_"},
  "create_time": {"type":"string", "format":"timestamp_ms", "description":"Send time as ms-epoch string"}
}

(3) Field semantics — see the format tag

Lark-defined semantic tags (not JSON Schema's standard format). Common values: open_id / chat_id / message_id / timestamp_ms / email. Purpose: distinguish "same string type, different meanings" fields so you can reverse-lookup via API or convert formats.

(4) Decoded state — read the field's description

event consume runs Process hooks that may pre-decode some payload fields (flattening V2 envelopes, rendering .content to plain text, etc.) — behavior differs from raw OAPI. Always read the field's description before writing jq, especially for generic field names like content / data / body / payload.

Why it matters: blindly applying fromjson to an already-decoded text field makes jq error on every event and silently drop it — the consumer looks alive but emits nothing, with only a single WARN line buried on stderr. (This is the general behavior: any jq runtime error skips the event with a one-line WARN; the loop does not abort.)

Don't shortcut the schema: when projecting event schema --json with jq, do not strip .description from properties — that's the field that tells you whether a field is already decoded. Dump the full property objects, not just keys.


Aside: --param's valid parameters also live in the schema — the params section lists name / type / required / enum / default / description; section missing = this key accepts no --param.

Topic index

TopicReferenceCoverage
IMreferences/lark-event-im.mdCatalog of 11 IM EventKeys + shape notes (flat vs V2 envelope) + im.message.receive_v1 field gotchas (sender_id is open_id only; .content is plain text except for interactive cards) + common jq recipes (filter by chat_type / message_type / sender)
VCreferences/lark-event-vc.mdCatalog of 2 VC EventKeys (vc.meeting.participant_meeting_ended_v1, vc.note.generated_v1) + field reference + source type semantics (meeting only)
Minutesreferences/lark-event-minutes.mdCatalog of 1 Minutes EventKey (minutes.minute.generated_v1) + field reference + source type semantics (meeting only)
Whiteboardreferences/lark-event-whiteboard.mdCatalog of 1 Board EventKey (board.whiteboard.updated_v1) + per-whiteboard subscription model (requires -p whiteboard_id=<token>) + payload field reference (whiteboard_id / operator_ids triple-id)

來自 larksuite 的更多技能

lark-doc
larksuite
飛書雲文檔 / Docx / 知識庫 Wiki 文檔(v2):建立、開啟、讀取、取得、檢視、總結、整理、改寫、翻譯、審閱和編輯飛書文檔內容。當使用者提供飛書文檔 URL/token,或要求檢視/讀取/開啟某個文檔、提取文檔內容、總結文檔、生成/建立文檔、追加/取代/刪除/移動內容、調整排版、插入或下載文檔圖片/附件/素材/畫板縮圖時使用。文檔內容中出現嵌入試算表、多維表格、需要將重要資訊視覺化為畫板(含 SVG 畫板)、引用或同步區塊時,也先使用本 skill 讀取和提取 token,再切換至對應 skill 深入處理。使用本 skill 時,docs +create、docs +fetch、docs +update 必須攜帶 --api-version v2;預設使用 DocxXML,也
documentapiproductivity
lark-im
larksuite
飛書即時通訊:收發訊息和管理群聊。發送和回覆訊息、搜尋聊天記錄、管理群聊成員、上傳下載圖片和檔案(支援大檔案分片下載)、管理表情回覆。當用戶需要發訊息、查看或搜尋聊天記錄、下載聊天中的檔案、查看群成員、搜尋群、建立群聊或話題群、管理標記資料時使用。
communicationproductivityapi
lark-shared
larksuite
首次設定 lark-cli、執行 auth login、切換使用者/機器人身份(--as)、處理權限拒絕或範圍錯誤、需要更新 lark-cli,或是在 JSON 輸出中看到 _notice 時使用。
developmentapicommunication
lark-base
larksuite
當需要用 lark-cli 操作飛書多維表格(Base)時調用:搜尋 Base、建表、欄位管理、記錄讀寫、記錄分享連結、檢視配置、歷史查詢,以及角色/表單/儀表板管理/工作流程;也適用於把舊的 +table / +field / +record 寫法改成當前命令寫法。涉及欄位設計、公式欄位、查找引用、跨表計算、行級派生指標、資料分析需求時也必須使用本 skill。
databasedata-analysisapi
lark-drive
larksuite
飛書雲空間:管理雲端空間中的檔案與資料夾。可上傳與下載檔案、建立資料夾、複製/移動/刪除檔案、檢視檔案元資料、管理文件評論、管理文件權限、訂閱使用者評論變更事件、修改檔案標題(docx、sheet、bitable、file、folder、wiki);同時也負責將本機的 Word/Markdown/Excel/CSV 以及 Base 快照(.base)匯入為飛書線上雲端文件(docx、sheet、bitable)。當使用者需要上傳或下載檔案、整理雲端空間目錄、檢視檔案詳細資訊、管理評論、管理文件權限、修改檔案標題、訂閱使用者評論變更事件,或將本機檔案匯入為新版文件、電子表格、多維表格/Base 時使用。
documentproductivityapi
lark-whiteboard
larksuite
飛書畫板:查詢和編輯飛書雲文檔中的畫板。支援匯出畫板為預覽圖片、匯出原始節點結構、使用多種格式更新畫板內容。當用戶需要查看畫板內容、匯出畫板圖片、編輯畫板時使用此 skill。不負責:飛書雲文檔內容編輯(lark-doc)、文檔內嵌電子表格/Base(lark-sheets / lark-base)。
documentcreativeproductivity
lark-mail
larksuite
飛書郵箱 — 起草、撰寫、發送、回覆、轉發、閱讀及搜尋郵件;管理草稿、資料夾、標籤、聯絡人、附件及郵件規則。當使用者提及 起草郵件、寫一封郵件、擬郵件、草稿、發通知郵件、發送郵件、發郵件、回覆郵件、轉發郵件、查看郵件、看郵件、讀郵件、搜尋郵件、查郵件、收件箱、郵件會話、編輯草稿、管理草稿、下載附件、郵件資料夾、郵件標籤、郵件聯絡人、監聽新郵件、收信規則、郵件規則、draft、compose、send email、reply、forward、inbox、mail thread、mail rules 時使用。
communicationproductivityapi
lark-workflow-meeting-summary
larksuite
會議紀要整理工作流:彙總指定時間範圍內的會議紀要並生成結構化報告。當用戶需要整理會議紀要、生成會議週報、回顧一段時間內的會議內容時使用。
productivitydocumentcommunication