@xwang152/claw-lark 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +223 -68
- package/README_zh.md +227 -66
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,35 +1,57 @@
|
|
|
1
|
-
# OpenClaw Feishu/Lark Plugin
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
# Lark Plugin for OpenClaw
|
|
3
|
+
|
|
4
|
+
[中文文档](./README_zh.md)
|
|
5
|
+
|
|
6
|
+
A channel plugin that enables OpenClaw to communicate via Lark (Larksuite) messaging platform.
|
|
4
7
|
|
|
5
8
|
## Features
|
|
6
9
|
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
11
|
-
- **
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- **
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
- **Direct Messages**: Chat with your bot one-on-one
|
|
11
|
+
- **Group Chats**: Add your bot to group conversations
|
|
12
|
+
- **Text Messages**: Send and receive text messages
|
|
13
|
+
- **Multimedia Support**: Send and receive images and files (PDF, Excel, Word, etc.)
|
|
14
|
+
- **Advanced Interaction**: Typing indicators, smart @mentions, and context quoting
|
|
15
|
+
- **Multi-mode Rendering**: Support for `auto`, `raw`, and `card` modes
|
|
16
|
+
- **Webhook Mode**: For individual Lark accounts (tested)
|
|
17
|
+
- **WebSocket Mode**: For enterprise accounts (recommended for low latency)
|
|
18
|
+
- **Auto-Recovery**: Webhook server automatically restarts on crashes
|
|
19
|
+
|
|
20
|
+
## Requirements
|
|
21
|
+
|
|
22
|
+
- OpenClaw installed and configured
|
|
23
|
+
- A Lark Developer account
|
|
24
|
+
- A Lark app with Bot capability enabled
|
|
19
25
|
|
|
20
26
|
## Installation
|
|
21
27
|
|
|
22
28
|
### 1. Automatic Installation (Recommended)
|
|
23
29
|
|
|
24
|
-
Install directly via
|
|
30
|
+
Install directly via OpenClaw CLI:
|
|
25
31
|
|
|
26
32
|
```bash
|
|
27
33
|
openclaw plugins install @xwang152/claw-lark
|
|
28
34
|
```
|
|
29
35
|
|
|
30
|
-
### 2.
|
|
36
|
+
### 2. Manual Installation (Source Code)
|
|
31
37
|
|
|
32
|
-
|
|
38
|
+
If you wish to install from source or for development/debugging purposes:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
# 1. Clone the repository
|
|
42
|
+
git clone https://github.com/xwang152/claw-lark.git
|
|
43
|
+
cd claw-lark
|
|
44
|
+
|
|
45
|
+
# Install dependencies
|
|
46
|
+
npm install
|
|
47
|
+
|
|
48
|
+
# Install plugin into OpenClaw
|
|
49
|
+
openclaw plugins install --link .
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 3. Restart Gateway
|
|
53
|
+
|
|
54
|
+
After installation, restart the Gateway to load the plugin:
|
|
33
55
|
|
|
34
56
|
```bash
|
|
35
57
|
openclaw gateway restart
|
|
@@ -41,67 +63,200 @@ Verify installation:
|
|
|
41
63
|
openclaw plugins list
|
|
42
64
|
```
|
|
43
65
|
|
|
44
|
-
You should see
|
|
66
|
+
You should see `lark` with status `loaded`.
|
|
67
|
+
|
|
68
|
+
## Lark App Setup
|
|
69
|
+
|
|
70
|
+
1. Go to [Lark Developer Console](https://open.larksuite.com/app)
|
|
71
|
+
|
|
72
|
+
2. Create a new app or use an existing one
|
|
73
|
+
|
|
74
|
+
3. Enable **Bot** capability under App Features
|
|
75
|
+
|
|
76
|
+
4. Add the following permissions under Permissions & Scopes:
|
|
77
|
+
|
|
78
|
+
| Permission | Scope | Description |
|
|
79
|
+
| :--- | :--- | :--- |
|
|
80
|
+
| `contact:user.base:readonly` | User Info | Get basic user info (to resolve sender names and avoid identity confusion) |
|
|
81
|
+
| `im:message` | Message | Send and receive messages |
|
|
82
|
+
| `im:message.p2p_msg:readonly` | P2P Message | Read direct messages sent to the bot |
|
|
83
|
+
| `im:message.group_at_msg:readonly` | Group Message | Receive messages where the bot is @mentioned in groups |
|
|
84
|
+
| `im:message:send_as_bot` | Send | Send messages as the bot |
|
|
85
|
+
| `im:resource` | Resource | Upload/download images and files |
|
|
86
|
+
|
|
87
|
+
**Optional Permissions (add as needed):**
|
|
88
|
+
|
|
89
|
+
| Permission | Scope | Description |
|
|
90
|
+
| :--- | :--- | :--- |
|
|
91
|
+
| `im:message.group_msg` | Group | Read all group messages (Sensitive permission) |
|
|
92
|
+
| `im:message:readonly` | Read | Get historical messages |
|
|
93
|
+
| `im:message:update` | Edit | Update/edit sent messages |
|
|
94
|
+
| `im:message:recall` | Recall | Recall sent messages |
|
|
95
|
+
| `im:message.reactions:read` | Reaction | View message emoji reactions |
|
|
96
|
+
| `im:chat` | Group | Get group list info |
|
|
97
|
+
| `contact:user.employee:readonly` | Contact | Read employee info (alternative to user.base) |
|
|
98
|
+
|
|
99
|
+
5. Note your **App ID** and **App Secret** from Credentials & Basic Info (you'll need these for configuration)
|
|
100
|
+
|
|
101
|
+
6. Publish your app under Version Management
|
|
45
102
|
|
|
46
103
|
## Configuration
|
|
47
104
|
|
|
48
|
-
###
|
|
49
|
-
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
mediaMaxMb: 30
|
|
80
|
-
# Rendering mode: "auto" | "raw" | "card"
|
|
81
|
-
renderMode: "auto"
|
|
82
|
-
# History limit (default 10)
|
|
83
|
-
# historyLimit: 10
|
|
105
|
+
### Using Config Commands
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Required settings
|
|
109
|
+
openclaw config set channels.lark.accounts.default.appId 'cli_xxxxx'
|
|
110
|
+
openclaw config set channels.lark.accounts.default.appSecret 'your-app-secret'
|
|
111
|
+
openclaw config set channels.lark.accounts.default.connectionMode 'webhook'
|
|
112
|
+
|
|
113
|
+
# Optional settings
|
|
114
|
+
openclaw config set channels.lark.accounts.default.webhookPort 3000
|
|
115
|
+
openclaw config set channels.lark.accounts.default.domain 'lark'
|
|
116
|
+
openclaw config set channels.lark.accounts.default.dmPolicy 'open'
|
|
117
|
+
openclaw config set channels.lark.accounts.default.groupPolicy 'open'
|
|
118
|
+
openclaw config set channels.lark.accounts.default.groupMentionGated false
|
|
119
|
+
|
|
120
|
+
# Security settings (from Lark Developer Console > Events & Callbacks > Encryption Strategy)
|
|
121
|
+
openclaw config set channels.lark.accounts.default.encryptKey 'your-encrypt-key'
|
|
122
|
+
openclaw config set channels.lark.accounts.default.verificationToken 'your-verification-token'
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Using Environment Variables
|
|
126
|
+
|
|
127
|
+
For the default account, you can use environment variables:
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
LARK_APP_ID=cli_xxxxx
|
|
131
|
+
LARK_APP_SECRET=your-app-secret
|
|
132
|
+
|
|
133
|
+
# Security settings (from Lark Developer Console > Events & Callbacks > Encryption Strategy)
|
|
134
|
+
LARK_ENCRYPT_KEY=your-encrypt-key # Optional, for decrypting event payloads
|
|
135
|
+
LARK_VERIFICATION_TOKEN=your-token # Optional, for verifying request authenticity
|
|
84
136
|
```
|
|
85
137
|
|
|
86
|
-
###
|
|
138
|
+
### Configuration Options
|
|
139
|
+
|
|
140
|
+
| Option | Type | Default | Description |
|
|
141
|
+
|--------|------|---------|-------------|
|
|
142
|
+
| `appId` | string | - | Lark App ID (required) |
|
|
143
|
+
| `appSecret` | string | - | Lark App Secret (required) |
|
|
144
|
+
| `connectionMode` | string | `websocket` | `webhook` or `websocket` |
|
|
145
|
+
| `webhookPort` | number | `3000` | Port for webhook server |
|
|
146
|
+
| `domain` | string | `lark` | `lark` (international) or `feishu` (China) |
|
|
147
|
+
| `encryptKey` | string | - | Encrypt key for decrypting event payloads (from Events & Callbacks > Encryption Strategy) |
|
|
148
|
+
| `verificationToken` | string | - | Token for verifying request authenticity (from Events & Callbacks > Encryption Strategy) |
|
|
149
|
+
| `dmPolicy` | string | `pairing` | `open`, `pairing`, or `allowlist` |
|
|
150
|
+
| `groupPolicy` | string | `open` | `open`, `allowlist`, or `disabled` |
|
|
151
|
+
| `requireMention` | boolean | `true` | Require @mention in groups (previously `groupMentionGated`) |
|
|
152
|
+
| `renderMode` | string | `auto` | `auto`, `raw`, or `card` |
|
|
153
|
+
| `mediaMaxMb` | number | `30` | Max size for media files in MB |
|
|
154
|
+
| `historyLimit` | number | `10` | Number of historical messages to read |
|
|
155
|
+
|
|
156
|
+
## Render Modes
|
|
87
157
|
|
|
88
158
|
| Mode | Description |
|
|
89
159
|
| :--- | :--- |
|
|
90
|
-
| **auto** | (Default)
|
|
91
|
-
| **raw** | Always use plain text
|
|
92
|
-
| **card** | Always use
|
|
160
|
+
| **auto** | (Default) Automatically detects code blocks, lists, or tables to use card rendering; otherwise uses plain text |
|
|
161
|
+
| **raw** | Always use plain text; tables are converted to ASCII text |
|
|
162
|
+
| **card** | Always use Lark interactive cards; supports Markdown highlighting and advanced layouts |
|
|
163
|
+
|
|
164
|
+
## Webhook Mode Setup
|
|
165
|
+
|
|
166
|
+
Choose the setup method based on your deployment environment.
|
|
167
|
+
|
|
168
|
+
### 1. Development (Using ngrok)
|
|
169
|
+
|
|
170
|
+
Recommended for local development and testing.
|
|
171
|
+
|
|
172
|
+
> **Security & Privacy Notice**: ngrok exposes your local server to the internet. Keep the following in mind:
|
|
173
|
+
> - Never share your ngrok URL publicly — anyone with the URL can send requests to your local machine
|
|
174
|
+
> - Use a paid ngrok plan with authentication or IP restrictions for production use
|
|
175
|
+
> - Stop ngrok when not in use to close the tunnel
|
|
176
|
+
> - Consider using Lark's `encryptKey` and `verificationToken` for additional request validation
|
|
93
177
|
|
|
94
|
-
|
|
178
|
+
1. Start ngrok to expose your local webhook server:
|
|
95
179
|
|
|
96
180
|
```bash
|
|
97
|
-
|
|
98
|
-
cd claw-lark
|
|
99
|
-
npm install
|
|
100
|
-
npm run typecheck
|
|
101
|
-
openclaw plugins install --link .
|
|
181
|
+
ngrok http 3000
|
|
102
182
|
```
|
|
103
183
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
-
|
|
184
|
+
2. Copy the HTTPS URL from ngrok (e.g., `https://abc123.ngrok.io`)
|
|
185
|
+
|
|
186
|
+
3. Configure Events & Callbacks in Lark Developer Console:
|
|
187
|
+
- Add event subscription: `im.message.receive_v1`
|
|
188
|
+
- Set Request URL to your ngrok HTTPS URL (e.g., `https://abc123.ngrok.io`)
|
|
189
|
+
|
|
190
|
+
### 2. Production (Server Deployment)
|
|
191
|
+
|
|
192
|
+
When deploying on a server, ngrok is **not** required.
|
|
193
|
+
|
|
194
|
+
1. **Open Port**: Ensure your server's firewall (Security Group) allows traffic on the port used by the plugin (default is `3000`).
|
|
195
|
+
2. **Configure URL**: In Lark Developer Console, configure "Events & Callbacks":
|
|
196
|
+
- Set the "Request URL" to your server's public address: `http://your-server-ip:3000`.
|
|
197
|
+
3. **(Recommended) Reverse Proxy**: Use Nginx or Caddy to set up a reverse proxy with SSL (HTTPS) and forward traffic to port `3000`.
|
|
198
|
+
|
|
199
|
+
### 3. Start the Plugin
|
|
200
|
+
|
|
201
|
+
1. Start OpenClaw:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
openclaw start
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
2. The webhook server will start automatically and handle URL verification.
|
|
208
|
+
|
|
209
|
+
## WebSocket Mode
|
|
210
|
+
|
|
211
|
+
WebSocket mode is available for enterprise Lark accounts that support long connections. Set `connectionMode` to `websocket`:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
openclaw config set channels.lark.accounts.default.connectionMode 'websocket'
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
> **Note**: WebSocket mode requires enterprise Lark accounts and does not need a public IP or webhook configuration.
|
|
218
|
+
|
|
219
|
+
## Multiple Accounts
|
|
220
|
+
|
|
221
|
+
You can configure multiple Lark accounts:
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
openclaw config set channels.lark.accounts.work.appId 'cli_work_app'
|
|
225
|
+
openclaw config set channels.lark.accounts.work.appSecret 'work-secret'
|
|
226
|
+
openclaw config set channels.lark.accounts.personal.appId 'cli_personal_app'
|
|
227
|
+
openclaw config set channels.lark.accounts.personal.appSecret 'personal-secret'
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Troubleshooting
|
|
231
|
+
|
|
232
|
+
### Bot not receiving messages
|
|
233
|
+
|
|
234
|
+
1. Verify the event subscription `im.message.receive_v1` is added
|
|
235
|
+
2. Check that the callback URL is correctly configured
|
|
236
|
+
3. Ensure the required permissions are enabled
|
|
237
|
+
4. Make sure the app is published (not just saved as draft)
|
|
238
|
+
|
|
239
|
+
### Permission errors when sending images
|
|
240
|
+
|
|
241
|
+
Add the `im:resource` permission in Lark Developer Console and republish your app.
|
|
242
|
+
|
|
243
|
+
### Webhook server not starting
|
|
244
|
+
|
|
245
|
+
Check if port 3000 is already in use. Change the port:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
openclaw config set channels.lark.accounts.default.webhookPort 3001
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Connection issues with WebSocket mode
|
|
252
|
+
|
|
253
|
+
WebSocket mode requires enterprise Lark accounts. If you have an individual account, use webhook mode instead.
|
|
254
|
+
|
|
255
|
+
## Contributing
|
|
256
|
+
|
|
257
|
+
Issues and pull requests are welcome! If you encounter bugs or have feature requests, please open an issue at https://github.com/xwang152-jack/claw-lark/issues.
|
|
258
|
+
|
|
259
|
+
## License
|
|
260
|
+
|
|
261
|
+
MIT
|
|
262
|
+
|
package/README_zh.md
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
# OpenClaw 飞书/Lark 插件
|
|
2
2
|
|
|
3
|
+
[English Document](./README.md)
|
|
4
|
+
|
|
3
5
|
这是一个为 OpenClaw 开发的频道插件,使 OpenClaw 能够通过飞书 (Feishu) 或 Lark 平台进行通信。
|
|
4
6
|
|
|
5
7
|
## 功能特性
|
|
6
8
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
- **私聊 (Direct Messages)**:与机器人一对一聊天
|
|
10
|
+
- **群聊 (Group Chats)**:将机器人添加到群组对话中
|
|
11
|
+
- **文本消息 (Text Messages)**:发送和接收文本消息
|
|
12
|
+
- **多媒体支持 (Multimedia Support)**:发送和接收图片及文件(PDF, Excel, Word 等)
|
|
13
|
+
- **高级交互 (Advanced Interaction)**:输入状态指示、智能 @提及 和 上下文引用
|
|
14
|
+
- **多模式渲染 (Multi-mode Rendering)**:支持 `auto`、`raw` 和 `card` 模式
|
|
15
|
+
- **Webhook 模式 (Webhook Mode)**:适用于个人飞书账号(已测试)
|
|
16
|
+
- **WebSocket 模式 (WebSocket Mode)**:适用于企业账号(推荐用于低延迟)
|
|
17
|
+
- **自动恢复 (Auto-Recovery)**:Webhook 服务崩溃后自动重启
|
|
18
|
+
|
|
19
|
+
## 环境要求
|
|
20
|
+
|
|
21
|
+
- 已安装并配置 OpenClaw
|
|
22
|
+
- 拥有飞书/Lark 开发者账号
|
|
23
|
+
- 一个已启用**机器人**能力的应用
|
|
19
24
|
|
|
20
25
|
## 安装步骤
|
|
21
26
|
|
|
@@ -27,7 +32,21 @@
|
|
|
27
32
|
openclaw plugins install @xwang152/claw-lark
|
|
28
33
|
```
|
|
29
34
|
|
|
30
|
-
### 2.
|
|
35
|
+
### 2. 手动安装 (源码安装)
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# 克隆仓库
|
|
39
|
+
git clone https://github.com/xwang152-jack/claw-lark.git
|
|
40
|
+
cd claw-lark
|
|
41
|
+
|
|
42
|
+
# 安装依赖
|
|
43
|
+
npm install
|
|
44
|
+
|
|
45
|
+
# 安装插件到 OpenClaw
|
|
46
|
+
openclaw plugins install --link .
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 3. 重启 Gateway
|
|
31
50
|
|
|
32
51
|
安装完成后,重启 Gateway 以加载插件:
|
|
33
52
|
|
|
@@ -41,83 +60,225 @@ openclaw gateway restart
|
|
|
41
60
|
openclaw plugins list
|
|
42
61
|
```
|
|
43
62
|
|
|
44
|
-
您应该能看到 `
|
|
63
|
+
您应该能看到 `lark` 插件且状态为 `loaded`。
|
|
45
64
|
|
|
46
65
|
## 飞书应用设置
|
|
47
66
|
|
|
48
67
|
1. 前往 [飞书开放平台](https://open.feishu.cn/app) (国内) 或 [Lark Developer Console](https://open.larksuite.com/app) (国际)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
68
|
+
|
|
69
|
+
2. 创建新应用或使用现有应用
|
|
70
|
+
|
|
71
|
+
3. 在“应用能力”下启用 **机器人** 能力
|
|
72
|
+
|
|
73
|
+
4. 在“权限管理”中添加以下权限:
|
|
74
|
+
|
|
75
|
+
| 权限 | 作用范围 | 描述 |
|
|
76
|
+
| :--- | :--- | :--- |
|
|
77
|
+
| `contact:user.base:readonly` | 通讯录 | 获取基本用户信息(用于解析发送者名称,避免身份混淆) |
|
|
78
|
+
| `im:message` | 消息 | 发送和接收消息 |
|
|
79
|
+
| `im:message.p2p_msg:readonly` | 私聊消息 | 读取发送给机器人的私聊消息 |
|
|
80
|
+
| `im:message.group_at_msg:readonly` | 群聊消息 | 接收机器人在群组中被 @ 的消息 |
|
|
81
|
+
| `im:message:send_as_bot` | 发送消息 | 以机器人身份发送消息 |
|
|
82
|
+
| `im:resource` | 资源 | 上传/下载图片和文件 |
|
|
83
|
+
|
|
84
|
+
**可选权限(按需添加):**
|
|
85
|
+
|
|
86
|
+
| 权限 | 作用范围 | 描述 |
|
|
87
|
+
| :--- | :--- | :--- |
|
|
88
|
+
| `im:message.group_msg` | 群组 | 读取所有群组消息(敏感权限) |
|
|
89
|
+
| `im:message:readonly` | 读取 | 获取历史消息 |
|
|
90
|
+
| `im:message:update` | 编辑 | 更新/编辑已发送的消息 |
|
|
91
|
+
| `im:message:recall` | 撤回 | 撤回已发送的消息 |
|
|
92
|
+
| `im:message.reactions:read` | 表情回应 | 查看消息的表情回应 |
|
|
93
|
+
| `im:chat` | 群组 | 获取群组列表信息 |
|
|
94
|
+
| `contact:user.employee:readonly` | 通讯录 | 读取员工信息(user.base 的替代方案) |
|
|
95
|
+
|
|
96
|
+
5. 在“凭证与基础信息”中记录您的 **App ID** 和 **App Secret**(配置时需要用到)
|
|
97
|
+
|
|
98
|
+
6. 在“版本管理与发布”中发布您的应用
|
|
59
99
|
|
|
60
100
|
## 配置说明
|
|
61
101
|
|
|
62
|
-
###
|
|
63
|
-
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
dmPolicy: "pairing"
|
|
82
|
-
# 私聊白名单 (仅 dmPolicy=allowlist 时生效,填写 OpenID)
|
|
83
|
-
# dmAllowlist:
|
|
84
|
-
# - "ou_xxx"
|
|
85
|
-
# 群聊策略: "open" | "allowlist" | "disabled"
|
|
86
|
-
groupPolicy: "allowlist"
|
|
87
|
-
# 群聊白名单 (仅 groupPolicy=allowlist 时生效,填写 ChatID)
|
|
88
|
-
# groupAllowlist:
|
|
89
|
-
# - "oc_xxx"
|
|
90
|
-
# 群聊是否需要 @机器人
|
|
91
|
-
requireMention: true
|
|
92
|
-
# 媒体文件最大大小 (MB, 默认 30)
|
|
93
|
-
mediaMaxMb: 30
|
|
94
|
-
# 回复渲染模式: "auto" | "raw" | "card"
|
|
95
|
-
renderMode: "auto"
|
|
96
|
-
# 历史消息读取条数 (默认 10)
|
|
97
|
-
# historyLimit: 10
|
|
102
|
+
### 使用配置命令
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# 必填设置
|
|
106
|
+
openclaw config set channels.lark.accounts.default.appId 'cli_xxxxx'
|
|
107
|
+
openclaw config set channels.lark.accounts.default.appSecret 'your-app-secret'
|
|
108
|
+
openclaw config set channels.lark.accounts.default.connectionMode 'webhook'
|
|
109
|
+
|
|
110
|
+
# 选填设置
|
|
111
|
+
openclaw config set channels.lark.accounts.default.webhookPort 3000
|
|
112
|
+
openclaw config set channels.lark.accounts.default.domain 'lark'
|
|
113
|
+
openclaw config set channels.lark.accounts.default.dmPolicy 'open'
|
|
114
|
+
openclaw config set channels.lark.accounts.default.groupPolicy 'open'
|
|
115
|
+
openclaw config set channels.lark.accounts.default.requireMention true
|
|
116
|
+
openclaw config set channels.lark.accounts.default.renderMode 'auto'
|
|
117
|
+
|
|
118
|
+
# 安全设置 (来自 飞书开发者后台 > 事件订阅 > 加密策略)
|
|
119
|
+
openclaw config set channels.lark.accounts.default.encryptKey 'your-encrypt-key'
|
|
120
|
+
openclaw config set channels.lark.accounts.default.verificationToken 'your-verification-token'
|
|
98
121
|
```
|
|
99
122
|
|
|
100
|
-
###
|
|
123
|
+
### 使用环境变量
|
|
124
|
+
|
|
125
|
+
对于默认账号,您可以使用环境变量进行配置:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
LARK_APP_ID=cli_xxxxx
|
|
129
|
+
LARK_APP_SECRET=your-app-secret
|
|
130
|
+
|
|
131
|
+
# 安全设置 (来自 飞书开发者后台 > 事件订阅 > 加密策略)
|
|
132
|
+
LARK_ENCRYPT_KEY=your-encrypt-key # 可选,用于解密事件负载
|
|
133
|
+
LARK_VERIFICATION_TOKEN=your-token # 可选,用于验证请求真实性
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### 配置选项
|
|
137
|
+
|
|
138
|
+
| 选项 | 类型 | 默认值 | 描述 |
|
|
139
|
+
|--------|------|---------|-------------|
|
|
140
|
+
| `appId` | string | - | 飞书 App ID (必填) |
|
|
141
|
+
| `appSecret` | string | - | 飞书 App Secret (必填) |
|
|
142
|
+
| `connectionMode` | string | `websocket` | `webhook` 或 `websocket` |
|
|
143
|
+
| `webhookPort` | number | `3000` | Webhook 服务器端口 |
|
|
144
|
+
| `domain` | string | `lark` | `lark` (国际版) 或 `feishu` (国内版) |
|
|
145
|
+
| `encryptKey` | string | - | 加密密钥,用于解密事件负载 (来自 事件订阅 > 加密策略) |
|
|
146
|
+
| `verificationToken` | string | - | 验证令牌,用于验证请求真实性 (来自 事件订阅 > 加密策略) |
|
|
147
|
+
| `dmPolicy` | string | `pairing` | `open` (开放), `pairing` (配对), 或 `allowlist` (白名单) |
|
|
148
|
+
| `groupPolicy` | string | `open` | `open` (开放), `allowlist` (白名单), 或 `disabled` (禁用) |
|
|
149
|
+
| `requireMention` | boolean | `true` | 群聊中是否需要 @提及 (原 `groupMentionGated`) |
|
|
150
|
+
| `renderMode` | string | `auto` | `auto`, `raw`, 或 `card` |
|
|
151
|
+
| `mediaMaxMb` | number | `30` | 媒体文件最大大小 (MB) |
|
|
152
|
+
| `historyLimit` | number | `10` | 读取历史消息的数量 |
|
|
101
153
|
|
|
102
|
-
|
|
154
|
+
## 渲染模式
|
|
155
|
+
|
|
156
|
+
| 模式 | 描述 |
|
|
103
157
|
| :--- | :--- |
|
|
104
|
-
| **auto** | (默认)
|
|
105
|
-
| **raw** |
|
|
106
|
-
| **card** |
|
|
158
|
+
| **auto** | (默认) 自动检测:检测到代码块、列表或表格时使用卡片渲染;否则使用纯文本 |
|
|
159
|
+
| **raw** | 始终使用纯文本渲染;表格会被转换为 ASCII 文本 |
|
|
160
|
+
| **card** | 始终使用飞书交互式卡片渲染;支持 Markdown 语法高亮和高级布局 |
|
|
161
|
+
|
|
162
|
+
## Webhook 模式指引
|
|
163
|
+
|
|
164
|
+
根据您的部署环境选择设置方法。
|
|
165
|
+
|
|
166
|
+
### 1. 开发环境 (使用 ngrok)
|
|
167
|
+
|
|
168
|
+
推荐用于本地开发和测试。
|
|
169
|
+
|
|
170
|
+
> **安全与隐私提示**:ngrok 会将您的本地服务器暴露给互联网。请注意以下几点:
|
|
171
|
+
> - 永远不要公开分享您的 ngrok URL —— 任何拥有该 URL 的人都可以向您的本地机器发送请求
|
|
172
|
+
> - 生产环境请使用带有身份验证或 IP 限制的付费 ngrok 计划
|
|
173
|
+
> - 不使用时请停止 ngrok 以关闭隧道
|
|
174
|
+
> - 建议使用飞书的 `encryptKey` 和 `verificationToken` 进行额外的请求验证
|
|
175
|
+
|
|
176
|
+
1. 启动 ngrok 以暴露本地 webhook 服务器:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
ngrok http 3000
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
2. 从 ngrok 复制 HTTPS URL (例如 `https://abc123.ngrok.io`)
|
|
183
|
+
|
|
184
|
+
3. 在飞书开发者后台配置“事件订阅”:
|
|
185
|
+
- 添加事件订阅:`im.message.receive_v1`
|
|
186
|
+
- 将请求网址 URL 设置为您的 ngrok HTTPS URL (例如 `https://abc123.ngrok.io`)
|
|
187
|
+
|
|
188
|
+
### 2. 生产环境 (服务器部署)
|
|
189
|
+
|
|
190
|
+
部署在服务器上时,**不需要** ngrok。
|
|
191
|
+
|
|
192
|
+
1. **开放端口**:确保您服务器的防火墙 (安全组) 允许插件使用的端口流量 (默认为 `3000`)。
|
|
193
|
+
2. **配置 URL**:在飞书开发者后台,配置“事件订阅”:
|
|
194
|
+
- 将“请求网址 URL”设置为您服务器的公网地址:`http://your-server-ip:3000`。
|
|
195
|
+
3. **(推荐) 反向代理**:使用 Nginx 或 Caddy 设置带有 SSL (HTTPS) 的反向代理,并将流量转发到端口 `3000`。
|
|
196
|
+
|
|
197
|
+
### 3. 启动插件
|
|
198
|
+
|
|
199
|
+
1. 启动 OpenClaw:
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
openclaw start
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
2. Webhook 服务器将自动启动并处理 URL 验证。
|
|
206
|
+
|
|
207
|
+
## WebSocket 模式
|
|
208
|
+
|
|
209
|
+
WebSocket 模式适用于支持长连接的企业自建应用。将 `connectionMode` 设置为 `websocket`:
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
openclaw config set channels.lark.accounts.default.connectionMode 'websocket'
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
> **注意**:WebSocket 模式需要企业自建应用,无需配置公网 IP 或回调地址。
|
|
216
|
+
|
|
217
|
+
## 多账号配置
|
|
218
|
+
|
|
219
|
+
您可以配置多个飞书账号:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
openclaw config set channels.lark.accounts.work.appId 'cli_work_app'
|
|
223
|
+
openclaw config set channels.lark.accounts.work.appSecret 'work-secret'
|
|
224
|
+
openclaw config set channels.lark.accounts.personal.appId 'cli_personal_app'
|
|
225
|
+
openclaw config set channels.lark.accounts.personal.appSecret 'personal-secret'
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## 故障排除
|
|
229
|
+
|
|
230
|
+
### 机器人无法接收消息
|
|
231
|
+
|
|
232
|
+
1. 验证是否已添加事件订阅 `im.message.receive_v1`
|
|
233
|
+
2. 检查回调 URL 是否配置正确
|
|
234
|
+
3. 确保已启用所需的权限
|
|
235
|
+
4. 确保应用已发布(不仅仅是保存为草稿)
|
|
236
|
+
|
|
237
|
+
### 发送图片时出现权限错误
|
|
238
|
+
|
|
239
|
+
在飞书开发者后台添加 `im:resource` 权限并重新发布应用。
|
|
240
|
+
|
|
241
|
+
### Webhook 服务无法启动
|
|
242
|
+
|
|
243
|
+
检查端口 3000 是否已被占用。更改端口:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
openclaw config set channels.lark.accounts.default.webhookPort 3001
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### WebSocket 模式连接问题
|
|
250
|
+
|
|
251
|
+
WebSocket 模式需要企业自建应用。如果您是个人账号,请改用 webhook 模式。
|
|
107
252
|
|
|
108
253
|
## 开发者相关
|
|
109
254
|
|
|
255
|
+
欢迎提交 Issue 和 Pull Request!如果您遇到 Bug 或有功能请求,请在 https://github.com/xwang152-jack/claw-lark/issues 提交 Issue。
|
|
256
|
+
|
|
257
|
+
### 开发环境设置
|
|
258
|
+
|
|
110
259
|
如果您想参与开发:
|
|
111
260
|
|
|
112
261
|
```bash
|
|
262
|
+
# 克隆仓库
|
|
113
263
|
git clone https://github.com/xwang152-jack/claw-lark.git
|
|
114
264
|
cd claw-lark
|
|
265
|
+
|
|
266
|
+
# 安装依赖
|
|
115
267
|
npm install
|
|
268
|
+
|
|
269
|
+
# 运行类型检查
|
|
116
270
|
npm run typecheck
|
|
271
|
+
|
|
272
|
+
# 链接插件以进行本地开发
|
|
117
273
|
openclaw plugins install --link .
|
|
118
274
|
```
|
|
119
275
|
|
|
120
276
|
### 常用命令
|
|
277
|
+
|
|
121
278
|
- `npm run lint`: 代码风格检查
|
|
122
279
|
- `npm run format`: 自动格式化代码
|
|
123
|
-
- `npm test`:
|
|
280
|
+
- `npm test`: 运行测试
|
|
281
|
+
|
|
282
|
+
## 许可证
|
|
283
|
+
|
|
284
|
+
MIT
|