@xwang152/claw-lark 0.1.0 → 0.1.2

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/.eslintrc.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "parser": "@typescript-eslint/parser",
3
+ "extends": [
4
+ "eslint:recommended",
5
+ "plugin:@typescript-eslint/recommended",
6
+ "plugin:prettier/recommended"
7
+ ],
8
+ "plugins": ["@typescript-eslint", "prettier"],
9
+ "rules": {
10
+ "prettier/prettier": "error",
11
+ "@typescript-eslint/no-explicit-any": "warn",
12
+ "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
13
+ },
14
+ "env": {
15
+ "node": true,
16
+ "es2022": true
17
+ }
18
+ }
@@ -0,0 +1,39 @@
1
+ name: Node.js Package Publish
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+
14
+ - uses: actions/setup-node@v4
15
+ with:
16
+ node-version: '20.x'
17
+ registry-url: 'https://registry.npmjs.org'
18
+
19
+ - name: Install dependencies
20
+ run: npm install
21
+
22
+ - name: Check if version exists on npm
23
+ id: check_version
24
+ run: |
25
+ VERSION=$(node -p "require('./package.json').version")
26
+ NAME=$(node -p "require('./package.json').name")
27
+ if npm view "$NAME@$VERSION" version >/dev/null 2>&1; then
28
+ echo "Version $VERSION already exists on npm. Skipping publish."
29
+ echo "exists=true" >> $GITHUB_OUTPUT
30
+ else
31
+ echo "Version $VERSION is new. Proceeding to publish."
32
+ echo "exists=false" >> $GITHUB_OUTPUT
33
+ fi
34
+
35
+ - name: Publish to npm
36
+ if: steps.check_version.outputs.exists == 'false'
37
+ run: npm publish --access public
38
+ env:
39
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "es5",
4
+ "singleQuote": false,
5
+ "printWidth": 100,
6
+ "tabWidth": 2
7
+ }
package/README.md CHANGED
@@ -1,46 +1,37 @@
1
- # Lark Plugin for OpenClaw
1
+ # OpenClaw Feishu/Lark Plugin
2
2
 
3
- [中文文档](./README_zh.md)
4
-
5
- A channel plugin that enables OpenClaw to communicate via Lark (Larksuite) messaging platform.
3
+ A channel plugin for OpenClaw that enables communication through the Feishu or Lark platform.
6
4
 
7
5
  ## Features
8
6
 
9
- - **Direct Messages**: Chat with your bot one-on-one
10
- - **Group Chats**: Add your bot to group conversations
11
- - **Text Messages**: Send and receive text messages
12
- - **Image Support**: Bot can send images generated by agents
13
- - **Webhook Mode**: For individual Lark accounts (tested)
14
- - **WebSocket Mode**: For enterprise accounts (tested, recommended)
15
- - **Auto-Recovery**: WebSocket and Webhook servers automatically reconnect/restart on crashes
16
-
17
- ## Requirements
18
-
19
- - OpenClaw installed and configured
20
- - A Lark Developer account
21
- - A Lark app with Bot capability enabled
7
+ - **Dual Platform Support**: Full compatibility with Feishu (China) and Lark (International).
8
+ - **WebSocket (Long Connection)**: Recommended for custom apps, low latency, no public IP required.
9
+ - **Webhook Mode**: For traditional deployments, supports event verification and encryption.
10
+ - **Multi-Mode Rendering**: Supports `auto` / `raw` / `card`, with Interactive Cards for Markdown, tables, and highlighting.
11
+ - **Media Support**:
12
+ - **Inbound**: AI can receive images and files (PDF, Excel, Word, etc.).
13
+ - **Outbound**: Support for sending images and files.
14
+ - **Advanced Interaction**:
15
+ - **Typing Indicator**: Simulated via message reactions.
16
+ - **@ Forwarding**: Automatic handling of @mentions in group chats.
17
+ - **Contextual Replies**: Support for message threading and replies.
18
+ - **Auto-Recovery**: Automatic reconnection for WebSocket and server restarts for Webhooks.
22
19
 
23
20
  ## Installation
24
21
 
25
- ```bash
26
- # Clone the repository
27
- git clone https://github.com/xwang152-jack/claw-lark.git
28
- cd claw-lark
29
-
30
- # Install dependencies
31
- npm install
32
-
33
- # Install plugin into OpenClaw
34
- openclaw plugins install --link .
35
- ```
22
+ ### 1. Automatic Installation (Recommended)
36
23
 
37
- Or install directly via npm:
24
+ Install directly via the OpenClaw CLI:
38
25
 
39
26
  ```bash
40
27
  openclaw plugins install @xwang152/claw-lark
41
28
  ```
42
29
 
43
- Verify installation:Restart Gateway to load the plugin
30
+ ### 2. Restart Gateway
31
+
32
+ Restart the Gateway to load the plugin:
33
+
34
+ ```bash
44
35
  openclaw gateway restart
45
36
  ```
