# Webhooks Dashboard

> Configure and manage webhooks for real-time event notifications.

Source: https://wav1.recrav.com/docs/learn/webhooks

## What Are Webhooks? [#what-are-webhooks]

Webhooks are HTTP callbacks Sendable pushes to your application when subscribed events happen, such as:

* outgoing message status changes
* incoming messages
* session socket connect or disconnect events
* WhatsApp account events: edits, reactions, deletes, group changes and join requests, calls, labels, channels, contacts, account settings, and history sync

This is the recommended way to react to delivery state and inbound traffic without polling.

## Setting Up Webhooks [#setting-up-webhooks]

### Step 1: Create an Endpoint [#step-1-create-an-endpoint]

Your application needs a public HTTPS endpoint that accepts POST requests and preserves the raw body for signature verification.

```typescript
import express from 'express'
import { Sendable } from '@sendable-dev/sdk'

const sendable = new Sendable({
  apiKey: process.env.SENDABLE_API_KEY!,
  apiKeyScope: 'session',
  webhookSecret: process.env.SENDABLE_WEBHOOK_SECRET,
})

app.post('/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
  const payload = req.body.toString()

  try {
    const event = await sendable.webhooks.verifyAndParse(payload, req.headers)
    handleEvent(event).catch(console.error)
    return res.sendStatus(200)
  } catch {
    return res.status(401).send('Invalid signature')
  }
})
```

### Step 2: Add the Webhook in Dashboard [#step-2-add-the-webhook-in-dashboard]

1. Go to your session
2. Open the `Webhooks` tab
3. Click `Add Webhook`
4. Enter your URL
5. Choose subscribed event types
6. Save

### Step 3: Save the Secret [#step-3-save-the-secret]

Every endpoint has a signing secret in the form `whsec_...`. Store it in `SENDABLE_WEBHOOK_SECRET` and never expose it to the browser.

## Event Types [#event-types]

### Message Events [#message-events]

| Event                       | When It Fires                 | Use Case               |
| --------------------------- | ----------------------------- | ---------------------- |
| `message.sent`              | WhatsApp accepted an API send | Track outbound traffic |
| `message.delivered`         | Message delivered             | Confirm delivery       |
| `message.read`              | Recipient read message        | Track engagement       |
| `message.failed`            | API send failed               | Retry or alert         |
| `message.received`          | Direct incoming message       | Store or respond       |
| `message-personal.received` | Personal chat message         | Personal inbox flows   |
| `message-group.received`    | Group or community message    | Group automations      |

### Session Events [#session-events]

| Event                         | When It Fires        | Use Case                  |
| ----------------------------- | -------------------- | ------------------------- |
| `session.socket-connected`    | Session goes online  | Resume sending            |
| `session.socket-disconnected` | Session goes offline | Alert team, pause sending |

### Normalized Events [#normalized-events]

| Event                                                             | When It Fires                                     | Use Case                    |
| ----------------------------------------------------------------- | ------------------------------------------------- | --------------------------- |
| `message.deleted` / `message.edited` / `message.reaction`         | Message revoked, edited, or reacted to            | Keep a mirror in sync       |
| `status.received` / `status.posted`                               | Contact posted a status (opt-in) / you posted one | Status feeds                |
| `chat.upsert` / `chat.updated` / `chat.deleted` / `chat.locked`   | Chat app-state changed                            | Inbox sync                  |
| `group.upserted` / `group.updated` / `group.participants.updated` | Group joined, changed, or membership changed      | Group automations           |
| `group.join-request` / `group.member-tag.updated`                 | Join request or member tag change                 | Approve members, moderation |
| `contact.upserted` / `contact.updated`                            | Contacts synced or changed                        | CRM sync                    |
| `label.edited` / `label.association.updated`                      | Business labels changed                           | CRM pipelines               |
| `call.updated`                                                    | Incoming call status                              | Auto-reject, call logs      |
| `newsletter.*`                                                    | Channel reactions, views, admins, settings        | Channel analytics           |
| `settings.updated` / `message-capping.updated` / `blocklist.*`    | Account settings, caps, blocklist                 | Compliance and limits       |
| `history.synced` / `history.status`                               | History sync progress                             | Know when backfill is done  |

See [Webhook Events](/docs/webhook-events#normalized-events) for payloads. Each one can also be replayed from `GET /v1/events`.

## Security [#security]

### Signature Verification [#signature-verification]

Sendable uses [Standard Webhooks](https://www.standardwebhooks.com) signatures. Requests include:

* `webhook-id`
* `webhook-timestamp`
* `webhook-signature`

The SDK also accepts the older `svix-*` header names.

You should verify against the raw request body before parsing JSON:

```typescript
const payload = req.body.toString()
const event = await sendable.webhooks.verifyAndParse(payload, req.headers)
```

## Best Practices [#best-practices]

### Respond Quickly [#respond-quickly]

Return HTTP 200 after verification and push real work into background jobs when possible.

### Handle Duplicates [#handle-duplicates]

Webhook delivery is at-least-once, so build idempotency around the envelope:

```typescript
async function handleEvent(event) {
  const key = `${event.type}-${event.data.id ?? event.data.sessionId}-${event.createdAt}`

  if (await wasProcessed(key)) {
    return
  }

  await processEvent(event)
}
```

### Log Failures [#log-failures]

```typescript
async function processEvent(event) {
  if (event.type === 'message.failed') {
    console.error('message failed', event.data.id, event.data.status)
  }
}
```

## Use Cases [#use-cases]

### Delivery Tracking [#delivery-tracking]

```typescript
if (event.type === 'message.delivered') {
  await updateOrderStatus(event.data.id, 'delivered')
}
```

### Incoming Chat Automation [#incoming-chat-automation]

```typescript
if (event.type === 'message.received') {
  await saveMessage(event.data)
  await maybeAutoReply(event.data.chatId, event.data.text?.content)
}
```

### Session Monitoring [#session-monitoring]

```typescript
if (event.type === 'session.socket-disconnected') {
  await notifyOps(`Session ${event.data.sessionId} disconnected`)
}
```

## Troubleshooting [#troubleshooting]

### Invalid Signature [#invalid-signature]

* Use the raw body, not `JSON.stringify(req.body)`
* Verify the `whsec_...` secret matches the endpoint in the dashboard
* Make sure body parsing middleware is not running before verification

### Missing Events [#missing-events]

* Confirm the webhook is active
* Confirm the event type is subscribed
* Check delivery logs in the dashboard
