so

simple-onesignal

A simple wrapper for onesignal. Used to send Push Notifications to end-users.

Showing:

Popularity

Downloads/wk

72

GitHub Stars

2

Maintenance

Last Commit

3yrs ago

Contributors

3

Package

Dependencies

2

Size (min+gzip)

198.8KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

simple-onesignal

A simple Node.js wrapper for onesignal. Used to send Push Notifications to end-users.

Sign up for free at: onesignal.com

Install

npm install simple-onesignal

Setup

var onesignal = require('simple-onesignal');
onesignal.configure('[APP ID]', '[REST API KEY]');

Usage

Sending a message

The sendMessage method accepts either a string, or an Object. If you decide to send an object, ensure it is in the correct format as described below.

Simple Text to everyone

The following code will send a message in English to all subscribers!

onesignal.sendMessage('Hello world!', function(err, resp) {
    if(err) {
        // Handle error
    } else {
        // Handle success!
    }
});

Message with specific messages and targeting

onesignal.sendMessage({
    contents: {en:'Hello world!'}, 
    included_segments:['All']
}, function(err, resp) {
    if(err) {
        // Handle error
    } else {
        // Handle success!
    }
});

Convenience methods

The following methods essentially do the same as sendMessage([data]), but wrap some of the boiler plate up for you.

Send text to segments

The second argument is an array of your segments configured in OneSignal.

onesignal.sendMessageTextToSegments('Hello world', ['All'], function(err, resp) {
    //...
});

Send text to filters

The second argument is an array of your filters configured in OneSignal. In the example below, we are targeting users who have not opened the app for at least 12 hours.

var filters = [
    {field:'last_session', relation:'>', hours_ago:'12'}
]

onesignal.sendMessageTextWithFilters('Hello world', filters, function(err, resp) {
    //...
});

License

© Jamie Chapman, 57Digital Ltd — ISC

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100