46
37
 
@@ -50,193 +41,67 @@ Verify installation:
50
41
  openclaw plugins list
51
42
  ```
52
43
 
53
- You should see `lark` with status `loaded`.
54
-
55
- ## Lark App Setup
56
-
57
- 1. Go to [Lark Developer Console](https://open.larksuite.com/app)
58
-
59
- 2. Create a new app or use an existing one
60
-
61
- 3. Enable **Bot** capability under App Features
62
-
63
- 4. Add the following permissions under Permissions & Scopes:
64
-
65
- | Permission | Scope | Description |
66
- | :--- | :--- | :--- |
67
- | `im:message` | Message | Send and receive messages |
68
- | `im:message.p2p_msg:readonly` | P2P Message | Read direct messages sent to the bot |
69
- | `im:message.group_at_msg:readonly` | Group Message | Receive messages where the bot is @mentioned in groups |
70
- | `im:message:send_as_bot` | Send | Send messages as the bot |
71
- | `im:resource` | Resource | Upload/download images and files |
72
-
73
- **Optional Permissions (add as needed):**
74
-
75
- | Permission | Scope | Description |
76
- | :--- | :--- | :--- |
77
- | `im:message.group_msg` | Group | Read all group messages (Sensitive permission) |
78
- | `im:message:readonly` | Read | Get historical messages |
79
- | `im:message:update` | Edit | Update/edit sent messages |
80
- | `im:message:recall` | Recall | Recall sent messages |
81
- | `im:message.reactions:read` | Reaction | View message emoji reactions |
82
-
83
- 5. Note your **App ID** and **App Secret** from Credentials & Basic Info (you'll need these for configuration)
84
-
85
- 6. Publish your app under Version Management
44
+ You should see the `feishu` plugin with a `loaded` status.
86
45
 
87
46
  ## Configuration
88
47
 
89
- ### Using Config Commands
90
-
91
- ```bash
92
- # Required settings
93
- openclaw config set channels.lark.accounts.default.appId 'cli_xxxxx'
94
- openclaw config set channels.lark.accounts.default.appSecret 'your-app-secret'
95
- openclaw config set channels.lark.accounts.default.connectionMode 'webhook'
96
-
97
- # Optional settings
98
- openclaw config set channels.lark.accounts.default.webhookPort 3000
99
- openclaw config set channels.lark.accounts.default.domain 'lark'
100
- openclaw config set channels.lark.accounts.default.dmPolicy 'open'
101
- openclaw config set channels.lark.accounts.default.groupPolicy 'open'
102
- openclaw config set channels.lark.accounts.default.groupMentionGated false
103
-
104
- # Security settings (from Lark Developer Console > Events & Callbacks > Encryption Strategy)
105
- openclaw config set channels.lark.accounts.default.encryptKey 'your-encrypt-key'
106
- openclaw config set channels.lark.accounts.default.verificationToken 'your-verification-token'
107
- ```
108
-
109
- ### Using Environment Variables
110
-
111
- For the default account, you can use environment variables:
112
-
113
- ```bash
114
- LARK_APP_ID=cli_xxxxx
115
- LARK_APP_SECRET=your-app-secret
116
-
117
- # Security settings (from Lark Developer Console > Events & Callbacks > Encryption Strategy)
118
- LARK_ENCRYPT_KEY=your-encrypt-key # Optional, for decrypting event payloads
119
- LARK_VERIFICATION_TOKEN=your-token # Optional, for verifying request authenticity
48
+ ### Example Configuration (`openclaw.yaml`)
49
+
50
+ ```yaml
51
+ channels:
52
+ feishu:
53
+ accounts:
54
+ default:
55
+ enabled: true
56
+ appId: "cli_a9f722ad2cb9dccb"
57
+ appSecret: "********"
58
+ # Domain: "feishu" (China) or "lark" (International)
59
+ domain: "feishu"
60
+ # Mode: "websocket" (recommended) or "webhook"
61
+ connectionMode: "websocket"
62
+ # Webhook settings (required only for webhook mode)
63
+ # verificationToken: "********"
64
+ # encryptKey: "********"
65
+ # webhookPort: 3000
66
+ # DM Policy: "pairing" | "open" | "allowlist"
67
+ dmPolicy: "pairing"
68
+ # DM allowlist (only when dmPolicy=allowlist, OpenID)
69
+ # dmAllowlist:
70
+ # - "ou_xxx"
71
+ # Group Policy: "open" | "allowlist" | "disabled"
72
+ groupPolicy: "allowlist"
73
+ # Group allowlist (only when groupPolicy=allowlist, ChatID)
74
+ # groupAllowlist:
75
+ # - "oc_xxx"
76
+ # Require @mention in groups
77
+ requireMention: true
78
+ # Max media size (MB, default 30)
79
+ mediaMaxMb: 30
80
+ # Rendering mode: "auto" | "raw" | "card"
81
+ renderMode: "auto"
82
+ # History limit (default 10)
83
+ # historyLimit: 10
120
84
  ```
121
85
 
122
- ### Configuration Options
123
-
124
- | Option | Type | Default | Description |
125
- |--------|------|---------|-------------|
126
- | `appId` | string | - | Lark App ID (required) |
127
- | `appSecret` | string | - | Lark App Secret (required) |
128
- | `connectionMode` | string | `websocket` | `webhook` or `websocket` |
129
- | `webhookPort` | number | `3000` | Port for webhook server |
130
- | `domain` | string | `feishu` | `feishu` (China) or `lark` (international) |
131
- | `encryptKey` | string | - | Encrypt key for decrypting event payloads (from Events & Callbacks > Encryption Strategy) |
132
- | `verificationToken` | string | - | Token for verifying request authenticity (from Events & Callbacks > Encryption Strategy) |
133
- | `dmPolicy` | string | `pairing` | `open`, `pairing`, or `allowlist` |
134
- | `groupPolicy` | string | `open` | `open`, `allowlist`, or `disabled` |
135
- | `groupMentionGated` | boolean | `true` | Require @mention in groups |
136
-
137
- ## Webhook Mode Setup
138
-
139
- Choose the setup method based on your deployment environment.
86
+ ### Rendering Modes
140
87
 
141
- ### 1. Development (Using ngrok)
88
+ | Mode | Description |
89
+ | :--- | :--- |
90
+ | **auto** | (Default) Automatic detection: Use cards for code blocks, lists, or tables, otherwise use plain text. |
91
+ | **raw** | Always use plain text. Tables are converted to ASCII text. |
92
+ | **card** | Always use Feishu Interactive Cards with Markdown syntax highlighting. |
142
93
 
143
- Recommended for local development and testing.
144
-
145
- > **Security & Privacy Notice**: ngrok exposes your local server to the internet. Keep the following in mind:
146
- > - Never share your ngrok URL publicly — anyone with the URL can send requests to your local machine
147
- > - Use a paid ngrok plan with authentication or IP restrictions for production use
148
- > - Stop ngrok when not in use to close the tunnel
149
- > - Consider using Lark's `encryptKey` and `verificationToken` for additional request validation
150
-
151
- 1. Start ngrok to expose your local webhook server:
94
+ ## Development
152
95
 
153
96
  ```bash
154
- ngrok http 3000
155
- ```
156
-
157
- 2. Copy the HTTPS URL from ngrok (e.g., `https://abc123.ngrok.io`)
158
-
159
- 3. Configure Events & Callbacks in Lark Developer Console:
160
- - Add event subscription: `im.message.receive_v1`
161
- - Set Request URL to your ngrok HTTPS URL (e.g., `https://abc123.ngrok.io`)
162
-
163
- ### 2. Production (Server Deployment)
164
-
165
- When deploying on a server, ngrok is **not** required.
166
-
167
- 1. **Open Port**: Ensure your server's firewall (Security Group) allows traffic on the port used by the plugin (default is `3000`).
168
- 2. **Configure URL**: In Lark Developer Console, configure "Events & Callbacks":
169
- - Set the "Request URL" to your server's public address: `http://your-server-ip:3000`.
170
- 3. **(Recommended) Reverse Proxy**: Use Nginx or Caddy to set up a reverse proxy with SSL (HTTPS) and forward traffic to port `3000`.
171
-
172
- ### 3. Start the Plugin
173
-
174
- 1. Start OpenClaw:
175
-
176
- ```bash
177
- openclaw start
178
- ```
179
-
180
- 2. The webhook server will start automatically and handle URL verification.
181
-
182
- ## WebSocket Mode
183
-
184
- WebSocket mode is available for enterprise Lark accounts (Custom Apps) that support long connections. Set `connectionMode` to `websocket`:
185
-
186
- ```bash
187
- openclaw config set channels.lark.accounts.default.connectionMode 'websocket'
188
- ```
189
-
190
- **Advantages:**
191
- - **No Public IP Needed**: No need for ngrok or reverse proxy, suitable for local or intranet environments.
192
- - **Easy Setup**: Simply enable the "Receive events through persistent connection" toggle in the Lark Developer Console.
193
- - **High Stability**: The plugin supports automatic reconnection.
194
-
195
- **Configuration Steps:**
196
- 1. Go to **Events & Callbacks** in the Lark Developer Console.
197
- 2. Select **Receive events through persistent connection** under "Subscription Mode".
198
- 3. Ensure the `im.message.receive_v1` event is added.
199
-
200
- ## Multiple Accounts
201
-
202
- You can configure multiple Lark accounts:
203
-
204
- ```bash
205
- openclaw config set channels.lark.accounts.work.appId 'cli_work_app'
206
- openclaw config set channels.lark.accounts.work.appSecret 'work-secret'
207
- openclaw config set channels.lark.accounts.personal.appId 'cli_personal_app'
208
- openclaw config set channels.lark.accounts.personal.appSecret 'personal-secret'
209
- ```
210
-
211
- ## Troubleshooting
212
-
213
- ### Bot not receiving messages
214
-
215
- 1. Verify the event subscription `im.message.receive_v1` is added
216
- 2. Check that the callback URL is correctly configured
217
- 3. Ensure the required permissions are enabled
218
- 4. Make sure the app is published (not just saved as draft)
219
-
220
- ### Permission errors when sending images
221
-
222
- Add the `im:resource` permission in Lark Developer Console and republish your app.
223
-
224
- ### Webhook server not starting
225
-
226
- Check if port 3000 is already in use. Change the port:
227
-
228
- ```bash
229
- openclaw config set channels.lark.accounts.default.webhookPort 3001
97
+ git clone https://github.com/xwang152-jack/claw-lark.git
98
+ cd claw-lark
99
+ npm install
100
+ npm run typecheck
101
+ openclaw plugins install --link .
230
102
  ```
