https://github.com/kvandake/onesignal-nest
OneSignal API wrapper for the Server Rest API made to work with the Nest framework
https://github.com/kvandake/onesignal-nest
nest nestjs onesignal onesignal-api typescript
Last synced: 8 months ago
JSON representation
OneSignal API wrapper for the Server Rest API made to work with the Nest framework
- Host: GitHub
- URL: https://github.com/kvandake/onesignal-nest
- Owner: kvandake
- Created: 2019-08-29T20:46:40.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-04-20T12:42:30.000Z (about 3 years ago)
- Last Synced: 2025-09-03T17:43:26.080Z (10 months ago)
- Topics: nest, nestjs, onesignal, onesignal-api, typescript
- Language: TypeScript
- Homepage:
- Size: 363 KB
- Stars: 16
- Watchers: 3
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OneSignal API Client for NestJS
[](https://badge.fury.io/js/onesignal-api-client-nest)
OneSignal API wrapper for the Server Rest API made to work with the [Nest]((https://github.com/nestjs/nest)) framework.
## Getting Started
Npm
```sh
$ npm install onesignal-api-client-nest
```
Yarn
```sh
$ yarn add onesignal-api-client-nest
```
## Using the Module
```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],
),
],
})
```
## Using in the Service
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);
}
}
```
## Documentation
All documentation for this wrapper comes from the [OneSignal API client](https://github.com/kvandake/onesignal), if there are any typos, please let me know or open a PR to fix it.
## Support
If any bugs are found in the API wrapper, please open an issue on GitHub, or a Pull Request if you want to fix it yourself!
Please be as explicit as possible and provide a minimum reproducing repository if at all possible, as it helps track down what went wrong.
## License
MIT