# Send customer data with a webhook

> Send customer data from a Roddely automation to your CRM by webhook: set up a destination, verify each signature, and handle retries without duplicate leads.

This guide is for the developer connecting a store's own endpoint (a CRM, a script, or any system that accepts HTTPS requests) so it receives customer data from a Roddely automation.

## How it works [#how-it-works]

1. In the **Send customer data** automation, add a destination with a name and an HTTPS URL. Roddely creates a signing secret and shows it **only once**, when you save.
2. Choose **First customer message** to send once per conversation, or **Every customer message** to get a notification with every incoming message.
3. You can send a test event of type `webhook.test.v1` and follow the latest deliveries from the same destination step.

Each destination has one URL. Whatever condition triggers sending customer data, the first notification for a customer at a destination is `lead.created.v1`, and every notification after it is `lead.updated.v1` with the same `data.leadId`. An update means the customer messaged you again, not that their personal details changed.

Notifications fire even when your team has taken over the conversation or AI replies are paused. They don't change who replies, they don't include your team's or the AI's replies, and they don't send message content or attachments. Every message gets its own notification, even when the customer sends several messages quickly.

The **Every customer message** option is available only in the Send customer data automation. If you have a first-message automation for the same destination and want ongoing notifications, change its condition instead of leaving both running. Turning the automation on doesn't resend old messages; notifications start with new messages while it's on. Turning it off stops new notifications, but notifications saved before you turned it off keep their delivery attempts going.

First-message automations and message-matching conditions follow the same rule: if the destination already knows the customer, the notification is `lead.updated.v1` with the same `data.leadId`. If more than one automation fires for the same customer, you may get more than one notification, but the customer is created only once. Old saved notifications keep their original type. `webhook.test.v1` is sent only from the **Test** button and carries no customer data.

## Set up the destination in the dashboard [#set-up-the-destination-in-the-dashboard]

Open **Automations** and create a new automation, then:

1. Choose **Send customer data**.
2. Name the automation and set when it runs.
3. In the **Destination** step, enter the system's name and the HTTPS URL.
4. Save the secret as soon as it appears; you can't view it again.
5. Press **Test** and make sure the result is successful before you turn the automation on.

If you lose the secret or change the URL, delete the destination and create a new one. Editing an existing URL or rotating the secret on its own isn't available at the moment.

## The request Roddely sends [#the-request-roddely-sends]

```http
POST <destination URL>
content-type: application/json
x-roddely-event: lead.created.v1
x-roddely-event-id: <event id, the same value on every retry>
x-roddely-timestamp: <unix seconds>
x-roddely-signature: v1=<hex HMAC-SHA256 of `${timestamp}.${body}` under your destination secret>
```

An illustrative example for a WhatsApp customer, with numbers and IDs for illustration only. The first message under the **Every customer message** condition:

```json
{
  "id": "evt_001",
  "type": "lead.created.v1",
  "occurredAt": "2026-09-08T10:00:00.000Z",
  "data": {
    "leadId": "lead_abc123",
    "conversationId": "conv_456",
    "automationId": "auto_789",
    "customer": {
      "channel": "whatsapp",
      "externalId": "201012345678",
      "externalIdKind": "phone_number",
      "phone": "201012345678",
      "displayName": "Ahmed Hassan"
    }
  }
}
```

The same customer sent a second message five minutes later. Here the `x-roddely-event` header is `lead.updated.v1` and `x-roddely-event-id` is `evt_002`:

```json
{
  "id": "evt_002",
  "type": "lead.updated.v1",
  "occurredAt": "2026-09-08T10:05:00.000Z",
  "data": {
    "leadId": "lead_abc123",
    "conversationId": "conv_456",
    "automationId": "auto_789",
    "customer": {
      "channel": "whatsapp",
      "externalId": "201012345678",
      "externalIdKind": "phone_number",
      "phone": "201012345678",
      "displayName": "Ahmed Hassan"
    }
  }
}
```

What the fields mean:

* `data.leadId` is the customer's stable ID at this destination; use it to update the same lead. A customer known by the same channel ID in a new conversation is still an update, and a new destination receives a create the first time. There is no automatic merge between a WhatsApp customer and a customer on another channel.

* `occurredAt` is the time of the customer's message in every-message notifications, not the time of the webhook delivery attempt.

* `id` is the notification's ID: different for every message and the same if the same notification is sent again. Don't use it as the customer's ID.

* Requests can arrive out of order because of retries; upsert by `leadId` even if the update arrives before the create, and update "last contact" only with the latest `occurredAt`.

* Old notifications saved before updates were added may arrive without `leadId`, with the same old body. Customers already sent are treated as known when updates are turned on; their first historical event serves as the lead's ID. If there are no saved historical notifications, the first new notification is where tracking starts.

* `channel` is one of `whatsapp`, `instagram`, `messenger`, `telegram` or `web`.

