1.0.2 • Published 12 months ago
cscmobi-nestjs-fcm v1.0.2
Installation
npm install --save cscmobi-nestjs-fcm
FcmModule
To user FcmService you must add the module first. The FcmModule
has a @Global()
attribute so you should only import it once.
import { Module } from '@nestjs/common';
import { FcmModule } from 'cscmobi-nestjs-fcm';
@Module({
imports: [
FcmModule.forRoot({
serviceAccount: {
projectId: '----YOUR PROJECTID----',
clientEmail: '---YOUR CLIENT EMAIL---',
privateKey: '---YOUR PRIVATEKEY----'
}
},'fcm_service'),
],
controllers: [],
})
export class AppModule {}
FcmService
use firebase.spec.json file to send notifications using firebase-admin dependency.
@Injectable()
export class SampleService {
constructor(@Inject('fcm_service') private readonly fcmService: FcmService) {}
async sendToDevices() {
await this.fcmService.sendNotification([
'device_token_1',
'device_token_2',
]
payload,
silent,
);
}
async sendToTopic(topic: string) {
await this.fcmService.sendToTopic(
topic,
payload,
silent,
);
}
}
Change Log
See Changelog for more information.
Contributing
Contributions welcome! See Contributing.
Author
Tuyennv
License
Licensed under the MIT License - see the LICENSE file for details.