Skip to main content

Webhooks

Complete guide to Netasampark webhooks for real-time event notifications.

Overview

Webhooks allow you to receive real-time notifications when events occur in the Netasampark platform. This enables you to integrate Netasampark with your own systems and applications.

Available Events

Message Events

  • message.sent - Message was sent
  • message.delivered - Message was delivered
  • message.failed - Message delivery failed
  • message.read - Message was read (WhatsApp only)

Grievance Events

  • grievance.created - New grievance created
  • grievance.updated - Grievance status updated
  • grievance.resolved - Grievance resolved

Payment Events

  • payment.processed - Payment processed
  • payment.failed - Payment failed
  • payment.refunded - Payment refunded

Campaign Events

  • campaign.started - Campaign started
  • campaign.completed - Campaign completed
  • campaign.failed - Campaign failed

Setting Up Webhooks

1. Configure Webhook URL

Navigate to SettingsWebhooks in the admin panel and add your webhook URL.

2. Select Events

Choose which events you want to receive notifications for.

3. Verify Webhook

The system will send a verification request to your URL. Respond with the verification token.

Webhook Payload

All webhooks send POST requests with JSON payloads:

{
"event": "message.delivered",
"timestamp": "2024-01-01T00:00:00Z",
"data": {
"message_id": "msg_123",
"channel": "whatsapp",
"to": "+919876543210",
"status": "delivered"
}
}

Security

Signature Verification

All webhook requests include a signature header for verification:

X-Netasampark-Signature: sha256=...

Verify the signature using your webhook secret:

const crypto = require('crypto');

function verifySignature(payload, signature, secret) {
const hash = crypto
.createHmac('sha256', secret)
.update(JSON.stringify(payload))
.digest('hex');

return hash === signature.replace('sha256=', '');
}

Handling Webhooks

Example Implementation

app.post('/webhooks/netasampark', (req, res) => {
const signature = req.headers['x-netasampark-signature'];
const payload = req.body;

// Verify signature
if (!verifySignature(payload, signature, WEBHOOK_SECRET)) {
return res.status(401).send('Invalid signature');
}

// Handle event
switch (payload.event) {
case 'message.delivered':
handleMessageDelivered(payload.data);
break;
case 'grievance.created':
handleGrievanceCreated(payload.data);
break;
// ... other events
}

res.status(200).send('OK');
});

Retry Logic

If your webhook endpoint returns a non-2xx status code, Netasampark will retry:

  • Retry Schedule: 1 minute, 5 minutes, 15 minutes, 1 hour
  • Max Retries: 4 attempts
  • Timeout: 30 seconds

Best Practices

  1. Verify Signatures: Always verify webhook signatures
  2. Idempotency: Handle duplicate events gracefully
  3. Fast Response: Respond quickly (within 5 seconds)
  4. Error Handling: Log errors for debugging
  5. HTTPS Only: Use HTTPS for webhook endpoints

Testing Webhooks

Use the webhook testing tool in the admin panel to send test events to your endpoint.

Next Steps


Need help? Contact Support