Skip to content

HuGtoX/wecom-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@garrent/openclaw-plugin-wecom

OpenClaw 企业微信(WeCom)Channel Plugin,将企业微信接入 OpenClaw AI 助手平台。

参考 sunnoy/openclaw-plugin-wecom,兼容 OpenClaw 2026.2+。

架构概览

企业微信用户 │ │ 消息回调 (XML + AES-256-CBC) ▼ ┌──────────────────────────────────────┐ │ OpenClaw Gateway │ │ │ │ GET /webhooks/wecom → URL 验证 │ │ POST /webhooks/wecom → 消息回调 │ │ │ │ │ ▼ │ │ ┌──────────────┐ │ │ │ WeCom Plugin │ │ │ │ • 签名校验 │ │ │ │ • AES 解密 │ │ │ │ • 消息标准化 │ │ │ │ • 去重处理 │ │ │ └──────┬───────┘ │ │ │ │ │ ▼ │ │ ┌──────────────┐ │ │ │ OpenClaw │ │ │ │ Agent 处理 │ │ │ └──────┬───────┘ │ │ │ │ │ ▼ │ │ ┌──────────────┐ │ │ │ outbound.send│ │ │ │ → 企微 API │ │ │ │ (文本/MD/图文)│ │ │ └──────────────┘ │ └──────────────────────────────────────┘ 

核心原则:插件只负责 Channel Adapter(消息协议适配),不负责 AI 业务逻辑。

项目结构

@garrent/openclaw-plugin-wecom/ ├── package.json # 含 openclaw.extensions 声明 ├── openclaw.plugin.json # 插件清单(configSchema) ├── tsconfig.json ├── .env.example # 配置参考 └── src/ ├── index.ts # 入口:导出 register + dock ├── channel.ts # ChannelDock + createWecomPlugin ├── normalize.ts # 消息标准化(企微 ↔ OpenClaw) ├── types/ │ └── index.ts # 完整类型定义 ├── utils/ │ ├── crypto.ts # AES-256-CBC + SHA1 签名 │ ├── xml.ts # XML 解析/构建 │ └── logger.ts # 日志工具 └── services/ ├── tokenService.ts # Token 管理(内存缓存+重试) └── wecomApi.ts # 企微 API 封装 

安装

方式一:直接安装

openclaw plugins install @garrent/openclaw-plugin-wecom

方式二:从源码安装

git clone https://github.com/garrent/openclaw-plugin-wecom.git cd openclaw-plugin-wecom npm install npm run build openclaw plugins install -l ./

配置

1. 企业微信管理后台

  1. 登录 企业微信管理后台
  2. 我的企业 → 记录 CorpID
  3. 应用管理 → 创建自建应用 → 记录 AgentIdSecret
  4. 应用详情 → 接收消息 → 设置 API 接收:
    • URL: http(s)://你的域名:18789/webhooks/wecom
    • Token: 随机字符串(记录下来)
    • EncodingAESKey: 随机生成(记录下来)

2. OpenClaw 配置

编辑 ~/.openclaw/openclaw.json

{ "plugins": { "entries": { "garrent-wecom": { "enabled": true } } }, "channels": { "garrent-wecom": { "enabled": true, "corpId": "你的企业ID", "agentId": "应用AgentId", "secret": "应用Secret", "token": "回调Token", "encodingAESKey": "回调EncodingAESKey" } } }

3. 确认 Gateway 绑定

确保 Gateway 绑定到局域网(而非 loopback),以便企微服务器可以回调:

openclaw config set gateway.bind lan

4. 重启

openclaw gateway restart openclaw channels status

核心设计

消息流转

1. 用户在企微发送消息 2. 企微服务器 POST → /webhooks/wecom 3. Plugin: SHA1 签名校验 → AES-256-CBC 解密 → XML 解析 4. Plugin: 消息去重(MsgId) 5. Plugin: 立即返回 "success"(解决 5 秒超时) 6. Plugin: 异步调用 api.messaging.receive(normalizedMessage) 7. OpenClaw Agent 处理 → 生成回复 8. OpenClaw 调用 outbound.send(outgoingMessage) 9. Plugin: 转换格式 → 调用企微 API 主动推送回复 

5 秒超时解决方案

企微要求 5 秒内响应,否则重试 3 次。本插件:

  • 收到消息后 立即返回 "success"
  • 异步 将消息分发给 OpenClaw Agent
  • Agent 回复后通过 主动推送 API 发送
  • MsgId 去重 防止重试导致的重复处理

Token 管理

  • 内存缓存(适配 OpenClaw 单进程插件模型)
  • 提前 5 分钟刷新(留 buffer)
  • 并发请求合并(多个消息同时到达时只刷新一次)
  • 失败指数退避重试(1s → 2s → 4s,最多 3 次)

安全

  • 完整 SHA1 签名校验(每条消息都验证)
  • AES-256-CBC 加解密(含 CorpId 校验)
  • Token 失效自动重试(errcode 40014/42001)

支持的消息类型

类型 入站(接收) 出站(回复)
文本
Markdown - ✅ (自动检测)
图片 ✅ (转文本描述) -
语音 ✅ (转文本描述) -
视频 ✅ (转文本描述) -
位置 ✅ (转文本描述) -
链接 ✅ (转文本描述) -
图文 - ✅ (附件模式)
事件 ✅ (subscribe等) -

开发

# 安装依赖 npm install # 监听编译 npm run dev # 构建 npm run build

技术栈

组件 选型 说明
语言 TypeScript 完整类型安全
加解密 Node.js crypto AES-256-CBC + SHA1
HTTP axios 企微 API 调用
XML xml2js 消息解析
日志 winston 结构化日志
宿主 OpenClaw >= 2026.2 peerDependency

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors