Skip to content

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

Notifications You must be signed in to change notification settings

SamDelgado/simple-onesignal

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%