notifme / notifme-sdk

A Node.js library to send all kinds of transactional notifications.
https://notifme.github.io/www/
MIT License
1.94k stars 149 forks source link

Nestjs Implementation #90

Closed pryme0 closed 6 months ago

pryme0 commented 2 years ago

Hello is there a Nestjs Wrapper for Notifme?. Or can you optionally give me pointers on how to implement this in Nestjs?

serebro commented 2 years ago

Hi

I am doing the following

// message.module.ts

import NotifmeSdk from 'notifme-sdk'

@Module({
    imports: [AppConfigModule],
    controllers: [MessageController],
    providers: [
        MessageService,
        {
            provide: NotifmeSdk,
            inject: [AppConfigService, Logger],
            useFactory: (config: AppConfigService) => new NotifmeSdk(config.get('app.notifmeConfig'))
        },
    ],
})
export class MessageModule {
}

Usage

// message.service.ts

import NotifmeSdk from 'notifme-sdk'

@Injectable()
export class MessageService {
    constructor(
        private readonly notifmeSdk: NotifmeSdk,
    ) {
    }

    public async send(channel: string, payload: any) {
        // ...
        const response = await this.notifmeSdk.send({ [channel]: payload })
        // ...
    }
}