Add OpenClaw workspace configuration and tools
- Add agent configuration files (AGENTS.md, USER.md, IDENTITY.md, SOUL.md) - Add git configuration and skills management scripts - Add frontend/backend analysis tools and reports - Add DingTalk media sender utilities and documentation - Fix OpenClaw runtime environment (Node.js and Python) - Configure git remotes and push scripts
This commit is contained in:
114
send_markdown_image.js
Normal file
114
send_markdown_image.js
Normal file
@@ -0,0 +1,114 @@
|
||||
// 使用 Markdown 格式发送图片(在文本中嵌入 media_id)
|
||||
const axios = require('axios');
|
||||
|
||||
const ACCESS_TOKEN_URL = "https://api.dingtalk.com/v1.0/oauth2/accessToken";
|
||||
const UPLOAD_URL = "https://oapi.dingtalk.com/media/upload";
|
||||
const SEND_URL = "https://api.dingtalk.com/v1.0/robot/groupMessages/send";
|
||||
|
||||
const APP_KEY = "ding4ursdp0l2giat4bj";
|
||||
const APP_SECRET = "J0gBicjKiIHoKla7WfKKhRs1Tv8L6Xd5UhW3EVQByF16G7Vn7UUcRhP6u-PBCQNo";
|
||||
const OPEN_CONVERSATION_ID = "cidcjYshXVtKck5LfOO9AqOJg==";
|
||||
const ROBOT_CODE = "ding4ursdp0l2giat4bj";
|
||||
const IMAGE_PATH = "C:/Users/ALC/.openclaw/workspace/yahoo_japan_screenshot.jpg";
|
||||
|
||||
async function getAccessToken() {
|
||||
const response = await axios.post(ACCESS_TOKEN_URL, {
|
||||
appKey: APP_KEY,
|
||||
appSecret: APP_SECRET
|
||||
});
|
||||
return response.data.accessToken;
|
||||
}
|
||||
|
||||
async function uploadMedia(accessToken, filePath, type) {
|
||||
const FormData = require('form-data');
|
||||
const form = new FormData();
|
||||
form.append('media', require('fs').createReadStream(filePath));
|
||||
form.append('type', type);
|
||||
|
||||
const response = await axios.post(`${UPLOAD_URL}?access_token=${accessToken}`, form, {
|
||||
headers: form.getHeaders()
|
||||
});
|
||||
|
||||
return response.data.media_id;
|
||||
}
|
||||
|
||||
async function sendMarkdownWithImage(accessToken, media_id) {
|
||||
const headers = {
|
||||
"x-acs-dingtalk-access-token": accessToken,
|
||||
"Content-Type": "application/json"
|
||||
};
|
||||
|
||||
// 使用 sampleMarkdown 在文本中嵌入 media_id
|
||||
const body = {
|
||||
robotCode: ROBOT_CODE,
|
||||
openConversationId: OPEN_CONVERSATION_ID,
|
||||
msgKey: "sampleMarkdown",
|
||||
// 注意:msgParam 必须是 JSON 字符串,不是 JSON 对象
|
||||
msgParam: JSON.stringify({
|
||||
title: "日本 Yahoo 首页截图",
|
||||
text: "# 日本 Yahoo 首页\n\n\n\n\n\n以下是一张日本 Yahoo 首页的截图:\n\n- 拍摄时间:2026年3月4日 18:46\n- 天气:新宿区,今夜 15℃/5℃\n- 花粉预警:非常多\n\n## 天气详情\n\n- **当前温度**:15℃\n- **夜间最低**:5℃\n- **降水概率**:0%\n\n## 热搜排行\n\n1. イクラちゃん\n2. SFL\n3. 国立博物馆\n\n---\n由 GLM 自动生成"
|
||||
})
|
||||
};
|
||||
|
||||
try {
|
||||
console.log('\n发送 Markdown 格式消息(嵌入图片)...');
|
||||
console.log(`URL: ${SEND_URL}`);
|
||||
console.log(`Body:\n${JSON.stringify(body, null, 2)}\n`);
|
||||
|
||||
const response = await axios.post(SEND_URL, body, { headers });
|
||||
|
||||
console.log('响应状态码:', response.status);
|
||||
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
||||
|
||||
if (response.status === 200 && response.data.processQueryKey) {
|
||||
console.log('\n✅✅✅ 成功!Markdown 格式的消息(包含图片)已发送到钉钉群聊!✅✅✅\n');
|
||||
return true;
|
||||
} else {
|
||||
console.log('\n❌ 发送失败\n');
|
||||
return false;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('\n❌ 发送异常');
|
||||
console.log('错误:', err.message);
|
||||
if (err.response) {
|
||||
console.log('详细错误:', JSON.stringify(err.response.data, null, 2));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
console.log('='.repeat(60));
|
||||
console.log('使用 Markdown 格式发送图片(嵌入 media_id)');
|
||||
console.log('='.repeat(60));
|
||||
|
||||
const accessToken = await getAccessToken();
|
||||
console.log('✓ Access Token 获取成功');
|
||||
|
||||
const media_id = await uploadMedia(accessToken, IMAGE_PATH, "image");
|
||||
console.log('✓ 媒体上传成功');
|
||||
console.log(` media_id: ${media_id}`);
|
||||
|
||||
const markdownContent = JSON.stringify({
|
||||
title: "日本 Yahoo 首页",
|
||||
text: ``
|
||||
});
|
||||
|
||||
const body = {
|
||||
robotCode: ROBOT_CODE,
|
||||
openConversationId: OPEN_CONVERSATION_ID,
|
||||
msgKey: "sampleMarkdown",
|
||||
msgParam: `{"title":"日本 Yahoo 首页截图","text":""}`
|
||||
};
|
||||
|
||||
await sendMarkdownWithImage(accessToken, media_id);
|
||||
|
||||
console.log('='.repeat(60));
|
||||
} catch (err) {
|
||||
console.error('\n错误:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user