npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pushwoosh-client

v1.5.0

Published

A node js client to consume the Pushwoosh API to send push notifications to mobile devices

Downloads

4,351

Readme

pushwoosh-node-client

Build Status Join the chat at https://gitter.im/nluo/pushwoosh-node-client

A node js client to consume the Pushwoosh API to send push notifications to mobile devices

Quick Reference

Installation

npm i pushwoosh-client --save

Send message to all devices

var Pushwoosh = require('pushwoosh-client');
var client= new Pushwoosh("AppCode", "AuthToken");

client.sendMessage('Hello world', function(error, response) {
     if (error) {
        console.log('Some error occurs: ', error);
     }

     console.log('Pushwoosh API response is', response);
});

To a specific device or devices

To send messages to a specificed device or devices, you can pass a device token or an arrays with devices

// Push to a device
client.sendMessage('Hello world', 'device token', function(error, response) {
     ...
});
// Push to multiple devices
client.sendMessage('Hello world', ['deviceToken1', 'deivceToken2'], function(error, response) {
     ...
});

Configure option if we don't want to send to all devices by default

By default, if we don't provide the device params, it will send push notifications to all devices. Sometimes this might not be what we want.

If we initialise Pushwoosh Client with shouldSendToAllDevices to false, then it will NOT send push notifications and return a callback error if we did not provide any device/devices.

var Pushwoosh = require('pushwoosh-client');
var client= new Pushwoosh("AppsGroupCode", "AuthToken", {
    shouldSendToAllDevices: false
});

client.sendMessage('Hello world', function(error, response) {
     // We will get error here as we don't have any device/devices provided
});

Note: shouldSendToAllDevices is set to true if we don't configure it in option

Extra options/payload

To pass extra options (please refer to the Pushwoosh doc for the available options) , you could define an option object and pass it to the function as a 2nd or 3rd parameter. E.g. if you want to pass addtional payload to the device, you could do:

var Pushwoosh = require('pushwoosh-client'),
    client= new Pushwoosh("AppCode", "AuthToken"),
    options = {
        data: {
            username: 'bob smith',
            email: '[email protected]'
        }
    };
    client.sendMessage('Hello world', 'device token', options, function(error, response) {
     ...
    });

Note that if you define devices or content in the options, the devices and message will be overwritten.

var options = {
        data: {
            username: 'bob smith',
            email: '[email protected]'
        },
        devices: ['deviceToken1', 'deviceToken2', 'deviceToken3']
    };
client.sendMessage('Hello world', 'device token', options, function(error, response) {
     ...
});

Then this will send to ['deviceToken1', 'deviceToken2', 'deviceToken3'] as defined in options. so you probably just want to just do

client.sendMessage('Hello world', options, function(error, response) {
    ...
});

Applications group

To use Puswoosh applications_group code(which allows you to send to multilple applications) instead of application code, you must pass a third options argument when creating the client with useApplicationsGroup set to true:

var Pushwoosh = require('pushwoosh-client');
var client= new Pushwoosh("AppsGroupCode", "AuthToken", {
    useApplicationsGroup: true,
    ...
});

// Will push using "applications_group":"AppsGroupCode" for all of the explained invocation patterns
client.sendMessage('Hello world', function(error, response) {
     ...
});
// or
client.sendMessage('Hello world', options, function(error, response) {
    ...
});
// ... and so on

Register device

To register a device's push token in Pushwoosh:

var Pushwoosh = require('pushwoosh-client');
var client= new Pushwoosh('AppCode', 'AuthToken');

var registerDeviceOptions = {
    push_token: 'pushtoken',
    hwid: 'hwid',
    device_type: 3,
    language: 'en', // optional, two-letter code ISO-639-1
    timezone: -3600 // optional, offset in seconds
};

// this will register the device for the client's 'AppCode' application
client.registerDevice(registerDeviceOptions, function(error, response) {
     ...
});

Unregister device

To unregister a device in Pushwoosh:

var Pushwoosh = require('pushwoosh-client');
var client= new Pushwoosh('AppCode', 'AuthToken');

var unregisterDeviceOptions = {
    hwid: 'hwid'
};

// this will unregister the device from the client's 'AppCode' application
client.unregisterDevice(unregisterDeviceOptions, function(error, response) {
     ...
});

Set tags for device

To set tags for a device in Pushwoosh:

var Pushwoosh = require('pushwoosh-client');
var client= new Pushwoosh('AppCode', 'AuthToken');
 
var setTagsOptions = {
    hwid: 'hwid',
    tags: {
        price: "1.99",
        language: "pl"
    }
};
 
// this will set the device tags for the client's 'AppCode' application
client.setTags(setTagsOptions , function(error, response) {
    ...
});

Get tags for device

To get tags for a device from Pushwoosh:

var Pushwoosh = require('pushwoosh-client');
var client= new Pushwoosh('AppCode', 'AuthToken');

var getTagsOptions = {
    hwid: 'hwid'
};

// this will get the device tags for the client's 'AppCode' application
client.getTags(getTagsOptions , function(error, response) {
    ...
});

Tests

npm test

Currently tests are all passed and with 100% coverage