Merge pull request #1976 from alexhoshina/refactor/wecom

docs(wecom): align docs with unified channel
This commit is contained in:
daming大铭
2026-03-25 00:19:10 +08:00
committed by GitHub
4 changed files with 244 additions and 172 deletions
+104
View File
@@ -0,0 +1,104 @@
> Back to [README](../../../README.md)
# WeCom
PicoClaw now exposes WeCom as a single `channels.wecom` channel built on the official WeCom AI Bot WebSocket API.
This replaces the legacy `wecom`, `wecom_app`, and `wecom_aibot` split with one configuration model.
## What This Channel Supports
- Direct chat and group chat delivery
- Channel-side streaming replies over WeCom's AI Bot protocol
- Incoming text, voice, image, file, video, and mixed messages
- Outbound text and media replies (`image`, `file`, `voice`, `video`)
- QR-based CLI onboarding with `picoclaw auth wecom`
- Shared allowlist and `reasoning_channel_id` routing
> No public webhook callback URL is required for this channel. PicoClaw opens an outbound WebSocket connection to WeCom.
## Quick Start
### Option 1: QR Login From CLI
Run:
```bash
picoclaw auth wecom
```
The command prints a QR code in the terminal, waits for confirmation in WeCom, and then writes the resulting
`bot_id` and `secret` into `channels.wecom`.
Use `--timeout` if you want to wait longer:
```bash
picoclaw auth wecom --timeout 10m
```
### Option 2: Configure Manually
```json
{
"channels": {
"wecom": {
"enabled": true,
"bot_id": "YOUR_BOT_ID",
"secret": "YOUR_SECRET",
"websocket_url": "wss://openws.work.weixin.qq.com",
"send_thinking_message": true,
"allow_from": [],
"reasoning_channel_id": ""
}
}
}
```
## Configuration
| Field | Type | Required | Description |
| ----- | ---- | -------- | ----------- |
| `enabled` | bool | No | Enables the WeCom channel. |
| `bot_id` | string | Yes | WeCom AI Bot identifier. Required when the channel is enabled. |
| `secret` | string | Yes | WeCom AI Bot secret. Required when the channel is enabled. |
| `websocket_url` | string | No | WebSocket endpoint. Defaults to `wss://openws.work.weixin.qq.com`. |
| `send_thinking_message` | bool | No | Sends an initial `Processing...` chunk before the final streamed reply. Defaults to `true`. |
| `allow_from` | array | No | Sender allowlist. Empty means allow all senders. |
| `reasoning_channel_id` | string | No | Optional destination for reasoning/thinking output. |
## Runtime Behavior
- PicoClaw keeps the active WeCom turn so normal replies can continue the same stream when possible.
- If streaming is no longer available, replies fall back to active push delivery to the resolved chat route.
- Incoming media is downloaded into the media store before being handed to the agent.
- Outbound media is uploaded to WeCom in temporary chunks and then sent as a regular media message.
## Migration Notes
This branch removes the old multi-channel WeCom model.
| Previous config | Now |
| --------------- | --- |
| `channels.wecom` webhook bot | Replace with `channels.wecom` using `bot_id` + `secret`. |
| `channels.wecom_app` | Remove it and use `channels.wecom`. |
| `channels.wecom_aibot` | Move the config to `channels.wecom`. |
| `token`, `encoding_aes_key`, `webhook_url`, `webhook_path` | No longer used by the WeCom channel. |
| `corp_id`, `corp_secret`, `agent_id` | No longer used by the WeCom channel. |
| `welcome_message`, `processing_message`, `max_steps` under WeCom | No longer part of the WeCom channel config. |
## Troubleshooting
### `picoclaw auth wecom` times out
- Re-run with a larger `--timeout`.
- Make sure the QR code was confirmed inside WeCom, not only scanned.
### WebSocket connection fails
- Verify `bot_id` and `secret`.
- Confirm the host can reach `wss://openws.work.weixin.qq.com`.
### Replies do not arrive
- Check whether `allow_from` blocks the sender.
- Check launcher or startup validation for missing `channels.wecom.bot_id` / `channels.wecom.secret`.
+104
View File
@@ -0,0 +1,104 @@
> 返回 [README](../../../README.zh.md)
# 企业微信
PicoClaw 现在将企业微信统一为一个 `channels.wecom` 渠道,并基于企业微信官方 AI Bot WebSocket 协议实现。
这取代了旧的 `wecom``wecom_app``wecom_aibot` 三套配置模型。
## 当前渠道能力
- 支持私聊和群聊
- 支持企业微信侧流式回复
- 支持接收文本、语音、图片、文件、视频和 mixed 消息
- 支持发送文本与媒体消息(`image``file``voice``video`
- 支持通过 `picoclaw auth wecom` 扫码写入配置
- 支持统一白名单与 `reasoning_channel_id`
> 这个渠道不再需要公网 webhook 回调地址。PicoClaw 会主动向企业微信发起 WebSocket 连接。
## 快速开始
### 方式 1:命令行扫码登录
运行:
```bash
picoclaw auth wecom
```
该命令会在终端打印二维码,等待你在企业微信中确认,然后把生成的 `bot_id``secret` 写入
`channels.wecom`
如果需要更长等待时间,可以加 `--timeout`
```bash
picoclaw auth wecom --timeout 10m
```
### 方式 2:手动配置
```json
{
"channels": {
"wecom": {
"enabled": true,
"bot_id": "YOUR_BOT_ID",
"secret": "YOUR_SECRET",
"websocket_url": "wss://openws.work.weixin.qq.com",
"send_thinking_message": true,
"allow_from": [],
"reasoning_channel_id": ""
}
}
}
```
## 配置字段
| 字段 | 类型 | 必填 | 说明 |
| ---- | ---- | ---- | ---- |
| `enabled` | bool | 否 | 是否启用企业微信渠道。 |
| `bot_id` | string | 是 | 企业微信 AI Bot 标识。渠道启用时必填。 |
| `secret` | string | 是 | 企业微信 AI Bot 密钥。渠道启用时必填。 |
| `websocket_url` | string | 否 | WebSocket 地址,默认 `wss://openws.work.weixin.qq.com`。 |
| `send_thinking_message` | bool | 否 | 是否在流式最终回复前先发送一段 `Processing...` 开场消息,默认 `true`。 |
| `allow_from` | array | 否 | 发送者白名单;空数组表示允许所有发送者。 |
| `reasoning_channel_id` | string | 否 | 可选的 reasoning/thinking 输出目标。 |
## 运行时行为
- PicoClaw 会保留当前会话对应的企业微信 turn,优先继续同一个流式回复。
- 如果流式上下文已经失效,回复会自动回退到主动推送消息。
- 收到的媒体会先下载到 media store,再交给 Agent 处理。
- 发出的媒体会先按分片上传到企业微信,再作为普通媒体消息发送。
## 迁移说明
这个分支移除了旧的多通道企业微信模型。
| 旧配置 | 现在怎么做 |
| ------ | ---------- |
| `channels.wecom` webhook 机器人 | 改为使用 `bot_id` + `secret``channels.wecom`。 |
| `channels.wecom_app` | 删除,统一迁移到 `channels.wecom`。 |
| `channels.wecom_aibot` | 配置迁移到 `channels.wecom`。 |
| `token``encoding_aes_key``webhook_url``webhook_path` | 企业微信渠道不再使用这些字段。 |
| `corp_id``corp_secret``agent_id` | 企业微信渠道不再使用这些字段。 |
| 企业微信下的 `welcome_message``processing_message``max_steps` | 不再属于企业微信渠道配置。 |
## 常见问题
### `picoclaw auth wecom` 超时
- 用更大的 `--timeout` 重新执行。
- 确认是在企业微信里完成了确认,而不只是扫描二维码。
### WebSocket 连接失败
- 检查 `bot_id``secret` 是否正确。
- 确认运行环境可以访问 `wss://openws.work.weixin.qq.com`
### 消息没有回到企业微信
- 检查 `allow_from` 是否拦截了发送者。
- 检查启动日志或 launcher 校验,确认 `channels.wecom.bot_id` / `channels.wecom.secret` 已填写。