Skip to content

feat: add WeCom (企业微信) smart bot via AIP long connection#321

Open
jimhy wants to merge 1 commit into
xvirobotics:mainfrom
jimhy:feat/wecom-aibot
Open

feat: add WeCom (企业微信) smart bot via AIP long connection#321
jimhy wants to merge 1 commit into
xvirobotics:mainfrom
jimhy:feat/wecom-aibot

Conversation

@jimhy

@jimhy jimhy commented Jun 1, 2026

Copy link
Copy Markdown

概述

新增企业微信(WeCom)智能机器人对接,基于「智能机器人 AIP WebSocket 长连接」(wss://openws.work.weixin.qq.com),使用官方 @wecom/aibot-node-sdk。与现有的个人微信 iLink 对接(src/wechat/)是相互独立的两个平台,互不影响。

改动

  • src/wecom/wecom-bot.tsstartWecomBot():创建 SDK WSClient,监听 message.* / event.enter_chat,把企业微信回调帧映射为平台无关的 IncomingMessage,绑定 frame(用于按 req_id 路由流式回复),接入共享的 MessageBridge
  • src/wecom/wecom-sender.tsWecomSender implements IMessageSender:把 bridge 的 sendCard → updateCard* → final 生命周期映射到企业微信流式回复(aibot_respond_msg + 共享 stream.id,全量替换内容,终态置 finish=true);命令回复 / 通知 / 产出文件走主动推送 aibot_send_msg 兜底;AES 媒体下载与分片上传由 SDK 处理。
  • src/config.ts — 新增 WecomBotConfig,支持环境变量(WECOM_BOT_ID / WECOM_BOT_SECRET / WECOM_WS_URL)与 bots.jsonwecomBots)两种配置方式。
  • src/index.ts / src/api/bot-registry.ts / src/api/bots-config-writer.ts — 在启动、注册表、配置 CRUD 中接入新平台 wecom
  • 文档CLAUDE.md.env.examplebots.example.json

配置

  • 单 bot(环境变量):WECOM_BOT_ID / WECOM_BOT_SECRET(私有化部署可选 WECOM_WS_URL)。
  • 多 bot(bots.json):wecomBots 数组(wecomBotId / wecomSecret / wecomWsUrl),可与 Feishu / Telegram 等共存。

测试

  • 真实企业微信机器人验证:长连接认证成功 + 应用完整启动注册 + 在真实企业微信组织里收发对话正常。
  • tsc / eslint / prettier(新文件)全部通过;既有测试 175 通过(8 个失败均为 Windows 上 skill-hub-store.test.ts 临时目录 EPERM 的预先存在问题,与本 PR 无关)。

说明

  • 流式内容按 SDK 官方示例采用「全量替换」语义;超过约 10 分钟的长任务可能超出流式窗口,终态会自动回退到主动推送以保证送达。
  • 群聊场景依赖企业微信服务端的 @机器人 过滤(收到回调即处理)。

🤖 Generated with Claude Code

Add Enterprise WeChat (WeCom) integration over the 智能机器人 AIP WebSocket
long connection, built on the official @wecom/aibot-node-sdk. This is a
separate platform from the existing personal-WeChat iLink integration
(src/wechat/).

- src/wecom/wecom-bot.ts: SDK WSClient setup, message/event wiring,
  frame -> IncomingMessage mapping, MessageBridge integration
- src/wecom/wecom-sender.ts: IMessageSender impl mapping the bridge's
  sendCard -> updateCard -> final lifecycle onto WeCom streaming replies
  (aibot_respond_msg with a shared stream.id); active-push fallback for
  notices/output files; AES media download + chunked upload via the SDK
- config.ts: WecomBotConfig plus env (WECOM_BOT_ID/WECOM_BOT_SECRET) and
  bots.json (wecomBots) parsing
- index.ts / api/bot-registry.ts / api/bots-config-writer.ts: register the
  new 'wecom' platform across startup, registry, and config CRUD
- docs: CLAUDE.md, .env.example, bots.example.json

Verified: long-connection auth + full app boot against a real WeCom bot.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants