- 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
100 lines
2.9 KiB
JavaScript
100 lines
2.9 KiB
JavaScript
// 再次发送 Yahoo 首页截图
|
||
const axios = require('axios');
|
||
const FormData = require('form-data');
|
||
|
||
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 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"
|
||
};
|
||
|
||
// 移除 @ 符号
|
||
const cleanMediaId = media_id.replace('@', '');
|
||
|
||
const body = {
|
||
robotCode: ROBOT_CODE,
|
||
openConversationId: OPEN_CONVERSATION_ID,
|
||
msgKey: "sampleMarkdown",
|
||
// 格式:只有图片,无文字
|
||
msgParam: JSON.stringify({
|
||
text: ``
|
||
})
|
||
};
|
||
|
||
try {
|
||
console.log('\n发送 Yahoo 首页截图到钉钉群聊...');
|
||
console.log(`media_id: ${media_id}`);
|
||
console.log(`Body:\n${JSON.stringify(body, null, 2)}\n`);
|
||
|
||
const response = await axios.post(SEND_URL, body, { headers });
|
||
|
||
if (response.status === 200) {
|
||
console.log(`✅ 发送成功!ProcessQueryKey: ${response.data.processQueryKey}\n`);
|
||
return true;
|
||
} else {
|
||
console.log(`❌ 发送失败\n`);
|
||
return false;
|
||
}
|
||
} catch (err) {
|
||
console.log(`❌ 发送异常: ${err.message}`);
|
||
if (err.response?.data) {
|
||
console.log(`详细错误: ${JSON.stringify(err.response.data, null, 2)}\n`);
|
||
}
|
||
return false;
|
||
}
|
||
}
|
||
|
||
async function main() {
|
||
try {
|
||
console.log('='.repeat(60));
|
||
console.log('再次发送 Yahoo 首页截图');
|
||
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}\n`);
|
||
|
||
await sendImageMessage(accessToken, media_id);
|
||
|
||
console.log('='.repeat(60));
|
||
} catch (err) {
|
||
console.error('\n错误:', err.message);
|
||
process.exit(1);
|
||
}
|
||
}
|
||
|
||
main();
|