138 lines
3.6 KiB
Markdown
Executable File
138 lines
3.6 KiB
Markdown
Executable File
# WeChat 集成指南 - bbav20311
|
|
|
|
> 基于 mcp-wechat-server 的微信集成方案
|
|
|
|
## 📋 功能概览
|
|
|
|
| 功能 | 状态 | 说明 |
|
|
|------|------|------|
|
|
| 任务完成通知 | ✅ | 自动发送微信通知 |
|
|
| 接收用户指令 | ✅ | 支持自然语言分析请求 |
|
|
| 任务状态查询 | ✅ | 查询任务进度和详情 |
|
|
| 多用户支持 | ✅ | 区分不同微信用户 |
|
|
|
|
## 🚀 快速开始
|
|
|
|
### 1. 安装依赖
|
|
|
|
```bash
|
|
# 安装 Bun (mcp-wechat-server 需要)
|
|
curl -fsSL https://bun.sh/install | bash
|
|
|
|
# 验证安装
|
|
bun --version # >= 1.0.0
|
|
```
|
|
|
|
### 2. 测试基础功能
|
|
|
|
```bash
|
|
cd /home/xia-lab/wutx/00test/bbav20311
|
|
|
|
# 运行基础测试
|
|
python wechat_integration.py
|
|
```
|
|
|
|
### 3. 启动完整服务
|
|
|
|
```bash
|
|
# 启动微信任务桥接服务
|
|
python wechat_task_bridge.py
|
|
```
|
|
|
|
## 📱 用户交互流程
|
|
|
|
```
|
|
用户微信 → 发送分析请求 → bbav20311 处理 → 微信通知结果
|
|
↓
|
|
支持命令:
|
|
• "帮助" - 显示帮助信息
|
|
• "状态" - 查询系统状态
|
|
• "Ft.SPL 基因家族鉴定" - 创建分析任务
|
|
• "任务列表" - 查看进行中的任务
|
|
• "详情 <任务ID>" - 查看任务详情
|
|
```
|
|
|
|
## 🔧 集成到现有系统
|
|
|
|
### 在 pipeline_backend.py 中添加通知
|
|
|
|
```python
|
|
from wechat_integration import WeChatTaskNotifier
|
|
|
|
async def run_stage_with_notification(job_id: str, stage: str, user_wechat_id: str):
|
|
"""运行 stage 并发送微信通知"""
|
|
|
|
notifier = WeChatTaskNotifier(user_wechat_id=user_wechat_id)
|
|
|
|
# 通知开始
|
|
await notifier.notify_task_started(task_id=job_id, task_type=stage)
|
|
|
|
try:
|
|
# 执行实际任务
|
|
result = await run_stage(job_id, stage)
|
|
|
|
# 通知完成
|
|
await notifier.notify_task_completed(
|
|
task_id=job_id,
|
|
task_type=stage,
|
|
output_files=result.get("output_files", [])
|
|
)
|
|
|
|
except Exception as e:
|
|
# 通知失败
|
|
await notifier.notify_task_failed(
|
|
task_id=job_id,
|
|
task_type=stage,
|
|
error=str(e)
|
|
)
|
|
```
|
|
|
|
### 在 API 中添加微信通知参数
|
|
|
|
```python
|
|
@app.post("/api/pipeline/run")
|
|
async def run_pipeline(
|
|
request: PipelineRequest,
|
|
wechat_user_id: Optional[str] = None # 新增参数
|
|
):
|
|
job = new_job()
|
|
|
|
if wechat_user_id:
|
|
# 后台运行并发送微信通知
|
|
asyncio.create_task(
|
|
run_with_wechat_notification(job.job_id, request, wechat_user_id)
|
|
)
|
|
return {"job_id": job.job_id, "message": "任务已提交,将通过微信通知结果"}
|
|
else:
|
|
# 原有逻辑
|
|
result = await run_stage(job.job_id, request.stage)
|
|
return result
|
|
```
|
|
|
|
## ⚠️ 注意事项
|
|
|
|
1. **登录状态**: 首次使用需要扫码登录,Cookie 会保存在 `~/.mcp-wechat-server/`
|
|
2. **封号风险**: 个人微信机器人存在封号风险,建议使用企业微信或测试号
|
|
3. **网络要求**: 扫码时如果页面加载慢,尝试切换到移动数据网络
|
|
4. **依赖 Bun**: mcp-wechat-server 需要 Bun 运行时
|
|
|
|
## 📁 文件说明
|
|
|
|
| 文件 | 说明 |
|
|
|------|------|
|
|
| `wechat_integration.py` | 核心集成模块,提供 WeChatIntegration 类 |
|
|
| `wechat_task_bridge.py` | 任务桥接服务,连接微信和 bbav20311 |
|
|
| `WECHAT_INTEGRATION.md` | 本文档 |
|
|
|
|
## 🔮 后续优化
|
|
|
|
- [ ] 接入真实的 MCP 协议(当前为模拟实现)
|
|
- [ ] 支持图片/文件发送
|
|
- [ ] 支持群聊 @机器人
|
|
- [ ] 添加任务队列管理
|
|
- [ ] 集成飞书作为备选通道
|
|
|
|
## 📚 参考
|
|
|
|
- [mcp-wechat-server](https://github.com/Howardzhangdqs/mcp-wechat-server)
|
|
- [MCP Protocol](https://modelcontextprotocol.io/) |