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:
88
test_dingtalk_message.ts
Normal file
88
test_dingtalk_message.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
// 测试发送钉钉群聊消息
|
||||
export {};
|
||||
|
||||
const { default: dingtalkRobot, OrgGroupSendHeaders, OrgGroupSendRequest } = require('@alicloud/dingtalk/robot_1_0');
|
||||
const { default: dingtalkOauth2_1_0, GetAccessTokenRequest } = require('@alicloud/dingtalk/oauth2_1_0');
|
||||
const { Config } = require('@alicloud/openapi-client');
|
||||
|
||||
const APP_KEY = "ding4ursdp0l2giat4bj";
|
||||
const APP_SECRET = "J0gBicjKiIHoKla7WfKKhRs1Tv8L6Xd5UhW3EVQByF16G7Vn7UUcRhP6u-PBCQNo";
|
||||
const OPEN_CONVERSATION_ID = "cidcjYshXVtKck5LfOO9AqOJg==";
|
||||
const ROBOT_CODE = "4293382733";
|
||||
|
||||
function createConfig(): any {
|
||||
const config = new Config({});
|
||||
config.protocol = "https";
|
||||
config.regionId = "central";
|
||||
return config;
|
||||
}
|
||||
|
||||
async function getAccessToken(): Promise<string> {
|
||||
const config = createConfig();
|
||||
const client = new dingtalkOauth2_1_0(config);
|
||||
|
||||
const request = new GetAccessTokenRequest({
|
||||
appKey: APP_KEY,
|
||||
appSecret: APP_SECRET,
|
||||
});
|
||||
|
||||
const response = await client.getAccessToken(request);
|
||||
const accessToken = response.body?.accessToken;
|
||||
|
||||
if (!accessToken) {
|
||||
throw new Error('获取 access_token 失败');
|
||||
}
|
||||
|
||||
console.log('✅ Access Token 获取成功');
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
async function sendGroupMessage(accessToken: string, message: string): Promise<void> {
|
||||
const client = new dingtalkRobot(createConfig());
|
||||
|
||||
const headers = new OrgGroupSendHeaders({});
|
||||
headers.xAcsDingtalkAccessToken = accessToken;
|
||||
|
||||
const msgParam = JSON.stringify({ content: message });
|
||||
|
||||
const request = new OrgGroupSendRequest({
|
||||
openConversationId: OPEN_CONVERSATION_ID,
|
||||
robotCode: ROBOT_CODE,
|
||||
msgKey: 'sampleText',
|
||||
msgParam: msgParam,
|
||||
});
|
||||
|
||||
const response = await client.orgGroupSendWithOptions(request, headers, new (require('@alicloud/tea-util')).RuntimeOptions({}));
|
||||
|
||||
if (response.statusCode === 200) {
|
||||
console.log('✅ 消息发送成功');
|
||||
console.log('ProcessQueryKey:', response.body?.processQueryKey);
|
||||
} else {
|
||||
console.log('❌ 消息发送失败');
|
||||
console.log('Status:', response.statusCode);
|
||||
console.log('Body:', response.body);
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('====================================');
|
||||
console.log('开始发送钉钉群聊消息');
|
||||
console.log('====================================\n');
|
||||
|
||||
try {
|
||||
const accessToken = await getAccessToken();
|
||||
const message = '日本 Yahoo 首页截图已保存到:C:\\Users\\ALC\\.openclaw\\media\\browser\\1ad3cfc9-2dd5-496b-9fa5-26d23b973f76.jpg';
|
||||
await sendGroupMessage(accessToken, message);
|
||||
} catch (error: any) {
|
||||
console.error('❌ 错误:', error.message);
|
||||
if (error.data) {
|
||||
console.error('详细错误:', error.data);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('\n====================================');
|
||||
console.log('执行完成');
|
||||
console.log('====================================');
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user