This repository allows you to deploy a Push Notifications package for IBM Cloud Functions. The package contains a set of simple functions to get you started composing Cloud Functions applications.
This package is available in Node.js 8.
- Make sure to execute
ibmcloud login
if not already logged in
- Install the Cloud Functions CLI plugin.
ibmcloud plugin install cloud-functions
- Make sure you are authenticated with Cloud Functions and can list entities without errors.
ibmcloud fn list
- Download the wskdeploy utility and add
wskdeploy
to your PATH.
Use wskdeploy
to deploy the package using manifest.yml
.
pushd runtimes/nodejs/
wskdeploy
popd
This creates a new package push-notifications
with the following actions:
- push-notifications/send-message
- push-notifications/webhooks
Future
The utility wskdeploy
will be integrated into a new Cloud Functions CLI plugin command ibmcloud fn deploy
.
Ensure you have created and configured your Push Notifications service on IBM Cloud.
Bind your Push Notifications service instance to the push-notifications
package. This gives actions in the package access to the Push Notifications service credentials.
ibmcloud fn service bind imfpush push-notifications
Send a push notification message using the send-message function.
ibmcloud fn action invoke push-notifications/send-message -b -p messageText "This is a push notification"
You can also include a URL with the push notification.
ibmcloud fn action invoke push-notifications/send-message -b -p messageText "Let's code something" -p messageUrl "http://developer.ibm.com"
If successful, you should see a successful response status, which includes the message and url sent as a part of the result.
"response": {
"result": {
"message": {
"alert": "let's code something",
"url": "http://developer.ibm.com"
},
"messageId": "aNJhg8XX"
},
"status": "success",
"success": true
}
In the Cloud Functions console, go to the Create page.
Using the Cloud Foundry Org and Cloud Foundry Space lists, select the namespace that you want to install the Push Notifications package into. Namespaces are formed from the combined org and space names.
Click Install Packages.
Click on the IBM Push Notifications Package group, and then click on the IBM Push Notifications Package.
Once the Package has been installed you will be redirected to the Actions page and can search for your new Package, which is named push-notifications. You can use the Actions in this Package as you would any other Actions as well as edit their code to suit any specific behavior you may need from the Push Notifications package.
To use the actions in the push-notifications package, you must bind service credentials to the actions. Note: You must complete the following steps for each action that you want to use.
- Click on an Action from the push-notifications Package that you want to use. The details page for that Action opens.
- In the left-hand navigation, click on the Parameters section.
- Enter a new parameter. For the key, enter
__bx_creds
. For the value, paste in the service credentials JSON object from the service instance that you created earlier.
Apache-2.0