Install
openclaw skills install wechat-account-sendThis skill provides integrated WeChat account management, message delivery, and file transmission capabilities. It supports querying current user account information and actively sending text messages or various file types (including images, videos, audio, and documents) to specified WeChat contacts or groups when invoked through OpenClaw. The functionality enables complete operation execution for user-driven communication and sharing tasks.
openclaw skills install wechat-account-send使用 OpenClaw 的微信集成功能,实现微信账号信息查询、会话管理、主动文本消息和文件发送功能。 调用时机:当用户需要查询当前微信账户信息,或主动向指定微信联系人/群组发送消息时,通过微信发送文件即可触发。
本技能提供以下核心功能:
当用户要求列出所有会话时,调用 sessions_list 工具: sessions_list()
#### 找到当前对话
当用户要求找到我们之间的对话时:
# 获取所有会话
sessions_list()
# 过滤出微信渠道的会话
# 找到最新的或与当前对话匹配的会话
使用 sessions_list 的参数来获取更详细的信息:
sessions_list(activeMinutes=60, messageLimit=5)
### 2. 主动消息发送功能
#### 命令行调用方式
```bash
python scripts/main_send_msg <account_id> <message>
python scripts/main_send_msg "6e2f83e62b99-im-bot" "这是发送的消息"
本技能提供两种核心文件发送场景:
# 发送图片
python scripts/main_send_file.py "XXXXXXX-im-bot" "/home/测试图片.jpg"
# 发送视频
python scripts/main_send_file.py "XXXXXXX-im-bot" "/home/测试视频.mp4"
# 发送文档
python scripts/main_send_file.py "XXXXXXX-im-bot" "/home/测试文档.pdf"
# 发送音频
python scripts/main_send_file.py "XXXXXXX-im-bot" "/home/测试音频.mp3"
当同时满足以下条件时,文件发送功能将被自动调用:
| 参数名称 | 类型 | 描述 | 默认值 |
|---|---|---|---|
activeMinutes | 整数 | 查询指定分钟内活跃的会话 | 60 |
messageLimit | 整数 | 每个会话返回的消息数量 | 5 |
| 参数名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
account_id | 字符串 | 微信账号唯一标识符(如:6e2f83e62b99-im-bot) | ✅ 是 |
message | 字符串 | 要发送的文本消息内容 | ✅ 是 |
| 参数名称 | 类型 | 描述 | 必填 |
|---|---|---|---|
account_id | 字符串 | 微信账号唯一标识符(如:XXXXXXX-im-bot) | ✅ 是 |
file_path | 字符串 | 待发送文件的完整本地路径 | ✅ 是 |
requests, uuid, pathlib 等)。| 文件类型 | 建议大小上限 |
|---|---|
| 图片 | ≤ 10 MB |
| 视频 | ≤ 20 MB |
| 其他文件 | ≤ 50 MB |
注:实际文件大小限制以微信官方API规定为准,超过限制可能导致发送失败。
账号配置文件默认存放在以下位置:
C:\Users\用户名\.openclaw\openclaw-weixin\accounts~/.openclaw/openclaw-weixin/accounts技能现在通过 get_openclaw_path() 函数实现自动路径检测:
OPENCLAW_STATE_DIR常见错误及解决方法:
| 错误类型 | 可能原因 | 解决方法 |
|---|---|---|
| 路径不存在 | OpenClaw路径配置错误 | 检查 OpenClaw 是否正确安装 |
| 配置文件缺失 | 账号ID不存在或配置文件损坏 | 重新登录微信账号 |
| 网络请求异常 | 网络连接失败或API地址错误 | 检查网络连接和API地址配置 |
| 权限验证失败 | Token失效或权限不足 | 重新获取身份验证令牌 |
| 文件发送失败 (新增) | 文件路径错误、网络异常、API返回非零状态码、文件类型不支持或大小超限 | 检查文件路径与网络,查看错误日志,确认文件格式与大小 |
sessions_list 返回示例:
{
"sessions": [
{
"sessionKey": "openclaw-weixin:xxxxxxxx-22f75d8b",
"kind": "openclaw-weixin",
"lastMessage": "检查微信助手的账号ID",
"lastMessageTime": "2026-04-01T17:12:00Z"
}
]
}
成功发送文本消息的输出:
==================================================
【微信消息发送测试】
目标用户: xxxxxxxx
客户端ID: openclaw-weixin:1735114630-abc123def
上下文Token: xxxxxxxx-22f75d8b
------------------------------
HTTP 状态码: 200
API 返回码 (ret): 0
✅ 消息发送成功!
服务器响应详情:
{
"ret": 0,
"msg": "success",
"data": {}
}
==================================================
成功发送文件的输出:
1. 准备上传参数...
准备成功,filekey: a1b2c3d4e5f67890..., aeskey: 0011223344556677...
2. 申请上传参数...
获取到upload_param: xyz123abc456def789...
3. 加密文件...
加密完成,原始大小: 102400, 加密后大小: 102416
4. 上传到CDN...
上传成功,encrypt_query_param: enc_param_abc123def456...
5. 发送文件...
HTTP 状态码: 200
API 返回码 (ret): 0
✅ 文件发送成功!
服务器响应详情:
{
"ret": 0,
"msg": "success",
"data": {}
}
| 版本 | 更新日期 | 更新内容 |
|---|---|---|
| 4.0.0 | 2026-04-03 | 新增文件发送功能,支持图片、视频、音频、文档、压缩文件等多种格式文件发送。 |
| 3.0.0 | 2026-04-02 | 新增主动消息发送功能,支持向指定用户发送消息;添加自动路径检测功能 |
| 2.0.0 | 2026-04-01 | 改用sessions_list工具查询会话信息 |
| 1.0.0 | 2026-04-01 | 初始版本发布,支持微信账号信息查询 |
def get_openclaw_path():
"""获取OpenClaw安装路径,支持Windows、Linux、MacOS"""
# 优先使用环境变量指定的路径
state_dir = os.environ.get('OPENCLAW_STATE_DIR')
if state_dir and os.path.exists(state_dir):
return Path(state_dir)
# 默认路径
home = Path.home()
if sys.platform == 'win32':
# Windows: C:\Users\用户名\.openclaw
return home / '.openclaw'
else:
# Linux/MacOS: ~/.openclaw
return home / '.openclaw'
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ 会话查询模块 │ │ 账号信息查询 │────▶│ 消息发送模块 │
└─────────────────┘ └──────────────────┘ └──────────────────┘
▲ ▲ ▲
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ 错误处理 │ │ 配置文件管理 │ │ 网络请求处理 │
└─────────────────┘ └──────────────────┘ └──────────────────┘
▲ ▲ ▲
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ 自动路径检测 │ │ 环境变量检测 │ │ 文件处理模块(新增)│
└─────────────────┘ └──────────────────┘ └──────────────────┘
requests: HTTP请求库json: JSON数据处理time: 时间戳管理base64: 编码解码os: 操作系统交互uuid: 唯一ID生成pathlib: 路径管理sys: 系统级操作wechat-account-send/ ├── SKILL.md # 技能文档 ├── scripts/ │ ├── main_send_msg # 文本消息发送主程序 │ └── main_send_file.py # (新增) 文件发送主程序 └── (其他配置文件)
技能现在支持自动路径检测,无需手动配置环境变量。但如果需要自定义 OpenClaw 路径,可以设置以下环境变量:
# Windows
set OPENCLAW_STATE_DIR=C:\path\to\your\openclaw
# Linux/MacOS
export OPENCLAW_STATE_DIR=/path/to/your/openclaw