Hermes 配置微信
环境
Win11,WSL2,Ubuntu24.04
一、相关文档
Weixin (微信)
Weixin (WeChat)
二、前置安装
pip install aiohttp cryptography # Optional: for terminal QR code display pip install hermes-agent[messaging]pip install aiohttp cryptography 安装
uadmin@UD26:~$ pip install aiohttp cryptography Command 'pip' not found, but can be installed with: sudo apt install python3-pip uadmin@UD26:~$ sudo apt update uadmin@UD26:~$ sudo apt install python3-pip uadmin@UD26:~$ pip3 install aiohttp cryptography error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install. If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. If you wish to install a non-Debian packaged Python application, it may be easiest to use pipx install xyz, which will manage a virtual environment for you. Make sure you have pipx installed. See /usr/share/doc/python3.12/README.venv for more information. note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification. 安装报错,安装这个简单,版本可能旧一点 uadmin@UD26:~$ sudo apt install python3-aiohttp python3-cryptography使用hermes的虚拟环境安装
uadmin@UD26:~$ source ~/.hermes/hermes-agent/venv/bin/activate
(venv) uadmin@UD26:~$ pip show aiohttp cryptography(先查一下,可能已经安装了)
(venv) uadmin@UD26:~$ pip install aiohttp cryptography
(venv) uadmin@UD26:~$ pip show aiohttp cryptography
其他venv相关用法
# 安装venv所需的程序包 sudo apt update && sudo apt install python3-full python3-venv -y # 查看安装情况 dpkg -l | grep python3-venv apt list --installed | grep python3-venv # 新建虚拟环境 python3 -m venv ~/venvs/hermes # 激活虚拟环境 source ~/venvs/hermes/bin/activate pip安装(在虚拟环境下) # 取消激活虚拟环境 deactivate # 删除虚拟环境 rm -rf ~/venvs/hermespip install hermes-agent[messaging]
安装报错,可以忽略,可以不安装。
也可以在venv中安装。
三、安装配置微信
gateway配置
hermes gateway setup
Select a platform to configure:
↑↓ navigate ENTER/SPACE select ESC cancel
(○) 💬 Mattermost (not configured)
(○) 📡 Signal (not configured)
(○) 💬 Weixin / WeChat (not configured)
(○) 💬 BlueBubbles (iMessage) (not configured)
(○) 🐧 QQ Bot (not configured)
(○) 💎 Yuanbao (not configured)
(○) 🐳 DingTalk (not configured)
(○) 🎮 Discord (not configured)
(○) 📧 Email (not configured)
(○) 🪽 Feishu / Lark (not configured)
(○) 💬 Google Chat (not configured)
(○) 🏠 Home Assistant (not configured)
(○) 💬 IRC (not configured)
(○) 💚 LINE (not configured)
(○) 🔐 Matrix (not configured)
(○) 🔔 ntfy (not configured)
(○) 📱 iMessage via Photon (not configured)
(○) 🔔 Raft (not configured)
(○) 🔒 SimpleX Chat (not configured)
(○) 💼 Slack (not configured)
(○) 📱 SMS (Twilio) (not configured)
(○) 💼 Microsoft Teams (not configured)
(○) ✈️ Telegram (not configured)
(○) 💼 WeCom (Enterprise WeChat) (not configured)
(○) 💼 WeCom Callback (self-built apps) (not configured)
(○) 💬 WhatsApp (not configured)
→ (●) Done
选择
→ (○) 💬 Weixin / WeChat (not configured)
使用微信扫码
私信消息授权
How should direct messages be authorized?
↑↓ navigate ENTER/SPACE select ESC cancel
→ (●) Use DM pairing approval (recommended)
(○) Allow all direct messages
(○) Only allow listed user IDs
(○) Disable direct messages
默认
处理群聊
How should group chats be handled?
↑↓ navigate ENTER/SPACE select ESC cancel
→ (●)Disable group chats (recommended)
(○) Allow all group chats
(○) Only allow listed group chat IDs
选择
→ (○) Only allow listed group chat IDs
微信群聊ID不好获取,建议选默认的选项
日志输出:
.
微信连接成功,account_id=6e1234567890@im.bot
Skipped (keeping current)
✓ DM pairing enabled.
Unknown DM users can request access and you approve them with `hermes pairing approve`.
Note: QR login connects an iLink bot identity (e.g. ...@im.bot), not a
scriptable personal WeChat account. Ordinary WeChat groups typically cannot
invite an @im.bot identity, and iLink does not deliver ordinary-group events
to most bot accounts. The settings below only apply when iLink actually
delivers group events for your account type — otherwise DM remains the only
working channel regardless of this choice.
Allowed group chat IDs (comma-separated, not member user IDs):(回车先不填)
✓ Group allowlist saved (only takes effect if iLink delivers group events).
设置主聊天
后续可以在聊天窗口,输入/sethome设置。
Use your Weixin user ID (o9cq807bOHexabcde_abcdefghij@im.wechat) as the home channel? [Y/n]: Y
✓ Home channel set to o9cq807bOHexabcde_abcdefghij@im.wechat
✓ Weixin configured!
Account ID: 6e1234567890@im.bot
User ID: o9cq807bOHexabcde_abcdefghij@im.wechat
选择Done
Select a platform to configure:
→ (●) Done
◆ Messaging Platforms
Skipped (keeping current)
重启gateway
────────────────────────────────────────────────────────── Restart the gateway to pick up changes? [Y/n]: Y
⏳ User service restarting gracefully (PID 2153)...
⚠ Graceful restart did not complete within 5s; forcing a service restart...
⏳ User service process started (PID 7594); waiting for gateway runtime...
✓ User service restarted (PID 7594)
四、配置文件
.env
~/.hermes/.env
WEIXIN_ACCOUNT_ID=6e1234567890@im.bot WEIXIN_TOKEN=6e1234567890@im.bot:060000bb1502d9f74dea7d8d4cbb1234567890 WEIXIN_BASE_URL=https://ilinkai.weixin.qq.com WEIXIN_CDN_BASE_URL=https://novac2c.cdn.weixin.qq.com/c2c WEIXIN_DM_POLICY=pairing WEIXIN_ALLOW_ALL_USERS=false WEIXIN_ALLOWED_USERS= WEIXIN_GROUP_POLICY=allowlist WEIXIN_GROUP_ALLOWED_USERS= WEIXIN_HOME_CHANNEL=o9cq807bOHexabcde_abcdefghij@im.wechat如果How should group chats be handled?
想选择Disable group chats (recommended),
可以修改
WEIXIN_GROUP_POLICY=disabled
# 下面这一行直接删掉或者留空都可以
# WEIXIN_GROUP_ALLOWED_USERS=
重启网关
hermes gateway restart
config.yaml
~/.hermes/config.yaml
platforms: weixin: enabled: false feishu: enabled: true这里的weixin:enabled: false,没什么影响,后续可以手动改成true。
五、使用测试
修改备注
修改微信机器人的名称从微信ClawBot改为hermes助手
聊天配对
在hermes命令行输入批准配对命令
uadmin@UD26:~$ hermes pairing approve weixin A1B2C3D4 Approved! User o9cq807bOHexabcde_abcdefghij@im.wechat (o9cq807bOHexabcde_abcdefghij@im.wechat) on weixin can now use the bot~ They'll be recognized automatically on their next message.