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:
96
send_with_correct_param.js
Normal file
96
send_with_correct_param.js
Normal file
@@ -0,0 +1,96 @@
|
||||
// 使用正确的 photoMediaId 参数发送图片
|
||||
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 sendImageMessage(accessToken, media_id) {
|
||||
const headers = {
|
||||
"x-acs-dingtalk-access-token": accessToken,
|
||||
"Content-Type": "application/json"
|
||||
};
|
||||
|
||||
// 使用正确的参数名:photoMediaId !!!
|
||||
const body = {
|
||||
robotCode: ROBOT_CODE,
|
||||
openConversationId: OPEN_CONVERSATION_ID,
|
||||
msgKey: "sampleImage",
|
||||
msgParam: `{"photoMediaId":"${media_id}"}`
|
||||
};
|
||||
|
||||
try {
|
||||
console.log('\n发送图片到钉钉群聊...');
|
||||
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) {
|
||||
console.log('\n✅✅✅ 成功!图片已发送到钉钉群聊!✅✅✅\n');
|
||||
return true;
|
||||
} else {
|
||||
console.log('\n❌ 发送失败(状态码非200)\n');
|
||||
return false;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('\n❌ 发送异常');
|
||||
console.log('错误:', err.message);
|
||||
console.log('错误响应:', JSON.stringify(err.response?.data, null, 2));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
console.log('='.repeat(60));
|
||||
console.log('使用正确的 photoMediaId 参数发送图片');
|
||||
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}`);
|
||||
|
||||
await sendImageMessage(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