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
| Kind | Types | Where it runs | Use it to |
|---|---|---|---|
| Server actions | webhook, event | Hookboard's server | Tell your code something happened |
| Device actions | set, toggle, increment, append, remove, openUrl, copy, toast, dismiss | The device, with no request | Change 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.
| Field | Type | What it is |
|---|---|---|
title | string | The question. Default "Are you sure?". May contain {{ }}. |
description | string | A sentence of detail under the title. |
confirmLabel | string | Text 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:
| Situation | Effects applied |
|---|---|
Webhook answered 2xx with an effects list in its JSON body | That list |
| Webhook answered 2xx without one | The action's onSuccess |
| Webhook failed, timed out, or answered non-2xx | The action's onError; if there is none, an error message naming your host |
| Event was queued | The 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"
}
]
}
}