commit | f374177a5ed6c59b94bd6ccdb8cb82a00ec46805 | [log] [tgz] |
---|---|---|
author | Anantha Krishnan K G <agirijak@in.ibm.com> | Mon Jul 04 16:18:17 2016 +0530 |
committer | GitHub <noreply@github.com> | Mon Jul 04 16:18:17 2016 +0530 |
tree | 451e66ec885f72e42acccc58f385bf99b9845a91 | |
parent | 9b25065da118bb65fa122da4c01cd078413cfe4c [diff] | |
parent | 9105398ffd84a9803c7c742142f77de108766ddc [diff] |
Merge pull request #27 from AnanthaKrish/master Changed the docs.
The /whisk.system/pushnotifications
package enables you to use Push Notification service with Whisk. It includes the following action and feed.
Entity | Type | Parameters | Description |
---|---|---|---|
/whisk.system/pushnotifications | package | appId, appSecret | Work with the Push Service |
/whisk.system/pushnotifications/sendMessage | action | text*, url, deviceIds, platforms, tagNames, apnsBadge, apnsCategory, apnsActionKeyTitle, apnsSound, apnsPayload, apnsType, gcmCollapseKey, gcmDelayWhileIdle, gcmPayload, gcmPriority, gcmSound, gcmTimeToLive | Send push notification to the specified device(s) |
/whisk.system/pushnotifications/webhook | feed | events | Fire trigger events on device activities (device (un)registration / (un)subscription) on the Push Service |
Even though its not mandatory , it‘s suggested that you create a package binding with the appId and appSecret values. This way you don’t need to specify these credentials every time you invoke the actions in the package. |
While creating a IBM Push Notifications package you have to give the following parameters,
appId
: The Bluemix app GUID.appSecret
: The Bluemix push notification service appSecret.The following is an example of creating a package binding.
Create a Bluemix application in Bluemix Dashboard.
Initialize the Push Notification Service and bind the service to the Bluemix application
Configure the IBM Push Notification application.
Be sure to remember the App GUID
and the App Secret
of the Bluemix app you created.
Make sure your OpenWhisk CLI is in the namespace corresponding to the Bluemix organization and space that you used in the previous step.
$ wsk property set --namespace myBluemixOrg_myBluemixSpace
Alternatively, you can use
wsk property set --namespace
to set a namespace from a list of those accessible to you.
/whisk.system/pushnotifications
.wsk package bind /whisk.system/pushnotifications myPush -p appId "myAppID" -p appSecret "myAppSecret"
wsk package list
packages /myNamespace/myPush private binding
{: #action parameters}
The /whisk.system/pushnotifications/sendMessage
action sends push notifications to registered devices. The parameters are as follows:
text
- A mandatory notification message to be sent to the user. Eg: -p text “Hi ,OpenWhisk send a push notification”.url
: An optional URL that can be sent along with the alert. Eg : -p url “https:\www.w3.ibm.com”.gcmPayload
- An optional custom JSON payload that will be sent as part of the notification message. Eg: -p gcmPayload “{“hi”:“hello”}”gcmSound
- An optional parameter. The sound file (on device) that will be attempted to play when the notification arrives on the device .gcmCollapseKey
- This optional parameter identifies a group of messagesgcmDelayWhileIdle
- When this optional parameter is set to true, it indicates that the message should not be sent until the device becomes active.gcmPriority
- This optional parameter sets the priority of the message.gcmTimeToLive
- This optional parameter specifies how long (in seconds) the message should be kept in GCM storage if the device is offline.apnsBadge
- This optional parameter is the number to display as the badge of the application icon.apnsCategory
- An optional parameter. The category identifier to be used for the interactive push notifications .apnsIosActionKey
- This optional title is for the Action key .apnsPayload
- An optional parameter. Custom JSON payload that will be sent as part of the notification message.apnsType
- An optional parameter. [‘DEFAULT’, ‘MIXED’, ‘SILENT’].apnsSound
- An optional parameter. The name of the sound file in the application bundle. The sound of this file is played as an alert.Here is an example of sending push notification from the pushnotification package.
sendMessage
action in the package binding that you created previously. Be sure to replace /myNamespace/myPush
with your package name.wsk action invoke /myNamespace/myPush/sendMessage --blocking --result -p url https://example.com -p text "this is my message" -p sound soundFileName -p deviceIds '["T1","T2"]'
{ "result": { "pushResponse": "{"messageId":"11111H","message":{"message":{"alert":"this is my message","url":"http.google.com"},"settings":{"apns":{"sound":"default"},"gcm":{"sound":"default"},"target":{"deviceIds":["T1","T2"]}}}" }, "status": "success", "success": true }
The /whisk.system/pushnotifications/webhook
configures the IBM Push Notifications 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:
appId:
The Bluemix app GUID.appSecret:
The Bluemix push notification service appSecret.events:
Supported events are onDeviceRegister
, onDeviceUnregister
, onDeviceUpdate
, onSubscribe
, onUnsubscribe
.To get notified for all events use the wildcard character *
.The following is an example of creating a trigger that will be fired each time there is a new device registered with the IBM Push Notifications Service application.
$ wsk package bind /whisk.system/pushnotifications myNewDeviceFeed --param appId myapp --param appSecret myAppSecret --param events onDeviceRegister
onDeviceRegister
event type using your myNewDeviceFeed/webhook
feed.$ wsk trigger create myPushTrigger --feed myPush/webhook --param events onDeviceRegister
You can use the push package actions and feed in your own openWhisk packages. For using it you have to download the Push package form the openwhisk-package-pushnotifications repository.
To create your own package follow the below steps,
openwhisk-package-pushnotifications
location.wsk package create package-name
commandwsk action create actionName sendMessage.js -p appId "your_AppId" -p appSecret "application_Secret" -p text "message"
You can add multiple parameters to sendMessage action. Check for the available parameters [here](#action parameters)
Create feed using the following command,
wsk action create /myNamespace/yourPackageName/webhook webhook.js -a feed true
Create a trigger using the feed created above,
wsk trigger create triggerName --feed /myNamespace/yourPackageName/webhook -p appId "your_AppId" -p appSecret "application_Secret" -p events "onDeviceUnregister"
Output will be like this:
``` { "response": { "name":"triggerName", "eventTypes":"onDeviceRegister", "url":"https://openWhiskAuth@openwhisk.ng.bluemix.net/api/v1/namespaces/myNamespace/triggers/triggerName" } } ```
We need to create a rule that will combine the trigger and the action created in previous steps.Create the rule using ,
wsk rule create --enable yourRule triggerName actionName
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://new-console.ng.bluemix.net/openwhisk/dashboard).
The action will send a push notification.
install.sh