docs: wecom_bot integration docs

This commit is contained in:
zhayujie
2026-03-16 19:03:18 +08:00
parent 4ecd4df2d4
commit 8b45d6c750
5 changed files with 153 additions and 5 deletions

View File

@@ -205,7 +205,7 @@ class WecomBotChannel(ChatChannel):
if errcode is not None and cmd == "":
if not self._connected:
if errcode == 0:
logger.info("[WecomBot] Subscribe success")
logger.info("[WecomBot] Subscribe success")
self._connected = True
self._start_heartbeat()
self.report_startup_success()
@@ -451,7 +451,7 @@ class WecomBotChannel(ChatChannel):
if req_id:
state = self._stream_states.pop(req_id, None)
if state:
final_content = state["committed"] + content
final_content = state["committed"]
stream_id = state["stream_id"]
else:
final_content = content
@@ -472,7 +472,7 @@ class WecomBotChannel(ChatChannel):
self._active_send_markdown(content, receiver, is_group)
def _send_image(self, img_path_or_url: str, receiver: str, is_group: bool, req_id: str = None):
"""Send image reply. Converts to JPG/PNG and compresses if >10MB."""
"""Send image reply. Converts to JPG/PNG and compresses if >2MB."""
local_path = img_path_or_url
if local_path.startswith("file://"):
local_path = local_path[7:]
@@ -505,7 +505,7 @@ class WecomBotChannel(ChatChannel):
logger.error(f"[WecomBot] Image file not found: {local_path}")
return
max_image_size = 10 * 1024 * 1024 # 10MB limit for image type
max_image_size = 2 * 1024 * 1024 # 2MB limit for image upload
local_path = self._ensure_image_format(local_path)
if not local_path:
self._send_text("[Image format conversion failed]", receiver, is_group, req_id)

View File

@@ -0,0 +1,73 @@
---
title: 企微智能机器人
description: 将 CowAgent 接入企业微信智能机器人(长连接模式)
---
> 通过企业微信智能机器人接入CowAgent支持企业内部单聊和内部群聊无需公网 IP使用 WebSocket 长连接模式支持Markdown渲染和流式输出。
<Note>
智能机器人与企业微信自建应用是两种不同的接入方式。智能机器人使用 WebSocket 长连接,无需服务器公网 IP 和域名,配置更简单。
</Note>
## 一、创建智能机器人
1. 打开企业微信客户端,进入工作台,点击**智能机器人**
<img src="https://cdn.link-ai.tech/doc/20260316180959.png" width="800"/>
2. 点击创建机器人 - 手动创建:
<img src="https://cdn.link-ai.tech/doc/20260316181118.png" width="800"/>
3. 右侧窗口拖到最下方,选择**API模式创建**
<img src="https://cdn.link-ai.tech/doc/20260316181215.png" width="800"/>
4. 设置机器人名称、头像、可见范围,并选择**长连接模式**,记录下 **Bot ID** 和 **Secret** 信息后点击保存。
## 二、配置和运行
### 方式一Web 控制台接入
启动程序后打开 Web 控制台 (本地连接为: http://127.0.0.1:9899/ ),选择 **通道** 菜单,点击 **接入通道**,选择 **企微智能机器人**,填写上一步保存的 Bot ID 和 Secret点击接入即可。
<img src="https://cdn.link-ai.tech/doc/20260316181711.png" width="800"/>
### 方式二:配置文件接入
在 `config.json` 中添加以下配置:
```json
{
"channel_type": "wecom_bot",
"wecom_bot_id": "YOUR_BOT_ID",
"wecom_bot_secret": "YOUR_SECRET"
}
```
| 参数 | 说明 |
| --- | --- |
| `wecom_bot_id` | 智能机器人的 BotID |
| `wecom_bot_secret` | 智能机器人的 Secret |
配置完成后启动程序,日志显示 `[WecomBot] Subscribe success` 即表示连接成功。
## 三、功能说明
| 功能 | 支持情况 |
| --- | --- |
| 单聊 | ✅ |
| 群聊(@机器人) | ✅ |
| 文本消息 | ✅ 收发 |
| 图片消息 | ✅ 收发 |
| 文件消息 | ✅ 收发 |
| 流式回复 | ✅ |
| 定时任务主动推送 | ✅ |
## 四、使用
在企业微信中搜索创建的机器人名称,即可开始单聊对话。
如需在企微内部群聊中使用,将机器人添加到群中,@机器人发送消息即可。
<img src="https://cdn.link-ai.tech/doc/20260316182902.png" width="800"/>

View File

@@ -1,5 +1,5 @@
---
title: 企业微信
title: 企微自建应用
description: 将 CowAgent 接入企业微信自建应用
---

View File

@@ -156,6 +156,7 @@
"channels/web",
"channels/feishu",
"channels/dingtalk",
"channels/wecom-bot",
"channels/wecom",
"channels/wechatmp"
]
@@ -298,6 +299,7 @@
"en/channels/web",
"en/channels/feishu",
"en/channels/dingtalk",
"en/channels/wecom-bot",
"en/channels/wecom",
"en/channels/wechatmp"
]

View File

@@ -0,0 +1,73 @@
---
title: WeCom Bot
description: Connect CowAgent to WeCom AI Bot (WebSocket long connection)
---
Connect CowAgent via WeCom AI Bot, supporting both direct messages and group chats. No public IP required — uses WebSocket long connection with Markdown rendering and streaming output.
<Note>
WeCom Bot and WeCom App are two different integration methods. WeCom Bot uses WebSocket long connection, requiring no public IP or domain, making it easier to set up.
</Note>
## 1. Create an AI Bot
1. Open the WeCom client, go to **Workbench**, and click **AI Bot**:
<img src="https://cdn.link-ai.tech/doc/20260316180959.png" width="800"/>
2. Click **Create Bot** → **Manual Creation**:
<img src="https://cdn.link-ai.tech/doc/20260316181118.png" width="600"/>
3. Scroll to the bottom of the right panel and select **API Mode**:
<img src="https://cdn.link-ai.tech/doc/20260316181215.png" width="600"/>
4. Set the bot name, avatar, and visibility scope. Select **Long Connection** mode, note down the **Bot ID** and **Secret**, then click Save.
## 2. Configuration
### Option A: Web Console
Start the program and open the Web console (local access: http://127.0.0.1:9899). Go to the **Channels** tab, click **Connect Channel**, select **WeCom Bot**, fill in the Bot ID and Secret from the previous step, and click Connect.
<img src="https://cdn.link-ai.tech/doc/20260316181711.png" width="600"/>
### Option B: Config File
Add the following to your `config.json`:
```json
{
"channel_type": "wecom_bot",
"wecom_bot_id": "YOUR_BOT_ID",
"wecom_bot_secret": "YOUR_SECRET"
}
```
| Parameter | Description |
| --- | --- |
| `wecom_bot_id` | Bot ID of the AI Bot |
| `wecom_bot_secret` | Secret for the AI Bot |
After configuration, start the program. The log message `[WecomBot] Subscribe success` indicates a successful connection.
## 3. Supported Features
| Feature | Status |
| --- | --- |
| Direct Messages | ✅ |
| Group Chat (@bot) | ✅ |
| Text Messages | ✅ Send & Receive |
| Image Messages | ✅ Send & Receive |
| File Messages | ✅ Send & Receive |
| Streaming Reply | ✅ |
| Scheduled Push | ✅ |
## 4. Usage
Search for the bot name in WeCom to start a direct conversation.
To use in group chats, add the bot to a group and @mention it to send messages.
<img src="https://cdn.link-ai.tech/doc/20260316182902.png" width="800"/>