Skip to content

NestJS notification system like laravel notification

License

Notifications You must be signed in to change notification settings

sinuoslabs/nestjs-notification

Folders and files

NameName
Last commit message
Last commit date
Mar 2, 2022
Dec 15, 2021
Dec 22, 2021
Dec 22, 2021
Dec 22, 2021
Dec 16, 2021
Dec 15, 2021
Dec 15, 2021
Dec 22, 2021
Dec 15, 2021
Dec 21, 2021
Dec 22, 2021
Jan 13, 2022
Dec 7, 2021
Dec 22, 2021
Dec 21, 2021
Dec 16, 2021
Dec 16, 2021
Dec 15, 2021
Feb 3, 2024
Apr 9, 2024
Jan 24, 2022
Dec 15, 2021

Repository files navigation

NestJS Notification

issues npm version license

Description

NestJs Notifications is a flexible multi-channel notification service inspired by Laravel Notifications.

Notifications are short, informative messages that inform users of an event that occurred in your application. For example, if you are writing a billing application, you can send a "Bill Paid" notification to your users via email and SMS channels.

This module works with existing channels that you can find here: https://github.com/nestjs-notification-channels. You have the possibility to create your own custom channels.

Installation

$ npm i @sinuos/nestjs-notification

Usage

Declare module

import { NestjsNotificationModule } from '@sinuos/nestjs-notification.module';

@Module({
  imports: [NestjsNotificationModule.register()],
})
export class AppModule {}

Channel

import { Injectable } from '@nestjs/common';
import { INestjsNotificationChannel } from '@sinuos/nestjs-notification.service';

@Injectable()
export class NexmoChannel implements INestjsNotificationChannel {
  constructor() {}

  send(): Promise<any> {
    return Promise.resolve(undefined);
  }
}

Notification

import { NestJsNotification } from '@sinuos/nestjs-notification.service';

export class InvoicPaidNotification implements NestJsNotification {
  public sendToChannels() {
    return [NexmoChannel];
  }

  toNexmo() {
    return new NexmoMessage();
  }
}

Send notification

import { Injectable } from '@nestjs/common';
import { NestjsNotificationService } from '@sinuos/nestjs-notification.service';

@Injectable()
export class AppService {
  constructor(private notification: NestjsNotificationService) {}

  notification() {
    const notification = new InvoicePaidNotification();
    this.notification.send(notification);
  }
}

Based on

Nestjs notification by edstevo

License

NestJS's notification is MIT licensed.