BluemixPushNotifications
Summary
BluemixPushNotifications is a Node.js SDK for sending push notifications through the IBM Bluemix Push Notifications service.
Installation
npm install bluemix-push-notifications --save
Prerequisite
-
Ensure that the following prerequisites are in place:
var PushNotifications = PushNotifications;var Notification = Notification;var PushMessageBuilder = PushMessageBuilder;
Usage
-
Initialize PushNotifications with details about your Bluemix Push Notifications service.
var myPushNotifications = PushNotificationsRegionUS_SOUTH "your-bluemix-app-guid" "your-push-service-appSecret";The first parameter in the initializer is the Bluemix region where the Push Notifications service is hosted. The four options are :
PushNotifications.Region.US_SOUTH
PushNotifications.Region.UK
PushNotifications.Region.SYDNEY
andPushNotifications.Region.FRANKFURT
Ifnull
is supplied for the last 2 parameters, their values will be automatically retrieved from the Bluemix app's environment variables, provided that your Node.js app is bound to the Bluemix app.
If you are using dedicated service, use
overrideServerHost
and add any of the bluemixRegion (bluemix region) value.PushNotificationsoverrideServerHost = "YOUR_SERVICE_HOST";var myPushNotifications = PushNotificationsRegionUS_SOUTH "your-bluemix-app-guid" "your-push-service-appSecret"; -
Create the push notification that you want to broadcast by supplying the alert message you want to be displayed. An optional URL may be supplied with the alert.
var message = PushMessageBuilderMessage;var notificationExample = Notification;Or
You can specify which devices, users, platforms, tag-subscriptions the notification should be sent to and customize the alert they receive.
-
Create the target. You can either set
deviceIds
oruserIds
or platforms ortagNames
.The following code snippet uses platforms, same way you can do it for deviceIds(...) or userIds(...) or tagNames(...).
var target = PushMessageBuilderTarget; -
Create the message as listed:
var message = PushMessageBuilderMessage;Functionality added for FirefoxWeb, ChromeWeb, SafariWeb, ChromeAppExtension and extra optional settings introduced for Apns and FCM.
-
Set all the optional settings for platforms (APNs, FCM, Safari etc).
//For APNs settingsvar apns = PushMessageBuilderAPNstypeNotificationAPNsTypeDEFAULTtitle"IBM";/* Options style and lights are new optional settings added to FCM,/ * If your require lights and style settings you can create style and lights objects as listed*/var style = PushMessageBuilderFCMStyletypeNotificationFCMStyleTypesBIGTEXT_NOTIFICATIONtext"IBM Push"title"Big Text Notification";var lights = PushMessageBuilderFCMLights;//For FCM settings.//Also timetolive setting is provided which specifies how long (in seconds)//The message should be kept in FCM storage if the device is offline.var fcm = PushMessageBuilderFCMvisibilityNotificationVisibilityPUBLICstylestyle;//For Safari.//All the three settings are mandatory to provide.var safariWeb = PushMessageBuilderSafariWebtitle"IBM"action"View";//For Firefoxvar firefoxWeb = PushMessageBuilderFirefoxWebtitle"IBM";//For ChromeAppExtension.//You need to provide proper iconUrl or else chromeApp would not work.var chromeAppExt = PushMessageBuilderChromeAppExttitle"IBM";//For Chromevar chromeWeb = PushMessageBuilderChromeWebtitle"IBM"; -
Create settings with all platforms optional settings.
var settings = PushMessageBuilderSettings; -
Create final notification using target, settings, and message.
var notificationExample = Notificationtargettarget; -
Send the Push notification.
myPushNotifications;
License
Copyright 2017 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.