๐ŸŽ Get the FREE AI Skills Starter Guide โ€” Subscribe โ†’
BytesAgainBytesAgain
๐Ÿฆ€ ClawHub

Feishu Doc Collab

by @dongweiii

Enable real-time AI collaboration in Feishu (Lark) documents. When a user edits a Feishu doc, the agent automatically detects the change, reads the document,...

Versionv1.2.0
Downloads1,054
TERMINAL
clawhub install feishu-doc-collab

๐Ÿ“– About This Skill


name: feishu-doc-collab description: | Enable real-time AI collaboration in Feishu (Lark) documents. When a user edits a Feishu doc, the agent automatically detects the change, reads the document, and responds inline โ€” turning any Feishu document into a live human-AI conversation.

Features: - Feishu document edit event โ†’ triggers isolated agent session automatically - Structured in-doc chat protocol (status flags prevent premature AI responses while user is still typing) - Multi-party support: multiple humans + multiple AI agents in one document - Bitable (spreadsheet) task board integration for collaborative task management - Anti-loop: bot's own edits are automatically ignored

Triggers: Feishu doc collaboration, ้ฃžไนฆๆ–‡ๆกฃๅไฝœ, document edit event, in-doc chat, ๆ–‡ๆกฃๅ†…ๅฏน่ฏ, Lark document AI, feishu doc auto-reply, ้ฃžไนฆๆ–‡ๆกฃ่‡ชๅŠจๅ›žๅค


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) 2. openclaw-lark extension installed (v2026.3+) or built-in feishu extension 3. 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:

       {
         "hooks": {
           "enabled": true,
           "token": "your-hooks-token-here"
         }
       }
       

    Quick Setup

    Step 1: Enable hooks in openclaw.json

    Add the hooks section if not present:

    # Generate a random token
    TOKEN=$(openssl rand -hex 16)
    echo "Your hooks token: $TOKEN"
    

    Then add to openclaw.json:

    "hooks": { "enabled": true, "token": "" }

    Step 2: Apply the monitor patch

    bash ./skills/feishu-doc-collab/scripts/patch-monitor.sh
    

    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 deliver: false
  • Silently ignore drive.file.read_v1 events (suppress warnings)
  • Step 3: Configure your agent identity

    Edit ./skills/feishu-doc-collab/config.json:

    {
      "agent_name": "MyBot",
      "agent_display_name": "My AI Assistant"
    }
    

    The patch script uses this to set up message routing (who the agent responds as).

    Step 4: Restart the gateway

    openclaw gateway restart
    

    Step 5: Set up the Doc Chat Protocol

    Copy the protocol template to your workspace:

    cp ./skills/feishu-doc-collab/assets/DOC_PROTOCOL_TEMPLATE.md ./DOC_PROTOCOL.md
    

    Edit DOC_PROTOCOL.md to fill in your participant roster.

    How It Works

    Document Edit Flow

    User edits Feishu doc
            โ†“
    Feishu sends drive.file.edit_v1 event
            โ†“
    Patched monitor.ts receives event
            โ†“
    Checks: is this the bot's own edit? โ†’ Yes: skip (anti-loop)
            โ†“ No
    Debounce: same file triggered within 30s? โ†’ Yes: skip
            โ†“ No
    POST /hooks/agent with deliver:false (isolated session)
            โ†“
    Agent reads DOC_PROTOCOL.md for message format
            โ†“
    Agent reads the document, finds last message block
            โ†“
    Checks: status=๐ŸŸข? addressed to me? not from me?
            โ†“ Yes
    Agent composes reply and appends to document
    

    In-Document Chat Protocol

    Messages in the document follow this format:

    ---
    > Sender Name โ†’ Receiver Name | ๐ŸŸข ๅฎŒๆˆ

    Your message content here.

    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
  • โ†’ all โ€” 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:

       {
         "bitable": {
           "app_token": "your_bitable_app_token",
           "table_id": "your_table_id"
         }
       }
       

    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:

    bash ./skills/feishu-doc-collab/scripts/patch-monitor.sh
    openclaw gateway restart
    

    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: rm -f /tmp/jiti/src-monitor.*.cjs

    Configuration Reference

    config.json

    | Field | Type | Required | Description | |-------|------|----------|-------------| | agent_name | string | Yes | Internal name used in protocol routing | | agent_display_name | 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
  • gateway.port โ€” 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 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

    โš™๏ธ Configuration

    1. OpenClaw with Feishu channel configured (app ID, app secret, event subscriptions) 2. openclaw-lark extension installed (v2026.3+) or built-in feishu extension 3. 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:

       {
         "hooks": {
           "enabled": true,
           "token": "your-hooks-token-here"
         }
       }