Webhooks
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. 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
Section titled “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.
import express from "express";import { Webhook } from "standardwebhooks";
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);package main
import ( "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))}<?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);use Illuminate\Support\Facades\Route;
Route::dimmiWebhooks('webhooks/dimmi');<?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.
import os
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)Install standardwebhooks from npm for Node.js, or use our Go, PHP, Laravel, or Python SDK.
Rotate a signing secret
Section titled “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), set overlap_seconds between 0 and 604800 (7 days). Passing 0 (the default) expires the old secret right away.