Skip to Content
Hookboard

Actions

What buttons and inputs can do, and how the result changes the card.

An action is what happens when someone presses a button, submits an input, or changes a control. It's an object with a type, and it goes on a property that takes an action: a button's onPress, an input's onSubmit, a segmented control's onChange, and so on. The component pages say which properties take one.

A property can hold one action or a list. A list runs in order.

The two kinds

KindTypesWhere it runsUse it to
Server actionswebhook, eventHookboard's serverTell your code something happened
Device actionsset, toggle, increment, append, remove, openUrl, copy, toast, dismissThe device, with no requestChange local state or give instant feedback

Every type and its fields are listed in the Actions reference.

Calling your code: webhook

Hookboard's server sends a signed HTTP request to your url, and your reply can say how the card should change. If your code has a public address, this is the one you want.

{
  "type": "button",
  "label": "Restart",
  "onPress": {
    "type": "webhook",
    "url": "https://your-app.example/hooks/restart",
    "name": "restart",
    "payload": { "server": "{{data.server}}" },
    "confirm": {
      "title": "Restart {{data.server}}?",
      "confirmLabel": "Restart"
    },
    "onSuccess": {
      "type": "toast",
      "message": "Restarting",
      "tone": "success"
    },
    "onError": {
      "type": "toast",
      "message": "Could not reach the server",
      "tone": "danger"
    }
  }
}

See Webhooks for the request, the signature and the reply.

Without a public address: event

An event action stores an event that your code picks up by polling. Nothing from outside has to reach you, so it works fine from behind a firewall or on a laptop.

{
  "type": "button",
  "label": "Run backup",
  "onPress": {
    "type": "event",
    "name": "run-backup",
    "payload": { "target": "db" },
    "onSuccess": { "type": "toast", "message": "Queued" }
  }
}

See Events.

Asking first: confirm

webhook and event take a confirm object. The action only runs if the person says yes.

FieldTypeWhat it is
titlestringThe question. Default "Are you sure?". May contain {{ }}.
descriptionstringA sentence of detail under the title.
confirmLabelstringText of the button that agrees.

What happens afterwards: effects

After a server action, Hookboard applies a list of effects. Which list it uses depends on how things went:

SituationEffects applied
Webhook answered 2xx with an effects list in its JSON bodyThat list
Webhook answered 2xx without oneThe action's onSuccess
Webhook failed, timed out, or answered non-2xxThe action's onError; if there is none, an error message naming your host
Event was queuedThe action's onSuccess

onSuccess and onError accept one effect, a list, or the bare name of an effect that has no fields:

{ "onSuccess": ["dismiss", { "type": "toast", "message": "Done" }] }

Changing the card without a request

Device actions run instantly. This card counts presses and opens a detail panel on demand, without a server anywhere in sight:

{
  "state": { "count": 0, "open": false },
  "ui": {
    "type": "stack",
    "children": [
      { "type": "text", "value": "Pressed {{state.count}} times" },
      {
        "type": "stack",
        "direction": "row",
        "children": [
          {
            "type": "button",
            "label": "Add one",
            "onPress": { "type": "increment", "path": "state.count" }
          },
          {
            "type": "button",
            "label": "Details",
            "variant": "outline",
            "onPress": { "type": "toggle", "path": "state.open" }
          }
        ]
      },
      {
        "type": "text",
        "value": "This stays on the device.",
        "tone": "muted",
        "visibleWhen": "state.open"
      }
    ]
  }
}

On this page