Notifications and badges
An app with the notify grant can send people notifications and keep a count on its icon, like how much mail is unread. Notifications reach people the way they chose in Notifications, where they can also turn off any app.
From the front end
solel.notify() sends a notification to the person using the app:
await solel.notify({ title: 'Export finished', body: 'Your 214 photos are in Files.', link: '/exports/7' });
See the reference for the details.
From the back end
Send the app's token to POST $SOLEL_CORE_URL/api/notifications/app:
curl -sS "$SOLEL_CORE_URL/api/notifications/app" \
-H "Authorization: Bearer $SOLEL_APP_TOKEN" \
-H "Content-Type: application/json" \
-d '{"title": "Backup finished", "link": "/backups", "people": ["'"$PERSON"'"]}'
| Field | What it is |
|---|---|
title |
Needed. Up to 120 characters; a longer one is cut short |
body |
Up to 1,000 characters |
link |
A path in your app, like /notes/7. Opening the notification opens your app there, and a running app gets an open event |
level |
info, the default, or warning. Only Solel sends critical ones |
key |
A notification with the same key as one still waiting replaces it, so a count or a status doesn't pile up |
people |
Who it's for, by Solel id, up to 100 |
everyone |
true sends it to everyone in the household |
Who you can reach depends on how the app was installed:
- For everyone. Name
people, or seteveryone. Leaving out both is a400. - For one person. It only ever reaches them. Naming anyone else, or
everyone, is a403.
The answer is {"sent": <how many people it reached>}.
How many
Each install can send 30 notifications a minute, from the front end and the back end together. Past that, the core answers 429 with a Retry-After header. Use key for anything that changes often.
Badges
Set the count on your app's icon for one person with PUT $SOLEL_CORE_URL/api/notifications/badge, acting for them:
curl -sS -X PUT "$SOLEL_CORE_URL/api/notifications/badge" \
-H "Authorization: Bearer $SOLEL_APP_TOKEN" \
-H "X-Solel-Person: $PERSON" \
-H "Content-Type: application/json" \
-d '{"count": 3}'
- The count is from 0 to 1,000,000.
0takes the badge away. - On the icon, the dock and the phone's app grid show it, and anything over 99 shows as 99+.
- The answer is
204, and the person's desktop updates at once.