* `externalId` is always present, but it belongs to the channel and isn't a phone number unless `externalIdKind` says so.

* `externalIdKind` is sent only with WhatsApp, and its value is `phone_number`, `business_scoped_user_id` or `linked_device_id`. The only value you can call as a number is `phone_number`.

* `phone` and `displayName` are left out entirely when Roddely has no real value; they're never sent as `null` or an empty string. Don't let a missing field wipe a good value in your CRM.

* With `channel: "web"`, `externalId` is empty on purpose, because a widget conversation has no provider identity. In that case Roddely uses the conversation as the identity boundary, so a new visit in a new conversation is a new lead.

* Message content isn't sent, and Roddely never guesses a number, a name or a profile link.

* `type` is versioned. A new field may be added within `lead.created.v1`, but any breaking change gets a new event such as `lead.created.v2`.

The `webhook.test.v1` test event uses the same headers and the same signature, and its body holds only `{ id, type, occurredAt }`, with no `data`.

## Verify the signature before you use the data [#verify-the-signature-before-you-use-the-data]

1. Read `x-roddely-timestamp` as Unix seconds, and reject the request if it differs from your server clock by more than **5 minutes**.
2. Compute `HMAC-SHA256("${timestamp}.${rawBody}")` with the destination's secret, and compare the result in constant time with the hex after `v1=` in `x-roddely-signature`.
3. Use **the raw request body bytes**, not JSON that was parsed and turned back into text; key order or whitespace can change and break the signature.
4. Use `x-roddely-event-id` as a stable dedup key. Store it in durable storage with a unique constraint before any side effect, and if you see it again, treat it as the same event. An in-memory Set isn't enough, because it's lost when the server restarts.
5. Return `2xx` as soon as you've stored the event durably, then do the slow work. Roddely doesn't read the response body and waits only **10 seconds**; if you're late, it closes the attempt and retries with the same event id.

A Node.js example:

```js
import crypto from "node:crypto"

function isValidRoddelySignature(headers, rawBody, secret) {
  const timestamp = Number(headers["x-roddely-timestamp"])
  if (!Number.isFinite(timestamp) || Math.abs(Date.now() / 1000 - timestamp) > 300) {
    return false
  }
  const expected = crypto
    .createHmac("sha256", secret)
    .update(`${timestamp}.${rawBody}`)
    .digest("hex")
  const provided = String(headers["x-roddely-signature"]).replace(/^v1=/, "")
  return (
    expected.length === provided.length &&
    crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(provided))
  )
}
```

## Retries and failures [#retries-and-failures]

Retries start once the notification is saved in the delivery queue. If an internal error happens while recording an **Every customer message** notification, the customer's message stays saved, but that notification is skipped with no automatic re-recording.

| What happened                                   | Result                    | What Roddely does                                                                        |
| ----------------------------------------------- | ------------------------- | ---------------------------------------------------------------------------------------- |
| A `2xx` response                                | `delivered`               | The only success; the response body isn't read                                           |
| `429`, `5xx`, a timeout or a connection failure | `retrying` then `blocked` | Exponential backoff: 30s, 1m, 2m, 4m, 8m, 16m, 32m across 8 attempts, capped at one hour |
| A DNS failure                                   | `retrying` then `blocked` | A temporary failure, with the same backoff                                               |
| Any other `4xx`                                 | `blocked` right away      | No automatic retry, because waiting won't fix a permanent rejection                      |
| A `3xx` redirect                                | `blocked` right away      | Roddely doesn't follow redirects                                                         |
| The URL resolved to a blocked address           | `blocked` right away      | The request isn't sent                                                                   |

A `blocked` delivery isn't thrown away. Once you've fixed the endpoint, open the delivery log from the destination step in the dashboard and press **Try again** to put it back in the queue with a fresh attempt count.

## Security [#security]

* HTTPS is required, and the URL is checked when you save it and before every attempt.
* Roddely resolves DNS again before every delivery, and blocks private, internal and metadata-service addresses. If a domain was public and later starts pointing at an internal address, the next attempt is refused.
* The connection is pinned to the addresses that were checked, so a DNS change between the check and the connection can't get past the protection.
* Any redirect is refused rather than followed.
* The destination URL, host and secret never appear in Roddely's logs or error messages.

## Receiver checklist [#receiver-checklist]

* Read the raw body before JSON parsing.
* Reject a timestamp more than 5 minutes old or ahead.
* Verify the HMAC signature in constant time.
* Store the event id under a unique constraint before any side effect.
* Return `2xx` quickly after the durable save, and continue processing after that.
* Don't assume `externalId` is a phone number.
* Treat a missing optional field as "information not available", not as an instruction to erase old data.

Once your receiver passes the test, go back to the **Automations** page and turn on the automation that uses the destination.
