> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zeus.agentspro.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# Feishu

> Zeus Feishu Digital Twin - Auto-Reply & Message Synchronization

# Feishu Digital Twin Integration

Zeus supports deep integration with Feishu (Lark), creating your digital twin with auto-reply, message synchronization, and intelligent assistant capabilities.

## Overview

The Feishu digital twin is an AI agent running on Feishu that can:

* **Auto-reply to messages** - Reply on your behalf in private chats and group chats
* **Smart activation strategies** - Support @ trigger or all-message reply
* **SSE streaming updates** - Real-time message card updates showing the thinking process
* **Tool call visualization** - Display tool execution status in message cards
* **Reuse Zeus capabilities** - Inherit full Agent capabilities and personality settings

## Architecture Design

```mermaid theme={null}
flowchart TD
    subgraph Gateway["Zeus Digital Twin Gateway"]
        FeishuCh["Feishu Channel"]
        SlackCh["Slack Channel"]
        OtherCh["Other Channel"]

        subgraph Router["Channel Router"]
            Normalize["Message Normalization"]
            Activation["Activation Strategy (mention / always)"]
            SessionIso["Session Isolation (session per chat/user)"]
        end

        subgraph Agent["AI Agent (DeepAgents)"]
            Memory["Context Memory (Memory Service)"]
            Tools["Tool Calls (MCP Tools)"]
            Persona["Personality (CORE + SOUL Prompts)"]
        end

        subgraph Response["Response Router"]
            SSE_update["SSE → Message Card Update"]
            Format["Format Conversion (markdown → Feishu post)"]
            Reply["Reply Sending"]
        end

        FeishuCh --> Router
        SlackCh --> Router
        OtherCh --> Router
        Router --> Agent
        Agent --> Response
    end
```

## Quick Start

### 1. Create Feishu Application