231
103
 
232
- ### Connection issues with WebSocket mode
233
-
234
- WebSocket mode requires enterprise Lark accounts. If you have an individual account, use webhook mode instead.
235
-
236
- ## Contributing
237
-
238
- 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.
239
-
240
- ## License
241
-
242
- MIT
104
+ ### Commands
105
+ - `npm run lint`: Lint code
106
+ - `npm run format`: Format code
107
+ - `npm test`: Run tests
package/README_zh.md CHANGED
@@ -1,44 +1,37 @@
1
1
  # OpenClaw 飞书/Lark 插件
2
2
 
3
- 这是一个为 OpenClaw 开发的频道插件,使 OpenClaw 能够通过飞书 (Larksuite) 平台进行通信。
3
+ 这是一个为 OpenClaw 开发的频道插件,使 OpenClaw 能够通过飞书 (Feishu) 或 Lark 平台进行通信。
4
4
 
5
5
  ## 功能特性
6
6
 
7
- - **私聊消息**:与您的机器人进行一对一对话
8
- - **群聊消息**:将机器人加入群组对话
9
- - **文本消息**:发送和接收文本消息
10
- - **图片支持**:机器人可以发送由智能体生成的图片
11
- - **Webhook 模式**:适用于个人飞书账号(已测试)
12
- - **WebSocket 模式**:适用于企业级账号(已通过测试,推荐使用)
13
- - **自动恢复**:WebSocket 和 Webhook 服务在崩溃时会自动重连或重启
14
-
15
- ## 前置要求
16
-
17
- - 已安装并配置 OpenClaw
18
- - 飞书开发者账号
19
- - 已启用机器人能力的飞书应用
7
+ - **双平台支持**:全面兼容飞书 (国内) 和 Lark (国际)
8
+ - **长连接 (WebSocket)**:企业自建应用推荐使用,低延迟,无需公网 IP
9
+ - **Webhook 模式**:适用于传统部署,支持事件验证和加密
10
+ - **多模式渲染**:支持 `auto` / `raw` / `card` 三种模式,卡片模式支持 Markdown 语法高亮和表格
11
+ - **多媒体支持**:
12
+ - **进站**:AI 可以接收图片、文件 (PDF, Excel, Word 等)
13
+ - **出站**:支持发送图片和文件
14
+ - **高级交互**:
15
+ - **输入指示器**:通过消息表情回复模拟 "正在输入" 状态
16
+ - **@ 转发**:自动处理群聊中的 @ 提及
17
+ - **上下文引用**:支持消息引用和回复上下文
18
+ - **自动恢复**:连接中断后自动重连,服务崩溃自动重启
20
19
 
21
20
  ## 安装步骤
22
21
 
23
- ```bash
24
- # 克隆仓库
25
- git clone https://github.com/xwang152-jack/claw-lark.git
26
- cd claw-lark
27
-
28
- # 安装依赖
29
- npm install
30
-
31
- # 将插件安装到 OpenClaw
32
- openclaw plugins install --link .
33
- ```
22
+ ### 1. 自动安装(推荐)
34
23
 
35
- 或者直接通过 npm 安装:
24
+ 直接通过 OpenClaw 命令行工具安装:
36
25
 
37
26
  ```bash
38
27
  openclaw plugins install @xwang152/claw-lark
39
28
  ```
40
29
 
41
- 验证安装:# 重启 Gateway 以加载插件
30
+ ### 2. 重启 Gateway
31
+
32
+ 安装完成后,重启 Gateway 以加载插件:
33
+
34
+ ```bash
42
35
  openclaw gateway restart
43
36
  ```
44
37
 
@@ -48,193 +41,83 @@ openclaw gateway restart
48
41
  openclaw plugins list
49
42
  ```
50
43
 
51
- 您应该能看到 `lark` 插件且状态为 `loaded`。
44
+ 您应该能看到 `feishu` 插件且状态为 `loaded`。
52
45
 
53
46
  ## 飞书应用设置
54
47
 
55
48
  1. 前往 [飞书开放平台](https://open.feishu.cn/app) (国内) 或 [Lark Developer Console](https://open.larksuite.com/app) (国际)
56
-
57
- 2. 创建新应用或使用现有应用
58
-
59
- 3. 在“应用能力”中启用 **机器人** 能力
60
-
61
- 4. 在“权限管理”中添加以下权限:
62
-
63
- | 权限 | 范围 | 说明 |
64
- | :--- | :--- | :--- |
65
- | `im:message` | 消息 | 发送和接收消息 |
66
- | `im:message.p2p_msg:readonly` | 私聊 | 读取发给机器人的私聊消息 |
67
- | `im:message.group_at_msg:readonly` | 群聊 | 接收群内 @机器人 的消息 |
68
- | `im:message:send_as_bot` | 发送 | 以机器人身份发送消息 |
69
- | `im:resource` | 媒体 | 上传和下载图片/文件 |
70
-
71
- **可选权限(根据需求添加):**
72
-
73
- | 权限 | 范围 | 说明 |
74
- | :--- | :--- | :--- |
75
- | `im:message.group_msg` | 群聊 | 读取所有群消息(敏感权限,慎用) |
76
- | `im:message:readonly` | 读取 | 获取历史消息 |
77
- | `im:message:update` | 编辑 | 更新/编辑已发送消息 |
78
- | `im:message:recall` | 撤回 | 撤回已发送消息 |
79
- | `im:message.reactions:read` | 表情 | 查看消息表情回复 |
80
-
81
- 5. 从“凭证与基础信息”中获取 **App ID** 和 **App Secret**(配置时需要用到)
82
-
83
- 6. 在“版本管理与发布”中发布您的应用
49
+ 2. 创建新应用,在“应用能力”中启用 **机器人** 能力
50
+ 3. 在“权限管理”中添加以下权限:
51
+ - `im:message` (消息)
52
+ - `im:message.p2p_msg:readonly` (读取私聊)
53
+ - `im:message.group_at_msg:readonly` (读取群聊 @ 提及)
54
+ - `im:message:send_as_bot` (以机器人身份发送消息)
55
+ - `im:resource` (媒体文件权限)
56
+ - `im:chat` (群组管理,用于获取群列表)
57
+ - `contact:user.employee:readonly` (通讯录读取,可选)
58
+ 4. 在“版本管理与发布”中发布应用。
84
59
 
85
60
  ## 配置说明
86
61
 
87
- ### 使用配置命令
88
-
89
- ```bash
90
- # 必要设置
91
- openclaw config set channels.lark.accounts.default.appId 'cli_xxxxx'
92
- openclaw config set channels.lark.accounts.default.appSecret 'your-app-secret'
93
- openclaw config set channels.lark.accounts.default.connectionMode 'webhook'
94
-
95
- # 可选设置
96
- openclaw config set channels.lark.accounts.default.webhookPort 3000
97
- openclaw config set channels.lark.accounts.default.domain 'feishu' # 'feishu' (国内) 或 'lark' (国际)
98
- openclaw config set channels.lark.accounts.default.dmPolicy 'open'
99
- openclaw config set channels.lark.accounts.default.groupPolicy 'open'
100
- openclaw config set channels.lark.accounts.default.groupMentionGated false
101
-
102
- # 安全设置(从飞书开发者后台 > 事件订阅 > 加密策略获取)
103
- openclaw config set channels.lark.accounts.default.encryptKey 'your-encrypt-key'
104
- openclaw config set channels.lark.accounts.default.verificationToken 'your-verification-token'
105
- ```
106
-
107
- ### 使用环境变量
108
-
109
- 对于默认账号,您可以使用环境变量:
110
-
111
- ```bash
112
- LARK_APP_ID=cli_xxxxx
113
- LARK_APP_SECRET=your-app-secret
114
-
115
- # 安全设置(从飞书开发者后台 > 事件订阅 > 加密策略获取)
116
- LARK_ENCRYPT_KEY=your-encrypt-key # 可选,用于解密事件数据
117
- LARK_VERIFICATION_TOKEN=your-token # 可选,用于验证请求真实性
62
+ ### 配置文件示例 (`openclaw.yaml`)
63
+
64
+ ```yaml
65
+ channels:
66
+ feishu:
67
+ accounts:
68
+ default:
69
+ enabled: true
70
+ appId: "cli_a9f722ad2cb9dccb"
71
+ appSecret: "********"
72
+ # 域名: "feishu" (国内) 或 "lark" (国际)
73
+ domain: "feishu"
74
+ # 连接模式: "websocket" (推荐) 或 "webhook"
75
+ connectionMode: "websocket"
76
+ # Webhook 相关 (仅在 webhook 模式需要)
77
+ # verificationToken: "********"
78
+ # encryptKey: "********"
79
+ # webhookPort: 3000
80
+ # 私聊策略: "pairing" | "open" | "allowlist"
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
118
98
  ```
