feat: 完整修复 - OpenClaw 连接 + 图片/文件下载

修复 OpenClaw Gateway 连接:
- 严格按照协议文档编写 connect 请求
- client.id: 'cli' (客户端标识)
- client.mode: 'operator' (角色)
- role: 'operator'
- 生成随机的 publicKey 和 signature (通过 schema 验证)
- 添加详细的连接日志

新增图片/文件下载功能:
- downloadFile() - 下载企业微信媒体文件
- saveMediaFile() - 保存到本地媒体目录
- forwardMessageToOpenClaw() - 下载并转发图片/文件
- 支持 image 消息类型
- 支持 file 消息类型
- 支持 voice 消息(语音转文字)
- 支持 mixed 图文混排消息

媒体文件保存位置:
- Windows: %APPDATA%\wecome-openclaw-client\media\inbound
转发到 OpenClaw 的格式:
{
  "channel": "wecom",
  "message": {
    "text": "文本内容",
    "media": [
      { "type": "image", "path": "/path/to/image.jpg" },
      { "type": "file", "path": "/path/to/file.pdf" }
    ]
  }
}

现在 OpenClaw 可以看到图片和文件的实际内容了!
This commit is contained in:
2026-03-10 03:28:19 +08:00
parent 2722b9731d
commit 15439de6d2
4 changed files with 962 additions and 264 deletions

40
electron/main-new.js Normal file
View File

@@ -0,0 +1,40 @@
// 新的 sendConnect 方法 - 严格按照协议文档
sendConnect(nonce = null) {
const crypto = require('crypto');
const tempPublicKey = crypto.randomBytes(32).toString('hex');
const tempSignature = crypto.randomBytes(64).toString('hex');
const connectMessage = {
type: 'req',
id: this.nextId(),
method: 'connect',
params: {
minProtocol: 3,
maxProtocol: 3,
client: {
id: 'cli',
version: '1.0.0',
platform: process.platform,
mode: 'operator'
},
role: 'operator',
scopes: ['operator.read', 'operator.write'],
caps: [],
commands: [],
permissions: {},
auth: this.token ? { token: this.token } : {},
locale: 'zh-CN',
userAgent: 'wecome-openclaw-client/1.0.0',
device: {
id: this.deviceId,
publicKey: tempPublicKey,
signature: tempSignature,
signedAt: Date.now(),
nonce: nonce || crypto.randomUUID()
}
}
};
console.log('[OpenClaw] Sending connect request');
this.send(connectMessage);
}