From 8b45d6c7507200aca9802531333c8fe3a04ce1b6 Mon Sep 17 00:00:00 2001 From: zhayujie Date: Mon, 16 Mar 2026 19:03:18 +0800 Subject: [PATCH] docs: wecom_bot integration docs --- channel/wecom_bot/wecom_bot_channel.py | 8 +-- docs/channels/wecom-bot.mdx | 73 ++++++++++++++++++++++++++ docs/channels/wecom.mdx | 2 +- docs/docs.json | 2 + docs/en/channels/wecom-bot.mdx | 73 ++++++++++++++++++++++++++ 5 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 docs/channels/wecom-bot.mdx create mode 100644 docs/en/channels/wecom-bot.mdx diff --git a/channel/wecom_bot/wecom_bot_channel.py b/channel/wecom_bot/wecom_bot_channel.py index b331fbc..550d561 100644 --- a/channel/wecom_bot/wecom_bot_channel.py +++ b/channel/wecom_bot/wecom_bot_channel.py @@ -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) diff --git a/docs/channels/wecom-bot.mdx b/docs/channels/wecom-bot.mdx new file mode 100644 index 0000000..47c46dd --- /dev/null +++ b/docs/channels/wecom-bot.mdx @@ -0,0 +1,73 @@ +--- +title: 企微智能机器人 +description: 将 CowAgent 接入企业微信智能机器人(长连接模式) +--- + +> 通过企业微信智能机器人接入CowAgent,支持企业内部单聊和内部群聊,无需公网 IP,使用 WebSocket 长连接模式,支持Markdown渲染和流式输出。 + + + 智能机器人与企业微信自建应用是两种不同的接入方式。智能机器人使用 WebSocket 长连接,无需服务器公网 IP 和域名,配置更简单。 + + +## 一、创建智能机器人 + +1. 打开企业微信客户端,进入工作台,点击**智能机器人**: + + + +2. 点击创建机器人 - 手动创建: + + + +3. 右侧窗口拖到最下方,选择**API模式创建**: + + + +4. 设置机器人名称、头像、可见范围,并选择**长连接模式**,记录下 **Bot ID** 和 **Secret** 信息后点击保存。 + +## 二、配置和运行 + +### 方式一:Web 控制台接入 + +启动程序后打开 Web 控制台 (本地连接为: http://127.0.0.1:9899/ ),选择 **通道** 菜单,点击 **接入通道**,选择 **企微智能机器人**,填写上一步保存的 Bot ID 和 Secret,点击接入即可。 + + + +### 方式二:配置文件接入 + +在 `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` 即表示连接成功。 + +## 三、功能说明 + +| 功能 | 支持情况 | +| --- | --- | +| 单聊 | ✅ | +| 群聊(@机器人) | ✅ | +| 文本消息 | ✅ 收发 | +| 图片消息 | ✅ 收发 | +| 文件消息 | ✅ 收发 | +| 流式回复 | ✅ | +| 定时任务主动推送 | ✅ | + +## 四、使用 + +在企业微信中搜索创建的机器人名称,即可开始单聊对话。 + +如需在企微内部群聊中使用,将机器人添加到群中,@机器人发送消息即可。 + + diff --git a/docs/channels/wecom.mdx b/docs/channels/wecom.mdx index d58afd7..0f57d51 100644 --- a/docs/channels/wecom.mdx +++ b/docs/channels/wecom.mdx @@ -1,5 +1,5 @@ --- -title: 企业微信 +title: 企微自建应用 description: 将 CowAgent 接入企业微信自建应用 --- diff --git a/docs/docs.json b/docs/docs.json index 86a42e9..f82f8c7 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -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" ] diff --git a/docs/en/channels/wecom-bot.mdx b/docs/en/channels/wecom-bot.mdx new file mode 100644 index 0000000..4959c8b --- /dev/null +++ b/docs/en/channels/wecom-bot.mdx @@ -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. + + + 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. + + +## 1. Create an AI Bot + +1. Open the WeCom client, go to **Workbench**, and click **AI Bot**: + + + +2. Click **Create Bot** → **Manual Creation**: + + + +3. Scroll to the bottom of the right panel and select **API Mode**: + + + +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. + + + +### 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. + +