Add DingTalk success notes and long-term memory - token and msgKey configuration
This commit is contained in:
83
TOOLS.md
83
TOOLS.md
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user