1. Visit [Feishu Open Platform](https://open.feishu.cn/app) to create an application
2. Add **Bot** capability
3. Configure permissions:
   * `im:message` - Get and send messages
   * `im:message.group_at_msg` - Receive group @ messages
   * `im:chat` - Get chat information
4. Obtain `App ID` and `App Secret`

### 2. Configure Event Subscription

Configure event subscription on the Feishu Open Platform:

* **Request URL**: `https://your-domain.com/api/channels/feishu/webhook`
* **Subscribe to events**: `im.message.receive_v1` (receive messages)

### 3. Environment Variables

Configure the following environment variables in your `.env` file:

* `FEISHU_APP_ID` - Feishu App ID
* `FEISHU_APP_SECRET` - Feishu App Secret
* `FEISHU_VERIFICATION_TOKEN` - Verification Token
* `FEISHU_ENCRYPT_KEY` - Message encryption key (optional)
* `FEISHU_DM_ACTIVATION` - Direct message activation strategy (`always` or `mention`)
* `FEISHU_GROUP_ACTIVATION` - Group chat activation strategy (`always` or `mention`)
* `FEISHU_ALLOWED_USERS` - User allowlist (optional, comma-separated)
* `FEISHU_ALLOWED_CHATS` - Chat allowlist (optional, comma-separated)

### 4. Publish Application

After configuration, publish the application on the Feishu Open Platform to start using it.

***

## Activation Strategies

Inspired by [OpenClaw](https://docs.openclaw.ai) design, supporting flexible activation strategies:

| Strategy  | Description                 | Use Case                                  |
| --------- | --------------------------- | ----------------------------------------- |
| `always`  | Reply to all messages       | Personal assistant, dedicated groups      |
| `mention` | Reply only when @ mentioned | Public groups, multi-person collaboration |

Independent configuration per scenario:

* **Direct message strategy** - Default `always` (always reply in DMs)
* **Group chat strategy** - Default `mention` (reply only when @ mentioned in groups)
* **Allowlist** - Configurable user and chat allowlists; when empty, all are allowed

***

## SSE Streaming Message Sync

Zeus supports synchronizing the complete SSE message stream to Feishu, delivering a real-time experience similar to the Web interface.

### Message Type Mapping

| SSE Message Type        | Feishu Display               |
| ----------------------- | ---------------------------- |
| `TextMessage`           | Real-time content update     |
| `ToolCallMessage`       | Show tool call status        |
| `ToolCallResultMessage` | Update tool execution result |
| `CompleteMessage`       | Final completion state       |
| `ErrorMessage`          | Error notification           |

### Implementation

```mermaid theme={null}
sequenceDiagram
    participant SSE as SSE Stream (Zeus)
    participant Feishu as Feishu API

    SSE->>Feishu: TextMessage (chunk 1) → Create message card (POST)
    SSE->>Feishu: TextMessage (chunk 2) → Update message card (PATCH)
    SSE->>Feishu: TextMessage (chunk 3) → Update message card (PATCH)
    SSE->>Feishu: ToolCallMessage → Update card: show tool call
    SSE->>Feishu: ToolCallResultMessage → Update card: show result
    SSE->>Feishu: TextMessage (final) → Update message card (PATCH)
    SSE->>Feishu: CompleteMessage → Final update (remove loading state)
```

### Preview

Message cards update in real-time, showing the complete thinking and execution process:

```
┌─────────────────────────────────────┐
│ Zeus AI                        🔵    │
├─────────────────────────────────────┤
│ Based on search results, today's     │
│ key news includes:                   │
│ 1. AI technology breakthrough...     │
│ 2. Tech company earnings...          │
│─────────────────────────────────────│
│ 🔧 Tool calls:                       │
│ ✅ web_search                        │
└─────────────────────────────────────┘
```

***

## API Endpoints

### Webhook Receiver

`POST /api/channels/feishu/webhook`

Handled event types:

* `url_verification` - URL verification (initial setup)
* `im.message.receive_v1` - Receive messages

***

## Message Card Templates

Recommended to use Feishu message cards for displaying AI replies, supporting:

* Status indicators (thinking/replying/completed)
* Markdown content rendering
* Collapsible tool call display
* Error message alerts

***

## Advanced Features

### Planned Features

| Feature                 | Priority | Description                                                 |
| ----------------------- | -------- | ----------------------------------------------------------- |
| Message Memory          | P0       | Use MemoryService, isolated by chat\_id                     |
| Group Chat Context      | P0       | Remember conversation context in group chats                |
| @ Reply                 | P0       | Automatically @ the questioner when replying in group chats |
| Message Cards           | P1       | Use Feishu message cards for complex content display        |
| Delayed Reply           | P1       | Simulate thinking time for more natural responses           |
| Calendar Integration    | P2       | Integrate Feishu Calendar, auto-reply "I'm in a meeting"    |
| File Processing         | P2       | Process images, documents, and other attachments            |
| Offline Mode            | P2       | Auto-reply during "do not disturb" periods                  |
| Cron Proactive Messages | P3       | Send daily reports, reminders on schedule                   |

### Integration with Other Channels

The Feishu channel design follows a generic Channel abstraction, extensible to support:

* Slack
* Discord
* WeCom
* Telegram
* DingTalk

***

## Security Considerations

### Signature Verification

It is recommended to enable Feishu event signature verification using SHA-256 HMAC to verify request signatures, ensuring trusted message sources. Verification requires checking the `X-Lark-Request-Timestamp` and `X-Lark-Request-Nonce` request headers.

### Allowlist Mechanism

* Supports user allowlist (`allowed_users`)
* Supports chat allowlist (`allowed_chats`)
* When not configured, all are allowed by default

### Sensitive Operation Protection

For major decisions, financial, legal, and other sensitive issues, the digital twin will explicitly state that the actual person's confirmation is needed.

***

## References

* [Feishu Open Platform Documentation](https://open.feishu.cn/document)
* [Feishu Message API](https://open.feishu.cn/document/server-docs/im-v1/message/create)
* [Feishu Message Card Builder](https://open.feishu.cn/tool/cardbuilder)
* [OpenClaw Multi-Channel Design](https://docs.openclaw.ai/channels)
