openclaw

关注公众号 jb51net

关闭
AI > openclaw >

OpenClaw本地配置QQ Bot的使用流程

kishu_iOS&AI

本文档用于在本地 Mac 环境把 OpenClaw + QQ Bot 打通,并完成:

1. 前置条件

确保以下条件已满足:

可先检查版本:

openclaw --version
node -v
npm -v

2. 安装 QQ Bot 插件

openclaw plugins install @tencent-connect/openclaw-qqbot@latest

安装后可确认插件已加载:

openclaw plugins list | rg -i qqbot

3.(可选)修复 npm TLS 证书问题

如果安装插件时报错 UNABLE_TO_GET_ISSUER_CERT_LOCALLY,执行:

mkdir -p ~/.certs
security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain > ~/.certs/macos-root-certs.pem
security find-certificate -a -p /Library/Keychains/System.keychain > ~/.certs/macos-system-certs.pem
cat ~/.certs/macos-root-certs.pem ~/.certs/macos-system-certs.pem > ~/.certs/macos-all-certs.pem
npm config set cafile "$HOME/.certs/macos-all-certs.pem"
npm config set strict-ssl true

然后重试插件安装。

4. 把 QQ Token 存入 Keychain(推荐)

建议把凭据存 Keychain,不要把明文写到文档或脚本里。

4.1 概念澄清(重要)

也就是说:bot1 不是 token,本质是你在 --account 配置后用于路由匹配的账号 ID(插件会做小写规范化)。

QQ Token 格式:

AppID:AppSecret

示例(会覆盖同名项):

security add-generic-password -a "$USER" -s "Key1" -w "APPID_1:APPSECRET_1" -U
security add-generic-password -a "$USER" -s "Key2" -w "APPID_2:APPSECRET_2" -U

验证能读到(只验证,不要泄漏到聊天记录):

security find-generic-password -a "$USER" -s "Key1" -w

5. 配置 QQ Bot 账号到 OpenClaw

5.0 对应 QQ 开放平台截图

https://q.qq.com/qqbot/openclaw/

QQ 开放平台“OpenClaw 原生接入流程”里的 3 条命令,含义如下:

  1. 安装插件
openclaw plugins install @tencent-connect/openclaw-qqbot@latest
  1. 绑定当前 QQ 机器人(--token 就是 AppID:AppSecret
openclaw channels add --channel qqbot --token "AppID:AppSecret"
  1. 重启 OpenClaw 服务
openclaw gateway restart

补充说明:

5.1 单账号

openclaw channels add \
  --channel qqbot \
  --account bot1 \
  --token "$(security find-generic-password -a "$USER" -s "Key1" -w)"

5.2 多账号

openclaw channels add \
  --channel qqbot \
  --account bot1 \
  --token "$(security find-generic-password -a "$USER" -s "Key1" -w)"
openclaw channels add \
  --channel qqbot \
  --account bot2 \
  --token "$(security find-generic-password -a "$USER" -s "Key2" -w)"

查看已配置账号:

openclaw channels list --json | sed -n '/^{/,$p' | jq '.chat.qqbot'

注意:插件通常会把 accountId 规范成小写,例如 Bot1 -> bot1

6. 创建 Agent 并绑定到指定 QQ Bot

6.1 创建 Agent

openclaw agents add qq_agent_bot \
  --non-interactive \
  --workspace ~/.openclaw/workspace-qq_agent_bot \
  --json
openclaw agents add qq_agent_edit_bot \
  --non-interactive \
  --workspace ~/.openclaw/workspace-qq_agent_edit_bot \
  --json

6.2 绑定路由(精准绑定到账号)

openclaw agents bind --agent qq_agent_bot --bind qqbot:bot1 --json
openclaw agents bind --agent qq_agent_edit_bot --bind qqbot:bot2 --json

查看绑定结果:

openclaw agents bindings --json | sed -n '/^\\[/,$p' | jq '.'

如果之前绑过泛路由(qqbot),建议移除,避免冲突:

openclaw agents unbind --agent qq_agent_bot --bind qqbot --json

7. 重启网关使配置生效

openclaw gateway restart

8. 验证是否真正打通

8.1 看配置层状态

openclaw channels status

期望看到类似:

8.2 看运行日志(最关键)

rg -n "qqbot:bot1|qqbot:bot2|READY|WebSocket connected|Access token obtained" \
  ~/.openclaw/logs/gateway.log -S | tail -n 80

出现以下日志即表示在线:

9. 日常运维命令

# 查看所有 agent
openclaw agents list
# 查看绑定关系
openclaw agents bindings
# 重启网关
openclaw gateway restart
# 查看网关日志
tail -f ~/.openclaw/logs/gateway.log

10. 常见问题排查

Q1:插件安装失败,报 TLS/证书错误

Q2:channels status提示很多 env var 缺失

Q3:已连上 QQ,但消息没进目标 Agent

优先检查:

Q4:多账号时默认路由不明确

11. 最小可用流程(速记)

# 1) 安装插件
openclaw plugins install @tencent-connect/openclaw-qqbot@latest
# 2) 存 token 到 keychain(示例)
security add-generic-password -a "$USER" -s "Key1" -w "APPID_1:APPSECRET_1" -U
# 3) 配置频道账号
openclaw channels add --channel qqbot --account bot1 --token "$(security find-generic-password -a "$USER" -s "Key1" -w)"
# 4) 创建并绑定 agent
openclaw agents add qq_agent_bot --non-interactive --workspace ~/.openclaw/workspace-qq_agent_bot
openclaw agents bind --agent qq_agent_bot --bind qqbot:bot1
# 5) 重启并看日志
openclaw gateway restart
rg -n "qqbot:bot1|READY|WebSocket connected" ~/.openclaw/logs/gateway.log -S | tail -n 50

到此这篇关于OpenClaw本地配置QQ Bot的使用流程的文章就介绍到这了,更多相关OpenClaw 本地配置 QQ Bot内容请搜索脚本之家以前的文章或继续浏览下面的相关文章,希望大家以后多多支持脚本之家!