Skip to main content

What is OneBot?

OneBot is a standardized chatbot protocol designed to provide a unified API interface for different chat platforms. NapCat implements the OneBot 11 standard to expose QQ bot functionality through HTTP, WebSocket, and other network protocols.
OneBot 11 is the most widely supported version, compatible with most bot frameworks and libraries in the ecosystem.

Architecture

NapCatOneBot11Adapter

The OneBot implementation is packaged as an adapter that wraps NapCatCore:
Source: packages/napcat-onebot/index.ts:69 Key components:
  • Core: Access to NapCat’s native QQ APIs
  • APIs: OneBot-specific API implementations
  • NetworkManager: Manages all network adapters (HTTP/WS/etc)
  • Actions: Maps OneBot actions to handler functions

Component Diagram

Action & Event Model

Actions (Requests)

Actions are requests sent to the bot to perform operations. They follow this structure:

Events (Push)

Events are pushed from the bot when something happens. Event types:
Source: packages/napcat-onebot/event/OneBotEvent.ts:3

Event Base Structure

All OneBot events extend this base class and include:
  • time: Unix timestamp
  • self_id: Bot’s QQ number
  • post_type: Event category
Source: packages/napcat-onebot/event/OneBotEvent.ts:11

Message Format

OneBot 11 supports two message formats:

String Format (CQ Code)

You can configure which format to use in the adapter configuration with messagePostFormat: "array" or "string".

Message Elements

Common message element types:

Action Implementation

Actions are implemented using a registry pattern:
Source: packages/napcat-onebot/action/index.ts

Action Handler Example

Here’s how an action handler is structured:

Event Handling

Message Events

Incoming messages are processed and converted to OneBot format:
Source: packages/napcat-onebot/index.ts:309

Notice Events

System events like group member changes, kicks, recalls:

Request Events

Friend and group requests:
Source: packages/napcat-onebot/index.ts:436

Network Manager

The OB11NetworkManager handles event distribution to all active adapters:
Source: packages/napcat-onebot/network/index.ts:15

Network Adapters

Supported adapter types:

HTTP Server

Listens for POST requests with actions

WebSocket Server

Bidirectional communication, client connects to bot

HTTP Client

Posts events to remote URL (reverse HTTP)

WebSocket Client

Connects to remote WS server (reverse WS)
Each adapter can be independently enabled/disabled in configuration.

Configuration

OneBot configuration is loaded via OB11ConfigLoader:
Source: packages/napcat-onebot/config/config.ts

Example Configuration

Common Actions

Extension: Quick Actions

NapCat extends OneBot with quick action support for rapid responses:
Quick actions allow responding to events without separate API calls. Source: packages/napcat-onebot/api/quick-action.ts

Adapters

Configure HTTP and WebSocket adapters

Architecture

Understand the core architecture

API Reference

Full action and event reference