@noah-claw/feishu 0.1.0

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,317 @@
1
+ # openclaw-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 @noah-claw/feishu
15
+ ```
16
+
17
+ Or install via npm:
18
+
19
+ ```bash
20
+ npm install @noah-claw/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
+ #### Event Subscriptions ⚠️
53
+
54
+ > **This is the most commonly missed configuration!** If the bot can send messages but cannot receive them, check this section.
55
+
56
+ In the Feishu Open Platform console, go to **Events & Callbacks**:
57
+
58
+ 1. **Event configuration**: Select **Long connection** (recommended)
59
+ 2. **Add event subscriptions**:
60
+
61
+ | Event | Description |
62
+ |-------|-------------|
63
+ | `im.message.receive_v1` | Receive messages (required) |
64
+ | `im.message.message_read_v1` | Message read receipts |
65
+ | `im.chat.member.bot.added_v1` | Bot added to group |
66
+ | `im.chat.member.bot.deleted_v1` | Bot removed from group |
67
+
68
+ 3. Ensure the event permissions are approved
69
+
70
+ ```bash
71
+ openclaw config set channels.feishu.appId "cli_xxxxx"
72
+ openclaw config set channels.feishu.appSecret "your_app_secret"
73
+ openclaw config set channels.feishu.enabled true
74
+ ```
75
+
76
+ ### Configuration Options
77
+
78
+ ```yaml
79
+ channels:
80
+ feishu:
81
+ enabled: true
82
+ appId: "cli_xxxxx"
83
+ appSecret: "secret"
84
+ # Domain: "feishu" (China) or "lark" (International)
85
+ domain: "feishu"
86
+ # Connection mode: "websocket" (recommended) or "webhook"
87
+ connectionMode: "websocket"
88
+ # DM policy: "pairing" | "open" | "allowlist"
89
+ dmPolicy: "pairing"
90
+ # Group policy: "open" | "allowlist" | "disabled"
91
+ groupPolicy: "allowlist"
92
+ # Require @mention in groups
93
+ requireMention: true
94
+ # Max media size in MB (default: 30)
95
+ mediaMaxMb: 30
96
+ # Render mode for bot replies: "auto" | "raw" | "card"
97
+ renderMode: "auto"
98
+ ```
99
+
100
+ #### Render Mode
101
+
102
+ | Mode | Description |
103
+ |------|-------------|
104
+ | `auto` | (Default) Automatically detect: use card for messages with code blocks or tables, plain text otherwise. |
105
+ | `raw` | Always send replies as plain text. Markdown tables are converted to ASCII. |
106
+ | `card` | Always send replies as interactive cards with full markdown rendering (syntax highlighting, tables, clickable links). |
107
+
108
+ ### Features
109
+
110
+ - WebSocket and Webhook connection modes
111
+ - Direct messages and group chats
112
+ - Message replies and quoted message context
113
+ - **Inbound media support**: AI can see images, read files (PDF, Excel, etc.), and process rich text with embedded images
114
+ - Image and file uploads (outbound)
115
+ - Typing indicator (via emoji reactions)
116
+ - Pairing flow for DM approval
117
+ - User and group directory lookup
118
+ - **Card render mode**: Optional markdown rendering with syntax highlighting
119
+
120
+ ### FAQ
121
+
122
+ #### Bot cannot receive messages
123
+
124
+ Check the following:
125
+ 1. Have you configured **event subscriptions**? (See Event Subscriptions section)
126
+ 2. Is the event configuration set to **long connection**?
127
+ 3. Did you add the `im.message.receive_v1` event?
128
+ 4. Are the permissions approved?
129
+
130
+ #### 403 error when sending messages
131
+
132
+ Ensure `im:message:send_as_bot` permission is approved.
133
+
134
+ #### How to clear history / start new conversation
135
+
136
+ Send `/new` command in the chat.
137
+
138
+ #### Why is the output not streaming
139
+
140
+ Feishu API has rate limits. Streaming updates can easily trigger throttling. We use complete-then-send approach for stability.
141
+
142
+ #### Windows install error `spawn npm ENOENT`
143
+
144
+ If `openclaw plugins install` fails, install manually:
145
+
146
+ ```bash
147
+ # 1. Download the package
148
+ curl -O https://registry.npmjs.org/@noah-claw/feishu/-/feishu-0.1.1.tgz
149
+
150
+ # 2. Install from local file
151
+ openclaw plugins install ./feishu-0.1.1.tgz
152
+ ```
153
+
154
+ #### Cannot find the bot in Feishu
155
+
156
+ 1. Ensure the app is published (at least to test version)
157
+ 2. Search for the bot name in Feishu search box
158
+ 3. Check if your account is in the app's availability scope
159
+
160
+ ---
161
+
162
+ ## 中文
163
+
164
+ ### 安装
165
+
166
+ ```bash
167
+ openclaw plugins install @noah-claw/feishu
168
+ ```
169
+
170
+ 或通过 npm 安装:
171
+
172
+ ```bash
173
+ npm install @noah-claw/feishu
174
+ ```
175
+
176
+ ### 配置
177
+
178
+ 1. 在 [飞书开放平台](https://open.feishu.cn) 创建自建应用
179
+ 2. 在凭证页面获取 App ID 和 App Secret
180
+ 3. 开启所需权限(见下方)
181
+ 4. **配置事件订阅**(见下方)⚠️ 重要
182
+ 5. 配置插件:
183
+
184
+ #### 必需权限
185
+
186
+ | 权限 | 范围 | 说明 |
187
+ |------|------|------|
188
+ | `contact:user.base:readonly` | 用户信息 | 获取用户基本信息(用于解析发送者姓名,避免群聊/私聊把不同人当成同一说话者) |
189
+ | `im:message` | 消息 | 发送和接收消息 |
190
+ | `im:message.p2p_msg:readonly` | 私聊 | 读取发给机器人的私聊消息 |
191
+ | `im:message.group_at_msg:readonly` | 群聊 | 接收群内 @机器人 的消息 |
192
+ | `im:message:send_as_bot` | 发送 | 以机器人身份发送消息 |
193
+ | `im:resource` | 媒体 | 上传和下载图片/文件 |
194
+
195
+ #### 可选权限
196
+
197
+ | 权限 | 范围 | 说明 |
198
+ |------|------|------|
199
+ | `im:message.group_msg` | 群聊 | 读取所有群消息(敏感) |
200
+ | `im:message:readonly` | 读取 | 获取历史消息 |
201
+ | `im:message:update` | 编辑 | 更新/编辑已发送消息 |
202
+ | `im:message:recall` | 撤回 | 撤回已发送消息 |
203
+ | `im:message.reactions:read` | 表情 | 查看消息表情回复 |
204
+
205
+ #### 事件订阅 ⚠️
206
+
207
+ > **这是最容易遗漏的配置!** 如果机器人能发消息但收不到消息,请检查此项。
208
+
209
+ 在飞书开放平台的应用后台,进入 **事件与回调** 页面:
210
+
211
+ 1. **事件配置方式**:选择 **使用长连接接收事件**(推荐)
212
+ 2. **添加事件订阅**,勾选以下事件:
213
+
214
+ | 事件 | 说明 |
215
+ |------|------|
216
+ | `im.message.receive_v1` | 接收消息(必需) |
217
+ | `im.message.message_read_v1` | 消息已读回执 |
218
+ | `im.chat.member.bot.added_v1` | 机器人进群 |
219
+ | `im.chat.member.bot.deleted_v1` | 机器人被移出群 |
220
+
221
+ 3. 确保事件订阅的权限已申请并通过审核
222
+
223
+ ```bash
224
+ openclaw config set channels.feishu.appId "cli_xxxxx"
225
+ openclaw config set channels.feishu.appSecret "your_app_secret"
226
+ openclaw config set channels.feishu.enabled true
227
+ ```
228
+
229
+ ### 配置选项
230
+
231
+ ```yaml
232
+ channels:
233
+ feishu:
234
+ enabled: true
235
+ appId: "cli_xxxxx"
236
+ appSecret: "secret"
237
+ # 域名: "feishu" (国内) 或 "lark" (国际)
238
+ domain: "feishu"
239
+ # 连接模式: "websocket" (推荐) 或 "webhook"
240
+ connectionMode: "websocket"
241
+ # 私聊策略: "pairing" | "open" | "allowlist"
242
+ dmPolicy: "pairing"
243
+ # 群聊策略: "open" | "allowlist" | "disabled"
244
+ groupPolicy: "allowlist"
245
+ # 群聊是否需要 @机器人
246
+ requireMention: true
247
+ # 媒体文件最大大小 (MB, 默认 30)
248
+ mediaMaxMb: 30
249
+ # 回复渲染模式: "auto" | "raw" | "card"
250
+ renderMode: "auto"
251
+ ```
252
+
253
+ #### 渲染模式
254
+
255
+ | 模式 | 说明 |
256
+ |------|------|
257
+ | `auto` | (默认)自动检测:有代码块或表格时用卡片,否则纯文本 |
258
+ | `raw` | 始终纯文本,表格转为 ASCII |
259
+ | `card` | 始终使用卡片,支持语法高亮、表格、链接等 |
260
+
261
+ ### 功能
262
+
263
+ - WebSocket 和 Webhook 连接模式
264
+ - 私聊和群聊
265
+ - 消息回复和引用上下文
266
+ - **入站媒体支持**:AI 可以看到图片、读取文件(PDF、Excel 等)、处理富文本中的嵌入图片
267
+ - 图片和文件上传(出站)
268
+ - 输入指示器(通过表情回复实现)
269
+ - 私聊配对审批流程
270
+ - 用户和群组目录查询
271
+ - **卡片渲染模式**:支持语法高亮的 Markdown 渲染
272
+
273
+ ### 常见问题
274
+
275
+ #### 机器人收不到消息
276
+
277
+ 检查以下配置:
278
+ 1. 是否配置了 **事件订阅**?(见上方事件订阅章节)
279
+ 2. 事件配置方式是否选择了 **长连接**?
280
+ 3. 是否添加了 `im.message.receive_v1` 事件?
281
+ 4. 相关权限是否已申请并审核通过?
282
+
283
+ #### 返回消息时 403 错误
284
+
285
+ 确保已申请 `im:message:send_as_bot` 权限,并且权限已审核通过。
286
+
287
+ #### 如何清理历史会话 / 开启新对话
288
+
289
+ 在聊天中发送 `/new` 命令即可开启新对话。
290
+
291
+ #### 消息为什么不是流式输出
292
+
293
+ 飞书 API 有请求频率限制,流式更新消息很容易触发限流。当前采用完整回复后一次性发送的方式,以保证稳定性。
294
+
295
+ #### Windows 安装报错 `spawn npm ENOENT`
296
+
297
+ 如果 `openclaw plugins install` 失败,可以手动安装:
298
+
299
+ ```bash
300
+ # 1. 下载插件包
301
+ curl -O https://registry.npmjs.org/@noah-claw/feishu/-/feishu-0.1.1.tgz
302
+
303
+ # 2. 从本地安装
304
+ openclaw plugins install ./feishu-0.1.1.tgz
305
+ ```
306
+
307
+ #### 在飞书里找不到机器人
308
+
309
+ 1. 确保应用已发布(至少发布到测试版本)
310
+ 2. 在飞书搜索框中搜索机器人名称
311
+ 3. 检查应用可用范围是否包含你的账号
312
+
313
+ ---
314
+
315
+ ## License
316
+
317
+ MIT
package/index.ts ADDED
@@ -0,0 +1,41 @@
1
+ import type { ClawdbotPluginApi } 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
+
6
+ export { monitorFeishuProvider } from "./src/monitor.js";
7
+ export {
8
+ sendMessageFeishu,
9
+ sendCardFeishu,
10
+ updateCardFeishu,
11
+ editMessageFeishu,
12
+ getMessageFeishu,
13
+ } from "./src/send.js";
14
+ export {
15
+ uploadImageFeishu,
16
+ uploadFileFeishu,
17
+ sendImageFeishu,
18
+ sendFileFeishu,
19
+ sendMediaFeishu,
20
+ } from "./src/media.js";
21
+ export { probeFeishu } from "./src/probe.js";
22
+ export {
23
+ addReactionFeishu,
24
+ removeReactionFeishu,
25
+ listReactionsFeishu,
26
+ FeishuEmoji,
27
+ } from "./src/reactions.js";
28
+ export { feishuPlugin } from "./src/channel.js";
29
+
30
+ const plugin = {
31
+ id: "feishu",
32
+ name: "Feishu",
33
+ description: "Feishu/Lark channel plugin",
34
+ configSchema: emptyPluginConfigSchema(),
35
+ register(api: ClawdbotPluginApi) {
36
+ setFeishuRuntime(api.runtime);
37
+ api.registerChannel({ plugin: feishuPlugin });
38
+ },
39
+ };
40
+
41
+ export default plugin;
@@ -0,0 +1,9 @@
1
+ {
2
+ "id": "feishu",
3
+ "channels": ["feishu"],
4
+ "configSchema": {
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "properties": {}
8
+ }
9
+ }
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@noah-claw/feishu",
3
+ "version": "0.1.0",
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/noah/openclaw-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": "@noah-claw/feishu",
43
+ "localPath": ".",
44
+ "defaultChoice": "npm"
45
+ }
46
+ },
47
+ "dependencies": {
48
+ "@larksuiteoapi/node-sdk": "^1.30.0",
49
+ "zod": "^4.3.6"
50
+ },
51
+ "devDependencies": {
52
+ "@types/node": "^25.0.10",
53
+ "openclaw": "2026.1.29",
54
+ "tsx": "^4.21.0",
55
+ "typescript": "^5.7.0"
56
+ },
57
+ "peerDependencies": {
58
+ "openclaw": ">=2026.1.24"
59
+ }
60
+ }
@@ -0,0 +1,53 @@
1
+ import type { ClawdbotConfig } from "clawdbot/plugin-sdk";
2
+ import { DEFAULT_ACCOUNT_ID } from "clawdbot/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
+ }