OneSignal API wrapper for the Server Rest API made to work with the Nest framework.
npm install onesignal-api-client-nestOneSignal API wrapper for the Server Rest API made to work with the Nest) framework.
Npm
``sh`
$ npm install onesignal-api-client-nest`
Yarnsh`
$ yarn add onesignal-api-client-nest
`typescript
// Inside of your module imports
@Module({
imports: [
OneSignalModule.forRoot({
appId: 'appId',
restApiKey: 'restApiKey',
})
]
})
// Or async
@Module({
imports: [
OneSignalModule.forRootAsync({
useFactory: async (configService: ConfigService) => {
return {
appId: configService.get('ONESIGNAL_APP_ID'),
restApiKey: configService.get('ONESIGNAL_REST_API_KEY'),
};
},
inject: [ConfigService],
),
],
})
`
In your service class you can inject the service like so and then use it in any function as you would any other service.
`typescript
import { NotificationBySegmentBuilder } from 'onesignal-api-client-core';
@Injectable()
export class MyService {
constructor(private readonly oneSignalService: OneSignalService) {}
async viewNotifications() {
return await this.oneSignalService.viewNotifications();
}
async createNotification(message: string) {
const input = new NotificationBySegmentBuilder()
.setIncludedSegments(['Active Users', 'Inactive Users'])
.notification() // .email()
.setContents({ en: message })
.build();
await this.oneSignalService.createNotification(input);
}
}
``