# Webhooks (/webhooks)



Register an endpoint with `POST /webhooks` and we `POST` a JSON event to it when
something happens. The URL must be `https://` — the payload can carry the text
of your customers' messages, and plain http would send that in the clear.

The response that creates an endpoint is the **only** one that carries the
signing secret in full. Every later read answers with `secret_preview` instead.

<WebhookEvents />

## Incoming messages [#incoming-messages]

`message.received` fires for every message a customer sends you, on WhatsApp
(QR, Chrome extension and Cloud API), SMS and email. Its `data` tells you who
wrote and where:

```json
{
  "object": "conversation_message",
  "id": "cms_9cBe3A1H-SLhW5fONWZ32wb-IIio5Ts3",
  "conversation_id": "cnv_2Kq0hN7a-PbZx1yLw4mT8e-VcR3uJ6s",
  "body": "Halo, pesanan saya belum sampai",
  "created_at": "2026-11-01T09:00:00+07:00",
  "updated_at": "2026-11-01T09:00:00+07:00",
  "channel": "whatsapp",
  "from": "+6281234567890",
  "gateway_id": "gw_9cBe3A1H-SLhW5fONWZ32wb-IIio5Ts3",
  "provider_message_id": "wamid.HBgNNjI4MTIzNDU2Nzg5MBUCABIYFjNFQjA",
  "received_at": "2026-11-01T09:00:00+07:00",
  "subject": null,
  "media": null
}
```

Use `provider_message_id` to skip a message you already handled. `media`, when
present, names the type and file; its `url` is filled when the channel hands
us the file.

### Keep them in SendKuy, or forward them only [#keep-them-in-sendkuy-or-forward-them-only]

By default the message is also kept in the SendKuy inbox, and `id` and
`conversation_id` point at it: you can answer with
`POST /conversations/{id}/reply`.

If your own helpdesk keeps the conversations, turn on **Forward incoming
messages to my webhook only** under Developers › Webhooks. Messages are then
not stored in SendKuy, so `id` and `conversation_id` are `null`; answer with
`POST /messages` to `from`. A forwarded media `url` stays valid for seven days,
so copy the file. A forwarded message your endpoint never accepts, after every
retry, is kept in the inbox instead, and so is everything while no active
endpoint listens to `message.received`.

## Verify with an SDK [#verify-with-an-sdk]

Each SDK checks `X-SendKuy-Signature` for you. Give it the **raw** request body, because re-encoding parsed JSON changes the bytes and the signature stops matching, and the endpoint secret in full, `whsec_` included.

<CodeBlockTabs defaultValue="Node.js">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="Node.js">
      Node.js
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="PHP">
      PHP
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="Laravel">
      Laravel
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="Node.js">
    ```ts
    import { SignatureVerificationError, verifyWebhook } from 'sendkuy';

    export async function POST(request: Request) {
      try {
        const event = await verifyWebhook({
          payload: await request.text(),
          signature: request.headers.get('x-sendkuy-signature'),
          secret: process.env.SENDKUY_WEBHOOK_SECRET ?? '',
        });

        return new Response(null, { status: 200 });
      } catch (error) {
        if (error instanceof SignatureVerificationError) {
          return new Response(null, { status: 403 });
        }

        throw error;
      }
    }
    ```
  </CodeBlockTab>

  <CodeBlockTab value="PHP">
    ```php
    use SendKuy\Exceptions\SignatureVerificationException;
    use SendKuy\Webhook;

    try {
        $event = Webhook::verify(
            file_get_contents('php://input'),
            $_SERVER['HTTP_X_SENDKUY_SIGNATURE'] ?? '',
            (string) getenv('SENDKUY_WEBHOOK_SECRET'),
        );
    } catch (SignatureVerificationException $e) {
        http_response_code(403);
        exit;
    }
    ```
  </CodeBlockTab>

  <CodeBlockTab value="Laravel">
    ```php
    use Illuminate\Support\Facades\Event;
    use SendKuy\Laravel\Events\WebhookReceived;

    Event::listen(function (WebhookReceived $event) {
        // POST /sendkuy/webhook already checked the signature
    });
    ```
  </CodeBlockTab>
</CodeBlockTabs>

With Express, read the body raw with `express.raw({ type: 'application/json' })` and pass `req.body` as `payload`. An empty secret is a configuration mistake, not a bad signature: the SDKs throw `SendKuyError` or `SendKuyException` for it, so it surfaces as a `500` in your delivery history instead of a quiet `403`.

`X-SendKuy-Event-Id` stays the same across every retry of one delivery: store it and skip ids you have seen.
