SpaceMIX v0.1.0 (latest)

Notifications

stablefor bothsince protocol 1

host.notifications: put one line of plain text in someone's notification center, with a target back into your view, and mark it read when they've seen it.

Every person on the team has their own notification center (the bell in the sidebar). Any extension can put a notification there, and unread ones of a kind with a badge count on the extension's navigation item. What a notification may contain is strict on purpose: one line of plain text, and optionally a target inside the sending extension's own view.

interface SpacemixHost {
  notifications: NotificationsApi; // always present
}

interface NotificationsApi {
  send(notification: NotificationInput): Promise<{ sent: number }>;
  people(): Promise<NotificationPerson[]>;
  markRead(filter?: NotificationFilter): Promise<{ marked: number }>;
}

interface NotificationInput {
  kind: string;
  text: string;
  target?: string;
  to?: string[];
}

interface NotificationFilter {
  kind?: string;
  target?: string;
}

interface NotificationPerson {
  id: string;
  name: string;
  me: boolean;
}

Permission: none. But every send names a kind the manifest declares in notifications (see NotificationKind in manifest.md); an extension that declares none can't send any.

The core stamps who sent each notification (the extension id and the signed-in person) and the link always leads back into the sender's view. An extension can't send as another extension, link elsewhere, or change anyone's notifications but its own to the signed-in person.

Not every notification comes from an extension. One sent by a script or service with an API key through the SpaceMIX API has source: "api" and no kind; the app shows it under the name API, it opens no view (clicking it only marks it read), and its target is kept only for the API caller to read back. host.notifications.markRead never touches it, since it marks only your own extension's notifications.

host.notifications.send

send(notification: NotificationInput): Promise<{ sent: number }>;

Delivers one notification to each recipient. Resolves with how many got it. Bridge method: notifications.send.

  • kind: a name from the manifest's notifications. Anything else rejects, listing the declared kinds.
  • text: plain text. The core turns control characters and invisible or reordering characters (zero-width, bidi controls, BOM) into spaces, collapses whitespace, and trims. The result must be 1–280 characters. It is shown as text: markup, markdown and links are never interpreted.
  • target: optional, up to 512 characters, no control characters, never shown. Opaque to everyone but your extension: a record id, "note:abc", "c1/m9". When the person opens the notification, SpaceMIX opens your view and hands you the target through host.view.onTarget (view.md). Empty or omitted: the notification just opens the view.
  • to: user ids from people(), deduplicated, 1–50 of them. Omit to notify only the person signed in where the extension runs. An unknown id rejects the whole send. Someone who may not use your extension (see Who can use an extension) still gets it, but can't open your view from it.

Each center keeps the newest 200 notifications.

While a paid extension is turned off on the server, send rejects with <Name> is turned off on this server until it's paid for. (see Turned off until it's paid for).

Errors (examples): <Name> declares no notification kind "x"; declared: "a", "b"., A notification needs some text., Notification text is limited to 280 characters; this is 301., A notification target is limited to 512 characters; this is 600., A notification can go to at most 50 people; this is 51., No team member with id "<id>". Use people() to find valid ids., "<id>" is reserved for SpaceMIX itself, so nothing can be sent from it. (the source is an id reserved for SpaceMIX, or a core.* id that isn't an installed extension's)

host.notifications.people

people(): Promise<NotificationPerson[]>;

Everyone on the team, for to, including people who may not use your extension. name is the display name, falling back to the email; me marks the person signed in. Bridge method: notifications.people.

host.notifications.markRead

markRead(filter?: NotificationFilter): Promise<{ marked: number }>;

Marks the signed-in person's unread notifications from this extension read: all of them, or those matching filter. Resolves with how many changed. Call it when the person has seen the thing a notification was about (opened the conversation, the task), so the count on your navigation item goes down. Bridge method: notifications.markRead.

  • kind: only that kind.
  • target: the target itself and everything under it: "c1" matches "c1", "c1/m9" and "c1/m9/r2", not "c10". Design targets as /-separated paths to use this.

It never affects other extensions' notifications or other people's.

Badges

Unread notifications count on the sender's navigation item when their kind has badge (the default, true) in the installed manifest. Kinds with badge: false only show in the center.

Example

import { host } from "@spacemix/sdk";

export async function notifyAssignee(taskId: string, title: string, userId: string): Promise<void> {
  await host.notifications.send({ kind: "task_assigned", text: `Assigned to you: ${title}`, target: taskId, to: [userId] });
}

export async function seenTask(taskId: string): Promise<void> {
  await host.notifications.markRead({ kind: "task_assigned", target: taskId });
}

The example assumes the manifest declares the kind task_assigned.

Stability

Stable.

This page as markdown · All pages as one file