Metadata-Version: 2.4
Name: wecom-ws-channel
Version: 1.0.0
Summary: 企业微信智能机器人 WebSocket 频道的独立 Python 实现
Author-email: Siva <siva@example.com>
License: MIT
Project-URL: Homepage, https://github.com/lcq225/wecom-ws-channel
Project-URL: Documentation, https://github.com/lcq225/wecom-ws-channel#readme
Project-URL: Repository, https://github.com/lcq225/wecom-ws-channel.git
Project-URL: Issues, https://github.com/lcq225/wecom-ws-channel/issues
Keywords: wecom,wechat,enterprise-wechat,websocket,bot,chatbot
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Communications :: Chat
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp>=3.8.0
Requires-Dist: pycryptodome>=3.15.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: isort>=5.0; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Dynamic: license-file

# WeCom WebSocket Channel

企业微信智能机器人 WebSocket 频道的独立 Python 实现。

## ✨ 特性

- 🔌 **独立运行** — 不依赖特定框架，可单独使用
- 🌐 **代理支持** — 支持 HTTP/HTTPS 代理，适配各种网络环境
- 💬 **图文混排** — 支持发送图文混排消息
- 🔄 **自动重连** — 断线自动重连，稳定可靠
- 💓 **心跳保活** — 自定义心跳机制，保持连接活跃
- 🔐 **消息加密** — 支持企业微信消息加解密

## 📦 安装

```bash
pip install wecom-ws-channel
```

或从源码安装：

```bash
git clone https://github.com/lcq225/wecom-ws-channel.git
cd wecom-ws-channel
pip install -e .
```

## 🚀 快速开始

### 基本用法

```python
import asyncio
from wecom_ws_channel import WeComChannel

async def main():
    channel = WeComChannel(
        bot_id="your_bot_id",
        secret="your_secret",
    )
    
    # 设置消息处理回调
    channel.on_message = lambda msg: print(f"收到消息: {msg}")
    
    # 启动频道
    await channel.start()
    
    # 保持运行
    try:
        while True:
            await asyncio.sleep(1)
    except KeyboardInterrupt:
        await channel.stop()

asyncio.run(main())
```

### 使用代理

```python
channel = WeComChannel(
    bot_id="your_bot_id",
    secret="your_secret",
    http_proxy="http://proxy.example.com:8080",
    http_proxy_auth="username:password",  # 可选
)
```

### 发送消息

```python
# 发送文本
await channel.send_text(user_id, "Hello!")

# 发送图片
await channel.send_image(user_id, image_url)

# 发送文件
await channel.send_file(user_id, file_url, filename)

# 发送图文混排
await channel.send_mixed(user_id, [
    {"type": "text", "content": "这是一段文字"},
    {"type": "image", "url": "https://example.com/image.jpg"},
])
```

## ⚙️ 配置参数

| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| `bot_id` | str | ✅ | 智能机器人 BotID |
| `secret` | str | ✅ | 智能机器人 Secret |
| `http_proxy` | str | ❌ | HTTP 代理地址 |
| `http_proxy_auth` | str | ❌ | 代理认证 (username:password) |
| `encoding_aes_key` | str | ❌ | 消息加密密钥 |
| `heartbeat_interval` | int | ❌ | 心跳间隔（秒），默认 10 |

## 📋 依赖

- Python >= 3.9
- aiohttp >= 3.8
- pycryptodome >= 3.15

## 🔧 与 CoPaw 集成

本项目最初为 [CoPaw](https://github.com/agentscope-ai/CoPaw) 开发，可作为自定义频道使用：

```python
# 放置到 .copaw/custom_channels/wecom/ 目录
# config.json 中配置：
{
    "channels": {
        "wecom": {
            "enabled": true,
            "bot_id": "your_bot_id",
            "secret": "your_secret"
        }
    }
}
```

## 📖 企业微信文档

- [智能机器人开发文档](https://developer.work.weixin.qq.com/document/path/101463)

## 🤝 贡献

欢迎提交 Issue 和 Pull Request！

## 📄 许可证

MIT License

## 🙏 致谢

- 企业微信官方提供的 WebSocket 接口
- [CoPaw](https://github.com/agentscope-ai/CoPaw) 项目框架参考
