NotificationGetting StartedSending

Sending

Send single, multi-channel and batched notifications

Sending notifications

Multi-channel send

Each channel present in the message is delivered in parallel; you receive one receipt per channel.

const receipts = await notify.send({
    sms: { to: "+15555550100", text: "Your code is 123" },
    chat: { text: "🚀 Deploy finished" },
    push: { to: ["device-token"], title: "Deploy", body: "Finished" },
});

for (const receipt of receipts) {
    if (receipt.successful) {
        console.log(`${receipt.channel}: ${receipt.messageId}`);
    } else {
        console.error(`${receipt.channel} failed:`, receipt.errorMessages);
    }
}

Single channel

const receipt = await notify.sendToChannel("sms", { to: "+15555550100", text: "Hi" });

Batch with bounded concurrency

const messages = users.map((user) => ({ sms: { to: user.phone, text: `Hi ${user.name}` } }));

for await (const receipts of notify.sendMany(messages, { concurrency: 10 })) {
    // receipts for one message
}

Fluent message builder

createNotificationMessage() (or new NotificationMessageBuilder()) is a thin, chainable convenience for assembling a multi-channel message — .build() returns the same plain object send() accepts.

import { createNotificationMessage } from "@visulima/notification";

const message = createNotificationMessage()
    .sms({ to: "+15555550100", text: "Your code is 123" })
    .push({ to: ["device-token"], title: "Code", body: "123" })
    .idempotencyKey("login-otp-42")
    .build();

await notify.send(message);

Lifecycle

initialize() is called lazily and once per provider before its first send. Call notify.initialize() to eagerly initialise all providers, and notify.shutdown() to release provider resources.

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