119
99
 
120
- ### 配置项详情
100
+ ### 渲染模式说明
121
101
 
122
- | 选项 | 类型 | 默认值 | 描述 |
123
- |--------|------|---------|-------------|
124
- | `appId` | string | - | 飞书 App ID (必填) |
125
- | `appSecret` | string | - | 飞书 App Secret (必填) |
126
- | `connectionMode` | string | `websocket` | `webhook` 或 `websocket` |
127
- | `webhookPort` | number | `3000` | Webhook 服务器端口 |
128
- | `domain` | string | `feishu` | `feishu` (国内版) 或 `lark` (国际版) |
129
- | `encryptKey` | string | - | 加密密钥(从事件订阅 > 加密策略获取) |
130
- | `verificationToken` | string | - | 验证令牌(从事件订阅 > 加密策略获取) |
131
- | `dmPolicy` | string | `pairing` | 私聊策略:`open`, `pairing`, 或 `allowlist` |
132
- | `groupPolicy` | string | `open` | 群聊策略:`open`, `allowlist`, 或 `disabled` |
133
- | `groupMentionGated` | boolean | `true` | 是否要求在群聊中 @机器人 |
102
+ | 模式 | 说明 |
103
+ | :--- | :--- |
104
+ | **auto** | (默认) 自动检测:检测到代码块、列表或表格时使用卡片渲染,否则使用纯文本 |
105
+ | **raw** | 始终使用纯文本渲染,表格会被转换为 ASCII 文本 |
106
+ | **card** | 始终使用飞书交互式卡片渲染,支持 Markdown 语法高亮和高级布局 |
134
107
 
135
- ## Webhook 模式设置
108
+ ## 开发者相关
136
109
 
137
- 根据您的部署环境,选择相应的配置方式。
138
-
139
- ### 1. 开发环境(使用 ngrok)
140
-
141
- 推荐在本地开发调试时使用。
142
-
143
- > **安全与隐私提示**:ngrok 会将您的本地服务器暴露到公网。请注意:
144
- > - 不要公开分享您的 ngrok URL
145
- > - 生产环境建议使用付费版 ngrok 或自建反向代理
146
- > - 不使用时请关闭 ngrok 隧道
147
- > - 建议配置飞书的 `encryptKey` 和 `verificationToken` 以增强安全性
148
-
149
- 1. 启动 ngrok 暴露本地 Webhook 端口:
110
+ 如果您想参与开发:
150
111
 
151
112
  ```bash
152
- ngrok http 3000
153
- ```
154
-
155
- 2. ngrok 复制 HTTPS URL(例如:`https://abc123.ngrok.io`)
156
-
157
- 3. 在飞书开发者后台配置“事件订阅”:
158
- - 添加事件:`im.message.receive_v1` (接收消息 v1.0)
159
- - 将“请求地址”设置为您的 ngrok HTTPS URL(例如:`https://abc123.ngrok.io`)
160
-
161
- ### 2. 生产环境(服务器部署)
162
-
163
- 在服务器上部署时,**不需要**使用 ngrok。
164
-
165
- 1. **开放端口**:确保您的服务器防火墙(安全组)已开放插件使用的端口(默认是 `3000`)。
166
- 2. **配置地址**:在飞书开发者后台配置“事件订阅”:
167
- - 将“请求地址”设置为您的服务器公网地址:`http://您的服务器IP:3000`。
168
- 3. **(推荐)反向代理**:建议使用 Nginx 或 Caddy 配置反向代理和 SSL 证书(HTTPS),然后将流量转发到 `3000` 端口。
169
-
170
- ### 3. 启动插件
171
-
172
- 1. 启动 OpenClaw:
173
-
174
- ```bash
175
- openclaw start
176
- ```
177
-
178
- 2. Webhook 服务器会自动启动并处理 URL 验证。
179
-
180
- ## WebSocket 模式
181
-
182
- WebSocket 模式适用于支持长连接的企业级飞书账号(自建应用)。将 `connectionMode` 设置为 `websocket`:
183
-
184
- ```bash
185
- openclaw config set channels.lark.accounts.default.connectionMode 'websocket'
186
- ```
187
-
188
- **优势:**
189
- - **无需公网 IP**:不需要配置 ngrok 或反向代理,适合本地或内网环境。
190
- - **配置简单**:只需在飞书后台开启“使用长连接接收事件”开关即可。
191
- - **稳定性高**:插件支持自动重连。
192
-
193
- **配置步骤:**
194
- 1. 在飞书开发者后台 -> **事件订阅**。
195
- 2. 在“订阅方式”中选择 **使用长连接接收事件**。
196
- 3. 确保已添加 `im.message.receive_v1` 事件。
197
-
198
- ## 多账号配置
199
-
200
- 您可以配置多个飞书账号:
201
-
202
- ```bash
203
- openclaw config set channels.lark.accounts.work.appId 'cli_work_app'
204
- openclaw config set channels.lark.accounts.work.appSecret 'work-secret'
205
- openclaw config set channels.lark.accounts.personal.appId 'cli_personal_app'
206
- openclaw config set channels.lark.accounts.personal.appSecret 'personal-secret'
207
- ```
208
-
209
- ## 故障排除
210
-
211
- ### 机器人收不到消息
212
-
213
- 1. 检查是否订阅了 `im.message.receive_v1` 事件
214
- 2. 检查回调 URL 是否配置正确且公网可访问
215
- 3. 检查权限是否已开启
216
- 4. 确保应用已发布(不仅是保存草稿)
217
-
218
- ### 发送图片权限错误
219
-
220
- 在飞书开发者后台添加 `im:resource` 权限并重新发布应用。
221
-
222
- ### Webhook 服务器启动失败
223
-
224
- 检查端口 3000 是否被占用。可以修改端口:
225
-
226
- ```bash
227
- openclaw config set channels.lark.accounts.default.webhookPort 3001
113
+ git clone https://github.com/xwang152-jack/claw-lark.git
114
+ cd claw-lark
115
+ npm install
116
+ npm run typecheck
117
+ openclaw plugins install --link .
228
118
  ```
