Feishu Document Collaboration Skill
Turn any Feishu document into a real-time human-AI collaboration space.
Overview
This skill patches OpenClaw's Feishu extension to detect document edit events and trigger
isolated agent sessions. Combined with a structured in-document chat protocol, it enables:
- - ✍️ Write a question in a Feishu doc → AI reads it and appends a reply
- 🚦 Status flags (🔴 editing / 🟢 done) prevent premature responses
- 👥 Multi-party routing: messages can target specific participants
- 📋 Optional Bitable task board for structured task management
Prerequisites
- 1. OpenClaw with Feishu channel configured (app ID, app secret, event subscriptions)
- openclaw-lark extension installed (v2026.3+) or built-in feishu extension
- Feishu app event subscriptions enabled:
-
drive.file.edit_v1 — document edit events
-
drive.file.bitable_record_changed_v1 — (optional) bitable record changes
-
drive.file.read_v1 — (optional, auto-ignored to suppress warnings)
- 4. Required Feishu app permissions (enable in Open Platform console + user OAuth):
-
space:document:retrieve — read documents
-
docx:document:readonly — read docx content (app-level)
-
base:table:read — read bitable table structure
-
base:record:read — read bitable records
-
base:record:update — update bitable records (for task board)
-
base:field:read — read bitable field definitions
-
drive:drive:readonly — read drive file info
- 5. Hooks enabled in
openclaw.json:
CODEBLOCK0
Quick Setup
Step 1: Enable hooks in openclaw.json
Add the hooks section if not present:
CODEBLOCK1
Step 2: Apply the monitor patch
CODEBLOCK2
This patches the Feishu extension's monitor.js (or monitor.ts for older installs) to:
- - Detect
drive.file.edit_v1 and bitable_record_changed_v1 events - Apply 30-second debounce per file to prevent event storms
- Skip bot's own edits (anti-loop)
- Trigger an isolated agent session via
/hooks/agent with INLINECODE17 - Silently ignore
drive.file.read_v1 events (suppress warnings)
Step 3: Configure your agent identity
Edit ./skills/feishu-doc-collab/config.json:
CODEBLOCK3
The patch script uses this to set up message routing (who the agent responds as).
Step 4: Restart the gateway
CODEBLOCK4
Step 5: Set up the Doc Chat Protocol
Copy the protocol template to your workspace:
CODEBLOCK5
Edit DOC_PROTOCOL.md to fill in your participant roster.
How It Works
Document Edit Flow
CODEBLOCK6
In-Document Chat Protocol
Messages in the document follow this format:
CODEBLOCK7
Status flags:
- - 🔴 编辑中 (editing) — AI will NOT process this message (user is still typing)
- 🟢 完成 (done) — AI will read and respond to this message
Routing:
- -
→ AgentName — addressed to a specific AI agent - INLINECODE22 — broadcast to all participants
This solves a critical problem: Feishu auto-saves continuously while typing, which would
trigger multiple premature AI responses without the status flag mechanism.
Bitable Task Board (Optional)
For structured task management alongside document collaboration:
- 1. Create a Bitable with these fields:
- Task Summary (Text)
- Status (SingleSelect): Unread / Read / In Progress / Done / N/A
- Created (DateTime)
- From (SingleSelect): participant names
- To (MultiSelect): participant names
- Priority (SingleSelect): Low / Medium / High / Urgent
- Notes (Text)
- Related Doc (URL)
- 2. Configure in
config.json:
CODEBLOCK8
- 3. The patch also handles
bitable_record_changed_v1 events for task routing.
Re-applying After Updates
⚠️ OpenClaw or extension updates may overwrite monitor.js. After any update:
CODEBLOCK9
The patch script is idempotent — safe to run multiple times.
Note: For the openclaw-lark extension (compiled .js), no jiti cache clearing is needed.
For older built-in .ts installs, also run: INLINECODE29
Configuration Reference
config.json
| Field | Type | Required | Description |
|---|
| INLINECODE30 | string | Yes | Internal name used in protocol routing |
| INLINECODE31 |
string | Yes | Display name shown in doc replies |
|
bitable.app_token | string | No | Bitable app token for task board |
|
bitable.table_id | string | No | Bitable table ID for task board |
Environment
The patch reads from ~/.openclaw/openclaw.json:
- -
hooks.token — authentication for /hooks/agent endpoint - INLINECODE36 — gateway port (default: 18789)
Known Issues & Solutions
Event Storm (事件风暴)
Problem: Feishu sends multiple drive.file.edit_v1 and bitable_record_changed_v1 events
for a single logical edit. Bitable edits are especially bad — changing one record field can trigger
10-20+ events in rapid succession. Without debounce, each event spawns a separate isolated agent
session (using the full model), causing massive token waste.
Real-world impact: A single bitable task edit triggered 15+ Hook sessions consuming 350k+ tokens,
all running in parallel and all reaching the same conclusion: "nothing to do".
Solution: 30-second debounce per fileToken (implemented in patch-monitor.sh v2):
- - A
Map<string, number> tracks the last trigger timestamp per file/table - If the same file was triggered within 30 seconds, the event is silently skipped
- For bitable events, the debounce key includes both fileToken and tableId
- The debounce is applied before the
/hooks/agent call, so no session is created
Bot self-edit loop: When the agent updates a bitable record (e.g., changing status to "处理完"),
that edit triggers MORE events. The bot self-edit check (comparing operator_id to botOpenId)
catches most of these, but the debounce provides a critical safety net for cases where the
operator ID doesn't match (e.g., API calls vs. bot identity).
Important: Already-running sessions cannot be stopped by debounce. If an event storm has
already started, the sessions will run to completion. Debounce only prevents NEW triggers.
Re-patching After Updates
OpenClaw or extension updates may overwrite monitor.js. After any update:
bash ./skills/feishu-doc-collab/scripts/patch-monitor.sh
openclaw gateway restart
The patch script is idempotent — checks for both
/hooks/agent and
_editDebounce markers.
Limitations
- - Requires patching OpenClaw extension files (fragile across updates)
- Feishu app needs
drive.file.edit_v1 event subscription approval - Multiple OAuth scopes must be authorized (use batch auth for convenience)
- Document must use the structured protocol format for reliable routing
- Works best with docx type; other file types (sheets, slides) are not supported
- Isolated hook sessions reuse cached OAuth tokens from the main interactive session
Credits
Created by dongwei. Inspired by the need for real-time human-AI collaboration
in Chinese enterprise workflows using Feishu/Lark.
License
MIT
飞书文档协作技能
将任何飞书文档转变为实时的人机协作空间。
概述
本技能对OpenClaw的飞书扩展进行补丁,以检测文档编辑事件并触发隔离的智能体会话。结合结构化的文档内聊天协议,可实现:
- - ✍️ 在飞书文档中写入问题 → AI读取并追加回复
- 🚦 状态标记(🔴 编辑中 / 🟢 完成)防止过早响应
- 👥 多方路由:消息可定向至特定参与者
- 📋 可选的多维表格任务看板,用于结构化任务管理
前置条件
- 1. 已配置飞书渠道的OpenClaw(应用ID、应用密钥、事件订阅)
- 已安装openclaw-lark扩展(v2026.3+)或内置飞书扩展
- 已启用飞书应用事件订阅:
- drive.file.edit_v1 — 文档编辑事件
- drive.file.bitable
recordchanged_v1 —(可选)多维表格记录变更
- drive.file.read_v1 —(可选,自动忽略以抑制警告)
- 4. 所需的飞书应用权限(在开放平台控制台启用 + 用户OAuth):
- space:document:retrieve — 读取文档
- docx:document:readonly — 读取docx内容(应用级)
- base:table:read — 读取多维表格表结构
- base:record:read — 读取多维表格记录
- base:record:update — 更新多维表格记录(用于任务看板)
- base:field:read — 读取多维表格字段定义
- drive:drive:readonly — 读取云盘文件信息
- 5. 在openclaw.json中启用钩子:
json
{
hooks: {
enabled: true,
token: your-hooks-token-here
}
}
快速设置
步骤1:在openclaw.json中启用钩子
如果不存在,添加hooks部分:
bash
生成随机令牌
TOKEN=$(openssl rand -hex 16)
echo 您的钩子令牌: $TOKEN
然后添加到openclaw.json:
hooks: { enabled: true, token: }
步骤2:应用监控补丁
bash
bash ./skills/feishu-doc-collab/scripts/patch-monitor.sh
这将修补飞书扩展的monitor.js(旧版安装为monitor.ts),以:
- - 检测drive.file.editv1和bitablerecordchangedv1事件
- 对每个文件应用30秒防抖,防止事件风暴
- 跳过机器人自身的编辑(防循环)
- 通过/hooks/agent触发隔离的智能体会话,并设置deliver: false
- 静默忽略drive.file.read_v1事件(抑制警告)
步骤3:配置智能体身份
编辑./skills/feishu-doc-collab/config.json:
json
{
agent_name: MyBot,
agentdisplayname: My AI Assistant
}
补丁脚本使用此配置设置消息路由(智能体以谁的身份响应)。
步骤4:重启网关
bash
openclaw gateway restart
步骤5:设置文档聊天协议
将协议模板复制到您的工作空间:
bash
cp ./skills/feishu-doc-collab/assets/DOCPROTOCOLTEMPLATE.md ./DOC_PROTOCOL.md
编辑DOC_PROTOCOL.md以填写您的参与者名单。
工作原理
文档编辑流程
用户编辑飞书文档
↓
飞书发送drive.file.edit_v1事件
↓
修补后的monitor.ts接收事件
↓
检查:是否为机器人自身的编辑?→ 是:跳过(防循环)
↓ 否
防抖:同一文件在30秒内触发?→ 是:跳过
↓ 否
POST /hooks/agent 并设置deliver:false(隔离会话)
↓
智能体读取DOC_PROTOCOL.md获取消息格式
↓
智能体读取文档,找到最后的消息块
↓
检查:状态=🟢?是否发给我?是否不是来自我?
↓ 是
智能体撰写回复并追加到文档
文档内聊天协议
文档中的消息遵循以下格式:
markdown
发送者名称 → 接收者名称 | 🟢 完成
您的消息内容在此。
状态标记:
- - 🔴 编辑中 — AI将不会处理此消息(用户仍在输入)
- 🟢 完成 — AI将读取并回复此消息
路由:
- - → AgentName — 定向至特定AI智能体
- → all — 广播给所有参与者
这解决了一个关键问题:飞书在输入时持续自动保存,如果没有状态标记机制,将触发多次过早的AI响应。
多维表格任务看板(可选)
用于与文档协作并行的结构化任务管理:
- 1. 创建包含以下字段的多维表格:
- 任务摘要(文本)
- 状态(单选):未读 / 已读 / 进行中 / 完成 / 不适用
- 创建时间(日期时间)
- 来自(单选):参与者名称
- 发送至(多选):参与者名称
- 优先级(单选):低 / 中 / 高 / 紧急
- 备注(文本)
- 相关文档(URL)
- 2. 在config.json中配置:
json
{
bitable: {
app
token: yourbitable
apptoken,
table
id: yourtable_id
}
}
- 3. 补丁还会处理bitablerecordchanged_v1事件,用于任务路由。
更新后重新应用
⚠️ OpenClaw或扩展更新可能会覆盖monitor.js。 每次更新后:
bash
bash ./skills/feishu-doc-collab/scripts/patch-monitor.sh
openclaw gateway restart
补丁脚本是幂等的——可安全多次运行。
注意: 对于openclaw-lark扩展(编译后的.js),无需清除jiti缓存。对于旧版内置的.ts安装,还需运行:rm -f /tmp/jiti/src-monitor.*.cjs
配置参考
config.json
| 字段 | 类型 | 必填 | 描述 |
|---|
| agentname | 字符串 | 是 | 协议路由中使用的内部名称 |
| agentdisplay_name |
字符串 | 是 | 文档回复中显示的显示名称 |
| bitable.app_token | 字符串 | 否 | 任务看板的多维表格应用令牌 |
| bitable.table_id | 字符串 | 否 | 任务看板的多维表格表ID |
环境
补丁从~/.openclaw/openclaw.json读取:
- - hooks.token — /hooks/agent端点的认证
- gateway.port — 网关端口(默认:18789)
已知问题与解决方案
事件风暴
问题: 飞书对单次逻辑编辑会发送多个drive.file.editv1和bitablerecordchangedv1事件。多维表格编辑尤其严重——更改一个记录字段可能在短时间内触发10-20+个事件。如果没有防抖,每个事件都会生成一个独立的隔离智能体会话(使用完整模型),导致大量令牌浪费。
实际影响: 一次多维表格任务编辑触发了15+个钩子会话,消耗35万+令牌,所有会话并行运行且得出相同结论:无需操作。
解决方案: 每个fileToken应用30秒防抖(在patch-monitor.sh v2中实现):
- - 使用Map跟踪每个文件/表的最后触发时间戳
- 如果同一文件在30秒内被触发,则静默跳过该事件
- 对于多维表格事件,防抖键包含fileToken和tableId
- 防抖在调用/hooks/agent之前应用,因此不会创建会话
机器人自编辑循环: 当智能体更新多维表格记录(例如,将状态更改为处理完)时,该编辑会触发更多事件。机器人自编辑检查(比较operator_id和botOpenId)能捕获大部分情况,但防抖为操作员ID不匹配的情况(例如API调用与机器人身份)提供了关键的安全网。
重要提示: 已运行的会话无法通过防抖停止。如果事件风暴已经开始,会话将运行至完成。防抖仅阻止新的触发。
###