apache / openwhisk-package-pushnotifications

OpenWhisk Package for Bluemix Push Notifications Service
Apache License 2.0
10 stars 17 forks source link
openwhisk

Using the Push package

License Build Status

The /whisk.system/pushnotifications package enables you to work with a push service.

The package includes the following action and feed:

Entity Type Parameters Description
/whisk.system/pushnotifications package appId, appSecret, admin_url Work with the Push Service
/whisk.system/pushnotifications/sendMessage action text, url, apiHost, deviceIds, platforms, userIds, tagNames, gcmCollapseKey, gcmCategory, gcmIcon, gcmDelayWhileIdle, gcmSync, gcmVisibility, gcmPayload, gcmPriority, gcmSound, gcmTimeToLive, gcmStyleType, gcmStyleTitle, gcmStyleUrl, gcmStyleText, gcmStyleLines, gcmLightsLedArgb, gcmLightsLedOnMs, gcmLightsLedOffMs, apnsBadge, apnsCategory, apnsIosActionKey, apnsPayload, apnsType, apnsSound, apnsTitleLocKey, apnsLocKey, apnsLaunchImage, apnsTitleLocArgs, apnsLocArgs, apnstitle, apnsSubtitle, apnsAttachmentUrl, fireFoxTitle, fireFoxIconUrl, fireFoxTimeToLive, fireFoxPayload, safariTitle, safariUrlArgs, safariAction, chromeTitle, chromeIconUrl, chromeTimeToLive, chromePayload, chromeAppExtTitle, chromeAppExtCollapseKey, chromeAppExtDelayWhileIdle, chromeAppExtIconUrl, chromeAppExtTimeToLive, chromeAppExtPayload Send push notification to one or more specified devices
/whisk.system/pushnotifications/webhook feed events Fire trigger events on device activities (device registration, unregistration, subscription, or unsubscription) on the Push service

Creating a package binding with the appId and appSecret values is suggested. This way, you don't need to specify these credentials every time you invoke the actions in the package.

Creating a Push package binding

While creating a Push Notifications package binding, you must specify the following parameters,

The following is an example of creating a package binding.

  1. Create a Bluemix application in Bluemix Dashboard.

  2. Initialize the Push Notification Service and bind the service to the Bluemix application

  3. Configure the Push Notification application.

    Be sure to remember the App GUID and the App Secret of the Bluemix app you created.

  4. Create a package binding with the /whisk.system/pushnotifications.

    wsk package bind /whisk.system/pushnotifications myPush -p appId myAppID -p appSecret myAppSecret
  5. Verify that the package binding exists.

    wsk package list
    packages
    /myNamespace/myPush private binding

Sending push notifications

The /whisk.system/pushnotifications/sendMessage action sends push notifications to registered devices. The parameters are as follows:

Here is an example of sending push notification from the pushnotification package.

Firing a trigger event on Push Notifications service activity

The /whisk.system/pushnotifications/webhook configures the Push service to fire a trigger when there is a device activity such as device registration / unregistration or subscription / unsubscription in a specified application

The parameters are as follows:

The following is an example of creating a trigger that will be fired each time there is a new device registered with the Push Notifications service application.

  1. Create a package binding configured for your Push Notifications service with your appId and appSecret.

    wsk package bind /whisk.system/pushnotifications myNewDeviceFeed --param appID myapp --param appSecret myAppSecret --param events onDeviceRegister
  2. Create a trigger for the Push Notifications service onDeviceRegister event type using your myPush/webhook feed.

    wsk trigger create myPushTrigger --feed myPush/webhook --param events onDeviceRegister
  3. You could create a rule that sends a message every time a new device gets register. Create a new rule using the previous action and trigger.

    wsk rule create --enable myRule myPushTrigger sendMessage

    {: pre}

    Check the results in the wsk activation poll.

    Register a device in your Bluemix application , you can see the rule,trigger and action getting executed in the openWhisk [dashboard] (https://console.{Domain}/openwhisk/dashboard).

    The action will send a push notification.

Working with repository

Deploying Push Package using installCatalog.sh

  1. git clone https://github.com/openwhisk/openwhisk-package-pushnotifications
  2. cd openwhisk-package-pushnotifications/packages
  3. ./installCatalog.sh AUTH APIHOST WSK_CLI AUTH is your auth key. APIHOST is the OpenWhisk hostname. WSK_CLI is location of the Openwhisk CLI binary.