notifme-sdk icon indicating copy to clipboard operation
notifme-sdk copied to clipboard

Nestjs Implementation

Open pryme0 opened this issue 2 years ago • 1 comments

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

pryme0 avatar Nov 04 '21 13:11 pryme0

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 })
        // ...
    }
}

serebro avatar Nov 29 '21 22:11 serebro