ibm-push-notification
v0.1.1
Published
create a remote notification payload and sends it to Android / iOS servers
Downloads
12
Maintainers
Readme
IBM Push Notification (Hybrid [iOS and Android]) [WiP]
This module will allow you to send push notification to iOS and Android devices without depending from other stuff.
This module aren't finished yet, we are building / testing it the usage is not recommended
Prerequisite
Since this module uses features available after Node7, it is required of the module usage, so we decide to put the version used to build this module as starter:
- Node 7.10.0 or higher;
Dependencies
Since this module communicate with other server it will install the module below:
Installation
npm install ibm-push-notification
Parameters
Initialization
Here follow the params used on the client initialization
| Property | Type | Required | Description | ---------- | ------- | ---------------- | ----------- | ios | Object | True | Holds the initilization parameters used on | android | Object | True | Holds the initilization parameters used on
Notification
The notification parameters will be the same defined on iOS / Android individually (but since iOS has more parameters than android, consider to use iOS model):
Usage
This module allow you to work with both notifications or if you are working with just one platform (android/ios) you can require just what u
- Hybrid, just keep reading :D
Create the client
Below you can see several different ways to create your push client
//Read the ios readme for more details about possibilities when initializing a client.
const ios = {
p12: '/path/to/Certificate.p12',
password: 'test',
bundle: 'com.yourapp.bundle'
}
const android = {
key: 'here-goes-your-google-client-key'
}
const PushNotification = require('ibm-push-notification')({ ios, android })
Send the Push Notification
After create the client for the push notification, you can send it anytime following the examples below:
One device only
Here is an example about how to send the notification to one device only
Only Mandatory Params
const ios = {
p12: '/path/to/Certificate.p12',
password: 'test',
bundle: 'com.yourapp.bundle'
}
const android = {
key: 'here-goes-your-google-client-key'
}
const PushNotification = require('ibm-push-notification')({ ios, android })
async function sendNotification(message) {
try {
return await PushNotification.send({
notification: message
}, { ios: <DEVICE_ID>, android: <DEVICE_ID> })
} catch (err) {
throw err
}
}
Custom Properties
const ios = {
p12: '/path/to/Certificate.p12',
password: 'test',
bundle: 'com.yourapp.bundle'
}
const android = {
key: 'here-goes-your-google-client-key'
}
const PushNotification = require('ibm-push-notification')({ ios, android })
async function sendNotification(message) {
try {
return await PushNotification.send({
aps: { badge:3, sound:"bingbong.aiff" },
notification: { title: "Foo", body: "Bar" },
priority: 5,
expiration: 0
}, { ios: <DEVICE_ID>, android: <DEVICE_ID> })
} catch (err) {
throw err
}
}
Multiple devices
Here is an example about how to send the notification to multiple devices (same message)
Only Mandatory Params
const ios = {
p12: '/path/to/Certificate.p12',
password: 'test',
bundle: 'com.yourapp.bundle'
}
const android = {
key: 'here-goes-your-google-client-key'
}
const PushNotification = require('ibm-push-notification')({ ios, android })
async function sendNotification(message) {
try {
return await PushNotification.send({
notification: message
}, { ios: [<DEVICE_ID_1>, <DEVICE_ID_2>], android: [<DEVICE_ID_3>, <DEVICE_ID_4>] })
} catch (err) {
throw err
}
}
Custom Properties
const ios = {
p12: '/path/to/Certificate.p12',
password: 'test',
bundle: 'com.yourapp.bundle'
}
const android = {
key: 'here-goes-your-google-client-key'
}
const PushNotification = require('ibm-push-notification')({ ios, android })
async function sendNotification(message) {
try {
return await PushNotification.send({
aps: { badge:3, sound:"bingbong.aiff" },
notification: { title: "Foo", body: "Bar" },
priority: 5,
expiration: 0
}, { ios: [<DEVICE_ID_1>, <DEVICE_ID_2>], android: [<DEVICE_ID_3>, <DEVICE_ID_4>] })
} catch (err) {
throw err
}
}
Authors
- Adriano - Initial Work -
- Night - Review and Improvements -