# How to Connect OpenClaw with Feishu Bot

This guide explains how to configure the connection between OpenClaw and your Feishu bot.

## Step 1: Create a Feishu Bot

1. Go to [Feishu Open Platform](https://open.feishu.cn/)
2. Create a new application
3. Get your `App ID` and `App Secret`

## Step 2: Send Credentials to OpenClaw

Send the following to your OpenClaw agent:

```
My Feishu bot credentials:
- App ID: cli_xxx
- App Secret: xxx
```

## Step 3: Configure Feishu Bot Permissions

### Basic Chat Bot Permissions

```json
{
  "scopes": {
    "tenant": [
      "contact:contact.base:readonly",
      "im:chat",
      "im:message",
      "im:message.group_at_msg:readonly",
      "im:message.group_msg",
      "im:message.p2p_msg:readonly",
      "im:message:readonly",
      "im:message:send_as_bot"
    ],
    "user": [
      "cardkit:card:write"
    ]
  }
}
```

### Feishu Doc Access Bot Permissions (Requires Approval)

```json
{
  "scopes": {
    "tenant": [
      "application:bot.menu:write",
      "bitable:app",
      "cardkit:card:write",
      "contact:contact.base:readonly",
      "docs:document.comment:read",
      "docs:document.comment:update",
      "docs:document.content:read",
      "docx:document",
      "docx:document.block:convert",
      "docx:document:create",
      "docx:document:readonly",
      "docx:document:write_only",
      "drive:drive",
      "im:chat",
      "im:chat.members:bot_access",
      "im:message",
      "im:message.group_at_msg:readonly",
      "im:message.group_msg",
      "im:message.p2p_msg:readonly",
      "wiki:wiki",
      "wiki:wiki:readonly"
    ],
    "user": [
      "bitable:app",
      "docs:doc"
    ]
  }
}
```

## Step 4: Configure WebSocket Long Connection

In the Feishu Open Platform console, you need to enable receiving events through a persistent WebSocket connection:

1. Go to **Events and Callbacks** (事件与回调)
2. Under **Subscription Method** (订阅方式), select **Receive events/callbacks through persistent connection** (使用长连接接收事件/回调)
3. Set your WebSocket endpoint URL:
   - Format: `http://<your-server-ip>:18791/webhook/feishu`
   - Example: `http://47.96.72.176:18791/webhook/feishu`
4. Enable the following events:
   - `im.message.receive_v1` (Message received)

## Step 5: Configure Webhook

Enable the receiving endpoint:
- Create a receive URL: `https://your-domain.com/receive_v1`

## Step 5: Publish the Bot

Submit your bot for approval in the Feishu Open Platform console.

## Step 6: Pair with OpenClaw

Send a private message to your OpenClaw agent with the pairing code to complete the connection.

---

## Troubleshooting

### Bot Not Receiving Messages

1. Verify bot is added to the chat
2. Check permissions are properly configured
3. Ensure webhook URL is accessible

### Authentication Failed

1. Verify App ID and App Secret are correct
2. Check that bot is published and approved

### Need Help

- Feishu Developer Docs: https://open.feishu.cn/document/
- OpenClaw Docs: https://docs.openclaw.ai
