lark-event
open.feishu.cn
Stream Lark/Feishu events in real-time as NDJSON for bots and event processors.
What is lark-event?
Lark-event enables real-time consumption of Lark/Feishu platform events (messages, reactions, tasks, meetings, etc.) via `lark-cli event consume`. Use it to build event-driven bots, process incoming messages, or subscribe to long-running event streams with bounded or unbounded runs.
- Stream events as NDJSON from a single EventKey per process
- Filter and transform events using jq expressions via `--jq`
- Bounded runs with `--max-events` or `--timeout` for controlled consumption
- Graceful shutdown via stdin EOF or SIGTERM with ready-marker contract
- Support for IM messages, reactions, chat changes, tasks, meetings, minutes, and whiteboard updates
- Concurrent multi-key listening via parallel subprocesses sharing a single bus daemon
How to install lark-event
npx skills add null --skill lark-event- lark-cli binary installed
- Lark/Feishu authentication configured (see lark-shared SKILL.md)
- Valid EventKey from `lark-cli event list`
- Appropriate Lark API scopes for the event type
How to use lark-event
- 1.Run `lark-cli event list --json` to find available EventKeys
- 2.Run `lark-cli event schema <EventKey> --json` to inspect the event payload structure and jq_root_path
- 3.Optionally write a jq filter expression using the schema fields
- 4.Run `lark-cli event consume <EventKey> [--jq '<expr>'] [--max-events N] [--timeout D] --as bot` to start consuming
- 5.For parent processes: block on stderr until the ready marker `[event] ready event_key=<key>` appears, then read NDJSON from stdout
- 6.For multiple EventKeys, spawn separate `lark-cli event consume` processes in parallel
Use cases
- Build a Lark bot that reacts to incoming messages in real-time
- Process task updates and meeting events for workflow automation
- Stream filtered events to external systems with timeout-bounded runs
- Monitor whiteboard or minutes changes and trigger downstream actions
- Consume one sample event to inspect payload structure before full deployment
- Lark/Feishu bot developers
- Event-driven application builders
- AI agents running as subprocesses
- Real-time message processing pipelines
- Workflow automation engineers
lark-event FAQ
`event consume` emits `[event] ready event_key=<key>` on stderr when ready. Parent processes should block on stderr until this line appears before reading stdout. Do not use sleep as a workaround.
Run one `lark-cli event consume` subprocess per EventKey. All consumers share a single bus daemon via local IPC, so overhead is minimal. This design ensures one shape per process and fault isolation.
For unbounded runs (no `--max-events` or `--timeout`), stdin EOF triggers graceful shutdown. For bounded runs, stdin EOF is ignored and the process exits only via its own limit, timeout, or SIGTERM.
Use SIGTERM or close stdin instead of `kill -9`. EventKeys with PreConsume hooks register server-side subscriptions; `kill -9` skips the unsubscribe and causes 'subscription already exists' errors on restart.
Run `event schema <EventKey> --json` to get `jq_root_path` (where fields start, e.g. '.' or '.event') and `resolved_output_schema.properties` (field names and types). Write your jq expression relative to the root path, e.g., `.chat_id` or `.event.sender_id`. Always check the field's description to see if it is already decoded.
Full instructions (SKILL.md)
Source of truth, from open.feishu.cn.
name: lark-event
version: 1.0.0
description: "Lark/Feishu real-time event listening / subscribing / consuming: stream events as NDJSON via lark-cli event consume <EventKey> (covers IM messages/reactions/chat changes, Task updates, VC meeting started/joined/ended, Minutes generated, Whiteboard updated, 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."
metadata:
requires:
bins: ["lark-cli"]
cliHelp: "lark-cli event --help"
Lark Events
Prerequisite: Read
../lark-shared/SKILL.mdfirst for authentication,--as user/botswitching,Permission deniedhandling, and safety rules.
Core commands
| Command | Purpose |
|---|---|
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
| Flag | Description |
|---|---|
--param key=value / -p | Business 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 N | Exit after N events. Default 0 = unlimited |
--timeout D | Exit 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) |
--quiet | Suppress stderr diagnostics. AI should not use this — it silences the ready marker |
--as user|bot|auto | Identity 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
lark-cli event list --json→ pick a legal keylark-cli event schema <key> --json→ readresolved_output_schema+jq_root_pathto determine field pathslark-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 code | reason | Trigger |
|---|---|---|
| 0 | reason: limit | --max-events reached |
| 0 | reason: timeout | --timeout reached |
| 0 | reason: signal | Ctrl+C / SIGTERM / stdin EOF (stdin EOF applies to unbounded runs only) |
| 1 | JSON error envelope on stderr | Lark API business failure during pre-consume setup (for example subscription create/delete) |
| 2 | JSON error envelope on stderr (no exited line) | Validation failure (unknown EventKey, bad --param / --jq, another bus already connected) |
| 3 | JSON error envelope on stderr | Auth failure (missing token, missing scopes) |
| 4 / 5 | JSON error envelope on stderr | Network / 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/--timeoutper 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
| Topic | Reference | Coverage |
|---|---|---|
| IM | references/lark-event-im.md | Catalog of 12 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); for card.action.trigger see also ../lark-im/references/lark-im-card-action-reply.md |
| Task | references/lark-event-task.md | Catalog of 1 Task EventKey (task.task.update_user_access_v2) + Native V2 envelope shape + task commit types + user/bot subscription notes |
| VC | references/lark-event-vc.md | Catalog of 4 VC EventKeys (vc.meeting.participant_meeting_started_v1, vc.meeting.participant_meeting_joined_v1, vc.meeting.participant_meeting_ended_v1, vc.note.generated_v1) + field reference + source type semantics (meeting only) |
| Minutes | references/lark-event-minutes.md | Catalog of 1 Minutes EventKey (minutes.minute.generated_v1) + field reference + source type semantics (meeting only) |
| Whiteboard | references/lark-event-whiteboard.md | Catalog 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) |
Related skills
More from open.feishu.cn and the wider catalog.
lark-approval
飞书审批:查询和处理审批待办/已办/实例,搜索可发起审批定义、查看定义详情并发起原生审批实例。当用户要处理审批任务、查看审批实例、搜索或发起审批时使用。审批待办不是飞书任务;非审批类待办走 lark-task。不负责创建审批定义;三方审批定义不走原生提单。
lark-doc
飞书云文档(Docx / Wiki 文档):读取和编辑飞书文档内容。当用户给出文档 URL 或 token,或需要查看、创建、编辑文档、插入或下载文档图片附件时使用。文档中嵌入的电子表格、多维表格、画板,先用本 skill 提取 token 再切到对应 skill。当用户给出 doubao.com 的 /docx/ 或 /wiki/ URL/token 时,也应直接使用本 skill;路由依据是 URL 路径模式和 token,而不是域名。不负责文档评论管理,也不负责表格或 Base 的数据操作。
lark-base
飞书多维表格(Base)操作:建表、字段、记录、视图、统计、公式/lookup、表单、仪表盘、workflow、角色权限;遇到 Base/多维表格/bitable 或 /base/ 链接时使用。文件导入转 lark-drive,认证/授权转 lark-shared。
lark-calendar
飞书日历:管理日历日程和会议室。查看/搜索日程、创建/更新日程、管理参会人、查询忙闲和推荐时段、预定会议室。当用户需要查看日程安排、创建/修改会议、查询/预定会议室时使用。不负责:查询过去的视频会议记录(走 lark-vc)、待办任务(走 lark-task)。
lark-drive
飞书云空间(云盘/云存储):管理 Drive 文件和文件夹,包含上传/下载、创建文件夹、复制/移动/删除、查看元数据、评论/权限/订阅、标题、版本和本地文件导入。用户需要整理云盘目录、处理云空间资源 URL/token,或导入 Word/Markdown/Excel/CSV/PPTX/.base 为 docx/sheet/bitable/slides 时使用;doubao.com 云空间 URL/token 也按资源路径和 token 路由,不回退 WebFetch。不负责:文档内容编辑(走 lark-doc)、表格/Base 表内数据操作(走 lark-sheets/lark-base)、知识空间节点/成员管理(走 lark-wiki)、原生 Markdown 文件读写/patch/diff(走 lark-markdown)。
lark-contact
飞书 / Lark 通讯录:按姓名 / 邮箱解析成 open_id,或按 open_id 反查姓名 / 部门 / 邮箱 / 联系方式 / 个人状态 / 签名。当用户提到某人姓名要下一步发消息 / 排日程,或拿到 open_id 想查具体信息时使用。不负责部门树遍历、按部门列员工、组织架构图,这类需求走原生 OpenAPI。