Notifications
An App's server code calls notify, and Charming delivers the notification to the people who use the App.
What you can do
Tell people when something happens. An App’s route handler or Routine sends a notification with a title, an optional body, and a link to a page in the App. A shared to-do App can tell everyone when a task is done, and a contact form on a public App can tell its owner about a new message.
Reach the people who use the App. The owner, members of the team that owns the App, and people invited to it receive its notifications without setting anything up. A signed-in visitor to a public App is asked once, in the App’s widget, whether the App may notify them, and receives its notifications after choosing Allow. Each person can mute an App.
It finds the person. A notification appears in the person’s Charming inbox and in the App’s widget. A person who turned on browser notifications for the App, in a tab or with the App installed to their Home Screen, also gets it as a push, unless they have the App open. If it is still unread 15 minutes later, Charming emails it to them. The App never picks how a notification is delivered and never learns whether anyone read it.
It works on the App’s custom domain. A person signed in on the App’s custom domain sees their notifications in the widget there, can mute the App, and can turn on browser notifications for the App on that domain. In the email and the charm.ing inbox, a notification’s link opens the App on its custom domain. In the widget, it opens where the page is: on the custom domain, or on charm.ing. A push opens the App where the browser subscribed: on the custom domain, or on charm.ing.
Technical
Copy this prompt for your agent
Make my Charming app send a notification when something happens.
Read https://charm.ing/docs/capabilities/notifications.md first.
Call notify from the route handler or Routine where it happens,
with a short title and a path back to the page it is about.
Send a notification
In a package App, import { notify } from 'charming:notifications/[email protected]' in server code and call it from a route handler or a Routine. Browser code cannot send a notification: a button that should notify people calls one of the App’s routes, and that route calls notify. An App on a dated manifest contract calls env.notify(input) from a handler instead, without declaring anything.
import { notify } from 'charming:notifications/[email protected]';
export const routes = [
{
op: 'completeTask',
inputSchema: {
type: 'object',
required: ['taskId', 'title'],
properties: { taskId: { type: 'string' }, title: { type: 'string' } },
additionalProperties: false,
},
annotations: { readOnlyHint: false, destructiveHint: false },
handler: async ({ taskId, title }) => {
const sent = await notify({
title: 'Task done',
body: title,
path: `/tasks/${taskId}`,
idempotencyKey: `task-done:${taskId}`,
});
return { notified: sent.recipients };
},
},
];
notify(input) takes:
| Field | Rules |
|---|---|
title |
Plain text, 1 to 120 characters after trimming. Required. |
body |
Plain text, up to 500 characters. |
path |
A link inside the App that starts with one /, up to 512 characters. Charming builds the full URL. |
to |
Up to 100 user ids. Leave it out to reach everyone the App may notify. |
idempotencyKey |
Up to 200 characters. A second send with the same key from the same App creates nothing and returns the first notification’s id with recipients: 0. |
It resolves to { id, recipients }, where recipients is how many people the notification was created for after Charming removed the people it may not reach and the people over their daily cap.
Who it reaches
Without to, a notification reaches everyone who may receive the App’s notifications: the owner, members of the owning team, invited people of any role, and signed-in visitors who allowed the App while it has a public link, minus anyone who muted the App or turned App notifications off. The person whose request caused the send is left out, because they already know. With to, it reaches only the named people among those, and any other id is dropped without saying which.
A signed-in visitor without access starts receiving an App’s notifications by allowing it. The first time they open a public App that sends notifications, the widget asks them, naming the App. Allow grants the App permission and then offers browser notifications for that browser when it can show them. Not now, closing the notice, or pressing Escape declines, and the notice doesn’t come back for that App on any browser. Leaving the page without answering changes nothing, so the widget asks again on the next visit. Either answer can be changed later with the switch at the bottom of the widget’s Notifications tab. The owner, team members, invited people, and signed-out visitors are never asked, and neither is anyone who narrowed Which apps can notify you in their Charming settings below Apps they’ve granted permission to.
An App counts as sending notifications when its live version can call notify: a package App that imports charming:notifications/[email protected], or an App on a dated contract whose server code names notify. An App that sends nothing never asks.
A Routine tick reaches everyone above. A request from someone who is not a member of the App, such as a signed-out visitor, a signed-in visitor without access, a webhook delivery, an App token that names no person, or a call from another App, still sends, but only to the people who manage the App. Charming records who caused a send for the people who manage the App; App code never sees that record.
Refusals
A refused send throws a NotificationError, whose kind says why:
kind |
When | What to do |
|---|---|---|
invalid_notification |
A field breaks the rules above. | Fix the input. The message names the field. |
rate_limited |
The App or the person who caused the send reached a cap below. | Send less often, or try again later. |
capability_denied |
This server has no notification sender. | Nothing reaches anyone here; run the App on Charming. |
A call that has view-only access, such as a viewer’s call to a read-only route, cannot send: notify fails with forbidden_write, the same as a storage write. A NotificationError the handler does not catch fails the operation as operation_failed with the error’s message.
charming dev runs Apps without a notification sender, so notify is not available there. Test a send on Charming.
Limits
Each App may send 100 notifications a day on Free, 1,000 on Pro, and 5,000 on Business, and each person receives at most 20, 50, or 100 a day from one App. One member’s requests may cause 30 sends an hour in one App, and requests from everyone who is not a member share 20 sends an hour per App. A Routine tick counts only toward the daily caps.