Skip to main content

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

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

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

  1. Return responses quickly - NapCat may timeout on slow responses
  2. Handle errors gracefully - Log errors but don’t crash
  3. Verify signatures - Always verify HMAC signatures in production
  4. Process asynchronously - Handle heavy operations in background tasks
  5. 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 in packages/napcat-onebot/network/http-client.ts:
  • Uses HMAC-SHA1 for request signing
  • Sends X-Self-ID header with bot’s QQ number
  • Supports quick action responses
  • Asynchronous event delivery with error logging

Webhook vs WebSocket

Security Considerations

  1. Use HTTPS - Encrypt webhook traffic in production
  2. Verify signatures - Always check X-Signature header
  3. Restrict access - Use firewall rules to limit webhook endpoint access
  4. Rotate tokens - Change tokens periodically
  5. 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