@dingtalk-real-ai/dingtalk-connector 0.7.10 → 0.8.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.
Files changed (111) hide show
  1. package/README.en.md +418 -0
  2. package/README.md +267 -538
  3. package/docs/images/dingtalk.svg +1 -0
  4. package/docs/images/image-1.png +0 -0
  5. package/docs/images/image-2.png +0 -0
  6. package/docs/images/image-3.png +0 -0
  7. package/docs/images/image-4.png +0 -0
  8. package/index.ts +28 -0
  9. package/install-beta.sh +438 -0
  10. package/openclaw.plugin.json +2 -1
  11. package/package.json +19 -10
  12. package/src/channel.ts +559 -0
  13. package/src/config/accounts.ts +230 -0
  14. package/src/config/schema.ts +144 -0
  15. package/src/core/connection.ts +655 -0
  16. package/src/core/message-handler.ts +1265 -0
  17. package/src/core/provider.ts +106 -0
  18. package/src/core/state.ts +54 -0
  19. package/src/directory.ts +95 -0
  20. package/src/docs.ts +293 -0
  21. package/src/gateway-methods.ts +444 -0
  22. package/src/onboarding.ts +387 -0
  23. package/src/policy.ts +19 -0
  24. package/src/probe.ts +212 -0
  25. package/src/reply-dispatcher.ts +661 -0
  26. package/src/runtime.ts +7 -0
  27. package/src/sdk/helpers.ts +317 -0
  28. package/src/sdk/types.ts +515 -0
  29. package/src/secret-input.ts +19 -0
  30. package/src/services/media/audio.ts +54 -0
  31. package/src/services/media/chunk-upload.ts +306 -0
  32. package/src/services/media/common.ts +153 -0
  33. package/src/services/media/file.ts +70 -0
  34. package/src/services/media/image.ts +67 -0
  35. package/src/services/media/index.ts +10 -0
  36. package/src/services/media/video.ts +162 -0
  37. package/src/services/media.ts +1133 -0
  38. package/src/services/messaging/card.ts +342 -0
  39. package/src/services/messaging/index.ts +17 -0
  40. package/src/services/messaging/send.ts +141 -0
  41. package/src/services/messaging.ts +995 -0
  42. package/src/targets.ts +45 -0
  43. package/src/types/index.ts +52 -0
  44. package/src/utils/agent.ts +63 -0
  45. package/src/utils/async.ts +51 -0
  46. package/src/utils/constants.ts +9 -0
  47. package/src/utils/http-client.ts +84 -0
  48. package/src/utils/index.ts +8 -0
  49. package/src/utils/logger.ts +78 -0
  50. package/src/utils/session.ts +118 -0
  51. package/src/utils/token.ts +93 -0
  52. package/src/utils/utils-legacy.ts +505 -0
  53. package/test-dingtalk-connection.mjs +105 -0
  54. package/.github/workflows/ai-fix-and-test.yml +0 -518
  55. package/.github/workflows/issue-to-AI-table.yml +0 -52
  56. package/.github/workflows/issue-to-dingtalk.yml +0 -49
  57. package/.github/workflows/pr-review.yml +0 -108
  58. package/docs/RELEASE_NOTES_V0.7.10.md +0 -40
  59. package/docs/RELEASE_NOTES_V0.7.2.md +0 -143
  60. package/docs/RELEASE_NOTES_V0.7.3.md +0 -149
  61. package/docs/RELEASE_NOTES_V0.7.4.md +0 -206
  62. package/docs/RELEASE_NOTES_V0.7.5.md +0 -267
  63. package/docs/RELEASE_NOTES_V0.7.6.md +0 -219
  64. package/docs/RELEASE_NOTES_V0.7.7.md +0 -122
  65. package/docs/RELEASE_NOTES_V0.7.8.md +0 -101
  66. package/docs/RELEASE_NOTES_V0.7.9.md +0 -65
  67. package/docs/RELEASE_NOTES_v0.7.0.md +0 -142
  68. package/docs/RELEASE_NOTES_v0.7.1.md +0 -74
  69. package/plugin.ts +0 -4138
  70. package/src/socket-manager.ts +0 -312
  71. package/tests/README.md +0 -54
  72. package/tests/ai-card/PLAN.md +0 -54
  73. package/tests/ai-card/ai-card.test.ts +0 -372
  74. package/tests/audio/PLAN.md +0 -64
  75. package/tests/audio/audio.test.ts +0 -283
  76. package/tests/bindings/PLAN.md +0 -99
  77. package/tests/bindings/bindings.test.ts +0 -191
  78. package/tests/card-update/PLAN.md +0 -29
  79. package/tests/card-update/card-update.test.ts +0 -127
  80. package/tests/config-token/PLAN.md +0 -94
  81. package/tests/config-token/config-token.test.ts +0 -153
  82. package/tests/core/PLAN.md +0 -65
  83. package/tests/core/core.test.ts +0 -286
  84. package/tests/deliver-payload/PLAN.md +0 -59
  85. package/tests/deliver-payload/deliver-payload.test.ts +0 -91
  86. package/tests/download/PLAN.md +0 -47
  87. package/tests/download/download.test.ts +0 -261
  88. package/tests/file-markers/PLAN.md +0 -74
  89. package/tests/file-markers/file-markers.test.ts +0 -105
  90. package/tests/index.ts +0 -129
  91. package/tests/integration/PLAN.md +0 -65
  92. package/tests/integration/integration.test.ts +0 -232
  93. package/tests/mcp-tools/PLAN.md +0 -67
  94. package/tests/mcp-tools/mcp-tools.test.ts +0 -327
  95. package/tests/media/PLAN.md +0 -37
  96. package/tests/media/media.test.ts +0 -50
  97. package/tests/message-extract/PLAN.md +0 -83
  98. package/tests/message-extract/message-extract.test.ts +0 -205
  99. package/tests/proactive/PLAN.md +0 -88
  100. package/tests/proactive/proactive.test.ts +0 -502
  101. package/tests/prompts/PLAN.md +0 -71
  102. package/tests/prompts/prompts.test.ts +0 -64
  103. package/tests/send-message/PLAN.md +0 -44
  104. package/tests/send-message/send-message.test.ts +0 -228
  105. package/tests/session/PLAN.md +0 -90
  106. package/tests/session/session.test.ts +0 -166
  107. package/tests/upload/PLAN.md +0 -72
  108. package/tests/upload/upload.test.ts +0 -390
  109. package/tests/video/PLAN.md +0 -118
  110. package/tests/video/video.test.ts +0 -40
  111. package/vitest.config.ts +0 -13
