Add DingTalk success notes and long-term memory - token and msgKey configuration

This commit is contained in:
aitest
2026-03-05 18:47:56 +09:00
parent 114d1090b0
commit 6d22374d00
2 changed files with 251 additions and 0 deletions

View File

@@ -44,4 +44,87 @@ Skills are shared. Your setup is yours. Keeping them apart means you can update
- **robotCode**: ding4ursdp0l2giat4bj
- **OpenConversationId**: cidcjYshXVtKck5LfOO9AqOJg==
## DingTalk成功发送的关键配置
### Token获取必须使用GET + URL参数
```javascript
// ✓ 正确方式
const tokenUrl = `https://oapi.dingtalk.com/gettoken?appkey=${APP_KEY}&appsecret=${APP_SECRET}`;
const token = await axios.get(tokenUrl).data.access_token;
// ✗ 错误方式(会失败)
const tokenUrl = "https://oapi.dingtalk.com/gettoken";
const token = await axios.get(tokenUrl, {
params: {appkey: APP_KEY, appsecret: APP_SECRET}
}).data.access_token;
```
### v1.0 API发送消息成功方式
```javascript
// API端点
const url = "https://api.dingtalk.com/v1.0/robot/groupMessages/send";
// Headers关键包含access_token
const headers = {
"x-acs-dingtalk-access-token": accessToken,
"Content-Type": "application/json"
};
// Body格式
const body = {
robotCode: ROBOT_CODE,
openConversationId: OPEN_CONVERSATION_ID,
msgKey: "sampleFile", // 或 "sampleMarkdown"
msgParam: JSON.stringify({ // ← 必须是字符串!
mediaId: media_id,
fileName: "file.txt"
})
};
await axios.post(url, body, { headers });
```
### 关键msgKey对应关系
| 媒体类型 | msgKey | 说明 |
|---------|--------|------|
| **文件** | `sampleFile` | 发送.txt, .docx, .pdf等文件 |
| **图片** | `sampleMarkdown` | 使用Markdown格式嵌入图片 |
| **视频** | `sampleVideo` | 发送.mp4等视频文件待测试 |
### 重要注意事项
1. **msgParam必须是字符串**
```javascript
// ✓ 正确
msgParam: JSON.stringify({mediaId: "@xxx", fileName: "test.txt"})
// ✗ 错误
msgParam: {mediaId: "@xxx", fileName: "test.txt"}
```
2. **直接调用API会失败于OpenClaw环境**
- OpenClaw的DingTalk插件会拦截所有API请求
- 直接调用`robot/send`会返回"token is not exist"或"缺少参数 access_token"
- 必须使用v1.0 API + Headers中的access_token
3. **文件上传API**
```javascript
// 上传GET方式获取token已经验证有效
const uploadUrl = `https://oapi.dingtalk.com/media/upload?access_token=${accessToken}`;
const form = new FormData();
form.append('media', fs.createReadStream(filePath));
form.append('type', 'file');
await axios.post(uploadUrl, form, {headers: form.getHeaders()});
```
### 成功案例记录
**2026-03-05 18:44** - 成功发送database_analysis_summary.txt
- 文件: database_analysis_summary.txt (3,155 bytes)
- media_id: @lAjPM2GaR32g2U3OC2pNq84Clg_0
- msgKey: sampleFile
- API: /v1.0/robot/groupMessages/send
- ProcessQueryKey: lXs/uLRd0YxJVk1x0VyTLfSdY2YKCE1yrGn2vGlQ+GM=
Add whatever helps you do your job. This is your cheat sheet.