# Webhooks

LoopDesk can call your service when a decision is made, and receive callbacks from external systems.

## Outbound (LoopDesk → you)

Configure a webhook URL per project. On each terminal decision (`approved`, `rejected`, `escalated_final`), LoopDesk POSTs:

```json
{
  "event": "item.decided",
  "item_id": "uuid",
  "project_id": "uuid",
  "status": "approved",
  "decision": { ... },
  "reviewer_id": "uuid",
  "decided_at": "2026-05-20T12:00:00Z"
}
```

Requests are signed with HMAC-SHA256 over the raw body using your project's webhook secret. Verify before processing:

```ts
const expected = createHmac("sha256", secret).update(rawBody).digest("hex");
if (!timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
  return new Response("Invalid signature", { status: 401 });
}
```

## Inbound

Custom inbound webhooks live under `src/routes/api/public/`. Always verify signatures before touching the database — these endpoints are unauthenticated by design.

## Source

* `src/lib/webhooks.functions.ts`
* `src/lib/webhooks.server.ts`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hitl-01.gitbook.io/hitl-docs/api/webhooks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
