我开源了一个视觉驱动的 IM Agent,零封号风险自动化微信聊天
先上项目地址:https://github.com/deepdadou/sightflow-agent
背景
做自动化的老铁都知道,微信/WhatsApp 这类 IM 应用的自动化一直是个坑:
- 官方 API?个人开发者别想了
- Web 协议?分分钟封号
- 逆向工程?每次更新都要重新来
所以我换了个思路:既然 API 不靠谱,那就让 AI 像人一样"看"屏幕操作不就行了?
于是有了 SightFlow Agent 这个项目。
技术原理
核心思路就三步:
1. 屏幕截图 → pyautogui.screenshot()
2. OCR 识别文字 → PaddleOCR/EasyOCR
3. 模拟点击输入 → pyautogui.click()/write()
听起来简单,但有几个技术难点:
难点 1:未读消息红点检测
红点很小,而且不同应用位置不固定。我最开始用模板匹配,后来发现直接检测红色更靠谱:
def detect_red_dots_by_color(self, image):
import numpy as np
img_array = np.array(image)
red_mask = (
(img_array[:, :, 0] > 200) &
(img_array[:, :, 1] < 100) &
(img_array[:, :, 2] < 100)
)
from scipy import ndimage
labeled, num_features = ndimage.label(red_mask)
dots = []
for i in range(1, num_features + 1):
positions = np.where(labeled == i)
if len(positions[0]) > 10:
y_center = int(np.mean(positions[0]))
x_center = int(np.mean(positions[1]))
dots.append({"position": (x_center, y_center), "count": 1})
return dots
难点 2:OCR 文字识别准确率
微信聊天界面的文字大小不一,还有气泡背景。我试了三个 OCR 引擎:
- Tesseract:免费但中文识别一般
- EasyOCR:多语言支持好,速度慢
- PaddleOCR:中文识别最准,速度也快 ← 最终选择
难点 3:输入框定位
不同应用、不同窗口大小,输入框位置都不同。我的解决方案是:
def detect_input_field(self, image, app="wechat"):
bottom_region = (0, image.height - 150, image.width, 150)
input_field = self._detect_input_by_shape(image, bottom_region)
return input_field
核心代码
先上完整的使用示例:
from sightflow_agent import VisionAgent, WeChatDriver
driver = WeChatDriver()
agent = VisionAgent(driver=driver)
if not driver.attach():
print("无法连接到微信")
exit(1)
agent.send_message("豆哥", "你好!我是 SightFlow Agent 👋")
messages = agent.read_chat("豆哥", limit=5)
for msg in messages:
print(f"{msg.sender}: {msg.text}")
unread = agent.detect_unread()
print(f"未读消息:{len(unread)} 条")
agent.auto_reply(mode="smart", interval=10)
项目结构
sightflow-agent/
├── agent.py
├── scanner.py
├── ocr.py
├── drivers/
│ ├── base.py
│ ├── wechat.py
│ └── whatsapp.py
├── skills/
│ └── openclaw.py
├── tools/
│ └── hermes.py
└── cli.py
安装
git clone https://github.com/deepdadou/sightflow-agent.git
cd sightflow-agent
pip install -e .
sightflow unread
sightflow read --contact "豆哥"
sightflow send --contact "豆哥" --message "你好"
sightflow auto-reply --mode smart
实际应用场景
场景 1:客服自动回复
keywords = {
"你好": "你好!有什么可以帮你的吗?",
"价格": "我们的产品定价是...",
"发货": "一般 48 小时内发货",
"再见": "拜拜,下次聊!",
}
agent.auto_reply(mode="keyword", keywords=keywords, interval=5)
场景 2:重要消息监控
def on_important_message(msg):
if msg.sender == "老板":
send_email("boss_msg@example.com", "老板找你!", msg.text)
agent.on_message(on_important_message)
场景 3:定时日报
from apscheduler.schedulers.blocking import BlockingScheduler
scheduler = BlockingScheduler()
@scheduler.scheduled_job('cron', hour=9, minute=0)
def send_daily_report():
agent.send_message("工作群", """
今日工作计划:
1. 完成 XX 功能开发
2. 修复 XX Bug
3. 参加 XX 会议
""")
scheduler.start()
注意事项
虽然视觉识别方案封号风险极低(因为完全模拟真人操作),但还是建议:
1. 不要设置过快的回复频率 - 像真人一样思考
2. 避免 24 小时不间断运行 - 该休息就休息
3. 敏感操作建议人工确认 - 涉及金钱/隐私要谨慎
与 Agent 框架集成
OpenClaw:
from sightflow_agent.skills import OpenClawWeChat
skill = OpenClawWeChat()
skill.send_message("豆哥", "任务已完成!")
Hermes Agent:
from sightflow_agent.tools import wechat_tool
result = wechat_tool._run(
action="send_message",
contact="豆哥",
message="Hello from Hermes!"
)
项目链接
GitHub: https://github.com/deepdadou/sightflow-agent
知乎教程:https://zhuanlan.zhihu.com/p/2030301756064806001
下一步计划
- 支持更多 IM 应用(Telegram/QQ/Discord)
- 开发工作流编辑器(可视化编排)
- 探索企业客服自动化场景
- 考虑商业化(SaaS 服务/企业定制)
用视觉赋能 Agent,让自动化更安全!
欢迎 Star、Fork、提 Issue!🚀