@milerliu/feishu 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 m1heng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,363 @@
1
+ # clawd-feishu
2
+
3
+ Feishu/Lark (飞书) channel plugin for [OpenClaw](https://github.com/openclaw/openclaw).
4
+
5
+ [English](#english) | [中文](#中文)
6
+
7
+ ---
8
+
9
+ ## English
10
+
11
+ ### Installation
12
+
13
+ ```bash
14
+ openclaw plugins install @m1heng-clawd/feishu
15
+ ```
16
+
17
+ Or install via npm:
18
+
19
+ ```bash
20
+ npm install @m1heng-clawd/feishu
21
+ ```
22
+
23
+ ### Configuration
24
+
25
+ 1. Create a self-built app on [Feishu Open Platform](https://open.feishu.cn)
26
+ 2. Get your App ID and App Secret from the Credentials page
27
+ 3. Enable required permissions (see below)
28
+ 4. **Configure event subscriptions** (see below) ⚠️ Important
29
+ 5. Configure the plugin:
30
+
31
+ #### Required Permissions
32
+
33
+ | Permission | Scope | Description |
34
+ |------------|-------|-------------|
35
+ | `contact:user.base:readonly` | User info | Get basic user info (required to resolve sender display names for speaker attribution) |
36
+ | `im:message` | Messaging | Send and receive messages |
37
+ | `im:message.p2p_msg:readonly` | DM | Read direct messages to bot |
38
+ | `im:message.group_at_msg:readonly` | Group | Receive @mention messages in groups |
39
+ | `im:message:send_as_bot` | Send | Send messages as the bot |
40
+ | `im:resource` | Media | Upload and download images/files |
41
+
42
+ #### Optional Permissions
43
+
44
+ | Permission | Scope | Description |
45
+ |------------|-------|-------------|
46
+ | `im:message.group_msg` | Group | Read all group messages (sensitive) |
47
+ | `im:message:readonly` | Read | Get message history |
48
+ | `im:message:update` | Edit | Update/edit sent messages |
49
+ | `im:message:recall` | Recall | Recall sent messages |
50
+ | `im:message.reactions:read` | Reactions | View message reactions |
51
+
52
+ #### Document Tools Permissions
53
+
54
+ Required if using Feishu document tools (`feishu_doc_*`):
55
+
56
+ | Permission | Description |
57
+ |------------|-------------|
58
+ | `docx:document` | Create/edit documents |
59
+ | `docx:document:readonly` | Read documents |
60
+ | `docx:document.block:convert` | Markdown to blocks conversion (required for write/append) |
61
+ | `drive:drive` | Upload images to documents |
62
+ | `drive:drive:readonly` | List folders |
63
+
64
+ #### Event Subscriptions ⚠️
65
+
66
+ > **This is the most commonly missed configuration!** If the bot can send messages but cannot receive them, check this section.
67
+
68
+ In the Feishu Open Platform console, go to **Events & Callbacks**:
69
+
70
+ 1. **Event configuration**: Select **Long connection** (recommended)
71
+ 2. **Add event subscriptions**:
72
+
73
+ | Event | Description |
74
+ |-------|-------------|
75
+ | `im.message.receive_v1` | Receive messages (required) |
76
+ | `im.message.message_read_v1` | Message read receipts |
77
+ | `im.chat.member.bot.added_v1` | Bot added to group |
78
+ | `im.chat.member.bot.deleted_v1` | Bot removed from group |
79
+
80
+ 3. Ensure the event permissions are approved
81
+
82
+ ```bash
83
+ openclaw config set channels.feishu.appId "cli_xxxxx"
84
+ openclaw config set channels.feishu.appSecret "your_app_secret"
85
+ openclaw config set channels.feishu.enabled true
86
+ ```
87
+
88
+ ### Configuration Options
89
+
90
+ ```yaml
91
+ channels:
92
+ feishu:
93
+ enabled: true
94
+ appId: "cli_xxxxx"
95
+ appSecret: "secret"
96
+ # Domain: "feishu" (China) or "lark" (International)
97
+ domain: "feishu"
98
+ # Connection mode: "websocket" (recommended) or "webhook"
99
+ connectionMode: "websocket"
100
+ # DM policy: "pairing" | "open" | "allowlist"
101
+ dmPolicy: "pairing"
102
+ # Group policy: "open" | "allowlist" | "disabled"
103
+ groupPolicy: "allowlist"
104
+ # Require @mention in groups
105
+ requireMention: true
106
+ # Max media size in MB (default: 30)
107
+ mediaMaxMb: 30
108
+ # Render mode for bot replies: "auto" | "raw" | "card"
109
+ renderMode: "auto"
110
+ ```
111
+
112
+ #### Render Mode
113
+
114
+ | Mode | Description |
115
+ |------|-------------|
116
+ | `auto` | (Default) Automatically detect: use card for messages with code blocks or tables, plain text otherwise. |
117
+ | `raw` | Always send replies as plain text. Markdown tables are converted to ASCII. |
118
+ | `card` | Always send replies as interactive cards with full markdown rendering (syntax highlighting, tables, clickable links). |
119
+
120
+ ### Features
121
+
122
+ - WebSocket and Webhook connection modes
123
+ - Direct messages and group chats
124
+ - Message replies and quoted message context
125
+ - **Inbound media support**: AI can see images, read files (PDF, Excel, etc.), and process rich text with embedded images
126
+ - Image and file uploads (outbound)
127
+ - Typing indicator (via emoji reactions)
128
+ - Pairing flow for DM approval
129
+ - User and group directory lookup
130
+ - **Card render mode**: Optional markdown rendering with syntax highlighting
131
+ - **Document tools**: Read, create, and write Feishu documents with markdown (tables not supported due to API limitations)
132
+ - **@mention forwarding**: When you @mention someone in your message, the bot's reply will automatically @mention them too
133
+
134
+ #### @Mention Forwarding
135
+
136
+ When you want the bot to @mention someone in its reply, simply @mention them in your message:
137
+
138
+ - **In DM**: `@张三 say hello` → Bot replies with `@张三 Hello!`
139
+ - **In Group**: `@bot @张三 say hello` → Bot replies with `@张三 Hello!`
140
+
141
+ The bot automatically detects @mentions in your message and includes them in its reply. No extra permissions required beyond the standard messaging permissions.
142
+
143
+ ### FAQ
144
+
145
+ #### Bot cannot receive messages
146
+
147
+ Check the following:
148
+ 1. Have you configured **event subscriptions**? (See Event Subscriptions section)
149
+ 2. Is the event configuration set to **long connection**?
150
+ 3. Did you add the `im.message.receive_v1` event?
151
+ 4. Are the permissions approved?
152
+
153
+ #### 403 error when sending messages
154
+
155
+ Ensure `im:message:send_as_bot` permission is approved.
156
+
157
+ #### How to clear history / start new conversation
158
+
159
+ Send `/new` command in the chat.
160
+
161
+ #### Why is the output not streaming
162
+
163
+ Feishu API has rate limits. Streaming updates can easily trigger throttling. We use complete-then-send approach for stability.
164
+
165
+ #### Windows install error `spawn npm ENOENT`
166
+
167
+ If `openclaw plugins install` fails, install manually:
168
+
169
+ ```bash
170
+ # 1. Download the package
171
+ curl -O https://registry.npmjs.org/@m1heng-clawd/feishu/-/feishu-0.1.3.tgz
172
+
173
+ # 2. Install from local file
174
+ openclaw plugins install ./feishu-0.1.3.tgz
175
+ ```
176
+
177
+ #### Cannot find the bot in Feishu
178
+
179
+ 1. Ensure the app is published (at least to test version)
180
+ 2. Search for the bot name in Feishu search box
181
+ 3. Check if your account is in the app's availability scope
182
+
183
+ ---
184
+
185
+ ## 中文
186
+
187
+ ### 安装
188
+
189
+ ```bash
190
+ openclaw plugins install @m1heng-clawd/feishu
191
+ ```
192
+
193
+ 或通过 npm 安装:
194
+
195
+ ```bash
196
+ npm install @m1heng-clawd/feishu
197
+ ```
198
+
199
+ ### 配置
200
+
201
+ 1. 在 [飞书开放平台](https://open.feishu.cn) 创建自建应用
202
+ 2. 在凭证页面获取 App ID 和 App Secret
203
+ 3. 开启所需权限(见下方)
204
+ 4. **配置事件订阅**(见下方)⚠️ 重要
205
+ 5. 配置插件:
206
+
207
+ #### 必需权限
208
+
209
+ | 权限 | 范围 | 说明 |
210
+ |------|------|------|
211
+ | `contact:user.base:readonly` | 用户信息 | 获取用户基本信息(用于解析发送者姓名,避免群聊/私聊把不同人当成同一说话者) |
212
+ | `im:message` | 消息 | 发送和接收消息 |
213
+ | `im:message.p2p_msg:readonly` | 私聊 | 读取发给机器人的私聊消息 |
214
+ | `im:message.group_at_msg:readonly` | 群聊 | 接收群内 @机器人 的消息 |
215
+ | `im:message:send_as_bot` | 发送 | 以机器人身份发送消息 |
216
+ | `im:resource` | 媒体 | 上传和下载图片/文件 |
217
+
218
+ #### 可选权限
219
+
220
+ | 权限 | 范围 | 说明 |
221
+ |------|------|------|
222
+ | `im:message.group_msg` | 群聊 | 读取所有群消息(敏感) |
223
+ | `im:message:readonly` | 读取 | 获取历史消息 |
224
+ | `im:message:update` | 编辑 | 更新/编辑已发送消息 |
225
+ | `im:message:recall` | 撤回 | 撤回已发送消息 |
226
+ | `im:message.reactions:read` | 表情 | 查看消息表情回复 |
227
+
228
+ #### 文档工具权限
229
+
230
+ 使用飞书文档工具(`feishu_doc_*`)需要以下权限:
231
+
232
+ | 权限 | 说明 |
233
+ |------|------|
234
+ | `docx:document` | 创建/编辑文档 |
235
+ | `docx:document:readonly` | 读取文档 |
236
+ | `docx:document.block:convert` | Markdown 转 blocks(write/append 必需) |
237
+ | `drive:drive` | 上传图片到文档 |
238
+ | `drive:drive:readonly` | 列出文件夹 |
239
+
240
+ #### 事件订阅 ⚠️
241
+
242
+ > **这是最容易遗漏的配置!** 如果机器人能发消息但收不到消息,请检查此项。
243
+
244
+ 在飞书开放平台的应用后台,进入 **事件与回调** 页面:
245
+
246
+ 1. **事件配置方式**:选择 **使用长连接接收事件**(推荐)
247
+ 2. **添加事件订阅**,勾选以下事件:
248
+
249
+ | 事件 | 说明 |
250
+ |------|------|
251
+ | `im.message.receive_v1` | 接收消息(必需) |
252
+ | `im.message.message_read_v1` | 消息已读回执 |
253
+ | `im.chat.member.bot.added_v1` | 机器人进群 |
254
+ | `im.chat.member.bot.deleted_v1` | 机器人被移出群 |
255
+
256
+ 3. 确保事件订阅的权限已申请并通过审核
257
+
258
+ ```bash
259
+ openclaw config set channels.feishu.appId "cli_xxxxx"
260
+ openclaw config set channels.feishu.appSecret "your_app_secret"
261
+ openclaw config set channels.feishu.enabled true
262
+ ```
263
+
264
+ ### 配置选项
265
+
266
+ ```yaml
267
+ channels:
268
+ feishu:
269
+ enabled: true
270
+ appId: "cli_xxxxx"
271
+ appSecret: "secret"
272
+ # 域名: "feishu" (国内) 或 "lark" (国际)
273
+ domain: "feishu"
274
+ # 连接模式: "websocket" (推荐) 或 "webhook"
275
+ connectionMode: "websocket"
276
+ # 私聊策略: "pairing" | "open" | "allowlist"
277
+ dmPolicy: "pairing"
278
+ # 群聊策略: "open" | "allowlist" | "disabled"
279
+ groupPolicy: "allowlist"
280
+ # 群聊是否需要 @机器人
281
+ requireMention: true
282
+ # 媒体文件最大大小 (MB, 默认 30)
283
+ mediaMaxMb: 30
284
+ # 回复渲染模式: "auto" | "raw" | "card"
285
+ renderMode: "auto"
286
+ ```
287
+
288
+ #### 渲染模式
289
+
290
+ | 模式 | 说明 |
291
+ |------|------|
292
+ | `auto` | (默认)自动检测:有代码块或表格时用卡片,否则纯文本 |
293
+ | `raw` | 始终纯文本,表格转为 ASCII |
294
+ | `card` | 始终使用卡片,支持语法高亮、表格、链接等 |
295
+
296
+ ### 功能
297
+
298
+ - WebSocket 和 Webhook 连接模式
299
+ - 私聊和群聊
300
+ - 消息回复和引用上下文
301
+ - **入站媒体支持**:AI 可以看到图片、读取文件(PDF、Excel 等)、处理富文本中的嵌入图片
302
+ - 图片和文件上传(出站)
303
+ - 输入指示器(通过表情回复实现)
304
+ - 私聊配对审批流程
305
+ - 用户和群组目录查询
306
+ - **卡片渲染模式**:支持语法高亮的 Markdown 渲染
307
+ - **文档工具**:读取、创建、用 Markdown 写入飞书文档(表格因 API 限制不支持)
308
+ - **@ 转发功能**:在消息中 @ 某人,机器人的回复会自动 @ 该用户
309
+
310
+ #### @ 转发功能
311
+
312
+ 如果你希望机器人的回复中 @ 某人,只需在你的消息中 @ 他们:
313
+
314
+ - **私聊**:`@张三 跟他问好` → 机器人回复 `@张三 你好!`
315
+ - **群聊**:`@机器人 @张三 跟他问好` → 机器人回复 `@张三 你好!`
316
+
317
+ 机器人会自动检测消息中的 @ 并在回复时带上。无需额外权限。
318
+
319
+ ### 常见问题
320
+
321
+ #### 机器人收不到消息
322
+
323
+ 检查以下配置:
324
+ 1. 是否配置了 **事件订阅**?(见上方事件订阅章节)
325
+ 2. 事件配置方式是否选择了 **长连接**?
326
+ 3. 是否添加了 `im.message.receive_v1` 事件?
327
+ 4. 相关权限是否已申请并审核通过?
328
+
329
+ #### 返回消息时 403 错误
330
+
331
+ 确保已申请 `im:message:send_as_bot` 权限,并且权限已审核通过。
332
+
333
+ #### 如何清理历史会话 / 开启新对话
334
+
335
+ 在聊天中发送 `/new` 命令即可开启新对话。
336
+
337
+ #### 消息为什么不是流式输出
338
+
339
+ 飞书 API 有请求频率限制,流式更新消息很容易触发限流。当前采用完整回复后一次性发送的方式,以保证稳定性。
340
+
341
+ #### Windows 安装报错 `spawn npm ENOENT`
342
+
343
+ 如果 `openclaw plugins install` 失败,可以手动安装:
344
+
345
+ ```bash
346
+ # 1. 下载插件包
347
+ curl -O https://registry.npmjs.org/@m1heng-clawd/feishu/-/feishu-0.1.3.tgz
348
+
349
+ # 2. 从本地安装
350
+ openclaw plugins install ./feishu-0.1.3.tgz
351
+ ```
352
+
353
+ #### 在飞书里找不到机器人
354
+
355
+ 1. 确保应用已发布(至少发布到测试版本)
356
+ 2. 在飞书搜索框中搜索机器人名称
357
+ 3. 检查应用可用范围是否包含你的账号
358
+
359
+ ---
360
+
361
+ ## License
362
+
363
+ MIT
package/index.ts ADDED
@@ -0,0 +1,55 @@
1
+ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
+ import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
3
+ import { feishuPlugin } from "./src/channel.js";
4
+ import { setFeishuRuntime } from "./src/runtime.js";
5
+ import { registerFeishuDocTools } from "./src/docx.js";
6
+
7
+ export { monitorFeishuProvider } from "./src/monitor.js";
8
+ export {
9
+ sendMessageFeishu,
10
+ sendCardFeishu,
11
+ updateCardFeishu,
12
+ editMessageFeishu,
13
+ getMessageFeishu,
14
+ } from "./src/send.js";
15
+ export {
16
+ uploadImageFeishu,
17
+ uploadFileFeishu,
18
+ sendImageFeishu,
19
+ sendFileFeishu,
20
+ sendMediaFeishu,
21
+ } from "./src/media.js";
22
+ export { probeFeishu } from "./src/probe.js";
23
+ export {
24
+ addReactionFeishu,
25
+ removeReactionFeishu,
26
+ listReactionsFeishu,
27
+ FeishuEmoji,
28
+ } from "./src/reactions.js";
29
+ export {
30
+ extractMentionTargets,
31
+ extractMessageBody,
32
+ isMentionForwardRequest,
33
+ formatMentionForText,
34
+ formatMentionForCard,
35
+ formatMentionAllForText,
36
+ formatMentionAllForCard,
37
+ buildMentionedMessage,
38
+ buildMentionedCardContent,
39
+ type MentionTarget,
40
+ } from "./src/mention.js";
41
+ export { feishuPlugin } from "./src/channel.js";
42
+
43
+ const plugin = {
44
+ id: "feishu",
45
+ name: "Feishu",
46
+ description: "Feishu/Lark channel plugin",
47
+ configSchema: emptyPluginConfigSchema(),
48
+ register(api: OpenClawPluginApi) {
49
+ setFeishuRuntime(api.runtime);
50
+ api.registerChannel({ plugin: feishuPlugin });
51
+ registerFeishuDocTools(api);
52
+ },
53
+ };
54
+
55
+ export default plugin;
@@ -0,0 +1,10 @@
1
+ {
2
+ "id": "feishu",
3
+ "channels": ["feishu"],
4
+ "skills": ["./skills"],
5
+ "configSchema": {
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "properties": {}
9
+ }
10
+ }
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@milerliu/feishu",
3
+ "version": "0.1.5",
4
+ "type": "module",
5
+ "description": "OpenClaw Feishu/Lark channel plugin",
6
+ "license": "MIT",
7
+ "files": [
8
+ "index.ts",
9
+ "src",
10
+ "openclaw.plugin.json"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/littlelk/clawdbot-feishu.git"
15
+ },
16
+ "keywords": [
17
+ "openclaw",
18
+ "feishu",
19
+ "lark",
20
+ "飞书",
21
+ "chatbot",
22
+ "ai",
23
+ "claude"
24
+ ],
25
+ "openclaw": {
26
+ "extensions": [
27
+ "./index.ts"
28
+ ],
29
+ "channel": {
30
+ "id": "feishu",
31
+ "label": "Feishu",
32
+ "selectionLabel": "Feishu/Lark (飞书)",
33
+ "docsPath": "/channels/feishu",
34
+ "docsLabel": "feishu",
35
+ "blurb": "飞书/Lark enterprise messaging.",
36
+ "aliases": [
37
+ "lark"
38
+ ],
39
+ "order": 70
40
+ },
41
+ "install": {
42
+ "npmSpec": "@milerliu/feishu",
43
+ "localPath": ".",
44
+ "defaultChoice": "npm"
45
+ }
46
+ },
47
+ "dependencies": {
48
+ "@larksuiteoapi/node-sdk": "^1.30.0",
49
+ "@sinclair/typebox": "^0.34.48",
50
+ "zod": "^4.3.6"
51
+ },
52
+ "devDependencies": {
53
+ "@types/node": "^25.0.10",
54
+ "openclaw": "2026.1.29",
55
+ "tsx": "^4.21.0",
56
+ "typescript": "^5.7.0"
57
+ },
58
+ "peerDependencies": {
59
+ "openclaw": ">=2026.1.29"
60
+ }
61
+ }
@@ -0,0 +1,53 @@
1
+ import type { ClawdbotConfig } from "openclaw/plugin-sdk";
2
+ import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk";
3
+ import type { FeishuConfig, FeishuDomain, ResolvedFeishuAccount } from "./types.js";
4
+
5
+ export function resolveFeishuCredentials(cfg?: FeishuConfig): {
6
+ appId: string;
7
+ appSecret: string;
8
+ encryptKey?: string;
9
+ verificationToken?: string;
10
+ domain: FeishuDomain;
11
+ } | null {
12
+ const appId = cfg?.appId?.trim();
13
+ const appSecret = cfg?.appSecret?.trim();
14
+ if (!appId || !appSecret) return null;
15
+ return {
16
+ appId,
17
+ appSecret,
18
+ encryptKey: cfg?.encryptKey?.trim() || undefined,
19
+ verificationToken: cfg?.verificationToken?.trim() || undefined,
20
+ domain: cfg?.domain ?? "feishu",
21
+ };
22
+ }
23
+
24
+ export function resolveFeishuAccount(params: {
25
+ cfg: ClawdbotConfig;
26
+ accountId?: string | null;
27
+ }): ResolvedFeishuAccount {
28
+ const feishuCfg = params.cfg.channels?.feishu as FeishuConfig | undefined;
29
+ const enabled = feishuCfg?.enabled !== false;
30
+ const creds = resolveFeishuCredentials(feishuCfg);
31
+
32
+ return {
33
+ accountId: params.accountId?.trim() || DEFAULT_ACCOUNT_ID,
34
+ enabled,
35
+ configured: Boolean(creds),
36
+ appId: creds?.appId,
37
+ domain: creds?.domain ?? "feishu",
38
+ };
39
+ }
40
+
41
+ export function listFeishuAccountIds(_cfg: ClawdbotConfig): string[] {
42
+ return [DEFAULT_ACCOUNT_ID];
43
+ }
44
+
45
+ export function resolveDefaultFeishuAccountId(_cfg: ClawdbotConfig): string {
46
+ return DEFAULT_ACCOUNT_ID;
47
+ }
48
+
49
+ export function listEnabledFeishuAccounts(cfg: ClawdbotConfig): ResolvedFeishuAccount[] {
50
+ return listFeishuAccountIds(cfg)
51
+ .map((accountId) => resolveFeishuAccount({ cfg, accountId }))
52
+ .filter((account) => account.enabled && account.configured);
53
+ }