229
119
 
230
- ### WebSocket 模式连接问题
231
-
232
- WebSocket 模式需要企业级飞书账号。如果是个人账号,请使用 Webhook 模式。
233
-
234
- ## 贡献
235
-
236
- 欢迎提交 Issue 和 Pull Request!如果您发现 Bug 或有功能建议,请在 https://github.com/xwang152-jack/claw-lark/issues 提交。
237
-
238
- ## 开源协议
239
-
240
- MIT
120
+ ### 常用命令
121
+ - `npm run lint`: 代码风格检查
122
+ - `npm run format`: 自动格式化代码
123
+ - `npm test`: 运行自动化测试
@@ -0,0 +1,34 @@
1
+ import tseslint from "@typescript-eslint/eslint-plugin";
2
+ import tsParser from "@typescript-eslint/parser";
3
+ import prettierConfig from "eslint-config-prettier";
4
+ import prettierPlugin from "eslint-plugin-prettier";
5
+
6
+ export default [
7
+ prettierConfig,
8
+ {
9
+ files: ["**/*.ts"],
10
+ ignores: [
11
+ "**/*.test.ts",
12
+ "**/*.spec.ts",
13
+ "src/__tests__/**",
14
+ ],
15
+ languageOptions: {
16
+ parser: tsParser,
17
+ parserOptions: {
18
+ ecmaVersion: 2022,
19
+ sourceType: "module",
20
+ },
21
+ },
22
+ plugins: {
23
+ "@typescript-eslint": tseslint,
24
+ prettier: prettierPlugin,
25
+ },
26
+ rules: {
27
+ ...tseslint.configs.recommended.rules,
28
+ "no-undef": "off",
29
+ "prettier/prettier": "error",
30
+ "@typescript-eslint/no-explicit-any": "warn",
31
+ "@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }],
32
+ },
33
+ },
34
+ ];
package/index.ts CHANGED
@@ -29,9 +29,9 @@ export type {
29
29
  } from "./src/types.js";
30
30
 
