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 = ;var client= "AppCode" "AuthToken"; client;
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 deviceclient;// Push to multiple devicesclient;
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 = ;var client= "AppsGroupCode" "AuthToken" shouldSendToAllDevices: false; client;
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 = client= "AppCode" "AuthToken" options = data: username: 'bob smith' email: 'bob@example.com' ; client;
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: 'bob@example.com' devices: 'deviceToken1' 'deviceToken2' 'deviceToken3' ;client;
Then this will send to ['deviceToken1', 'deviceToken2', 'deviceToken3'] as defined in options. so you probably just want to just do
client;
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 = ;var client= "AppsGroupCode" "AuthToken" useApplicationsGroup: true ...; // Will push using "applications_group":"AppsGroupCode" for all of the explained invocation patternsclient;// orclient;// ... and so on
Register device
To register a device's push token in Pushwoosh:
var Pushwoosh = ;var client= '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' applicationclient;
Unregister device
To unregister a device in Pushwoosh:
var Pushwoosh = ;var client= 'AppCode' 'AuthToken'; var unregisterDeviceOptions = hwid: 'hwid'; // this will unregister the device from the client's 'AppCode' applicationclient;
Set tags for device
To set tags for a device in Pushwoosh:
var Pushwoosh = ;var client= 'AppCode' 'AuthToken'; var setTagsOptions = hwid: 'hwid' tags: price: "1.99" language: "pl" ; // this will set the device tags for the client's 'AppCode' applicationclient;
Get tags for device
To get tags for a device from Pushwoosh:
var Pushwoosh = ;var client= 'AppCode' 'AuthToken'; var getTagsOptions = hwid: 'hwid'; // this will get the device tags for the client's 'AppCode' applicationclient;
Tests
npm test
Currently tests are all passed and with 100% coverage