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:
125
check_image_visibility.js
Normal file
125
check_image_visibility.js
Normal file
@@ -0,0 +1,125 @@
|
||||
// 检查图片是否真的发送成功,并尝试其他格式
|
||||
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()
|
||||
});
|
||||
|
||||
console.log('上传响应:', JSON.stringify(response.data, null, 2));
|
||||
return response.data.media_id;
|
||||
}
|
||||
|
||||
async function tryDifferentFormats(accessToken, media_id) {
|
||||
const headers = {
|
||||
"x-acs-dingtalk-access-token": accessToken,
|
||||
"Content-Type": "application/json"
|
||||
};
|
||||
|
||||
// 测试不同的图片引用格式
|
||||
const tests = [
|
||||
{
|
||||
name: "格式1:  - 标准",
|
||||
body: {
|
||||
robotCode: ROBOT_CODE,
|
||||
openConversationId: OPEN_CONVERSATION_ID,
|
||||
msgKey: "sampleMarkdown",
|
||||
msgParam: `{"title":"测试图片","text":"})"}`
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "格式2:
|
||||

|
||||
- 换行",
|
||||
body: {
|
||||
robotCode: ROBOT_CODE,
|
||||
openConversationId: OPEN_CONVERSATION_ID,
|
||||
msgKey: "sampleMarkdown",
|
||||
msgParam: `{"title":"测试图片换行","text":"
|
||||
})
|
||||
"}`
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "格式3:  标准语法(尝试用 media_id 作为 URL)",
|
||||
body: {
|
||||
robotCode: ROBOT_CODE,
|
||||
openConversationId: OPEN_CONVERSATION_ID,
|
||||
msgKey: "sampleMarkdown",
|
||||
msgParam: `{"title":"标准 Markdown 语法","text":"
|
||||
})
|
||||
|
||||
[查看原图](@${media_id.replace('@','')})
|
||||
"}`
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
for (const test of tests) {
|
||||
try {
|
||||
console.log(`\n\n${test.name}`);
|
||||
console.log(`Body:\n${test.body.msgParam}\n`);
|
||||
|
||||
const response = await axios.post(SEND_URL, test.body, { headers });
|
||||
|
||||
if (response.status === 200) {
|
||||
console.log('✅ 发送成功');
|
||||
console.log(`ProcessQueryKey: ${response.data.processQueryKey}\n`);
|
||||
} else {
|
||||
console.log('❌ 发送失败\n');
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(`❌ 异常: ${err.response?.data?.message || err.message}\n`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
console.log('='.repeat(60));
|
||||
console.log('检查图片显示问题');
|
||||
console.log('='.repeat(60));
|
||||
|
||||
const accessToken = await getAccessToken();
|
||||
console.log('✓ Access Token 获取成功\n');
|
||||
|
||||
const media_id = await uploadMedia(accessToken, IMAGE_PATH, "image");
|
||||
console.log(`✓ 媒体上传成功: ${media_id}\n`);
|
||||
|
||||
console.log('media_id 格式说明:');
|
||||
console.log(` 原始值: ${media_id}`);
|
||||
console.log(` 去掉 @ 后: ${media_id.replace('@','')}\n`);
|
||||
|
||||
await tryDifferentFormats(accessToken, media_id);
|
||||
|
||||
console.log('\n' + '='.repeat(60));
|
||||
} catch (err) {
|
||||
console.error('\n错误:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user