Notifications multicanal

Une seule Notification se décline par canal via ses méthodes toMail / toSlack / toDatabase, et notifier.send() la diffuse sur tous les canaux que via() retourne — en collectant un résultat par canal. Ici, e-mail et Slack sont simulés ; le canal database est réel et persiste dans le flux ci-dessous (via l'ORM).

Astuce
Les canaux sont branchables et leurs transports injectables : bext n'a pas de fournisseur SMS, vous injectez donc le vôtre (Twilio…). notifier.send() ne rejette jamais — chaque canal renvoie { ok } ou une erreur, sans faire échouer les autres.

Envoyer une notification

Flux in-app (10)

🔔smoke
🔔smoke
🔔smoke
🔔smoke
🔔smoke
🔔smoke
🔔smoke
🔔smoke
🔔smoke
🔔smoke
src/app/examples/notifications/page.tsxTSX
import { createNotifier, mailChannel, smsChannel, databaseChannel }
  from "@bext-stack/framework/notifications";

const notifier = createNotifier([
  mailChannel({ appId: "my-site" }),          // real: bext SDK email
  smsChannel({ send: twilioSend }),           // bext has no SMS provider — inject one
  databaseChannel({ model: Notifications }),  // in-app feed via the ORM
]);

// One Notification renders itself per channel via to<Channel>() methods.
const InvoicePaid = {
  via: () => ["mail", "database"],
  toMail: (u) => ({ subject: "Paid", html: `<p>Thanks ${u.name}</p>` }),
  toDatabase: (u) => ({ type: "invoice.paid", user_id: u.id, read: 0 }),
};

const results = await notifier.send(user, InvoicePaid);
// → { mail: { ok: true }, database: { ok: true, id: "42" } }