Templates
Template builder
Edit a template and its data, see it drawn the way the app draws it, and get the hub's own validation errors as you type. It all runs in your browser; nothing is sent anywhere.
Examples
The builder needs JavaScript. These are the example templates with their data. Register one with PUT /api/v1/templates/{id}, then send a message with template_id and data, as described in the docs.
Deploys list
A header and a foreach: one row per element of the items array.
{"type":"vstack","spacing":10,"align":"leading","children":[
{"type":"hstack","spacing":8,"children":[
{"type":"symbol","name":"shippingbox.fill","size":20},
{"type":"text","text":"{{title}}","style":"headline"},
{"type":"spacer"},
{"type":"badge","text":"{{env}}"}]},
{"type":"foreach","each":"items","max":5,"spacing":6,"body":
{"type":"hstack","spacing":8,"children":[
{"type":"text","text":"{{item.name}}"},
{"type":"spacer"},
{"type":"text","text":"{{item.status}}","style":"caption"}]}}]}{
"title": "Deploys",
"env": "prod",
"items": [
{"name": "web 4.14.0", "status": "ok"},
{"name": "api 2.9.1", "status": "ok"},
{"name": "worker 1.3.0", "status": "slow"},
{"name": "cron 0.8.2", "status": "ok"}
]
}Order progress
A progress bar bound to a number, a ticking countdown and a badge.
{"type":"vstack","spacing":10,"align":"leading","children":[
{"type":"hstack","spacing":8,"children":[
{"type":"symbol","name":"shippingbox.fill","size":22},
{"type":"text","text":"Order {{order}}","style":"headline"},
{"type":"spacer"},
{"type":"badge","text":"{{status}}","symbol":"truck.box.fill","color":{"light":"#1A7F37","dark":"#4CD964"}}]},
{"type":"progress","value":{"bind":"progress"},"label":"{{step}}"},
{"type":"hstack","spacing":6,"children":[
{"type":"text","text":"Arrives in","style":"footnote"},
{"type":"timer","to":{"bind":"arrives_at"},"style":"footnote"},
{"type":"spacer"},
{"type":"text","text":"{{carrier}}","style":"footnote","color":{"light":"#6C6C70","dark":"#AEAEB2"}}]}]}{
"order": "#48213",
"status": "Out for delivery",
"step": "Packed, shipped, out for delivery",
"progress": 0.75,
"arrives_at": 1795377600,
"carrier": "Parcel Co"
}Incident
A symbol, a severity badge, a gauge and a tint colour for the whole card.
{"type":"vstack","spacing":10,"align":"leading",
"tint":{"light":"#C93400","dark":"#FF9F0A"},"children":[
{"type":"hstack","spacing":10,"align":"leading","children":[
{"type":"symbol","name":"exclamationmark.triangle.fill","size":26},
{"type":"vstack","spacing":2,"children":[
{"type":"text","text":"{{service}}","style":"headline"},
{"type":"text","text":"{{summary}}","style":"footnote","lines":2}]},
{"type":"spacer"},
{"type":"badge","text":"{{severity}}"}]},
{"type":"gauge","value":{"bind":"error_rate"},"min":0,"max":100,"label":"Error rate {{error_rate}}%"},
{"type":"text","text":"Started {{started}} · {{responders}} responders","style":"caption"}]}{
"service": "payments-api",
"summary": "Checkout requests fail with 502 from the eu-west gateway.",
"severity": "SEV2",
"error_rate": 37.5,
"started": "14:02",
"responders": 3
}On-call card
Padding, a filled panel, text weight, a divider, and if to leave things out.
{"type":"vstack","spacing":10,"align":"leading",
"tint":{"light":"#0A84FF","dark":"#64D2FF"},"children":[
{"type":"hstack","spacing":8,"children":[
{"type":"symbol","name":"phone.badge.waveform.fill","size":20},
{"type":"text","text":"{{title}}","style":"headline","weight":"bold","lines":2},
{"type":"spacer","min":8},
{"type":"badge","text":"{{severity}}","if":"severity",
"color":{"light":"#C93400","dark":"#FF9F0A"}}]},
{"type":"vstack","spacing":2,"padding":12,"radius":12,"align":"leading","if":"primary.name",
"background":{"light":"#FFFFFF","dark":"#3A3A3C"},"children":[
{"type":"text","text":"On call now","style":"caption","weight":"medium",
"color":{"light":"#6C6C70","dark":"#AEAEB2"}},
{"type":"text","text":"{{primary.name}}","style":"headline","weight":"semibold"},
{"type":"text","text":"{{primary.phone}} · until {{primary.until}}","style":"footnote",
"color":{"light":"#6C6C70","dark":"#AEAEB2"}}]},
{"type":"text","text":"Nobody is on call","weight":"medium","if":"!primary.name",
"color":{"light":"#C93400","dark":"#FF9F0A"}},
{"type":"divider"},
{"type":"text","text":"Then","style":"caption","weight":"semibold",
"color":{"light":"#6C6C70","dark":"#AEAEB2"}},
{"type":"foreach","each":"escalation","max":4,"spacing":6,"body":
{"type":"hstack","spacing":6,"children":[
{"type":"text","text":"{{item.name}}","style":"footnote","weight":"medium"},
{"type":"text","text":"away","style":"caption","if":"!item.available",
"color":{"light":"#6C6C70","dark":"#AEAEB2"}},
{"type":"spacer"},
{"type":"badge","text":"{{item.channel}}","if":"item.channel"}]}}]}{
"title": "Payments API is down",
"severity": "SEV1",
"primary": {"name": "Ada Okafor", "phone": "+49 30 1234 5678", "until": "Mon 08:00"},
"escalation": [
{"name": "Ben Ruiz", "channel": "SMS", "available": true},
{"name": "Chi Tan", "channel": "Call"},
{"name": "Dara Vos", "channel": "Push"}
]
}Examples
A header and a foreach: one row per element of the items array.
Valid · 11 nodes
# register the template (the version must increase)
curl -X PUT https://hub.example.com/api/v1/templates/deploys \
-H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
-d '{"version":1,"body":{"type":"vstack","spacing":10,"align":"leading","children":[{"type":"hstack","spacing":8,"children":[{"type":"symbol","name":"shippingbox.fill","size":20},{"type":"text","text":"{{title}}","style":"headline"},{"type":"spacer"},{"type":"badge","text":"{{env}}"}]},{"type":"foreach","each":"items","max":5,"spacing":6,"body":{"type":"hstack","spacing":8,"children":[{"type":"text","text":"{{item.name}}"},{"type":"spacer"},{"type":"text","text":"{{item.status}}","style":"caption"}]}}]}}'# send a message that renders with it
curl -X POST https://hub.example.com/api/v1/messages \
-H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
-d '{"external_user_id":"user-42","channel":"ops","template_id":"deploys","title":"Deploys","body":"See the details","data":{"title":"Deploys","env":"prod","items":[{"name":"web 4.14.0","status":"ok"},{"name":"api 2.9.1","status":"ok"},{"name":"worker 1.3.0","status":"slow"},{"name":"cron 0.8.2","status":"ok"}]}}'You write Hansho templates: JSON that draws a notification, Live Activity or widget on an iPhone from the data of a message.
Reply with one JSON template only, no prose.
Rules
- The root is a vstack or hstack. Every node is {"type": ...}. Unknown properties are errors.
- Placeholders {{a.b.0.c}} read the message data (dot path, numeric array indexes); a missing value renders empty.
- "if": "path" or "!path" on any node drops it unless the value is truthy (falsy with !).
- foreach {"each": "path", "body": node} repeats body per array item; inside, {{item}}, {{item.field}}, {{index}}. No foreach inside foreach.
- Numbers may be a literal or {"bind": "path"}. Colors are {"light": "#RRGGBB", "dark": "#RRGGBB"}.
- Root only: tint and background (colors). Nested stacks may also have background.
- Limits: depth 8, 64 nodes, 512 characters per text, 16 placeholders per string.
- symbol.name is an SF Symbol. image.url is https or a pure {{path}}.
Components and their properties
- vstack, hstack: children (required), spacing 0-64, align leading/center/trailing, padding 0-32, radius 0-32, background (nested stacks; the root's is the card background)
- divider: color (a 1 pt hairline across the stack it sits in)
- spacer: min 0-256
- text: text (at most 512 characters), style largeTitle/title/headline/body/caption/footnote, color, lines 1-10, align leading/center/trailing, weight regular/medium/semibold/bold
- symbol: name (SF Symbol), color, size 8-96
- image: url (https), width 0-512, height 0-512, fit fill/fit, radius 0-64
- progress: value 0-1, color, label
- gauge: value, min, max, label, color
- timer: to (unix seconds), mode countdown/countup, style largeTitle/title/headline/body/caption/footnote, color
- badge: text, color, symbol
- foreach: each (data path to an array, required), max 1-12, axis vertical/horizontal, spacing 0-64, body (one node, required)
Example template
```json
{"type":"vstack","spacing":10,"align":"leading","children":[
{"type":"hstack","spacing":8,"children":[
{"type":"symbol","name":"shippingbox.fill","size":20},
{"type":"text","text":"{{title}}","style":"headline"},
{"type":"spacer"},
{"type":"badge","text":"{{env}}"}]},
{"type":"foreach","each":"items","max":5,"spacing":6,"body":
{"type":"hstack","spacing":8,"children":[
{"type":"text","text":"{{item.name}}"},
{"type":"spacer"},
{"type":"text","text":"{{item.status}}","style":"caption"}]}}]}
```
Its data
```json
{
"title": "Deploys",
"env": "prod",
"items": [
{"name": "web 4.14.0", "status": "ok"},
{"name": "api 2.9.1", "status": "ok"},
{"name": "worker 1.3.0", "status": "slow"},
{"name": "cron 0.8.2", "status": "ok"}
]
}
```
My current template:
```json
{"type":"vstack","spacing":10,"align":"leading","children":[
{"type":"hstack","spacing":8,"children":[
{"type":"symbol","name":"shippingbox.fill","size":20},
{"type":"text","text":"{{title}}","style":"headline"},
{"type":"spacer"},
{"type":"badge","text":"{{env}}"}]},
{"type":"foreach","each":"items","max":5,"spacing":6,"body":
{"type":"hstack","spacing":8,"children":[
{"type":"text","text":"{{item.name}}"},
{"type":"spacer"},
{"type":"text","text":"{{item.status}}","style":"caption"}]}}]}
```
My message data:
```json
{
"title": "Deploys",
"env": "prod",
"items": [
{"name": "web 4.14.0", "status": "ok"},
{"name": "api 2.9.1", "status": "ok"},
{"name": "worker 1.3.0", "status": "slow"},
{"name": "cron 0.8.2", "status": "ok"}
]
}
```
What I want: <describe the template here>
Deploys
prodweb 4.14.0
ok
api 2.9.1
ok
worker 1.3.0
slow
cron 0.8.2
ok
Symbols are drawn with matching open icons: the app draws the real SF Symbols, which are Apple's and cannot ship on the web. The Apple Watch, the Dynamic Island and small widgets show a summary of the message, not the template.