# Templates

Ready-made messages to copy: server alert, deploy, order, daily report and invoice.

Ready-made messages for a channel. Each template looks here the way it does in Packlets, and you can try out toggles, buttons, and inputs right away.

Here is how to use a template: copy the JSON, send it with `POST /v1/push`, and adapt texts and IDs to your tool. How that works is explained at the very bottom under [Sending](#sending). What the individual fields mean is covered under [Buttons](https://packlets.app/en/docs/knoepfe.md) and [Elements](https://packlets.app/en/docs/elemente.md).

## Server not responding

Your uptime check notices that a service is down. The alert comes with sound, even during quiet hours. One button restarts the service, the second opens the status page.

```json
{
  "title": "shop-api not responding",
  "text": "No health check since **9:38 AM**. Last status: 502.",
  "priority": "high",
  "elements": [
    {
      "type": "table", "id": "checks", "label": "Recent checks",
      "columns": ["Time", "Status", "ms"],
      "rows": [["9:36", "200", 182], ["9:37", "200", 240], ["9:38", "502", 30012], ["9:39", "502", 30008]]
    }
  ],
  "buttons": [
    { "id": "restart", "label": "Restart" },
    { "id": "status", "label": "Status", "url": "https://status.example.com" }
  ]
}
```

When you tap **Restart**, your webhook gets the `button` event with `button_id: "restart"`.

## Deploy failed

Your CI reports a red build. The table shows which tests fail. You can tap the **Run again** button several times, unlike a button in the `buttons` field.

```json
{
  "title": "Deploy failed",
  "text": "**shop-api** on `main`, commit a3f9c21 by Jonas.",
  "priority": "high",
  "elements": [
    {
      "type": "table", "id": "tests", "label": "Failed tests",
      "columns": ["Test", "Duration"],
      "rows": [["checkout › coupon", "1.2 s"], ["checkout › shipping", "0.8 s"]]
    },
    { "type": "button", "id": "retry", "label": "Run again", "width": 3 },
    { "type": "button", "id": "rollback", "label": "Roll back", "style": "secondary", "width": 3 }
  ],
  "buttons": [
    { "id": "log", "label": "Open log", "url": "https://ci.example.com/runs/4711" }
  ]
}
```

## New order

Your shop reports every order. The button marks it as shipped, the link opens it in the back office.

```json
{
  "title": "New order #1049",
  "text": "Tim R. from Leipzig, **€129.00**, paid with PayPal.",
  "elements": [
    {
      "type": "table", "id": "artikel",
      "columns": ["Item", "Qty", "€"],
      "rows": [["Classic coffee grinder", 1, 99], ["Espresso beans 1 kg", 2, 15]]
    }
  ],
  "buttons": [
    { "id": "shipped", "label": "Shipped" },
    { "id": "open", "label": "Open", "url": "https://shop.example.com/admin/orders/1049" }
  ]
}
```

## Daily report

A cron job sends yesterday's numbers every morning. With `priority: "silent"`, it arrives without sound.

```json
{
  "title": "Daily report",
  "text": "## Yesterday\n- **23 orders**, €1,204 revenue\n- 3 deploys, all successful\n- Backup finished at 3:00",
  "priority": "silent",
  "elements": [
    {
      "type": "chart", "id": "umsatz", "label": "Revenue this week", "unit": "€", "height": 160,
      "points": [
        { "label": "Thu", "value": 1310 }, { "label": "Fri", "value": 1580 }, { "label": "Sat", "value": 720 },
        { "label": "Sun", "value": 640 }, { "label": "Mon", "value": 860 }, { "label": "Tue", "value": 1204 }
      ]
    }
  ]
}
```

## Approve an invoice

A new invoice is waiting for your approval. Two buttons decide, the input sends a follow-up question to your tool. If you have to review many invoices in a row, a [custom app](https://packlets.app/en/docs/apps.md) is more convenient.

```json
{
  "title": "Invoice from Hosting GmbH",
  "text": "**€189.00**, due Nov 20. Service: server November.",
  "elements": [
    {
      "type": "input", "id": "frage", "label": "Question for accounting",
      "placeholder": "e.g. Why more expensive than in October?", "button": "Ask"
    }
  ],
  "buttons": [
    { "id": "approve", "label": "Approve" },
    { "id": "reject", "label": "Reject" },
    { "id": "pdf", "label": "PDF", "url": "https://example.com/invoices/2026-118.pdf" }
  ]
}
```

## Sending

Save the JSON of a template as `template.json` and send it as a message:

```bash
curl https://api.packlets.app/v1/push \
  -H "Authorization: Bearer $PACKLETS_KEY" \
  -H "Content-Type: application/json" \
  -d @template.json
```

```python
import json, os, requests

with open("template.json") as f:
    requests.post("https://api.packlets.app/v1/push", timeout=10, json=json.load(f),
                  headers={"Authorization": f"Bearer {os.environ['PACKLETS_KEY']}"}).raise_for_status()
```

```typescript
import template from "./template.json" with { type: "json" };

const res = await fetch("https://api.packlets.app/v1/push", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.PACKLETS_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify(template),
});
if (!res.ok) throw new Error(`Packlets ${res.status}: ${await res.text()}`);
```

After that, every tap on a button arrives as a `button` webhook event, and every use of an element as a `ui` event, both with the message's `message_id`. How your tool reacts is covered under [Set up a webhook](https://packlets.app/en/docs/webhook.md#5-react-to-events).
