DEV Community

Aloysius Chan
Aloysius Chan

Posted on • Originally published at insightginie.com

Connecting OpenClaw to QQ: A Guide to the OneBot Adapter Skill

Understanding the OpenClaw OneBot Adapter

In the rapidly evolving world of AI-driven automation, connecting your
intelligent agents to communication platforms is a critical step for real-
world utility. If you are a developer using OpenClaw, you may have encountered
the onebot-adapter skill in the GitHub repository. This tool is designed to
bridge the gap between the OpenClaw framework and the widespread QQ messaging
platform, leveraging the powerful OneBot protocol.

What is the OneBot Adapter?

The OneBot Adapter is a specialized skill within the OpenClaw ecosystem. Its
primary purpose is to enable OpenClaw agents to communicate via the OneBot
protocol, a universal interface standard for messaging bots. By utilizing this
adapter, your OpenClaw agent can seamlessly interact with QQ through
implementations like NapCat. Whether you need to build a customer support bot,
a personal assistant, or an automated monitoring system that notifies you via
QQ, this adapter provides the necessary infrastructure to send and receive
messages efficiently.

Why Use OneBot?

The OneBot protocol is the gold standard for QQ bot development because it
abstracts the underlying complexities of the NTQQ architecture. By using this
adapter, developers don't need to reinvent the wheel every time they want to
create a bot. The onebot-adapter simplifies the connection process, allowing
you to focus on the logic of your agent rather than the intricacies of message
formatting and WebSocket handling.

Setting Up Your Connection

To begin using the adapter, you need to configure your environment. The
adapter supports both WebSocket and HTTP connection modes. WebSocket is
generally recommended for production environments because it enables real-
time, bidirectional communication, ensuring that your agent receives incoming
events as they happen.

Configuration Steps

To establish a connection, you must define specific environment variables or
configuration settings:

  • ONEBOT_WS_URL: Set this to the address of your WebSocket server (e.g., ws://127.0.0.1:3001).
  • ONEBOT_HTTP_URL: Provide the HTTP endpoint for request-response operations (e.g., http://127.0.0.1:3000).
  • ONEBOT_TOKEN: A vital security measure for authenticating your connection with the server.

Once these variables are set, you can initiate the listener script provided in
the scripts/ directory of the repository to begin polling for incoming
messages from your QQ contacts or groups.

Practical Implementation: Sending Messages

The Python integration included with the adapter is incredibly intuitive. For
developers looking to push messages from their OpenClaw agent, the
OneBotClient class handles the heavy lifting. A simple implementation looks
like this:

from scripts.onebot_client import OneBotClient

client = OneBotClient()

client.send_private_msg(user_id=123456, message="Hello!")

client.send_group_msg(group_id=789012, message="Group message")

This snippet demonstrates how quickly you can trigger a message to a specific
user or a group, making it perfect for status alerts or automated responses
triggered by your AI agent's internal logic.

WebSocket vs. HTTP

Choosing the right mode for your bot is essential. WebSocket is the preferred
choice for most developers because it supports real-time event handling. This
is crucial if your bot needs to react instantly to user queries. Conversely,
the HTTP mode is best suited for simple tasks where you only need to send
messages and do not require instant response loops. HTTP, however, usually
requires polling, which can introduce latency.

Common Use Cases

What can you actually build with this? The possibilities are vast:

  • Personal Assistants: Create a bot that manages your daily tasks and notifies you on QQ.
  • Automated Monitoring: Connect server monitoring tools to an OpenClaw agent that sends emergency alerts to a group chat.
  • Customer Service: Implement an AI chatbot that answers standard user queries on QQ automatically.
  • Data Aggregation: Send daily reports or data summaries from your databases directly to your personal QQ account.

Troubleshooting Tips

Even the best integrations run into issues. If you find that your bot is not
communicating, check the following:

  1. Connection Refused: This usually means your OneBot server (like NapCat) is not running or is listening on the wrong port.
  2. Authentication Failed: Ensure your ONEBOT_TOKEN matches exactly what is configured in your NapCat or OneBot server settings.
  3. Message Not Delivered: Double-check the user_id or group_id. Also, ensure your bot account has the appropriate permissions to send messages in the target destination.

Conclusion

The onebot-adapter for OpenClaw is a powerful tool for developers looking to
integrate AI agents with one of the world's most popular messaging platforms.
By providing a clean interface for message handling and robust support for the
OneBot protocol, it significantly reduces development time. Whether you are
automating your business workflows or creating a personal AI companion, this
adapter provides the backbone you need to stay connected.

For further details, ensure you review the references/message-handling.md
file within the OpenClaw repository to master the advanced techniques of
message parsing and dynamic response pattern development.

Skill can be found at:
adapter/SKILL.md>

Top comments (0)