JSPM

  • Created
  • Published
  • Downloads 13550
  • Score
    100M100P100Q133672F

A cross-platform push service for Node.js

Package Exports

  • node-pushnotifications

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 (node-pushnotifications) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Node Push Notify

A Node.js module for interfacing with Apple Push Notification, Google Cloud Messaging, Microsoft Push Notification and Amazon Device Messaging services.

License NPM version Downloads Build Status

Installation

npm install node-pushnotifications

#Features

  • Powerful and intuitive.
  • Multi platform push sends.
  • Automatically detects destination device type.
  • Unified error handling.

Usage

iOS: Prepare cert.pem and key.pem as described in node-apn

Import and setup push module:

var settings = {
  gcm: {
    id: null, // PUT YOUR GCM SERVER API KEY,
    msgcnt: 1,
    dataDefaults: {
      delayWhileIdle: false,
      timeToLive: 4 * 7 * 24 * 3600, // 4 weeks
      retries: 4,
    },
    // Custom GCM request options https://github.com/ToothlessGear/node-gcm#custom-gcm-request-options
    options: {},
  },
  apn: {
    gateway: 'gateway.sandbox.push.apple.com',
    badge: 1,
    defaultData: {
      expiry: 4 * 7 * 24 * 3600, // 4 weeks
      sound: 'ping.aiff'
    },
    // See all available options at https://github.com/argon/node-apn/blob/master/doc/connection.markdown
    options: {},
    // I.e., change .cert location file:
    // options: {
    //    cert: "/certs/ios/mycert.cert" // {Buffer|String} The filename of the connection certificate to load from disk, or a Buffer/String containing the certificate data. (Defaults to: cert.pem)
    // }
  },
  adm: {
    client_id: null, // PUT YOUR ADM CLIENT ID,
    client_secret: null, // PUT YOUR ADM CLIENT SECRET,
    expiresAfter: 4 * 7 * 24 * 3600, // 4 weeks
    // Custom ADM request options, same as https://github.com/ToothlessGear/node-gcm#custom-gcm-request-options
    options: {},
  },
};
var PushNotifications = new require('node-pushnotifications');
var push = new PushNotifications(settings);

GCM and ADM options: see node-gcm

APN options: see node-apn

MPNS options see mpns

Define destination device ID. You can send to multiple devices, independently of platform, creating an array with different destination device IDs.

// Single destination
var deviceIds = 'INSERT_YOUR_DEVICE_ID';

// Multiple destinations
var deviceIds = [];
deviceIds.push('INSERT_YOUR_DEVICE_ID');
deviceIds.push('INSERT_OTHER_DEVICE_ID');

Next, create a JSON object witch MUST contain, at least, a title and message and send it to server.

var data = {
  title: 'New push notification',
  message: 'Powered by AppFeel',
  otherfields: 'optionally add more data'
};
push.send(deviceIds, data, function (err, result) {
    if (err) {
        console.log(err);
    } else {
        console.log(result);
    }
});

Error will be null if all went fine, will return the error otherwise. Result will contain 'true' if all went fine.

##Resources

Made in Barcelona with <3 and Code