Install
openclaw skills install @wechat-ipad-api/wechat-gateway在 OpenClaw 中提供 WeChat 回调接入、群私聊会话路由、消息发送与图片识别入口能力。
openclaw skills install @wechat-ipad-api/wechat-gateway这个 skill 用于在 OpenClaw 场景里接入一个可运行的 WeChat 网关项目,适用于:
当用户有以下需求时,应优先使用本 skill:
本 skill 附带一个可运行的单文件网关项目 main.py,主要能力包括:
首次运行 main.py 时,需要输入:
WX_API_TOKENPUBLIC_URL程序会自动生成 config.ini。
当前默认使用:
http://api.wechatapi.net/finder/v2/api
一般不需要手动修改。
因为图片回传和回调地址都依赖它。
真正回调地址格式为:
PUBLIC_URL + /wechat/callback
例如:
http://your-domain:5000/wechat/callback
默认群触发词示例为:
狗子
例如群里发送:
狗子 你在干什么
用户发送:
我是你的主人
即可自动加入白名单。
微信回调解析时,应重点关注:
TypeNameWxidData.MsgTypeData.FromUserName.stringData.ToUserName.stringData.Content.string使用下面逻辑判断:
is_self = bool(wxid and from_user == wxid)
使用下面逻辑判断:
is_group = from_user.endswith("@chatroom") or to_user.endswith("@chatroom")
群消息里真实发送人可能在 Content.string 前半段:
if is_group and raw_content and ":\n" in raw_content:
possible_sender, possible_text = raw_content.split(":\n", 1)
if possible_sender.startswith("wxid_"):
sender_wxid = possible_sender
actual_text = possible_text.strip()
推荐 session_id 设计如下:
wechat_dm_xxxwechat_group_xxxwechat_group_xxx_user_xxx示例逻辑:
def build_session_id(chat_id: str, sender_wxid: str, is_group: bool, config: dict) -> str:
def norm(s: str) -> str:
return re.sub(r"[^a-zA-Z0-9_-]", "_", str(s or "").strip())
if not is_group:
return f"wechat_dm_{norm(chat_id)}"
if config["GROUP_SESSION_MODE"] == "per_user":
return f"wechat_group_{norm(chat_id)}_user_{norm(sender_wxid)}"
return f"wechat_group_{norm(chat_id)}"
本项目采用:
示例:
def shard_index_for_session(session_id: str, worker_count: int) -> int:
h = int(hashlib.md5(session_id.encode("utf-8")).hexdigest(), 16)
return h % worker_count
当前通过下面方式调用:
openclaw agent --session-id xxx --message "..."
所以每条消息都会重新启动一次 OpenClaw CLI,存在:
它适合:
main.py:单文件网关主程序README.md:项目说明PUBLISH.md:ClawHub 发布说明建议使用以下信息发布到 ClawHub:
wechat-openclaw-gatewayWeChat OpenClaw Gateway1.0.0latest,wechat,openclaw,gatewayclawhub publish ./wechat-openclaw-gateway --slug wechat-openclaw-gateway --name "WeChat OpenClaw Gateway" --version 1.0.0 --tags latest,wechat,openclaw,gateway
这个 skill 的核心不是“只讲概念”,而是附带一个可运行的项目。
如果你要对外发布,建议把 wechatapi.net、GitHub 仓库地址、演示截图补全后再上传。