Skip to content

Latest commit

 

History

History
 
 

nest

NestJS Module Wrapper

A NestJS module wrapper for @novu/node

Usage

Initializing module with templates and providers:

    import { NovuModule } from "@novu/nest";

    @Module({
      imports: [
        NovuModule.forRoot({
          providers: [
            new SendgridEmailProvider({
              apiKey: process.env.SENDGRID_API_KEY,
              from: '[email protected]',
            }),
          ],
          templates: [
            {
              id: 'password-reset',
              messages: [
                {
                  subject: 'Your password reset request',
                  channel: ChannelTypeEnum.EMAIL,
                  template: `
                          Hi {{firstName}}!

                          To reset your password click <a href="{{resetLink}}">here.</a>
                          `,
                },
              ],
            },
          ],
        }),
      ],
    })

Using novu's singleton service in other services and modules:

import { Injectable, Inject } from '@nestjs/common';
import { NovuService } from '@novu/nest';

@Injectable()
export class UserService {
  constructor(private readonly novu: NovuService) {}

  async triggerEvent() {
    await this.novu.trigger('password-reset', {
      $email: '[email protected]',
      $user_id: 'id'
    });
  }
}