JSPM

simple-onesignal

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q48906F
  • License ISC

A simplified Node.js library for OneSignal

Package Exports

  • simple-onesignal

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (simple-onesignal) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

simple-onesignal

A simple 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

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 so 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

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