OneBot Adapter
Connect OpenClaw to OneBot protocol servers like NapCat for QQ bot functionality.
Quick Start
1. Configure Connection
Set OneBot server URL in environment or config:
CODEBLOCK0
2. Receive Messages
Use the WebSocket listener script to receive QQ messages:
CODEBLOCK1
3. Send Messages
Use HTTP API to send messages:
CODEBLOCK2
Connection Modes
WebSocket (Recommended)
- - Real-time bidirectional communication
- Receives events instantly
- Supports both sending and receiving
HTTP
- - Request-response model
- Good for simple sending
- Requires polling for receiving
Common Tasks
Get Login Info
CODEBLOCK3
Get Friend/Group List
CODEBLOCK4
Handle Messages
See
references/message-handling.md for message parsing and response patterns.
NapCat Specific
NapCat is a OneBot11 implementation based on NTQQ.
Default ports:
- - WebSocket: 3001
- HTTP: 3000
- WebUI: 6099
Token authentication is optional but recommended for public deployments.
Troubleshooting
Connection refused: Check if OneBot server is running and ports are correct.
Authentication failed: Verify token matches OneBot server configuration.
Message not delivered: Check userid/groupid exists and bot has permission.
OneBot适配器
将OpenClaw连接到NapCat等OneBot协议服务器,实现QQ机器人功能。
快速开始
1. 配置连接
在环境变量或配置文件中设置OneBot服务器地址:
bash
export ONEBOTWSURL=ws://127.0.0.1:3001
export ONEBOTHTTPURL=http://127.0.0.1:3000
export ONEBOT_TOKEN=your-token
2. 接收消息
使用WebSocket监听脚本接收QQ消息:
bash
python scripts/onebotwslistener.py
3. 发送消息
使用HTTP API发送消息:
python
from scripts.onebot_client import OneBotClient
client = OneBotClient()
client.sendprivatemsg(user_id=123456, message=你好!)
client.sendgroupmsg(group_id=789012, message=群消息)
连接模式
WebSocket(推荐)
HTTP
常见任务
获取登录信息
python
client.get
logininfo()
获取好友/群列表
python
client.get
friendlist()
client.get
grouplist()
处理消息
消息解析和响应模式请参见
references/message-handling.md。
NapCat相关说明
NapCat是基于NTQQ的OneBot11实现。
默认端口:
- - WebSocket:3001
- HTTP:3000
- WebUI:6099
令牌认证为可选配置,但建议在公开部署时启用。
故障排除
连接被拒绝:检查OneBot服务器是否运行,端口是否正确。
认证失败:验证令牌是否与OneBot服务器配置一致。
消息未送达:检查用户ID/群组ID是否存在,机器人是否具有权限。