index ↓

notifications

client.notifications

Phone notifications mirrored to a webapp. onPosted, onUpdated, and onRemoved track the list. invokePositive and invokeNegative run the actions a notification offers.

commands

fire-and-forget. the promise resolves once the daemon has taken the message

invokePositive(NotificationInvoke): Promise<void>

await client.notifications.invokePositive({ id: '...' });

invokeNegative(NotificationInvoke): Promise<void>

await client.notifications.invokeNegative({ id: '...' });

events

the daemon pushes these unprompted. subscribing returns an unsubscribe function

onPosted(handler: (Notification) => void): () => void

const off = client.notifications.onPosted((notification) => {
  console.log(notification.id);
});
// call off() to unsubscribe

onUpdated(handler: (Notification) => void): () => void

const off = client.notifications.onUpdated((notification) => {
  console.log(notification.id);
});
// call off() to unsubscribe

onRemoved(handler: (NotificationRemoved) => void): () => void

const off = client.notifications.onRemoved((notificationRemoved) => {
  console.log(notificationRemoved.id);
});
// call off() to unsubscribe

onErrorEvent(handler: (NotificationsErrorReply) => void): () => void

const off = client.notifications.onErrorEvent((reply) => {
  console.log(reply.error);
});
// call off() to unsubscribe

types

shapes referenced above, as the sdk types them

id stays the same while the notification exists. Pass it to invokePositive and invokeNegative, and match it against onRemoved.

type Notification = {
  id: string;
  app: NotificationApp;
  category: NotificationCategory;
  title?: string;
  subtitle?: string;
  message?: string;
  timestampUnixS?: number;
  flags: NotificationFlags;
  positiveAction?: NotificationAction;
  negativeAction?: NotificationAction;
};
type NotificationRemoved = {
  id: string;
  reason: DismissReason;
};
type NotificationsErrorReply = {
  error: NotificationsError;
};
type NotificationInvoke = {
  id: string;
};
type NotificationApp = {
  bundleId: string; // For example `com.apple.MobileSMS`.
  displayName?: string;
  iconAssetId?: string;
};
type NotificationCategory =
  | 'other'
  | 'incomingCall'
  | 'missedCall'
  | 'voicemail'
  | 'social'
  | 'schedule'
  | 'email'
  | 'news'
  | 'healthAndFitness'
  | 'businessAndFinance'
  | 'location'
  | 'entertainment';
type NotificationFlags = {
  silent: boolean;
  important: boolean;
};
type NotificationAction = {
  label: string; // Button text, in the phone's language.
};

acted covers both the positive and the negative action.

type DismissReason = 'userDismissed' | 'acted' | 'remoteDismissed';
type NotificationsError =
  | 'notFound' // The notification is gone from the phone.
  | 'actionRejected' // The notification has no action in that slot, or the phone refused it.
  | 'noTarget' // No phone is connected.;