@adongguo/dingtalk 0.1.3

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,247 @@
1
+ # openclaw-dingtalk
2
+
3
+ DingTalk (钉钉) 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 @adongguo/openclaw-dingtalk
15
+ ```
16
+
17
+ Or install via npm:
18
+
19
+ ```bash
20
+ npm install @adongguo/openclaw-dingtalk
21
+ ```
22
+
23
+ ### Configuration
24
+
25
+ 1. Create an enterprise internal application on [DingTalk Open Platform](https://open-dev.dingtalk.com)
26
+ 2. Get your AppKey (ClientID) and AppSecret (ClientSecret) from the Credentials page
27
+ 3. Enable Robot capability and select **Stream mode**
28
+ 4. Configure event subscriptions (see below)
29
+ 5. Configure the plugin:
30
+
31
+ #### Required Steps
32
+
33
+ 1. **Create Application**: Go to DingTalk Developer Console → Application Development → Enterprise Internal Development → Create Application
34
+
35
+ 2. **Enable Robot**: In your application, go to Application Capabilities → Robot → Enable Robot Configuration → Select **Stream mode**
36
+
37
+ 3. **Get Credentials**: Go to Basic Information → Application Information to get AppKey and AppSecret
38
+
39
+ 4. **Publish Application**: Publish the app (at least to test version) to make the bot available
40
+
41
+ ```bash
42
+ openclaw config set channels.dingtalk.appKey "dingXXXXXXXX"
43
+ openclaw config set channels.dingtalk.appSecret "your_app_secret"
44
+ openclaw config set channels.dingtalk.enabled true
45
+ ```
46
+
47
+ ### Configuration Options
48
+
49
+ ```yaml
50
+ channels:
51
+ dingtalk:
52
+ enabled: true
53
+ appKey: "dingXXXXXXXX"
54
+ appSecret: "secret"
55
+ # Robot code (optional, for media download)
56
+ robotCode: "dingXXXXXXXX"
57
+ # Connection mode: "stream" (recommended) or "webhook"
58
+ connectionMode: "stream"
59
+ # DM policy: "pairing" | "open" | "allowlist"
60
+ dmPolicy: "pairing"
61
+ # Group policy: "open" | "allowlist" | "disabled"
62
+ groupPolicy: "allowlist"
63
+ # Require @mention in groups
64
+ requireMention: true
65
+ # Max media size in MB (default: 30)
66
+ mediaMaxMb: 30
67
+ # Render mode for bot replies: "auto" | "raw" | "card"
68
+ renderMode: "auto"
69
+ ```
70
+
71
+ #### Render Mode
72
+
73
+ | Mode | Description |
74
+ |------|-------------|
75
+ | `auto` | (Default) Automatically detect: use ActionCard for messages with code blocks or tables, plain text otherwise. |
76
+ | `raw` | Always send replies as plain text. Markdown tables are converted to ASCII. |
77
+ | `card` | Always send replies as ActionCard with full markdown rendering. |
78
+
79
+ ### Features
80
+
81
+ - Stream mode connection (WebSocket-based)
82
+ - Direct messages and group chats
83
+ - Message replies
84
+ - Image and file support (via OpenAPI)
85
+ - Pairing flow for DM approval
86
+ - User and group directory lookup (config-based)
87
+ - ActionCard render mode for markdown rendering
88
+
89
+ ### Limitations
90
+
91
+ - **No message editing**: DingTalk doesn't support editing messages via sessionWebhook
92
+ - **No reactions**: Bot API doesn't support message reactions
93
+ - **sessionWebhook expiration**: Reply URLs are temporary and expire
94
+
95
+ ### FAQ
96
+
97
+ #### Bot cannot receive messages
98
+
99
+ Check the following:
100
+ 1. Is Robot capability enabled in your application?
101
+ 2. Is **Stream mode** selected (not HTTP mode)?
102
+ 3. Is the application published?
103
+ 4. Are the appKey and appSecret correct?
104
+
105
+ #### Failed to send messages
106
+
107
+ 1. Check if sessionWebhook has expired
108
+ 2. Verify message format is correct
109
+ 3. Ensure bot has necessary permissions
110
+
111
+ #### How to clear history / start new conversation
112
+
113
+ Send `/new` command in the chat.
114
+
115
+ #### Why is the output not streaming
116
+
117
+ DingTalk API has rate limits. Streaming updates can easily trigger throttling. We use complete-then-send approach for stability.
118
+
119
+ #### Cannot find the bot in DingTalk
120
+
121
+ 1. Ensure the app is published (at least to test version)
122
+ 2. Search for the bot name in DingTalk search box
123
+ 3. Check if your account is in the app's availability scope
124
+
125
+ ---
126
+
127
+ ## 中文
128
+
129
+ ### 安装
130
+
131
+ ```bash
132
+ openclaw plugins install @adongguo/openclaw-dingtalk
133
+ ```
134
+
135
+ 或通过 npm 安装:
136
+
137
+ ```bash
138
+ npm install @adongguo/openclaw-dingtalk
139
+ ```
140
+
141
+ ### 配置
142
+
143
+ 1. 在 [钉钉开放平台](https://open-dev.dingtalk.com) 创建企业内部应用
144
+ 2. 在凭证页面获取 AppKey (ClientID) 和 AppSecret (ClientSecret)
145
+ 3. 开启机器人能力并选择 **Stream 模式**
146
+ 4. 配置事件订阅(见下方)
147
+ 5. 配置插件:
148
+
149
+ #### 必需步骤
150
+
151
+ 1. **创建应用**:进入钉钉开发者后台 → 应用开发 → 企业内部开发 → 创建应用
152
+
153
+ 2. **开启机器人**:在应用页面,进入 应用功能 → 机器人 → 开启机器人配置 → 选择 **Stream 模式**
154
+
155
+ 3. **获取凭证**:进入 基础信息 → 应用信息,获取 AppKey 和 AppSecret
156
+
157
+ 4. **发布应用**:发布应用(至少发布到测试版本)使机器人可用
158
+
159
+ ```bash
160
+ openclaw config set channels.dingtalk.appKey "dingXXXXXXXX"
161
+ openclaw config set channels.dingtalk.appSecret "your_app_secret"
162
+ openclaw config set channels.dingtalk.enabled true
163
+ ```
164
+
165
+ ### 配置选项
166
+
167
+ ```yaml
168
+ channels:
169
+ dingtalk:
170
+ enabled: true
171
+ appKey: "dingXXXXXXXX"
172
+ appSecret: "secret"
173
+ # 机器人 code(可选,用于媒体下载)
174
+ robotCode: "dingXXXXXXXX"
175
+ # 连接模式: "stream" (推荐) 或 "webhook"
176
+ connectionMode: "stream"
177
+ # 私聊策略: "pairing" | "open" | "allowlist"
178
+ dmPolicy: "pairing"
179
+ # 群聊策略: "open" | "allowlist" | "disabled"
180
+ groupPolicy: "allowlist"
181
+ # 群聊是否需要 @机器人
182
+ requireMention: true
183
+ # 媒体文件最大大小 (MB, 默认 30)
184
+ mediaMaxMb: 30
185
+ # 回复渲染模式: "auto" | "raw" | "card"
186
+ renderMode: "auto"
187
+ ```
188
+
189
+ #### 渲染模式
190
+
191
+ | 模式 | 说明 |
192
+ |------|------|
193
+ | `auto` | (默认)自动检测:有代码块或表格时用 ActionCard,否则纯文本 |
194
+ | `raw` | 始终纯文本,表格转为 ASCII |
195
+ | `card` | 始终使用 ActionCard,支持完整 Markdown 渲染 |
196
+
197
+ ### 功能
198
+
199
+ - Stream 模式连接(基于 WebSocket)
200
+ - 私聊和群聊
201
+ - 消息回复
202
+ - 图片和文件支持(通过 OpenAPI)
203
+ - 私聊配对审批流程
204
+ - 用户和群组目录查询(基于配置)
205
+ - ActionCard 渲染模式支持 Markdown 渲染
206
+
207
+ ### 限制
208
+
209
+ - **不支持消息编辑**:钉钉不支持通过 sessionWebhook 编辑消息
210
+ - **不支持表情回复**:机器人 API 不支持消息表情回复
211
+ - **sessionWebhook 过期**:回复 URL 是临时的,会过期
212
+
213
+ ### 常见问题
214
+
215
+ #### 机器人收不到消息
216
+
217
+ 检查以下配置:
218
+ 1. 是否在应用中开启了机器人能力?
219
+ 2. 是否选择了 **Stream 模式**(而非 HTTP 模式)?
220
+ 3. 应用是否已发布?
221
+ 4. appKey 和 appSecret 是否正确?
222
+
223
+ #### 发送消息失败
224
+
225
+ 1. 检查 sessionWebhook 是否已过期
226
+ 2. 验证消息格式是否正确
227
+ 3. 确保机器人有必要的权限
228
+
229
+ #### 如何清理历史会话 / 开启新对话
230
+
231
+ 在聊天中发送 `/new` 命令即可开启新对话。
232
+
233
+ #### 消息为什么不是流式输出
234
+
235
+ 钉钉 API 有请求频率限制,流式更新消息很容易触发限流。当前采用完整回复后一次性发送的方式,以保证稳定性。
236
+
237
+ #### 在钉钉里找不到机器人
238
+
239
+ 1. 确保应用已发布(至少发布到测试版本)
240
+ 2. 在钉钉搜索框中搜索机器人名称
241
+ 3. 检查应用可用范围是否包含你的账号
242
+
243
+ ---
244
+
245
+ ## License
246
+
247
+ MIT
@@ -0,0 +1,9 @@
1
+ {
2
+ "id": "dingtalk",
3
+ "channels": ["dingtalk"],
4
+ "configSchema": {
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "properties": {}
8
+ }
9
+ }
package/index.ts ADDED
@@ -0,0 +1,86 @@
1
+ import type { ClawdbotPluginApi } from "openclaw/plugin-sdk";
2
+ import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
3
+ import { dingtalkPlugin } from "./src/channel.js";
4
+ import { setDingTalkRuntime } from "./src/runtime.js";
5
+
6
+ export { monitorDingTalkProvider } from "./src/monitor.js";
7
+ export {
8
+ sendMessageDingTalk,
9
+ sendMarkdownDingTalk,
10
+ sendActionCardDingTalk,
11
+ sendViaWebhook,
12
+ sendDingTalkMessage,
13
+ sendDingTalkTextMessage,
14
+ } from "./src/send.js";
15
+ export {
16
+ uploadMediaDingTalk,
17
+ downloadMediaDingTalk,
18
+ sendImageDingTalk,
19
+ sendFileDingTalk,
20
+ sendMediaDingTalk,
21
+ buildMediaSystemPrompt,
22
+ processLocalImages,
23
+ getOapiAccessToken,
24
+ } from "./src/media.js";
25
+ export { probeDingTalk } from "./src/probe.js";
26
+ export {
27
+ addReactionDingTalk,
28
+ removeReactionDingTalk,
29
+ listReactionsDingTalk,
30
+ DingTalkEmoji,
31
+ } from "./src/reactions.js";
32
+ export { dingtalkPlugin } from "./src/channel.js";
33
+
34
+ // AI Card streaming
35
+ export {
36
+ createAICard,
37
+ streamAICard,
38
+ finishAICard,
39
+ failAICard,
40
+ getAccessToken,
41
+ clearAccessTokenCache,
42
+ AICardStatus,
43
+ type AICardInstance,
44
+ type AICardStatusType,
45
+ } from "./src/ai-card.js";
46
+
47
+ // Session management
48
+ export {
49
+ isNewSessionCommand,
50
+ getSessionKey,
51
+ clearSession,
52
+ getSessionInfo,
53
+ clearAllSessions,
54
+ getActiveSessionCount,
55
+ cleanupExpiredSessions,
56
+ getNewSessionCommands,
57
+ DEFAULT_SESSION_TIMEOUT,
58
+ type UserSession,
59
+ } from "./src/session.js";
60
+
61
+ // Gateway streaming
62
+ export {
63
+ streamFromGateway,
64
+ getGatewayCompletion,
65
+ type GatewayOptions,
66
+ } from "./src/gateway-stream.js";
67
+
68
+ // Streaming message handler
69
+ export {
70
+ handleDingTalkStreamingMessage,
71
+ shouldUseStreamingMode,
72
+ type StreamingHandlerParams,
73
+ } from "./src/streaming-handler.js";
74
+
75
+ const plugin = {
76
+ id: "dingtalk",
77
+ name: "DingTalk",
78
+ description: "DingTalk channel plugin",
79
+ configSchema: emptyPluginConfigSchema(),
80
+ register(api: ClawdbotPluginApi) {
81
+ setDingTalkRuntime(api.runtime);
82
+ api.registerChannel({ plugin: dingtalkPlugin });
83
+ },
84
+ };
85
+
86
+ export default plugin;
@@ -0,0 +1,9 @@
1
+ {
2
+ "id": "dingtalk",
3
+ "channels": ["dingtalk"],
4
+ "configSchema": {
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "properties": {}
8
+ }
9
+ }
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@adongguo/dingtalk",
3
+ "version": "0.1.3",
4
+ "type": "module",
5
+ "description": "OpenClaw DingTalk channel plugin",
6
+ "license": "MIT",
7
+ "files": [
8
+ "index.ts",
9
+ "src",
10
+ "clawdbot.plugin.json",
11
+ "openclaw.plugin.json"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/adongguo/openclaw-dingtalk.git"
16
+ },
17
+ "keywords": [
18
+ "openclaw",
19
+ "dingtalk",
20
+ "钉钉",
21
+ "chatbot",
22
+ "ai",
23
+ "claude"
24
+ ],
25
+ "openclaw": {
26
+ "extensions": [
27
+ "./index.ts"
28
+ ],
29
+ "channel": {
30
+ "id": "dingtalk",
31
+ "label": "DingTalk",
32
+ "selectionLabel": "DingTalk (钉钉)",
33
+ "docsPath": "/channels/dingtalk",
34
+ "docsLabel": "dingtalk",
35
+ "blurb": "钉钉/DingTalk enterprise messaging.",
36
+ "aliases": [
37
+ "dingding"
38
+ ],
39
+ "order": 70
40
+ },
41
+ "install": {
42
+ "npmSpec": "@adongguo/dingtalk",
43
+ "localPath": ".",
44
+ "defaultChoice": "npm"
45
+ }
46
+ },
47
+ "dependencies": {
48
+ "dingtalk-stream": "^2.1.4",
49
+ "zod": "^4.3.6"
50
+ },
51
+ "devDependencies": {
52
+ "@types/node": "^25.0.10",
53
+ "clawdbot": "2026.1.24-2",
54
+ "tsx": "^4.21.0",
55
+ "typescript": "^5.7.0"
56
+ },
57
+ "peerDependencies": {
58
+ "clawdbot": ">=2026.1.24"
59
+ }
60
+ }
@@ -0,0 +1,49 @@
1
+ import type { ClawdbotConfig } from "openclaw/plugin-sdk";
2
+ import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk";
3
+ import type { DingTalkConfig, ResolvedDingTalkAccount } from "./types.js";
4
+
5
+ export function resolveDingTalkCredentials(cfg?: DingTalkConfig): {
6
+ appKey: string;
7
+ appSecret: string;
8
+ robotCode?: string;
9
+ } | null {
10
+ const appKey = cfg?.appKey?.trim();
11
+ const appSecret = cfg?.appSecret?.trim();
12
+ if (!appKey || !appSecret) return null;
13
+ return {
14
+ appKey,
15
+ appSecret,
16
+ robotCode: cfg?.robotCode?.trim() || undefined,
17
+ };
18
+ }
19
+
20
+ export function resolveDingTalkAccount(params: {
21
+ cfg: ClawdbotConfig;
22
+ accountId?: string | null;
23
+ }): ResolvedDingTalkAccount {
24
+ const dingtalkCfg = params.cfg.channels?.dingtalk as DingTalkConfig | undefined;
25
+ const enabled = dingtalkCfg?.enabled !== false;
26
+ const creds = resolveDingTalkCredentials(dingtalkCfg);
27
+
28
+ return {
29
+ accountId: params.accountId?.trim() || DEFAULT_ACCOUNT_ID,
30
+ enabled,
31
+ configured: Boolean(creds),
32
+ appKey: creds?.appKey,
33
+ robotCode: creds?.robotCode,
34
+ };
35
+ }
36
+
37
+ export function listDingTalkAccountIds(_cfg: ClawdbotConfig): string[] {
38
+ return [DEFAULT_ACCOUNT_ID];
39
+ }
40
+
41
+ export function resolveDefaultDingTalkAccountId(_cfg: ClawdbotConfig): string {
42
+ return DEFAULT_ACCOUNT_ID;
43
+ }
44
+
45
+ export function listEnabledDingTalkAccounts(cfg: ClawdbotConfig): ResolvedDingTalkAccount[] {
46
+ return listDingTalkAccountIds(cfg)
47
+ .map((accountId) => resolveDingTalkAccount({ cfg, accountId }))
48
+ .filter((account) => account.enabled && account.configured);
49
+ }