package/README.en.md ADDED
@@ -0,0 +1,418 @@
1
+ <div align="center">
2
+ <img alt="DingTalk" src="docs/images/dingtalk.svg" width="72" height="72" />
3
+ <h1>Official DingTalk OpenClaw Connector</h1>
4
+ <p>Connect DingTalk bots to OpenClaw Gateway with AI Card streaming and session management</p>
5
+
6
+ <p>
7
+ <a href="README.md">简体中文</a> •
8
+ <a href="CHANGELOG.md">Changelog</a>
9
+ </p>
10
+ </div>
11
+
12
+ ---
13
+
14
+ ## 📋 Table of Contents
15
+
16
+ - [Prerequisites](#prerequisites)
17
+ - [Quick Start](#quick-start)
18
+ - [Features](#features)
19
+ - [Configuration](#configuration)
20
+ - [Troubleshooting](#troubleshooting)
21
+ - [Advanced Topics](#advanced-topics)
22
+ - [License](#license)
23
+
24
+ ---
25
+
26
+ ## Prerequisites
27
+
28
+ Before you begin, ensure you have:
29
+
30
+ > This connector is used as an OpenClaw Gateway plugin, and you usually don't need to install or manage Node.js runtime by yourself.
31
+
32
+ ### 1. OpenClaw Gateway
33
+
34
+ - **Official Website**: https://openclaw.ai/
35
+ - **Installation**: Follow the official guide to install OpenClaw
36
+ - **Verify installation**:
37
+ ```bash
38
+ openclaw gateway status
39
+ ```
40
+ Expected output: `✓ Gateway is running on http://127.0.0.1:18789`
41
+
42
+ ### 2. DingTalk Enterprise Account
43
+
44
+ - You need a DingTalk enterprise account to create internal applications
45
+ - Official Website: https://www.dingtalk.com/
46
+
47
+ ---
48
+
49
+ ## Quick Start
50
+
51
+ > 💡 **Goal**: Get your DingTalk bot working in ~5 minutes
52
+
53
+ ### Operating System Support
54
+
55
+ - macOS / Linux: Use the default shell (zsh, bash, etc.).
56
+ - Windows:
57
+ - Recommended: **PowerShell** or **Windows Terminal**.
58
+ - OpenClaw config file path (default): `C:\Users\<YourUserName>\.openclaw\openclaw.json`.
59
+
60
+ Whenever you see `~/.openclaw/openclaw.json` below, it is equivalent to the above path on Windows.
61
+
62
+ ### Step 1: Install the Plugin
63
+
64
+ ```bash
65
+ # Recommended: Install from npm
66
+ openclaw plugins install @dingtalk-real-ai/dingtalk-connector
67
+
68
+ # Alternative: Install from Git
69
+ openclaw plugins install https://github.com/DingTalk-Real-AI/dingtalk-openclaw-connector.git
70
+ ```
71
+
72
+ **Verify installation**:
73
+ ```bash
74
+ openclaw plugins list
75
+ ```
76
+ You should see `✓ DingTalk Channel (v0.8.0) - loaded`
77
+
78
+ ---
79
+
80
+ ### Step 2: Create a DingTalk Bot
81
+
82
+ #### 2.1 Create Application
83
+
84
+ 1. Go to [DingTalk Open Platform](https://open-dev.dingtalk.com/)
85
+ 2. Click **"Application Development"**
86
+
87
+ ![Create Application](docs/images/image-1.png)
88
+
89
+ #### 2.2 Add Bot Capability
90
+
91
+ 1. On the application details page, use the “one-click OpenClaw bot app” flow
92
+
93
+ ![Create OpenClaw bot app](docs/images/image-2.png)
94
+
95
+ #### 2.3 Get Credentials
96
+
97
+ 1. Finish creation and open **"Credentials & Basic Info"**
98
+ 2. Copy your **AppKey** (Client ID)
99
+ 3. Copy your **AppSecret** (Client Secret)
100
+
101
+ ![Finish creation](docs/images/image-3.png)
102
+
103
+ ![Get credentials](docs/images/image-4.png)
104
+
105
+ > ⚠️ **Important**: Client ID and Client Secret are your bot’s unique credentials. Store them safely.
106
+
107
+ ---
108
+
109
+ ### Step 3: Configure OpenClaw
110
+
111
+ You have three options to configure the connector:
112
+
113
+ #### Option A: Configuration Wizard (Recommended for Beginners)
114
+
115
+ > You can directly copy and paste the following command into your terminal to run the configuration wizard.
116
+
117
+ ```bash
118
+ openclaw channels add
119
+ ```
120
+
121
+ Select **"DingTalk (钉钉)"** and follow the prompts to enter:
122
+ - `clientId` (AppKey)
123
+ - `clientSecret` (AppSecret)
124
+
125
+ #### Option B: Edit Configuration File
126
+
127
+ Edit the configuration file:
128
+
129
+ - macOS / Linux: `~/.openclaw/openclaw.json`
130
+ - Windows: `C:\Users\<YourUserName>\.openclaw\openclaw.json`
131
+
132
+ ```json
133
+ {
134
+ "channels": {
135
+ "dingtalk-connector": {
136
+ "enabled": true,
137
+ "clientId": "dingxxxxxxxxx",
138
+ "clientSecret": "your_app_secret"
139
+ }
140
+ }
141
+ }
142
+ ```
143
+
144
+ > 💡 **Tip**: If the file already has content, add the `dingtalk-connector` section under the `channels` node.
145
+
146
+ ---
147
+
148
+ ### Step 4: Restart and Test
149
+
150
+ ```bash
151
+ # Restart OpenClaw Gateway
152
+ openclaw gateway restart
153
+
154
+ # Watch logs in real-time
155
+ openclaw logs --follow
156
+ ```
157
+
158
+ **Test your bot**:
159
+ 1. Open DingTalk app
160
+ 2. Find your bot in the contact list
161
+ 3. Send a message: `Hello`
162
+ 4. You should receive a response within 10 seconds
163
+
164
+ ---
165
+
166
+ ## Features
167
+
168
+ ### ✅ Core Features
169
+
170
+ - **AI Card Streaming** - Typewriter-like replies with real-time streaming
171
+ - **Session Management** - Multi-turn conversations with context preservation
172
+ - **Session Isolation** - Separate sessions for DMs, groups, and different groups
173
+ - **Auto Session Reset** - Automatic new session after 30 minutes of inactivity
174
+ - **Manual Session Reset** - Send `/new` or `新会话` to clear conversation history
175
+ - **Image Auto-Upload** - Local image paths automatically uploaded to DingTalk
176
+ - **Proactive Messaging** - Send messages to users or groups programmatically
177
+ - **Rich Media Reception** - Receive and process JPEG/PNG images, pass to vision models
178
+ - **File Attachment Extraction** - Parse .docx, .pdf, text files, and binary files
179
+ - **Audio Message Support** - Send audio messages in multiple formats (mp3, wav, amr, ogg)
180
+ - **DingTalk Docs API** - Create, append, search, and list DingTalk documents
181
+ - **Multi-Agent Routing** - Connect multiple bots to different agents for specialized services
182
+ - **Markdown Table Conversion** - Auto-convert Markdown tables to DingTalk-compatible format
183
+ - **Async Mode** - Immediate acknowledgment with background processing (optional)
184
+
185
+ ---
186
+
187
+ ## Configuration
188
+
189
+ ### Basic Configuration
190
+
191
+ | Option | Environment Variable | Description |
192
+ |--------|---------------------|-------------|
193
+ | `clientId` | — | DingTalk AppKey |
194
+ | `clientSecret` | — | DingTalk AppSecret |
195
+
196
+ ### Session Management
197
+
198
+ | Option | Default | Description |
199
+ |--------|---------|-------------|
200
+ | `separateSessionByConversation` | `true` | Separate sessions for DMs/groups |
201
+ | `groupSessionScope` | `group` | Group session scope: `group` (shared) or `group_sender` (per-user) |
202
+ | `sharedMemoryAcrossConversations` | `false` | Share memory across different conversations |
203
+
204
+ ### Session routing policies (`pmpolicy` / `groupPolicy`)
205
+
206
+ Both session routing/message policy options (including `pmpolicy` and `groupPolicy`) are supported now, so you **do not need to remove** them from existing configurations.
207
+
208
+ > Note: field names may vary across versions/upstream; on the connector side, related policies are supported and applied (for example, `dmPolicy`/`groupPolicy` default to `open`).
209
+
210
+ ### Async Mode
211
+
212
+ | Option | Default | Description |
213
+ |--------|---------|-------------|
214
+ | `asyncMode` | `false` | Enable async mode for long-running tasks |
215
+ | `ackText` | `🫡 任务已接收,处理中...` | Acknowledgment message text |
216
+
217
+ ---
218
+
219
+ ## Troubleshooting
220
+
221
+ ### Bot Not Responding
222
+
223
+ **Symptoms**: Bot doesn't reply to messages
224
+
225
+ **Solutions**:
226
+ 1. Check plugin status: `openclaw plugins list`
227
+ 2. Check gateway status: `openclaw gateway status`
228
+ 3. Check logs: `openclaw logs --follow`
229
+ 4. Verify the app is published/enabled in DingTalk Open Platform
230
+
231
+ ---
232
+
233
+ ### HTTP 401 Error
234
+
235
+ **Symptoms**: Error message shows "401 Unauthorized"
236
+
237
+ **Solution**: Upgrade to the latest version.
238
+
239
+ ---
240
+
241
+ ### Stream Connection 400 Error
242
+
243
+ **Symptoms**: Logs show "Request failed with status code 400"
244
+
245
+ **Common Causes**:
246
+
247
+ | Cause | Solution |
248
+ |-------|----------|
249
+ | App not published | DingTalk Open Platform → Version Management → Publish |
250
+ | Invalid credentials | Check `clientId`/`clientSecret` for typos or extra spaces |
251
+ | Not Stream mode | Verify bot is configured for Stream mode (not Webhook) |
252
+ | IP whitelist | Check if the app has IP whitelist restrictions |
253
+
254
+ **Verification Steps**:
255
+ 1. Check app status in [DingTalk Open Platform](https://open-dev.dingtalk.com/)
256
+ 2. After any configuration change, click **Save** → **Publish**
257
+
258
+ ---
259
+
260
+ ## Advanced Topics
261
+
262
+ ### Multi-Agent Configuration
263
+
264
+ Configure multiple bots connected to different agents:
265
+
266
+ ```json5
267
+ {
268
+ "agents": {
269
+ "list": [
270
+ {
271
+ "agentId": "ding-bot1",
272
+ "model": "your-model-config",
273
+ "persona": {
274
+ "name": "Customer Service Bot",
275
+ "systemPrompt": "You are a professional customer service assistant..."
276
+ }
277
+ // Other agent configurations...
278
+ },
279
+ {
280
+ "agentId": "ding-bot2",
281
+ "model": "your-model-config",
282
+ "persona": {
283
+ "name": "Technical Support Bot",
284
+ "systemPrompt": "You are a technical support expert..."
285
+ }
286
+ // Other agent configurations...
287
+ }
288
+ ]
289
+ },
290
+ "channels": {
291
+ "dingtalk-connector": {
292
+ "enabled": true,
293
+ "accounts": {
294
+ "bot1": {
295
+ "enabled": true,
296
+ "clientId": "ding_bot1_app_key",
297
+ "clientSecret": "bot1_secret"
298
+ },
299
+ "bot2": {
300
+ "enabled": true,
301
+ "clientId": "ding_bot2_app_key",
302
+ "clientSecret": "bot2_secret"
303
+ }
304
+ }
305
+ }
306
+ },
307
+ "bindings": [
308
+ {
309
+ "agentId": "ding-bot1",
310
+ "match": {
311
+ "channel": "dingtalk-connector",
312
+ "accountId": "bot1"
313
+ }
314
+ },
315
+ {
316
+ "agentId": "ding-bot2",
317
+ "match": {
318
+ "channel": "dingtalk-connector",
319
+ "accountId": "bot2"
320
+ }
321
+ }
322
+ ]
323
+ }
324
+ ```
325
+
326
+ For more details, see [OpenClaw Multi-Agent Configuration Guide](https://gist.github.com/smallnest/c5c13482740fd179e40070e620f66a52).
327
+
328
+ ---
329
+
330
+ ### Session Commands
331
+
332
+ Users can send the following commands to start a fresh session:
333
+
334
+ - `/new`, `/reset`, `/clear`
335
+ - `新会话`, `重新开始`, `清空对话`
336
+
337
+ ---
338
+
339
+ ### DingTalk Docs via MCP (`docs.*`)
340
+
341
+ DingTalk Docs capabilities (`docs.*`, including `docs.create` / `docs.append` / `docs.search` / `docs.list` / `docs.read`) require MCP (Model Context Protocol) to provide the underlying tools. To enable `docs.*`, install and enable the corresponding MCP Server/Tool in the OpenClaw Gateway/Agent.
342
+
343
+ - **Where to get MCP Server/Tool**: via the [DingTalk MCP Marketplace](https://mcp.dingtalk.com/) (or your team’s internal MCP marketplace). You can also use a third-party marketplace to source an equivalent “DingTalk Docs Read / DingTalk Docs Reader” capability and connect it to OpenClaw.
344
+ - **Where to configure**: usually at the **Gateway or Agent tool configuration** level (not in this connector).
345
+ - **How it takes effect**: restart the Gateway and ensure the tool is exposed to the target agent.
346
+
347
+ References (OpenClaw configuration docs):
348
+ - `https://docs.openclaw.ai/configuration`
349
+ - `https://docs.openclaw.ai/gateway/configuration-reference`
350
+
351
+ Create and manage DingTalk documents from your agent:
352
+
353
+ ```javascript
354
+ // Create document
355
+ dingtalk-connector.docs.create({
356
+ spaceId: "your-space-id",
357
+ title: "Test Document",
358
+ content: "# Test Content"
359
+ })
360
+
361
+ // Append content
362
+ dingtalk-connector.docs.append({
363
+ docId: "your-doc-id",
364
+ markdownContent: "\n## Appended Content"
365
+ })
366
+
367
+ // Search documents
368
+ dingtalk-connector.docs.search({
369
+ keyword: "search keyword"
370
+ })
371
+
372
+ // List documents
373
+ dingtalk-connector.docs.list({
374
+ spaceId: "your-space-id"
375
+ })
376
+ ```
377
+
378
+ ---
379
+
380
+ ## Project Structure
381
+
382
+ ```
383
+ dingtalk-openclaw-connector/
384
+ ├── src/
385
+ │ ├── core/ # Core connector logic
386
+ │ ├── services/ # DingTalk API services
387
+ │ ├── utils/ # Utility functions
388
+ │ └── types/ # TypeScript type definitions
389
+ ├── docs/
390
+ │ └── images/ # Documentation images
391
+ ├── openclaw.plugin.json # Plugin manifest
392
+ ├── package.json # npm dependencies
393
+ └── LICENSE
394
+ ```
395
+
396
+ ---
397
+
398
+ ## Dependencies
399
+
400
+ | Package | Purpose |
401
+ |---------|---------|
402
+ | `dingtalk-stream` | DingTalk Stream protocol client |
403
+ | `axios` | HTTP client |
404
+ | `mammoth` | Word document (.docx) parsing |
405
+ | `pdf-parse` | PDF document parsing |
406
+
407
+ ---
408
+
409
+ ## License
410
+
411
+ [MIT](LICENSE)
412
+
413
+ ---
414
+
415
+ ## Support
416
+
417
+ - **Issues**: [GitHub Issues](https://github.com/DingTalk-Real-AI/dingtalk-openclaw-connector/issues)
418
+ - **Changelog**: [CHANGELOG.md](CHANGELOG.md)