31
31
  const plugin = {
32
- id: "lark",
33
- name: "Lark",
34
- description: "Lark (Larksuite) channel plugin for OpenClaw",
32
+ id: "feishu",
33
+ name: "Feishu",
34
+ description: "Feishu / Lark channel plugin for OpenClaw",
35
35
  configSchema: emptyPluginConfigSchema(),
36
36
  register(api: OpenClawPluginApi) {
37
37
  setLarkRuntime(api);
@@ -1,6 +1,6 @@
1
1
  {
2
- "id": "lark",
3
- "channels": ["lark"],
2
+ "id": "feishu",
3
+ "channels": ["feishu"],
4
4
  "configSchema": {
5
5
  "type": "object",
6
6
  "properties": {
@@ -12,57 +12,78 @@
12
12
  "enabled": {
13
13
  "type": "boolean",
14
14
  "default": true,
15
- "description": "Enable this account"
15
+ "description": "是否启用此账号"
16
16
  },
17
17
  "appId": {
18
18
  "type": "string",
19
- "description": "Lark App ID (cli_xxx)"
19
+ "description": "飞书应用 App ID (cli_xxx)"
20
20
  },
21
21
  "appSecret": {
22
22
  "type": "string",
23
- "description": "Lark App Secret"
23
+ "description": "飞书应用 App Secret"
24
24
  },
25
25
  "encryptKey": {
26
26
  "type": "string",
27
- "description": "Encrypt key for event verification (optional)"
27
+ "description": "事件解密密钥 (可选)"
28
28
  },
29
29
  "domain": {
30
30
  "type": "string",
31
31
  "enum": ["lark", "feishu"],
32
32
  "default": "feishu",
33
- "description": "API domain: feishu (China) or lark (international)"
33
+ "description": "API 域名: feishu (国内) lark (国际)"
34
34
  },
35
35
  "connectionMode": {
36
36
  "type": "string",
37
37
  "enum": ["websocket", "webhook"],
38
38
  "default": "websocket",
39
- "description": "Connection mode: websocket (enterprise) or webhook (individual accounts)"
39
+ "description": "连接模式: websocket (企业自建应用推荐) webhook"
40
40
  },
41
41
  "verificationToken": {
42
42
  "type": "string",
43
- "description": "Verification token for webhook events (from Lark app settings)"
43
+ "description": "事件校验令牌 (用于 Webhook 模式)"
44
44
  },
45
45
  "webhookPort": {
46
46
  "type": "number",
47
47
  "default": 3000,
48
- "description": "Port for webhook server (webhook mode only)"
48
+ "description": "Webhook 服务端口"
49
49
  },
50
50
  "dmPolicy": {
51
51
  "type": "string",
52
52
  "enum": ["open", "pairing", "allowlist"],
53
53
  "default": "pairing",
54
- "description": "DM access policy"
54
+ "description": "私聊策略"
55
+ },
56
+ "dmAllowlist": {
57
+ "type": "array",
58
+ "items": { "type": "string" },
59
+ "description": "私聊白名单 (OpenID)"
55
60
  },
56
61
  "groupPolicy": {
57
62
  "type": "string",
58
63
  "enum": ["open", "allowlist", "disabled"],
59
64
  "default": "open",
60
- "description": "Group chat access policy"
65
+ "description": "群聊策略"
66
+ },
67
+ "groupAllowlist": {
68
+ "type": "array",
69
+ "items": { "type": "string" },
70
+ "description": "群聊白名单 (ChatID)"
61
71
  },
62
- "groupMentionGated": {
72
+ "requireMention": {
63
73
  "type": "boolean",
64
74
  "default": true,
65
- "description": "Require @mention in group chats"
75
+ "description": "群聊是否需要 @ 机器人"
76
+ },
77
+ "mediaMaxMb": {
78
+ "type": "number",
79
+ "default": 30,
80
+ "description": "媒体文件最大大小 (MB)"
81
+ },
82
+ "renderMode": {
83
+ "type": "string",
84
+ "enum": ["auto", "raw", "card"],
85
+ "default": "auto",
86
+ "description": "回复渲染模式"
66
87
  }
67
88
  }
68
89
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xwang152/claw-lark",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "Lark/Feishu channel plugin for OpenClaw with WebSocket and Webhook support",
6
6
  "license": "MIT",
@@ -26,7 +26,12 @@
26
26
  ]
27
27
  },
28
28
  "scripts": {
29
- "typecheck": "tsc -p tsconfig.json"
29
+ "typecheck": "tsc -p tsconfig.json",
30
+ "lint": "eslint src/**/*.ts index.ts --no-warn-ignored",
31
+ "format": "prettier --write src/**/*.ts index.ts",
32
+ "test": "vitest run",
33
+ "test:watch": "vitest",
34
+ "test:coverage": "vitest run --coverage"
30
35
  },
31
36
  "dependencies": {
32
37
  "@larksuiteoapi/node-sdk": "^1.37.0"
@@ -36,7 +41,15 @@
36
41
  },
37
42
  "devDependencies": {
38
43
  "@types/node": "^20.0.0",
44
+ "@typescript-eslint/eslint-plugin": "^8.54.0",
45
+ "@typescript-eslint/parser": "^8.54.0",
46
+ "@vitest/coverage-v8": "^4.0.18",
47
+ "eslint": "^9.39.2",
48
+ "eslint-config-prettier": "^10.1.8",
49
+ "eslint-plugin-prettier": "^5.5.5",
39
50
  "openclaw": "^2026.1.29",
40
- "typescript": "^5.0.0"
51
+ "prettier": "^3.8.1",
52
+ "typescript": "^5.0.0",
53
+ "vitest": "^4.0.18"
41
54
  }
42
55
  }
@@ -0,0 +1,7 @@
1
+ import { describe, it, expect } from "vitest";
2
+
3
+ describe("Sample Test", () => {
4
+ it("should work", () => {
5
+ expect(1 + 1).toBe(2);
6
+ });
7
+ });