https://github.com/renddslow/onesignal-promise-nodejs
https://github.com/renddslow/onesignal-promise-nodejs
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/renddslow/onesignal-promise-nodejs
- Owner: Renddslow
- Created: 2017-11-15T21:27:34.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-21T15:21:07.000Z (almost 8 years ago)
- Last Synced: 2025-02-21T22:47:32.041Z (9 months ago)
- Language: JavaScript
- Size: 1.97 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OneSignal Promise SDK
A super simple promise-based node sdk for creating, canceling, and view notifications in OneSignal.
# Super simple to use
```js
const oneSignal = require('onesignal-promise')({ appId: 'APP_ID', apiKey: 'API_KEY' });
oneSignal.createNotification({ contents: {'en': 'Hello World'} })
.then(res => {
if (!res.errors) {
console.log(res.id);
}
});
```
# Installation
```
npm install --save onesignal-promise
```
# Methods
## `createNotification`
Expects a OneSignal [notification object](https://documentation.onesignal.com/reference#create-notification) and MUST include either a `contents` object or have `content_available` set to `true` or it will throw.
### Responses
`200 OK`
```
{
id: '458dcec4-cf53-11e3-add2-000c2940e62c',
recipients: 3
}
```
`400 Bad Request`
```
{
errors: ['Notification content must not be null for any languages.']
}
```
`200 No Subscribed Players`
Made if no phones are subscribed to a segment
```
{
id: '',
recipients: 0,
errors: ['All included players are not subscribed']
}
```
## `cancelNotification`
Expects an id of an existing notification.
```
onesignal.cancelNotification('6392d91a-b206-4b7b-a620-cd68e32c3a76')
.then(result => {
console.log(result)
})
>>> { success: true }
```
`