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:
139
send_old_api.js
Normal file
139
send_old_api.js
Normal file
@@ -0,0 +1,139 @@
|
||||
// 尝试使用旧版钉钉 API 发送纯图片
|
||||
const axios = require('axios');
|
||||
|
||||
const ACCESS_TOKEN_URL = "https://oapi.dingtalk.com/gettoken";
|
||||
const UPLOAD_URL = "https://oapi.dingtalk.com/media/upload";
|
||||
const APP_KEY = "ding4ursdp0l2giat4bj";
|
||||
const APP_SECRET = "J0gBicjKiIHoKla7WfKKhRs1Tv8L6Xd5UhW3EVQByF16G7Vn7UUcRhP6u-PBCQNo";
|
||||
const IMAGE_PATH = "C:/Users/ALC/.openclaw/workspace/yahoo_japan_screenshot.jpg";
|
||||
const CHAT_ID = "cidcjYshXVtKck5LfOO9AqOJg==";
|
||||
const AGENT_ID = "ding4ursdp0l2giat4bj";
|
||||
|
||||
// 可能的旧版 API endpoints
|
||||
const OLD_APIS = [
|
||||
{
|
||||
name: "sendgroupmessage",
|
||||
url: (token) => `https://oapi.dingtalk.com/message/sendgroupmessage?access_token=${token}`,
|
||||
buildBody: (media_id) => ({
|
||||
msg: {
|
||||
msgtype: "image",
|
||||
image: { media_id: media_id }
|
||||
},
|
||||
chatid: CHAT_ID
|
||||
})
|
||||
},
|
||||
{
|
||||
name: "send_to_conversation",
|
||||
url: (token) => `https://oapi.dingtalk.com/message/send_to_conversation?access_token=${token}`,
|
||||
buildBody: (media_id) => ({
|
||||
msg: {
|
||||
msgtype: "image",
|
||||
image: { media_id: media_id }
|
||||
},
|
||||
sender: AGENT_ID,
|
||||
cid: CHAT_ID
|
||||
})
|
||||
},
|
||||
{
|
||||
name: "robot_send",
|
||||
url: (token) => `https://oapi.dingtalk.com/robot/send?access_token=${token}`,
|
||||
buildBody: (media_id) => ({
|
||||
msg: {
|
||||
msgtype: "image",
|
||||
image: { media_id: media_id }
|
||||
},
|
||||
webhook: AGENT_ID
|
||||
})
|
||||
}
|
||||
];
|
||||
|
||||
async function getAccessToken() {
|
||||
const response = await axios.get(ACCESS_TOKEN_URL, {
|
||||
params: {
|
||||
appkey: APP_KEY,
|
||||
appsecret: APP_SECRET
|
||||
}
|
||||
});
|
||||
return response.data.access_token;
|
||||
}
|
||||
|
||||
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 trySendOldAPI(accessToken, apiConfig, media_id) {
|
||||
const { name, url, buildBody } = apiConfig;
|
||||
const api_url = url(accessToken);
|
||||
|
||||
try {
|
||||
console.log(`\n\n尝试旧版 API: ${name}`);
|
||||
console.log(`URL: ${api_url}`);
|
||||
|
||||
const body = buildBody(media_id);
|
||||
console.log(`Body:\n${JSON.stringify(body, null, 2)}\n`);
|
||||
|
||||
const response = await axios.post(api_url, body);
|
||||
|
||||
if (response.data.errcode === 0) {
|
||||
console.log(`✅ ${name} 成功!`);
|
||||
console.log(`响应: ${JSON.stringify(response.data, null, 2)}\n`);
|
||||
return true;
|
||||
} else {
|
||||
console.log(`❌ ${name} 失败: ${response.data.errmsg}\n`);
|
||||
return false;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(`❌ ${name} 异常: ${err.response?.data?.errmsg || 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('尝试使用旧版钉钉 API 发送纯图片');
|
||||
console.log('='.repeat(60));
|
||||
|
||||
const accessToken = await getAccessToken();
|
||||
console.log('✓ Access Token 获取成功');
|
||||
|
||||
const media_id = await uploadMedia(accessToken, IMAGE_PATH, "image");
|
||||
console.log(`✓ 媒体上传成功: ${media_id}\n`);
|
||||
|
||||
let success = false;
|
||||
for (const api of OLD_APIS) {
|
||||
success = await trySendOldAPI(accessToken, api, media_id);
|
||||
if (success) {
|
||||
console.log(`\n🎉 找到可用的旧版 API: ${api.name}!`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
console.log('\n❌ 所有旧版 API 也失败了');
|
||||
console.log('\n当前可行的方案:');
|
||||
console.log('1. ✅ 使用 Markdown 格式发送图片(已成功)');
|
||||
console.log('2. ✅ 手动发送本地图片');
|
||||
console.log(` 文件:${IMAGE_PATH}`);
|
||||
}
|
||||
|
||||
console.log('='.repeat(60));
|
||||
} catch (err) {
|
||||
console.error('\n错误:', err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user