@largezhou/ddingtalk 1.3.2 → 1.4.0-beta.1
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.en.md +361 -0
- package/README.md +281 -38
- package/package.json +6 -10
- package/src/accounts.ts +130 -45
- package/src/channel.ts +189 -89
- package/src/client.ts +75 -88
- package/src/ffmpeg.ts +206 -0
- package/src/monitor.ts +33 -8
- package/src/onboarding.ts +166 -56
- package/src/types.ts +38 -5
package/README.en.md
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
# @largezhou/ddingtalk
|
|
2
|
+
|
|
3
|
+
[中文文档](README.md)
|
|
4
|
+
|
|
5
|
+
OpenClaw DingTalk channel plugin, using Stream mode to connect enterprise robots.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- ✅ **Stream Mode**: No public IP or domain required, works out of the box
|
|
10
|
+
- ✅ **Multi-Account Support**: Connect multiple DingTalk robots simultaneously with separate credentials and permissions
|
|
11
|
+
- ✅ **Multi-Agent Routing**: Route different accounts, group chats, and direct messages to different Agents
|
|
12
|
+
- ✅ **Private/Group Chat**: Supports private chat and group chat (only when @robot)
|
|
13
|
+
- ✅ **Text Messages**: Send and receive text messages
|
|
14
|
+
- ✅ **Markdown Reply**: Robot replies in Markdown format
|
|
15
|
+
- ✅ **Image Messages**: Receive images from users, send local/remote images
|
|
16
|
+
- ✅ **Voice, Video, File, Rich Text**: Receive voice, video, file, and rich text messages from users
|
|
17
|
+
- ✅ **File Reply**: Support replying with files; audio, video, etc. are sent as files uniformly
|
|
18
|
+
- ✅ **Active Message Push**: Supports active message pushing, configurable for reminders or scheduled tasks
|
|
19
|
+
- ✅ **OpenClaw Commands**: Supports official OpenClaw commands such as /new, /compact
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
openclaw plugins install @largezhou/ddingtalk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
There are two ways to add the DingTalk channel:
|
|
32
|
+
|
|
33
|
+
### Method 1: Add via Installation Wizard (Recommended)
|
|
34
|
+
|
|
35
|
+
If you have just installed OpenClaw, you can run the wizard directly and follow the prompts to add DingTalk:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
openclaw onboard
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The wizard will guide you through:
|
|
42
|
+
|
|
43
|
+
1. Creating a DingTalk app robot and obtaining credentials
|
|
44
|
+
2. Configuring app credentials
|
|
45
|
+
3. Starting the gateway
|
|
46
|
+
|
|
47
|
+
**After completing the configuration**, you can use the following commands to check the gateway status:
|
|
48
|
+
|
|
49
|
+
- `openclaw gateway status` - View gateway running status
|
|
50
|
+
- `openclaw logs --follow` - View real-time logs
|
|
51
|
+
|
|
52
|
+
### Method 2: Add via Command Line
|
|
53
|
+
|
|
54
|
+
If you have already completed the initial installation, you can use the following command to add the DingTalk channel:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
openclaw channels add
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Then, follow the interactive prompts to select DingTalk, and enter the AppKey (Client ID) and AppSecret (Client Secret).
|
|
61
|
+
|
|
62
|
+
**After completing the configuration**, you can use the following commands to manage the gateway:
|
|
63
|
+
|
|
64
|
+
- `openclaw gateway status` - View gateway running status
|
|
65
|
+
- `openclaw gateway restart` - Restart the gateway to apply new configurations
|
|
66
|
+
- `openclaw logs --follow` - View real-time logs
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Step 1: Create a DingTalk App
|
|
71
|
+
|
|
72
|
+
### 1. Open the DingTalk Developer Platform
|
|
73
|
+
|
|
74
|
+
Visit the [DingTalk Developer Platform](https://open-dev.dingtalk.com/fe/app), log in with your DingTalk account, and select an organization to enter.
|
|
75
|
+
|
|
76
|
+
### 2. Create an App
|
|
77
|
+
|
|
78
|
+
1. Click **Create App** in the upper right corner
|
|
79
|
+
2. Fill in the app name and description, upload an image (optional)
|
|
80
|
+
|
|
81
|
+

|
|
82
|
+
|
|
83
|
+
### 3. Obtain App Credentials
|
|
84
|
+
|
|
85
|
+
On the app's **Credentials & Basic Information** page, copy:
|
|
86
|
+
|
|
87
|
+
- **Client ID** (format like `dingxxxx`)
|
|
88
|
+
- **Client Secret**
|
|
89
|
+
|
|
90
|
+
❗ **Important**: Please keep the Client Secret safe and do not share it with others.
|
|
91
|
+
|
|
92
|
+

|
|
93
|
+
|
|
94
|
+
### 4. Add an App Robot
|
|
95
|
+
|
|
96
|
+
1. On the app's **Add App Capabilities** page, select **Robot**, and click Add
|
|
97
|
+
|
|
98
|
+

|
|
99
|
+
|
|
100
|
+
2. Enter the relevant robot information, select **Stream Mode** for **Message Receiving Mode**, and then save
|
|
101
|
+
|
|
102
|
+

|
|
103
|
+
|
|
104
|
+

|
|
105
|
+
|
|
106
|
+
### 5. Configure App Permissions
|
|
107
|
+
|
|
108
|
+
In the app's permission management, make sure the following permissions are enabled:
|
|
109
|
+
|
|
110
|
+
- Permission for enterprise internal robots to send messages
|
|
111
|
+
- Permission to obtain download links for robot received messages via downloadCode (for receiving images)
|
|
112
|
+
|
|
113
|
+
### 6. Publish the Robot
|
|
114
|
+
|
|
115
|
+
Create a robot version, fill in the version number, description, and application availability scope, click save, then click confirm to publish.
|
|
116
|
+
|
|
117
|
+

|
|
118
|
+
|
|
119
|
+

|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Step 2: Configure OpenClaw
|
|
124
|
+
|
|
125
|
+
### Configure via Wizard (Recommended)
|
|
126
|
+
|
|
127
|
+
Run the following command, select DingTalk according to the prompts, and paste the AppKey (Client ID) and AppSecret (Client Secret):
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
openclaw channels add
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Configure via Configuration File
|
|
134
|
+
|
|
135
|
+
Edit `~/.openclaw/openclaw.json`:
|
|
136
|
+
|
|
137
|
+
```json
|
|
138
|
+
{
|
|
139
|
+
"channels": {
|
|
140
|
+
"ddingtalk": {
|
|
141
|
+
"enabled": true,
|
|
142
|
+
"clientId": "your_app_key",
|
|
143
|
+
"clientSecret": "your_app_secret",
|
|
144
|
+
"allowFrom": ["*"]
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### allowFrom Whitelist
|
|
151
|
+
|
|
152
|
+
`allowFrom` controls which users can interact with the robot and execute commands:
|
|
153
|
+
|
|
154
|
+
- **Default**: `["*"]` (allows everyone if not configured)
|
|
155
|
+
- **Specified users**: Fill in DingTalk user `staffId`, only whitelisted users can use commands (such as `/compact`, `/new`, etc.), messages from non-whitelisted users will be ignored
|
|
156
|
+
- `allowFrom[0]` also serves as the default target for active message push (`openclaw send`)
|
|
157
|
+
|
|
158
|
+
```json
|
|
159
|
+
{
|
|
160
|
+
"allowFrom": ["user_id_1", "user_id_2"]
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## Multi-Account Configuration
|
|
167
|
+
|
|
168
|
+
Supports connecting multiple DingTalk robots simultaneously, each corresponding to an independent account. Use cases:
|
|
169
|
+
|
|
170
|
+
- Different departments use different robots
|
|
171
|
+
- A single OpenClaw instance serves multiple DingTalk organizations
|
|
172
|
+
- Different robots with different permission policies
|
|
173
|
+
|
|
174
|
+
### Add a New Account
|
|
175
|
+
|
|
176
|
+
Add a new account via the wizard, which will interactively prompt for the account ID and credentials:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
openclaw channels add
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Configuration File Example
|
|
183
|
+
|
|
184
|
+
Edit `~/.openclaw/openclaw.json`:
|
|
185
|
+
|
|
186
|
+
```json
|
|
187
|
+
{
|
|
188
|
+
"channels": {
|
|
189
|
+
"ddingtalk": {
|
|
190
|
+
"enabled": true,
|
|
191
|
+
"accounts": {
|
|
192
|
+
"bot-hr": {
|
|
193
|
+
"name": "HR Assistant",
|
|
194
|
+
"clientId": "dingxxxxxxxx",
|
|
195
|
+
"clientSecret": "secret_1"
|
|
196
|
+
},
|
|
197
|
+
"bot-tech": {
|
|
198
|
+
"name": "Tech Support",
|
|
199
|
+
"clientId": "dingyyyyyyyy",
|
|
200
|
+
"clientSecret": "secret_2"
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
"defaultAccount": "bot-hr"
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Group-Specific Configuration
|
|
210
|
+
|
|
211
|
+
You can set independent permissions and behavior for specific group chats:
|
|
212
|
+
|
|
213
|
+
```json
|
|
214
|
+
{
|
|
215
|
+
"accounts": {
|
|
216
|
+
"bot-hr": {
|
|
217
|
+
"enabled": true,
|
|
218
|
+
"clientId": "dingxxxxxxxx",
|
|
219
|
+
"clientSecret": "secret_1"
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Single Account Compatibility
|
|
226
|
+
|
|
227
|
+
If you only have one robot, there is no need to use `accounts`. You can configure directly at the top level (compatible with the legacy format):
|
|
228
|
+
|
|
229
|
+
```json
|
|
230
|
+
{
|
|
231
|
+
"channels": {
|
|
232
|
+
"ddingtalk": {
|
|
233
|
+
"enabled": true,
|
|
234
|
+
"clientId": "your_app_key",
|
|
235
|
+
"clientSecret": "your_app_secret"
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Multi-Agent Routing
|
|
244
|
+
|
|
245
|
+
Through OpenClaw's routing bindings mechanism, you can assign different accounts, group chats, and direct messages to different Agents.
|
|
246
|
+
|
|
247
|
+
> For more about multi-agent concepts and usage, see the [OpenClaw Documentation - Multi-Agent](https://docs.openclaw.ai/zh-CN/concepts/multi-agent).
|
|
248
|
+
|
|
249
|
+
### Bind Agents by Account
|
|
250
|
+
|
|
251
|
+
Use the command line to bind different DingTalk accounts to different Agents:
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
# Bind bot-hr account to hr-agent
|
|
255
|
+
openclaw agents bind --agent hr-agent --bind ddingtalk:bot-hr
|
|
256
|
+
|
|
257
|
+
# Bind bot-tech account to tech-agent
|
|
258
|
+
openclaw agents bind --agent tech-agent --bind ddingtalk:bot-tech
|
|
259
|
+
|
|
260
|
+
# Bind the entire DingTalk channel (all accounts) to the default agent
|
|
261
|
+
openclaw agents bind --agent default-agent --bind ddingtalk
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
View current bindings:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
openclaw agents bindings
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Remove bindings:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
openclaw agents unbind --agent hr-agent --bind ddingtalk:bot-hr
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Bind Agents by Group/Direct Chat
|
|
277
|
+
|
|
278
|
+
The CLI currently only supports `channel[:accountId]` level bindings. To bind specific group chats or direct messages to different Agents, manually edit the `bindings` configuration in `~/.openclaw/openclaw.json`:
|
|
279
|
+
|
|
280
|
+
```json
|
|
281
|
+
{
|
|
282
|
+
"agents": {
|
|
283
|
+
"list": [
|
|
284
|
+
{ "id": "hr-agent", "name": "HR Assistant" },
|
|
285
|
+
{ "id": "tech-agent", "name": "Tech Support" },
|
|
286
|
+
{ "id": "general-agent", "name": "General Assistant" }
|
|
287
|
+
]
|
|
288
|
+
},
|
|
289
|
+
"bindings": [
|
|
290
|
+
{
|
|
291
|
+
"agentId": "tech-agent",
|
|
292
|
+
"comment": "Tech group routes to Tech Support Agent",
|
|
293
|
+
"match": {
|
|
294
|
+
"channel": "ddingtalk",
|
|
295
|
+
"peer": {
|
|
296
|
+
"kind": "group",
|
|
297
|
+
"id": "cidTechGroup001"
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
"agentId": "hr-agent",
|
|
303
|
+
"comment": "Zhang San's DM routes to HR Assistant",
|
|
304
|
+
"match": {
|
|
305
|
+
"channel": "ddingtalk",
|
|
306
|
+
"peer": {
|
|
307
|
+
"kind": "direct",
|
|
308
|
+
"id": "user_zhangsan_staffId"
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
"agentId": "general-agent",
|
|
314
|
+
"comment": "Other messages from bot-hr go to General Assistant",
|
|
315
|
+
"match": {
|
|
316
|
+
"channel": "ddingtalk",
|
|
317
|
+
"accountId": "bot-hr"
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
]
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## Step 3: Start and Test
|
|
327
|
+
|
|
328
|
+
### 1. Start the Gateway
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
openclaw gateway --verbose
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### 2. Send a Test Message
|
|
335
|
+
|
|
336
|
+
Find the robot you created in DingTalk, and you can start a normal conversation.
|
|
337
|
+
|
|
338
|
+

|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## Development
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
# Install dependencies
|
|
346
|
+
pnpm install
|
|
347
|
+
|
|
348
|
+
# Pack
|
|
349
|
+
pnpm pack
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## References
|
|
353
|
+
|
|
354
|
+
- [OpenClaw Multi-Agent Documentation](https://docs.openclaw.ai/concepts/multi-agent)
|
|
355
|
+
- [DingTalk Open Platform - Stream Mode](https://opensource.dingtalk.com/developerpedia/docs/learn/stream/overview)
|
|
356
|
+
- [DingTalk Open Platform - Robot Receive Messages](https://open.dingtalk.com/document/orgapp/robot-receive-message)
|
|
357
|
+
- [DingTalk Open Platform - Robot Send Messages](https://open.dingtalk.com/document/orgapp/robot-send-message)
|
|
358
|
+
|
|
359
|
+
## License
|
|
360
|
+
|
|
361
|
+
MIT
|