NotificationGetting StartedIntroduction

Introduction

Core concepts of @visulima/notification

Getting Started

Concepts

  • Channel — a logical delivery medium: sms, push, chat, inapp, webhook, email.
  • Provider — a concrete integration for a channel (e.g. twilio for sms). A provider declares its id, channel, capability features, and a send method.
  • FacadecreateNotification({ <channel>: <provider> }) returns a Notification that dispatches messages to the matching provider per channel.
  • Message — an object with a payload per channel: { sms: {...}, chat: {...} }.
  • Receipt — the discriminated result of a send: { successful: true, messageId, … } or { successful: false, errorMessages, … }.

Creating a facade

import { createNotification } from "@visulima/notification";
import { twilioProvider } from "@visulima/notification/providers/twilio";

const notify = createNotification({
    sms: twilioProvider({ accountSid: "AC…", authToken: "…", from: "+15555550100" }),
});

The provider contract

Every provider is built with defineProvider:

import { defineProvider } from "@visulima/notification";
import type { SmsPayload } from "@visulima/notification";

export const myProvider = defineProvider<{ apiKey: string }, SmsPayload>((config) => ({
    id: "my-provider",
    channel: "sms",
    features: { batchSending: false, media: false },
    initialize: () => {},
    isAvailable: () => Boolean(config?.apiKey),
    send: async (payload) => ({
        success: true,
        data: { channel: "sms", messageId: "…", provider: "my-provider", sent: true, timestamp: new Date() },
    }),
}));

Next steps

Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues