WasenderApi - Low Cost WhatsApp API for Developers Webhook Setup - API Documentation - WasenderApi - Low Cost WhatsApp API for Developers
WasenderApi API

API Documentation

WasenderApi WhatsApp API

Webhook Setup

Webhooks

POST/your-webhook-url

How to set up and verify webhooks to receive real-time events.

Webhook Setup

Webhooks allow your application to receive real-time notifications about events happening in your WhatsApp session, such as receiving messages, message status updates, or session status changes.

Configuration:

  1. Go to your WhatsApp Session settings in the Wasender dashboard.
  2. Enter your publicly accessible webhook URL in the 'Webhook URL' field. This URL must be HTTPS.
  3. Optionally, generate and save a 'Webhook Secret'. This secret is used to verify that incoming requests are genuinely from Wasender.
  4. Enable the specific events you want to subscribe to.
  5. Save your changes.

Verification:

It's crucial to verify that incoming webhook requests originate from Wasender. Check if the X-Webhook-Signature header in the request matches your stored Webhook Secret.

Always respond to webhook requests with a 200 OK status code quickly to acknowledge receipt, even if you process the event asynchronously.

Parameters

NameTypeRequiredDescription
X-Webhook-SignaturestringYesSecret key used to verify the webhook came from WasenderApi.
Content-TypestringYesShould be `application/json`.

Code Examples

// Example webhook endpoint in Express.js
const express = require('express');
const crypto = require('crypto');
const app = express();

app.use(express.json());

// Verify webhook signature to ensure it's from WasenderApi
function verifySignature(req) {
    const signature = req.headers['x-webhook-signature'];
    const webhookSecret = 'YOUR_WEBHOOK_SECRET'; // Store securely
    if (!signature || !webhookSecret || signature !== webhookSecret) return false;
    return true;
}

app.post('/webhook', (req, res) => {
    if (!verifySignature(req)) {
        return res.status(401).json({ error: 'Invalid signature' });
    }

    const payload = req.body;
    console.log('Received webhook event:', payload.event);

    // Handle different event types (e.g., message.sent, session.status)
    switch (payload.event) {
        case 'messages.upsert':
            console.log('New message received:', payload.data.key.id);
            // Process the incoming message
            break;
        // Add other cases
    }

    res.status(200).json({ received: true });
});

app.listen(3000, () => {
    console.log('Webhook server listening on port 3000');
});