# Elements in messages

Toggles, inputs, charts and tables right inside a message.

A message can hold more than text and buttons: a button, a toggle, an input, a chart, a table. These elements only exist in messages.

**You need:** [Send a message](https://packlets.app/en/docs/senden.md). For elements people can use, you also need a [webhook](https://packlets.app/en/docs/webhook.md).

## Sending elements

Elements go in the `elements` field, up to 12 per message. Each one has a `type` and an `id` that is unique within the message:

```bash
curl https://api.packlets.app/v1/push \
  -H "Authorization: Bearer $PACKLETS_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Error rate after deploy",
    "text": "Since deploy v2.14, 6% of requests fail.",
    "elements": [
      {"type": "button", "id": "rollback", "label": "Roll back to v2.13"},
      {"type": "toggle", "id": "auto_deploy", "label": "Automatic deploys", "value": true},
      {"type": "chart", "id": "fehler", "label": "Error rate", "unit": "%", "chart": "line",
       "points": [{"label": "9:00", "value": 0.2}, {"label": "10:00", "value": 6.2}]}
    ]
  }'
```

```python
import os, requests

requests.post("https://api.packlets.app/v1/push", timeout=10,
              headers={"Authorization": f"Bearer {os.environ['PACKLETS_KEY']}"},
              json={"title": "Error rate after deploy",
                    "text": "Since deploy v2.14, 6% of requests fail.",
                    "elements": [
                        {"type": "button", "id": "rollback", "label": "Roll back to v2.13"},
                        {"type": "toggle", "id": "auto_deploy", "label": "Automatic deploys", "value": True},
                        {"type": "chart", "id": "fehler", "label": "Error rate", "unit": "%", "chart": "line",
                         "points": [{"label": "9:00", "value": 0.2}, {"label": "10:00", "value": 6.2}]},
                    ]}).raise_for_status()
```

```typescript
await fetch("https://api.packlets.app/v1/push", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.PACKLETS_KEY}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    title: "Error rate after deploy",
    text: "Since deploy v2.14, 6% of requests fail.",
    elements: [
      { type: "button", id: "rollback", label: "Roll back to v2.13" },
      { type: "toggle", id: "auto_deploy", label: "Automatic deploys", value: true },
      { type: "chart", id: "fehler", label: "Error rate", unit: "%", chart: "line",
        points: [{ label: "9:00", value: 0.2 }, { label: "10:00", value: 6.2 }] },
    ],
  }),
});
```

Which elements exist and which fields they have is covered in the [Elements](https://packlets.app/en/docs/elemente.md) reference.

## Reacting to taps

When you tap the button, flip the toggle or submit an input, your webhook gets the `ui` event:

```json
{
  "type": "ui",
  "packlet_id": "9d2f7c10-3a5b-4c8e-9f21-6b7d8e9f0a12",
  "message_id": "5b0c1a52-7c1e-4a43-9d0b-2f6f0c7d1e11",
  "element_id": "auto_deploy",
  "value": false,
  "changed_at": "2026-11-10T18:00:00.000Z"
}
```

`element_id` tells you which element it was, `value` is the new value. For a button, `value` is `null`. `message_id` tells you which message the action came from.

How your tool receives the event is covered in [Set up a webhook](https://packlets.app/en/docs/webhook.md).

## Buttons or elements

| | [Buttons](https://packlets.app/en/docs/knoepfe.md) (`buttons`) | Elements (`elements`) |
|---|---|---|
| How often they can be used | once per message | as often as you like |
| What they can do | open a link or send an action | button, toggle, input, plus chart, table, text |
| The message shows afterwards | which button was chosen | the current state, for example the toggle |

You can use both in the same message.

## Good to know

- **You can't change them afterwards.** Values in a message only change when you use them in the app. Your tool can't update them. Send a new message instead. If you need a view that is always up to date, build your own [app](https://packlets.app/en/docs/apps.md).
- **It's narrow.** A message is narrower than the screen. Ideally leave elements at full width (no `width`) and keep labels short. More in [Element layout](https://packlets.app/en/docs/layout.md).
- **Ready-made examples** to copy are in [Templates](https://packlets.app/en/docs/vorlagen.md).
- **In the push**, only the text appears. You only see elements in the app.
