Overview
The HTTP POST webhook (HTTP Client) allows NapCat to push events to your server via HTTP POST requests. This is a one-way communication method where NapCat sends events to your endpoint.Configuration
Configure the HTTP client in your OneBot config:Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
enable | boolean | false | Enable HTTP POST webhook |
url | string | http://localhost:8080 | Target URL for event delivery |
token | string | "" | Secret token for HMAC signature |
messagePostFormat | string | array | Message format (array or string) |
reportSelfMessage | boolean | false | Report messages sent by bot itself |
debug | boolean | false | Enable debug logging |
Event Delivery
Request Format
NapCat sends POST requests with the following headers:Request Body
The request body contains the event data:Security and Authentication
HMAC Signature Verification
NapCat signs each request using HMAC-SHA1. Verify the signature to ensure requests are authentic:Python Example
Quick Actions
You can return quick actions in the webhook response to perform immediate operations:Available Quick Actions
| Action | Type | Description |
|---|---|---|
reply | string/array | Send a reply message |
reply_at | boolean | Include @mention in reply |
delete | boolean | Delete the message |
kick | boolean | Kick the user (group only) |
ban | boolean | Ban/mute the user (group only) |
ban_duration | number | Ban duration in seconds |
Quick Action Examples
Auto Reply
Reply with Mention
Delete and Ban
Event Types
Message Events
Notice Events
Request Events
Multiple Webhooks
You can configure multiple webhook endpoints:Error Handling
NapCat logs errors if webhook delivery fails:Webhook Server Best Practices
- Return responses quickly - NapCat may timeout on slow responses
- Handle errors gracefully - Log errors but don’t crash
- Verify signatures - Always verify HMAC signatures in production
- Process asynchronously - Handle heavy operations in background tasks
- Monitor uptime - NapCat doesn’t retry failed deliveries
Testing Your Webhook
Using ngrok for Local Testing
Manual Testing
Send a test POST request:Implementation Details
The HTTP client adapter is implemented inpackages/napcat-onebot/network/http-client.ts:
- Uses HMAC-SHA1 for request signing
- Sends
X-Self-IDheader with bot’s QQ number - Supports quick action responses
- Asynchronous event delivery with error logging
Webhook vs WebSocket
| Feature | HTTP Webhook | WebSocket |
|---|---|---|
| Direction | One-way (push only) | Bidirectional |
| Connection | Request per event | Persistent connection |
| API Calls | Via separate HTTP/WS | Through same connection |
| Latency | Higher | Lower |
| Setup | Simpler | More complex |
| Use Case | Simple bots, logging | Real-time apps |
Security Considerations
- Use HTTPS - Encrypt webhook traffic in production
- Verify signatures - Always check X-Signature header
- Restrict access - Use firewall rules to limit webhook endpoint access
- Rotate tokens - Change tokens periodically
- Log suspicious activity - Monitor for invalid signatures
Troubleshooting
Events Not Received
- Check that the HTTP client is enabled:
"enable": true - Verify the webhook URL is correct and accessible
- Check server logs for connection errors
- Test the endpoint with curl
Signature Verification Fails
- Ensure token matches exactly on both sides
- Verify you’re hashing the raw request body
- Check character encoding (use UTF-8)
- Compare generated signature with received one
Quick Actions Not Working
- Return actions in response within reasonable timeout
- Check response format matches expected structure
- Look for errors in NapCat debug logs
- Verify the event type supports the quick action
Next Steps
- Learn about WebSocket connections for bidirectional communication
- Explore HTTP API for making API calls
- Check API reference for available actions
- Read troubleshooting guide for common issues
