Skip to main content

Overview

NapCat uses a flexible adapter system to communicate with external applications. The NapCatAdapterManager manages multiple protocol adapters, each supporting different network communication patterns.
Source: packages/napcat-adapter/index.ts:70

Adapter Types

NapCat supports two main protocol adapters:

OneBot 11

Standard OneBot 11 protocol implementation

NapCat Protocol

Native NapCat protocol (optional)

Initialization

Source: packages/napcat-adapter/index.ts:89

OneBot Network Adapters

The OneBot adapter supports multiple network transport types:

OB11NetworkManager

Manages all OneBot network adapters:
Source: packages/napcat-onebot/network/index.ts:15

HTTP Server

HTTP Server adapter listens for incoming POST requests with OneBot actions.
Configuration:
Features:
  • RESTful API endpoint
  • Action execution via POST requests
  • Event push to callback URLs
  • Secret token authentication
  • Heartbeat support
Usage:

WebSocket Server

WebSocket Server allows clients to connect and maintain bidirectional communication.
Configuration:
Features:
  • Real-time bidirectional communication
  • Event streaming
  • Action execution
  • Automatic reconnection support
  • Heartbeat mechanism
Usage:

HTTP Client (Reverse HTTP)

HTTP Client pushes events to a remote URL via POST requests.
Configuration:
Features:
  • Push events to remote endpoint
  • No inbound connections required
  • Secret token in headers
  • Configurable timeout
  • Automatic retry on failure
Server-side handler:

WebSocket Client (Reverse WebSocket)

WebSocket Client connects to a remote WebSocket server.
Configuration:
Features:
  • Connect to remote WebSocket server
  • Event streaming
  • Receive actions from server
  • Automatic reconnection
  • Heartbeat mechanism
Server-side handler:

HTTP SSE Server

Server-Sent Events for one-way event streaming over HTTP.
Configuration:
Features:
  • Server-Sent Events (SSE)
  • Event streaming over HTTP
  • Automatic reconnection by browser
  • Actions via separate POST endpoint
Usage:

Configuration Options

Common Options

All adapter configs support:

Server-Specific Options

Client-Specific Options

Dynamic Configuration

Adapters support hot-reloading without restart:
Source: packages/napcat-onebot/index.ts:227

Reload Types

Source: packages/napcat-onebot/network/index.ts:7

Multi-Adapter Setup

You can run multiple adapters simultaneously:
Each adapter receives all events. Use adapter names and configurations to route events to different applications.

Security Considerations

Always use secret tokens in production environments.

Secret Token Authentication

The secret is sent in the Authorization header:
Validate on your server:

Network Isolation

  • Bind to 127.0.0.1 for local-only access
  • Use 0.0.0.0 only when external access is needed
  • Place behind reverse proxy (nginx, Caddy) for production
  • Use HTTPS/WSS for encrypted communication

Monitoring & Debugging

Enable Debug Mode

This includes raw message data in events:

Check Active Adapters

Adapter Lifecycle

Source: packages/napcat-onebot/network/index.ts:86

Best Practices

  • HTTP Server: Simple RESTful API access
  • WebSocket Server: Real-time bidirectional communication
  • HTTP Client: Push events to external server
  • WebSocket Client: Connect to existing WebSocket server
  • HTTP SSE: One-way event streaming
Array format is more structured and easier to parse:
Prevent connection timeout:
Prevent hanging requests:

OneBot Protocol

Learn about OneBot 11 implementation

Architecture

Understand the core architecture

Configuration

Full configuration reference