# Verify webhook signatures

Verify Standard Webhooks signatures from dimmi in Node.js, Go, PHP, Laravel, or Python, and rotate signing secrets safely.

dimmi signs every webhook delivery using [Standard Webhooks](https://www.standardwebhooks.com). Copy your endpoint's signing secret from **Settings → Webhooks**.

| Header | Contents |
| --- | --- |
| `webhook-id` | The event `id`. |
| `webhook-timestamp` | Unix timestamp (seconds) when dimmi sent this attempt. |
| `webhook-signature` | `v1,` followed by a base64 HMAC-SHA256 of `<webhook-id>.<webhook-timestamp>.<body>`. |

## Check signatures on your server

Always pass the raw request body before parsing JSON. Each library rejects timestamps more than 5 minutes away from your server clock.

<Tabs>
<TabItem label="Node.js">

```js title="server.js"

const app = express();
const webhook = new Webhook(process.env.DIMMI_WEBHOOK_SECRET);

app.post("/webhooks/dimmi", express.raw({ type: "application/json" }), (req, res) => {
  let event;
  try {
    event = webhook.verify(req.body, req.headers);
  } catch {
    return res.status(400).end();
  }

  console.log(event.type, event.data.object.id);
  res.status(204).end();
});

app.listen(3000);
```

</TabItem>
<TabItem label="Go">

```go title="main.go"
package main

	"log"
	"net/http"
	"os"

	dimmi "github.com/dimmihq/dimmi-go"
)

func main() {
	wh, err := dimmi.NewWebhook(os.Getenv("DIMMI_WEBHOOK_SECRET"))
	if err != nil {
		log.Fatal(err)
	}

	http.Handle("/webhooks/dimmi", wh.Handler(func(r *http.Request, e *dimmi.Event) error {
		log.Println(e.Type, e.ID)
		return nil
	}))

	log.Fatal(http.ListenAndServe(":3000", nil))
}
```

</TabItem>
<TabItem label="PHP">

```php title="webhook.php"
<?php

require __DIR__ . '/vendor/autoload.php';

$webhook = new Dimmi\Webhook(getenv('DIMMI_WEBHOOK_SECRET'));

try {
    $event = $webhook->verify(file_get_contents('php://input'), getallheaders());
} catch (Dimmi\WebhookVerificationException $e) {
    http_response_code(400);
    exit;
}

error_log($event->type . ' ' . $event->id);
http_response_code(204);
```

</TabItem>
<TabItem label="Laravel">

```php title="routes/web.php"
use Illuminate\Support\Facades\Route;

Route::dimmiWebhooks('webhooks/dimmi');
```

```php title="app/Providers/AppServiceProvider.php"
<?php

namespace App\Providers;

use Dimmi\WebhookEvent;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        Event::listen('dimmi.webhook.conversation.created', function (WebhookEvent $event) {
            logger('dimmi', ['conversation' => $event->object()['id']]);
        });
    }
}
```

The route reads `DIMMI_WEBHOOK_SECRET` from `.env` automatically.

</TabItem>
<TabItem label="Python">

```python title="app.py"

from fastapi import FastAPI, Request, Response

from dimmi import Webhook, WebhookVerificationError

app = FastAPI()
webhook = Webhook(os.environ["DIMMI_WEBHOOK_SECRET"])

@app.post("/webhooks/dimmi")
async def receive(request: Request) -> Response:
    try:
        event = webhook.verify(await request.body(), request.headers)
    except WebhookVerificationError:
        return Response(status_code=400)

    print(event.type, event.object["id"])
    return Response(status_code=204)
```

</TabItem>
</Tabs>

Install `standardwebhooks` from npm for Node.js, or use our [Go](/developers/sdks/go/), [PHP](/developers/sdks/php/), [Laravel](/developers/sdks/laravel/), or [Python](/developers/sdks/python/) SDK.

## Rotate a signing secret

Click **Rotate** on the endpoint's page in dimmi. For 24 hours, dimmi signs every delivery with both the old and new secrets so you can deploy without downtime.

Through the API ([Create webhook endpoint secret rotation](/api-reference/webhooks/create-webhook-endpoint-secret-rotation/)), set `overlap_seconds` between `0` and `604800` (7 days). Passing `0` (the default) expires the old secret right away.

---

Index of all dimmi docs: https://trydimmi.com/llms.txt (full text: https://trydimmi.com/llms-full.txt)
