Overview
NapCat uses a flexible adapter system to communicate with external applications. TheNapCatAdapterManager manages multiple protocol adapters, each supporting different network communication patterns.
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
packages/napcat-adapter/index.ts:89
OneBot Network Adapters
The OneBot adapter supports multiple network transport types:OB11NetworkManager
Manages all OneBot network adapters:packages/napcat-onebot/network/index.ts:15
HTTP Server
HTTP Server adapter listens for incoming POST requests with OneBot actions.
- RESTful API endpoint
- Action execution via POST requests
- Event push to callback URLs
- Secret token authentication
- Heartbeat support
WebSocket Server
WebSocket Server allows clients to connect and maintain bidirectional communication.
- Real-time bidirectional communication
- Event streaming
- Action execution
- Automatic reconnection support
- Heartbeat mechanism
HTTP Client (Reverse HTTP)
HTTP Client pushes events to a remote URL via POST requests.
- Push events to remote endpoint
- No inbound connections required
- Secret token in headers
- Configurable timeout
- Automatic retry on failure
WebSocket Client (Reverse WebSocket)
WebSocket Client connects to a remote WebSocket server.
- Connect to remote WebSocket server
- Event streaming
- Receive actions from server
- Automatic reconnection
- Heartbeat mechanism
HTTP SSE Server
Server-Sent Events for one-way event streaming over HTTP.
- Server-Sent Events (SSE)
- Event streaming over HTTP
- Automatic reconnection by browser
- Actions via separate POST endpoint
Configuration Options
Common Options
All adapter configs support:Server-Specific Options
Client-Specific Options
Dynamic Configuration
Adapters support hot-reloading without restart:packages/napcat-onebot/index.ts:227
Reload Types
packages/napcat-onebot/network/index.ts:7
Multi-Adapter Setup
You can run multiple adapters simultaneously:Security Considerations
Secret Token Authentication
Authorization header:
Network Isolation
- Bind to
127.0.0.1for local-only access - Use
0.0.0.0only when external access is needed - Place behind reverse proxy (nginx, Caddy) for production
- Use HTTPS/WSS for encrypted communication
Monitoring & Debugging
Enable Debug Mode
Check Active Adapters
Adapter Lifecycle
packages/napcat-onebot/network/index.ts:86
Best Practices
Choose the right adapter type
Choose the right adapter type
- 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
Use array format for rich messages
Use array format for rich messages
Array format is more structured and easier to parse:
Enable heartbeat for long connections
Enable heartbeat for long connections
Prevent connection timeout:
Set appropriate timeouts
Set appropriate timeouts
Prevent hanging requests:
Related
OneBot Protocol
Learn about OneBot 11 implementation
Architecture
Understand the core architecture
Configuration
Full configuration reference
