├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── packages ├── actions │ └── sendMessage.js ├── feeds │ └── webhook.js └── installCatalog.sh ├── settings.gradle ├── tests ├── build.gradle ├── credentials.json.enc ├── src │ └── test │ │ └── scala │ │ └── packages │ │ └── PushNotificationsTests.scala └── template_credentials.json └── tools └── travis └── build.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Gradle 2 | .gradle 3 | build/ 4 | tests/credentials.json 5 | openwhisk 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | language: scala 4 | 5 | scala: 6 | - 2.12.7 7 | 8 | services: 9 | - docker 10 | 11 | env: 12 | global: 13 | - TERM=dumb 14 | 15 | notifications: 16 | email: false 17 | 18 | install: true 19 | 20 | before_install: 21 | - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then openssl aes-256-cbc -K $encrypted_ff5bbb6225c5_key -iv $encrypted_ff5bbb6225c5_iv -in tests/credentials.json.enc -out tests/credentials.json -d; fi' 22 | - git clone https://github.com/openwhisk/openwhisk.git 23 | - cd openwhisk 24 | - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./tools/travis/setup.sh; fi' 25 | 26 | script: 27 | - ../tools/travis/build.sh 28 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 18 | 19 | # Contributing to Apache OpenWhisk 20 | 21 | Anyone can contribute to the OpenWhisk project, and we welcome your contributions. 22 | 23 | There are multiple ways to contribute: report bugs, improve the docs, and 24 | contribute code, but you must follow these prerequisites and guidelines: 25 | 26 | - [Contributor License Agreement](#contributor-license-agreement) 27 | - [Raising issues](#raising-issues) 28 | - [Coding Standards](#coding-standards) 29 | 30 | ### Contributor License Agreement 31 | 32 | All contributors must sign and submit an Apache CLA (Contributor License Agreement). 33 | 34 | Instructions on how to do this can be found here: 35 | [http://www.apache.org/licenses/#clas](http://www.apache.org/licenses/#clas) 36 | 37 | Once submitted, you will receive a confirmation email from the Apache Software Foundation (ASF) and be added to 38 | the following list: http://people.apache.org/unlistedclas.html. 39 | 40 | Project committers will use this list to verify pull requests (PRs) come from contributors that have signed a CLA. 41 | 42 | We look forward to your contributions! 43 | 44 | ## Raising issues 45 | 46 | Please raise any bug reports on the respective project repository's GitHub issue tracker. Be sure to search the 47 | list to see if your issue has already been raised. 48 | 49 | A good bug report is one that make it easy for us to understand what you were trying to do and what went wrong. 50 | Provide as much context as possible, so we can try to recreate the issue. 51 | 52 | ### Discussion 53 | 54 | Please use the project's developer email list to engage our community: 55 | [dev@openwhisk.incubator.apache.org](dev@openwhisk.incubator.apache.org) 56 | 57 | In addition, we provide a "dev" Slack team channel for conversations at: 58 | https://openwhisk-team.slack.com/messages/dev/ 59 | 60 | ### Coding standards 61 | 62 | Please ensure you follow the coding standards used throughout the existing 63 | code base. Some basic rules include: 64 | 65 | - all files must have the Apache license in the header. 66 | - all PRs must have passing builds for all operating systems. 67 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2015-2016 IBM Corporation 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Using the Push package 2 | 3 | [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0) 4 | [![Build Status](https://travis-ci.org/apache/incubator-openwhisk-package-pushnotifications.svg?branch=master)](https://travis-ci.org/apache/incubator-openwhisk-package-pushnotifications) 5 | 6 | The `/whisk.system/pushnotifications` package enables you to work with a push service. 7 | 8 | The package includes the following action and feed: 9 | 10 | | Entity | Type | Parameters | Description | 11 | | --- | --- | --- | --- | 12 | | `/whisk.system/pushnotifications` | package | appId, appSecret, admin_url | Work with the Push Service | 13 | | `/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 | 14 | | `/whisk.system/pushnotifications/webhook` | feed | events | Fire trigger events on device activities (device registration, unregistration, subscription, or unsubscription) on the Push service | 15 | 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. 16 | 17 | ## Creating a Push package binding 18 | 19 | While creating a Push Notifications package binding, you must specify the following parameters, 20 | 21 | - `appId`: The Bluemix app GUID. 22 | - `appSecret`: The Bluemix push notification service appSecret. 23 | 24 | The following is an example of creating a package binding. 25 | 26 | 1. Create a Bluemix application in [Bluemix Dashboard](http://console.ng.bluemix.net). 27 | 28 | 2. Initialize the Push Notification Service and bind the service to the Bluemix application 29 | 30 | 3. Configure the [Push Notification application](https://console.ng.bluemix.net/docs/services/mobilepush/index.html). 31 | 32 | Be sure to remember the `App GUID` and the `App Secret` of the Bluemix app you created. 33 | 34 | 4. Create a package binding with the `/whisk.system/pushnotifications`. 35 | 36 | ``` 37 | wsk package bind /whisk.system/pushnotifications myPush -p appId myAppID -p appSecret myAppSecret 38 | ``` 39 | 40 | 5. Verify that the package binding exists. 41 | 42 | ``` 43 | wsk package list 44 | ``` 45 | ``` 46 | packages 47 | /myNamespace/myPush private binding 48 | ``` 49 | 50 | 51 | ## Sending push notifications 52 | 53 | The `/whisk.system/pushnotifications/sendMessage` action sends push notifications to registered devices. The parameters are as follows: 54 | 55 | - `text`: The notification message to be shown to the user. For example: `-p text "Hi ,OpenWhisk send a notification"`. 56 | - `url`: An optional URL that can be sent along with the alert. For example: `-p url "https:\\www.w3.ibm.com"`. 57 | - `apiHost`: An optional string that specifies the API host. The default is 'mobile.ng.bluemix.net'. For example: `-p apiHost "mobile.eu-gb.bluemix.net"`. 58 | - `deviceIds` The list of specified devices. For example: `-p deviceIds "[\"deviceID1\"]"`. 59 | - `platforms` Send notification to the devices of the specified platforms. 'A' for apple (iOS) devices and 'G' for google (Android) devices. For example `-p platforms ["A"]`. 60 | - `userIds` - Send notification to the devices of the specified users. For example: `-p userIds "[\"testUser\"]"` 61 | - `tagNames` Send notification to the devices that have subscribed to any of these tags. For example `-p tagNames "[\"tag1\"]" `. 62 | 63 | - `gcmCollapseKey`: This parameter identifies a group of messages 64 | - `gcmCategory` - The category identifier to be used for the interactive push notifications. 65 | - `gcmIcon` - Specify the name of the icon to be displayed for the notification. Make sure the icon is already packaged with the client application. 66 | - `gcmDelayWhileIdle`: When this parameter is set to true, it indicates that the message will not be sent until the device becomes active. 67 | - `gcmSync`: Device group messaging makes it possible for every app instance in a group to reflect the latest messaging state. 68 | - `gcmVisibility`: private/public - Visibility of this notification, which affects how and when the notifications are revealed on a secure locked screen. 69 | - `gcmPayload`: Custom JSON payload that will be sent as part of the notification message. For example: `-p gcmPayload "{\"hi\":\"hello\"}"` 70 | - `gcmPriority`: Sets the priority of the message. 71 | - `gcmSound`: The sound file (on the device) that will be attempted to play when the notification arrives on the device. 72 | - `gcmTimeToLive`: This parameter specifies how long (in seconds) the message will be kept in GCM storage if the device is offline. 73 | - `gcmStyleType`: Specifies the type of expandable notifications. The possible values are `bigtext_notification`, `picture_notification`, `inbox_notification`. 74 | - `gcmStyleTitle`: Specifies the title of the notification. The title is displayed when the notification is expanded. Title must be specified for all three expandable notification. 75 | - `gcmStyleUrl`: An URL from which the picture has to be obtained for the notification. Must be specified for `picture_notification`. 76 | - `gcmStyleText`: The big text that needs to be displayed on expanding a `bigtext_notification`. Must be specified for `bigtext_notification`. 77 | - `gcmStyleLines`: An array of strings that is to be displayed in inbox style for `inbox_notification`. Must be specified for `inbox_notification`. 78 | - `gcmLightsLedArgb` - The color of the led. The hardware will do its best approximation. 79 | - `gcmLightsLedOnMs` - The number of milliseconds for the LED to be on while it's flashing. The hardware will do its best approximation. 80 | - `gcmLightsLedOffMs` - The number of milliseconds for the LED to be off while it's flashing. The hardware will do its best approximation. 81 | 82 | - `apnsBadge`: The number to display as the badge of the application icon. 83 | - `apnsCategory`: The category identifier to be used for the interactive push notifications. 84 | - `apnsIosActionKey`: The title for the Action key . 85 | - `apnsPayload`: Custom JSON payload that will be sent as part of the notification message. 86 | - `apnsType`: ['DEFAULT', 'MIXED', 'SILENT']. 87 | - `apnsSound`: The name of the sound file in the application bundle. The sound of this file is played as an alert. 88 | - `apnsTitleLocKey` - The key to a title string in the Localizable.strings file for the current localization. The key string can be formatted with %@ and %n$@ specifiers to take the variables specified in the `titleLocArgs` array. 89 | - `apnsLocKey` - A key to an alert-message string in a Localizable.strings file for the current localization (which is set by the user’s language preference). The key string can be formatted with %@ and %n$@ specifiers to take the variables specified in the locArgs array. 90 | - `apnsLaunchImage` - The filename of an image file in the app bundle, with or without the filename extension. The image is used as the launch image when users tap the action button or move the action slider. 91 | - `pnsTitleLocArgs` - Variable string values to appear in place of the format specifiers in `title-loc-key`. 92 | - `apnsLocArgs` - Variable string values to appear in place of the format specifiers in `locKey`. 93 | - `apnstitle` - The title of Rich Push notifications (Supported only on iOS 10 and above). 94 | - `apnsSubtitle` - The subtitle of the Rich Notifications. (Supported only on iOS 10 and above). 95 | - `apnsAttachmentUrl` - The link to the iOS notifications media (video, audio, GIF, images - Supported only on iOS 10 and above). 96 | 97 | - `fireFoxTitle`: Specifies the title to be set for the WebPush Notification. 98 | - `fireFoxIconUrl`: The URL of the icon to be set for the WebPush Notification. 99 | - `fireFoxTimeToLive`: This parameter specifies how long (in seconds) the message should be kept in GCM storage if the device is offline. 100 | - `fireFoxPayload`: Custom JSON payload that will be sent as part of the notification message. 101 | 102 | - `chromeTitle`: Specifies the title to be set for the WebPush Notification. 103 | - `chromeIconUrl`: The URL of the icon to be set for the WebPush Notification. 104 | - `chromeTimeToLive`: This parameter specifies how long (in seconds) the message should be kept in GCM storage if the device is offline. 105 | - `chromePayload`: Custom JSON payload that will be sent as part of the notification message. 106 | 107 | - `safariTitle` - Specifies the title to be set for the Safari Push Notifications. 108 | - `safariUrlArgs` - The URL arguments that need to be used with this notification. This has to provided in the form of a JSON Array. 109 | - `safariAction` - The label of the action button. 110 | 111 | - `chromeAppExtTitle`: Specifies the title to be set for the WebPush Notification. 112 | - `chromeAppExtCollapseKey`: This parameter identifies a group of messages. 113 | - `chromeAppExtDelayWhileIdle`: When this parameter is set to true, it indicates that the message should not be sent until the device becomes active. 114 | - `chromeAppExtIconUrl`: The URL of the icon to be set for the WebPush Notification. 115 | - `chromeAppExtTimeToLive`: This parameter specifies how long (in seconds) the message should be kept in GCM storage if the device is offline. 116 | - `chromeAppExtPayload`: Custom JSON payload that will be sent as part of the notification message. 117 | 118 | Here is an example of sending push notification from the *pushnotification* package. 119 | 120 | - Send a push notification by using the `sendMessage` action in the package binding that you created previously. Be sure to replace `/myNamespace/myPush` with your package name. 121 | 122 | ``` 123 | 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\"]" 124 | ``` 125 | {: pre} 126 | ```json 127 | { 128 | "result": { 129 | "pushResponse": 130 | { 131 | "messageId":"11111H", 132 | "message":{ 133 | "alert":"this is my message", 134 | "url":"" 135 | }, 136 | "settings":{ 137 | "apns":{ 138 | "sound":"default" 139 | }, 140 | "gcm":{ 141 | "sound":"default" 142 | }, 143 | "target":{ 144 | "deviceIds":["T1","T2"] 145 | } 146 | } 147 | } 148 | }, 149 | "status": "success", 150 | "success": true 151 | } 152 | ``` 153 | 154 | 155 | ## Firing a trigger event on Push Notifications service activity 156 | 157 | 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 158 | 159 | The parameters are as follows: 160 | 161 | - `appId:` The Bluemix app GUID. 162 | - `appSecret:` The Bluemix push notification service appSecret. 163 | - `events:` Supported events are `onDeviceRegister`, `onDeviceUnregister`, `onDeviceUpdate`, `onSubscribe`, `onUnsubscribe`.To get notified for all events use the wildcard character `*`. 164 | 165 | 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. 166 | 167 | 1. Create a package binding configured for your Push Notifications service with your appId and appSecret. 168 | 169 | ``` 170 | wsk package bind /whisk.system/pushnotifications myNewDeviceFeed --param appID myapp --param appSecret myAppSecret --param events onDeviceRegister 171 | ``` 172 | 173 | 2. Create a trigger for the Push Notifications service `onDeviceRegister` event type using your `myPush/webhook` feed. 174 | 175 | ``` 176 | wsk trigger create myPushTrigger --feed myPush/webhook --param events onDeviceRegister 177 | ``` 178 | 179 | 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. 180 | 181 | ``` 182 | wsk rule create --enable myRule myPushTrigger sendMessage 183 | ``` 184 | {: pre} 185 | 186 | Check the results in the `wsk activation poll`. 187 | 188 | 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). 189 | 190 | The action will send a push notification. 191 | 192 | # Working with repository 193 | 194 | ## Deploying Push Package using `installCatalog.sh` 195 | 196 | 1. git clone https://github.com/openwhisk/openwhisk-package-pushnotifications 197 | 2. cd openwhisk-package-pushnotifications/packages 198 | 3. ./installCatalog.sh AUTH APIHOST WSK_CLI 199 | AUTH is your auth key. APIHOST is the OpenWhisk hostname. WSK_CLI is location of the Openwhisk CLI binary. 200 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/openwhisk-package-pushnotifications/9e7a81eb3d8e94f40fb150372643194c740434c1/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /packages/actions/sendMessage.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Action to Send Push Notification using the IBM Push Notifications service 20 | * 21 | * @param {string} appGuid - appGuid to create webhook 22 | * @param {string} appSecret - appSecret of the application 23 | * @param {string} url - An optional URL that can be sent along with the alert. Eg : -p url "https:\\www.mycompany.com". 24 | * @param {string} apiHost - An optional string that specifies the API host. The default is 'mobile.ng.bluemix.net'. Eg : -p apiHost "mobile.eu-gb.bluemix.net". 25 | * @param {object} text - The notification message to be shown to the user. Eg: -p text "Hi ,OpenWhisk send a notification" 26 | * @param {string} deviceIds - Send notification to the list of specified devices. Eg: -p deviceIds "["deviceID1"]" 27 | * @param {object} platforms - Send notification to the devices of the specified platforms. 'A' for apple (iOS) devices and 'G' for google (Android) devices. Eg: -p platforms ["A"] 28 | * @param {object} userIds - Send notification to the devices of the specified users. Eg: -p userIds ["testUser"] 29 | * @param {string} tagNames - Send notification to the devices that have subscribed to any of these tags. Eg -p tagNames "["tag1"]" 30 | 31 | * @param {string} gcmCollapseKey - This parameter identifies a group of messages. 32 | * @param {string} gcmCategory - The category identifier to be used for the interactive push notifications. 33 | * @param {string} gcmIcon - Specify the name of the icon to be displayed for the notification. Make sure the icon is already packaged with the client application. 34 | * @param {string} gcmDelayWhileIdle - When this parameter is set to true, it indicates that the message should not be sent until the device becomes active. 35 | * @param {string} gcmSync - Device group messaging makes it possible for every app instance in a group to reflect the latest messaging state. 36 | * @param {string} gcmVisibility - private/public - Visibility of this notification, which affects how and when the notifications are revealed on a secure locked screen. 37 | * @param {string} gcmPayload - Custom JSON payload that will be sent as part of the notification message. Eg: -p gcmPayload "{"hi":"hello"}". 38 | * @param {string} gcmPriority - Sets the priority of the message. 39 | * @param {string} gcmSound - The sound file (on device) that will be attempted to play when the notification arrives on the device. 40 | * @param {string} gcmTimeToLive - This parameter specifies how long (in seconds) the message should be kept in GCM storage if the device is offline. 41 | * @param {string} gcmStyleType - Specifies the type of expandable notifications. The possible values are bigtext_notification, picture_notification, inbox_notification. 42 | * @param {string} gcmStyleTitle - Specifies the title of the notification. The title is displayed when the notification is expanded. Title must be specified for all three expandable notification. 43 | * @param {string} gcmStyleUrl - An URL from which the picture has to be obtained for the notification. Must be specified for picture_notification. 44 | * @param {string} gcmStyleText - The big text that needs to be displayed on expanding a bigtext_notification. Must be specified for bigtext_notification. 45 | * @param {string} gcmStyleLines - An array of strings that is to be displayed in inbox style for inbox_notification. Must be specified for inbox_notification. 46 | * @param {string} gcmLightsLedArgb - The color of the led. The hardware will do its best approximation. 47 | * @param {string} gcmLightsLedOnMs - The number of milliseconds for the LED to be on while it's flashing. The hardware will do its best approximation. 48 | * @param {string} gcmLightsLedOffMs - The number of milliseconds for the LED to be off while it's flashing. The hardware will do its best approximation. 49 | 50 | * @param {string} apnsBadge - The number to display as the badge of the application icon. 51 | * @param {string} apnsCategory - The category identifier to be used for the interactive push notifications. 52 | * @param {string} apnsIosActionKey - The title for the Action key. 53 | * @param {string} apnsPayload - Custom JSON payload that will be sent as part of the notification message. 54 | * @param {string} apnsType - ['DEFAULT', 'MIXED', 'SILENT']. 55 | * @param {string} apnsSound - The name of the sound file in the application bundle. The sound of this file is played as an alert. 56 | * @param {string} apnsTitleLocKey - The key to a title string in the Localizable.strings file for the current localization. The key string can be formatted with %@ and %n$@ specifiers to take the variables specified in the titleLocArgs array. 57 | * @param {string} apnsLocKey - A key to an alert-message string in a Localizable.strings file for the current localization (which is set by the user’s language preference). The key string can be formatted with %@ and %n$@ specifiers to take the variables specified in the locArgs array. 58 | * @param {string} apnsLaunchImage - The filename of an image file in the app bundle, with or without the filename extension. The image is used as the launch image when users tap the action button or move the action slider. 59 | * @param {string} apnsTitleLocArgs - Variable string values to appear in place of the format specifiers in title-loc-key. 60 | * @param {string} apnsLocArgs - Variable string values to appear in place of the format specifiers in locKey. 61 | * @param {string} apnstitle - The title of Rich Push notifications (Supported only on iOS 10 and above). 62 | * @param {string} apnsSubtitle - The subtitle of the Rich Notifications. (Supported only on iOS 10 and above). 63 | * @param {string} apnsAttachmentUrl - The link to the iOS notifications media (video, audio, GIF, images - Supported only on iOS 10 and above). 64 | 65 | * @param {string} fireFoxTitle - Specifies the title to be set for the WebPush Notification. 66 | * @param {string} fireFoxIconUrl - The URL of the icon to be set for the WebPush Notification. 67 | * @param {string} fireFoxTimeToLive - This parameter specifies how long (in seconds) the message should be kept in GCM storage if the device is offline. 68 | * @param {string} fireFoxPayload - Custom JSON payload that will be sent as part of the notification message. 69 | 70 | * @param {string} chromeTitle - Specifies the title to be set for the WebPush Notification. 71 | * @param {string} chromeIconUrl - The URL of the icon to be set for the WebPush Notification. 72 | * @param {string} chromeTimeToLive - This parameter specifies how long (in seconds) the message should be kept in GCM storage if the device is offline. 73 | * @param {string} chromePayload - Custom JSON payload that will be sent as part of the notification message. 74 | 75 | * @param {string} safariTitle - Specifies the title to be set for the Safari Push Notifications. 76 | * @param {string} safariUrlArgs - The URL arguments that need to be used with this notification. This has to provided in the form of a JSON Array. 77 | * @param {string} safariAction - The label of the action button. 78 | 79 | * @param {string} chromeAppExtTitle - Specifies the title to be set for the WebPush Notification. 80 | * @param {string} chromeAppExtCollapseKey - This parameter identifies a group of messages. 81 | * @param {string} chromeAppExtDelayWhileIdle - When this parameter is set to true, it indicates that the message should not be sent until the device becomes active. 82 | * @param {string} chromeAppExtIconUrl - The URL of the icon to be set for the WebPush Notification. 83 | * @param {string} chromeAppExtTimeToLive - This parameter specifies how long (in seconds) the message should be kept in GCM storage if the device is offline. 84 | * @param {string} chromeAppExtPayload - Custom JSON payload that will be sent as part of the notification message. 85 | * @return {object} whisk async. 86 | */ 87 | module.paths.push('/usr/lib/node_modules'); 88 | var https = require('https'); 89 | var url = require('url'); 90 | 91 | function main(params) { 92 | 93 | if (!params.appId && !params.appGuid) { 94 | return Promise.reject('appId / appGUID of the application is required.'); 95 | } 96 | if (!params.appSecret) { 97 | return Promise.reject('appSecret of the application is required.'); 98 | } 99 | 100 | var appId = params.appGuid || params.appId; 101 | var appSecret = params.appSecret; 102 | 103 | // message section settings 104 | var messageUrl = params.url; 105 | var messageText = params.text; 106 | 107 | // target section settings -- each param should be an array of string 108 | var targetDeviceIds = params.deviceIds; 109 | var targetPlatforms = params.platforms; 110 | var targetTagNames = params.tagNames; 111 | var targetUserIds = params.userIds; 112 | 113 | // apns settings 114 | var apnsBadge = params.apnsBadge; // should be an int 115 | var apnsCategory = params.apnsCategory; 116 | var apnsActionKeyTitle = params.apnsIosActionKey; 117 | var apnsSound = params.apnsSound; 118 | var apnsPayload = params.apnsPayload; 119 | var apnsType = params.apnsType; 120 | var apnsTitleLocKey = params.apnsTitleLocKey; 121 | var apnsLocKey = params.apnsLocKey; 122 | var apnsLaunchImage = params.apnsLaunchImage; 123 | var apnsTitleLocArgs = params.apnsTitleLocArgs; 124 | var apnsLocArgs = params.apnsLocArgs; 125 | var apnstitle = params.apnstitle; 126 | var apnsSubtitle = params.apnsSubtitle; 127 | var apnsAttachmentUrl = params.apnsAttachmentUrl; 128 | 129 | // gcm settings 130 | var gcmCollapseKey = params.gcmCollapseKey; 131 | var gcmDelayWhileIdle = params.gcmDelayWhileIdle; 132 | var gcmPayload = params.gcmPayload; 133 | var gcmPriority = params.gcmPriority; 134 | var gcmSound = params.gcmSound; 135 | var gcmTimeToLive = params.gcmTimeToLive; 136 | var gcmSync = params.gcmSync; 137 | var gcmVisibility = params.gcmVisibility; 138 | var gcmCategory = params.gcmCategory; 139 | var gcmIcon = params.gcmIcon; 140 | 141 | //GCM Style settings 142 | var gcmStyleType = params.gcmStyleType; 143 | var gcmStyleTitle = params.gcmStyleTitle; 144 | var gcmStyleUrl = params.gcmStyleUrl; 145 | var gcmStyleText = params.gcmStyleText; 146 | var gcmStyleLines = params.gcmStyleLines; 147 | 148 | //GCM Light settings 149 | var gcmLightsLedArgb = params.gcmLightsLedArgb; 150 | var gcmLightsLedOnMs = params.gcmLightsLedOnMs; 151 | var gcmLightsLedOffMs = params.gcmLightsLedOffMs; 152 | 153 | //Firefox web settings 154 | var fireFoxTitle = params.fireFoxTitle; 155 | var fireFoxIconUrl = params.fireFoxIconUrl; 156 | var fireFoxTimeToLive = params.fireFoxTimeToLive; 157 | var fireFoxPayload = params.fireFoxPayload; 158 | 159 | //Chrome web settings 160 | var chromeTitle = params.chromeTitle; 161 | var chromeIconUrl = params.chromeIconUrl; 162 | var chromeTimeToLive = params.chromeTimeToLive; 163 | var chromePayload = params.chromePayload; 164 | 165 | //Safari web settings 166 | var safariTitle = params.safariTitle; 167 | var safariUrlArgs = params.safariUrlArgs; 168 | var safariAction = params.safariAction; 169 | 170 | //Chrome Apps & Extensions web settings 171 | var chromeAppExtTitle = params.chromeAppExtTitle; 172 | var chromeAppExtCollapseKey = params.chromeAppExtCollapseKey; 173 | var chromeAppExtDelayWhileIdle = params.chromeAppExtDelayWhileIdle; 174 | var chromeAppExtIconUrl = params.chromeAppExtIconUrl; 175 | var chromeAppExtTimeToLive = params.chromeAppExtTimeToLive; 176 | var chromeAppExtPayload = params.chromeAppExtPayload; 177 | 178 | var sendMessage = {}; 179 | 180 | // create message section 181 | var message = {}; 182 | if (messageText) { 183 | message.alert = messageText; 184 | } 185 | if (messageUrl) { 186 | message.url = messageUrl; 187 | } 188 | 189 | if (isEmpty(message)) { 190 | return Promise.reject("No message to send"); 191 | } else { 192 | sendMessage.message = message; 193 | } 194 | 195 | // create target section 196 | var target = {}; 197 | if (targetDeviceIds) { 198 | target.deviceIds = targetDeviceIds; 199 | } 200 | if (targetPlatforms) { 201 | target.platforms = targetPlatforms; 202 | } 203 | if (targetTagNames) { 204 | target.tagNames = targetTagNames; 205 | } 206 | if (targetUserIds) { 207 | target.userIds = targetUserIds; 208 | } 209 | 210 | if (isEmpty(target)) { 211 | console.log("No target set, broadcasting message to all registered devices"); 212 | } else { 213 | sendMessage.target = target; 214 | } 215 | 216 | // create apns settings section 217 | var apns = {}; 218 | if (apnsBadge) { 219 | apns.badge = apnsBadge; 220 | } 221 | if (apnsCategory) { 222 | apns.category = apnsCategory; 223 | } 224 | if (apnsActionKeyTitle) { 225 | apns.iosActionKey = apnsActionKeyTitle; 226 | } 227 | if (apnsSound) { 228 | apns.sound = apnsSound; 229 | } 230 | if (apnsType) { 231 | apns.type = apnsType; 232 | } 233 | if (apnsPayload) { 234 | apns.payload = apnsPayload; 235 | } 236 | if (apnsTitleLocKey) { 237 | apns.titleLocKey = apnsTitleLocKey; 238 | } 239 | if (apnsLocKey) { 240 | apns.locKey = apnsLocKey; 241 | } 242 | if (apnsLaunchImage) { 243 | apns.launchImage = apnsLaunchImage; 244 | } 245 | if (apnsTitleLocArgs) { 246 | apns.titleLocArgs = apnsTitleLocArgs; 247 | } 248 | if (apnsLocArgs) { 249 | apns.locArgs = apnsLocArgs; 250 | } 251 | if (apnstitle) { 252 | apns.title = apnstitle; 253 | } 254 | if (apnsSubtitle) { 255 | apns.subtitle = apnsSubtitle; 256 | } 257 | if (apnsAttachmentUrl) { 258 | apns.attachmentUrl = apnsAttachmentUrl; 259 | } 260 | 261 | if (!isEmpty(apns)) { 262 | sendMessage.settings = {}; 263 | sendMessage.settings.apns = apns; 264 | } 265 | 266 | // create gcm settings section 267 | var gcm = {}; 268 | if (gcmCollapseKey) { 269 | gcm.collapseKey = gcmCollapseKey; 270 | } 271 | if (gcmDelayWhileIdle) { 272 | gcm.delayWhileIdle = gcmDelayWhileIdle; 273 | } 274 | if (gcmPayload) { 275 | gcm.payload = gcmPayload; 276 | } 277 | if (gcmPriority) { 278 | gcm.priority = gcmPriority; 279 | } 280 | if (gcmSound) { 281 | gcm.sound = gcmSound; 282 | } 283 | if (gcmTimeToLive) { 284 | gcm.timeToLive = gcmTimeToLive; 285 | } 286 | if (gcmVisibility) { 287 | gcm.visibility = gcmVisibility; 288 | } 289 | if (gcmSync) { 290 | gcm.sync = gcmSync; 291 | } 292 | if (gcmCategory) { 293 | gcm.interactiveCategory = gcmCategory; 294 | } 295 | if (gcmIcon) { 296 | gcm.icon = gcmIcon; 297 | } 298 | 299 | var gcmStyle = {}; 300 | if(gcmStyleType){ 301 | gcmStyle.type = gcmStyleType; 302 | } 303 | if (gcmStyleTitle) { 304 | gcmStyle.title = gcmStyleTitle; 305 | } 306 | if (gcmStyleUrl) { 307 | gcmStyle.url = gcmStyleUrl; 308 | } 309 | if (gcmStyleText) { 310 | gcmStyle.text = gcmStyleText; 311 | } 312 | if (gcmStyleLines) { 313 | gcmStyle.lines = gcmStyleLines; 314 | } 315 | if (!isEmpty(gcmStyle)) { 316 | gcm.style = gcmStyle; 317 | } 318 | 319 | var gcmLights = {}; 320 | if(gcmLightsLedArgb){ 321 | gcmLights.ledArgb = gcmLightsLedArgb; 322 | } 323 | if (gcmLightsLedOnMs) { 324 | gcmLights.ledOnMs = gcmLightsLedOnMs; 325 | } 326 | if (gcmLightsLedOffMs) { 327 | gcmLights.ledOffMs = gcmLightsLedOffMs; 328 | } 329 | if (!isEmpty(gcmLights)) { 330 | gcm.lights = gcmLights; 331 | } 332 | 333 | if (!isEmpty(gcm)) { 334 | if (!sendMessage.settings) { 335 | sendMessage.settings = {}; 336 | } 337 | sendMessage.settings.gcm = gcm; 338 | } 339 | 340 | // create FireFox settings section 341 | var firefoxWeb = {}; 342 | if (fireFoxTitle){ 343 | firefoxWeb.title = fireFoxTitle; 344 | } 345 | if (fireFoxIconUrl) { 346 | firefoxWeb.iconUrl = fireFoxIconUrl; 347 | } 348 | if (fireFoxTimeToLive) { 349 | firefoxWeb.timeToLive = fireFoxTimeToLive; 350 | } 351 | if (fireFoxPayload) { 352 | firefoxWeb.payload = fireFoxPayload; 353 | } 354 | 355 | if (!isEmpty(firefoxWeb)) { 356 | if (!sendMessage.settings) { 357 | sendMessage.settings = {}; 358 | } 359 | sendMessage.settings.firefoxWeb = firefoxWeb; 360 | } 361 | 362 | // create Safari settings section 363 | var safariWeb = {}; 364 | if (safariTitle){ 365 | safariWeb.title = safariTitle; 366 | } 367 | if (safariUrlArgs) { 368 | safariWeb.urlArgs = safariUrlArgs; 369 | } 370 | if (safariAction) { 371 | safariWeb.action = safariAction; 372 | } 373 | if (!isEmpty(safariWeb)) { 374 | if (!sendMessage.settings) { 375 | sendMessage.settings = {}; 376 | } 377 | sendMessage.settings.safariWeb = safariWeb; 378 | } 379 | 380 | // create Chrome settings section 381 | var chromeWeb = {}; 382 | if (chromeTitle){ 383 | chromeWeb.title = chromeTitle; 384 | } 385 | if (chromeIconUrl) { 386 | chromeWeb.iconUrl = chromeIconUrl; 387 | } 388 | if (chromeTimeToLive) { 389 | chromeWeb.timeToLive = chromeTimeToLive; 390 | } 391 | if (chromePayload) { 392 | chromeWeb.payload = chromePayload; 393 | } 394 | 395 | if (!isEmpty(chromeWeb)) { 396 | if (!sendMessage.settings) { 397 | sendMessage.settings = {}; 398 | } 399 | sendMessage.settings.chromeWeb = chromeWeb; 400 | } 401 | 402 | // create Chrome Apps & Extensions settings section 403 | var chromeAppExt = {}; 404 | if (chromeAppExtTitle){ 405 | chromeAppExt.title = chromeAppExtTitle; 406 | } 407 | if (chromeAppExtCollapseKey) { 408 | chromeAppExt.collapseKey = chromeAppExtCollapseKey; 409 | } 410 | if (chromeAppExtDelayWhileIdle) { 411 | chromeAppExt.delayWhileIdle = chromeAppExtDelayWhileIdle; 412 | } 413 | if (chromeAppExtIconUrl) { 414 | chromeAppExt.iconUrl = chromeAppExtIconUrl; 415 | } 416 | if (chromeAppExtTimeToLive) { 417 | chromeAppExt.timeToLive = chromeAppExtTimeToLive; 418 | } 419 | if (chromeAppExtPayload) { 420 | chromeAppExt.payload = chromeAppExtPayload; 421 | } 422 | if (!isEmpty(chromeAppExt)) { 423 | if (!sendMessage.settings) { 424 | sendMessage.settings = {}; 425 | } 426 | sendMessage.settings.chromeAppExt = chromeAppExt; 427 | } 428 | 429 | var bodyData = JSON.stringify(sendMessage); 430 | var request = require('request'); 431 | var apiHost; 432 | if (params.apiHost) { 433 | apiHost = params.apiHost; 434 | } 435 | else if (params.admin_url) { 436 | var adminURL = url.parse(params.admin_url).protocol === null ? `https:${params.admin_url}` : params.admin_url; 437 | apiHost = url.parse(adminURL).host; 438 | } 439 | else { 440 | apiHost = 'mobile.ng.bluemix.net'; 441 | } 442 | 443 | var promise = new Promise(function (resolve, reject) { 444 | request({ 445 | method: 'post', 446 | uri: `https://${apiHost}/imfpush/v1/apps/${appId}/messages`, 447 | headers: { 448 | 'appSecret': appSecret, 449 | 'Accept': 'application/json', 450 | 'Content-Type': 'application/json' 451 | }, 452 | body: bodyData 453 | }, function (error, response, body) { 454 | if (error) { 455 | reject(error); 456 | } 457 | var j = JSON.parse(body); 458 | resolve(j); 459 | }); 460 | }); 461 | return promise; 462 | } 463 | 464 | function isEmpty(obj) { 465 | if (obj === null) return true; 466 | if (obj.length > 0) return false; 467 | if (obj.length === 0) return true; 468 | for (var key in obj) { 469 | if (hasOwnProperty.call(obj, key)) return false; 470 | } 471 | 472 | return true; 473 | } 474 | -------------------------------------------------------------------------------- /packages/feeds/webhook.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Feed to create a webhook for IBM Push Notifications service 20 | * 21 | * @param {string} appGuid - appGuid to create webhook 22 | * @param {string} appSecret - appSecret of the application 23 | * @param {string} events - list of the events the webhook should fire on 24 | * @return {object} whisk async 25 | */ 26 | var request = require('request'); 27 | 28 | function main(params) { 29 | 30 | console.log("push trigger feed params: ", params); 31 | var parsedName = parseQName(params.triggerName); 32 | var trigger = parsedName.name; 33 | var namespace = parsedName.namespace; 34 | var endpoint = 'openwhisk.ng.bluemix.net'; 35 | // URL of the whisk system. The calls of push service will go here. 36 | var whiskCallbackUrl = 'https://' + process.env.__OW_API_KEY + "@" + endpoint + '/api/v1/namespaces/' + namespace + '/triggers/' + trigger; 37 | var appId = params.appGuid || params.appId; 38 | var appSecret = params.appSecret; 39 | // The URL to create the webhook on push service 40 | var registrationEndpoint = 'https://mobile.ng.bluemix.net/imfpush/v1/apps/' + appId + '/webhooks'; 41 | var lifecycleEvent = (params.lifecycleEvent || 'CREATE').trim().toUpperCase(); 42 | if (lifecycleEvent === 'CREATE' || lifecycleEvent === 'UPDATE') { 43 | 44 | var events = params.events; 45 | var body = { 46 | name:trigger, 47 | url: whiskCallbackUrl, 48 | eventTypes: events 49 | }; 50 | var options = { 51 | method: 'POST', 52 | url: registrationEndpoint, 53 | body: JSON.stringify(body), 54 | headers: { 55 | 'appSecret': appSecret, 56 | 'Content-Type': 'application/json' 57 | } 58 | }; 59 | var promise = new Promise(function(resolve, reject) { 60 | request(options, function (error, response, body) { 61 | if (error) { 62 | reject(error); 63 | } 64 | resolve({response: body}); 65 | }); 66 | }); 67 | 68 | return promise; 69 | } else if (lifecycleEvent === 'DELETE') { 70 | var options = { 71 | method: 'DELETE', 72 | url: registrationEndpoint, 73 | headers: { 74 | 'appSecret': appSecret 75 | } 76 | }; 77 | var promise = new Promise(function(resolve, reject) { 78 | request(options, function (error, response, body) { 79 | if (error) { 80 | reject(error); 81 | } 82 | resolve({response: body}); 83 | }); 84 | }); 85 | 86 | return promise; 87 | } 88 | } 89 | 90 | function parseQName(qname) { 91 | var parsed = {}; 92 | var delimiter = '/'; 93 | var defaultNamespace = '_'; 94 | if (qname && qname.charAt(0) === delimiter) { 95 | var parts = qname.split(delimiter); 96 | parsed.namespace = parts[1]; 97 | parsed.name = parts.length > 2 ? parts.slice(2).join(delimiter) : ''; 98 | } else { 99 | parsed.namespace = defaultNamespace; 100 | parsed.name = qname; 101 | } 102 | return parsed; 103 | } 104 | -------------------------------------------------------------------------------- /packages/installCatalog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # use the command line interface to install standard actions deployed 4 | # automatically 5 | # 6 | # To run this command 7 | # ./installCatalog.sh 8 | # AUTH and APIHOST are found in $HOME/.wskprops 9 | # WSK_CLI="$OPENWHISK_HOME/bin/wsk" 10 | 11 | set -e 12 | set -x 13 | 14 | if [ $# -eq 0 ] 15 | then 16 | echo "Usage: ./installCatalog.sh " 17 | fi 18 | 19 | AUTH="$1" 20 | APIHOST="$2" 21 | WSK_CLI="$3" 22 | 23 | # If the auth key file exists, read the key in the file. Otherwise, take the 24 | # first argument as the key itself. 25 | if [ -f "$AUTH" ]; then 26 | AUTH=`cat $AUTH` 27 | fi 28 | 29 | PACKAGE_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 30 | 31 | export WSK_CONFIG_FILE= # override local property file to avoid namespace clashes 32 | 33 | # pushnotifications actions 34 | 35 | echo Installing pushnotifications package. 36 | 37 | $WSK_CLI -i --apihost "$APIHOST" package update --auth "$AUTH" --shared yes "pushnotifications" \ 38 | -a description "This package supports sending push notifications to your mobile device, using the IBM Bluemix Push Notifications service." \ 39 | -a parameters '[ {"name":"appGuid", "required":true, "bindTime":true, "description":"Bluemix application GUID"}, {"name":"appSecret", "required":true, "bindTime":true, "type":"password", "description":"Bluemix Push Service Secret"}, {"name":"admin_url", "required":false, "bindTime":true}]' \ 40 | -a prettyName "Push Notifications" \ 41 | -p bluemixServiceName 'imfpush' 42 | 43 | $WSK_CLI -i --apihost "$APIHOST" action update --kind nodejs:6 --auth "$AUTH" "pushnotifications/webhook" "$PACKAGE_HOME/feeds/webhook.js" \ 44 | -a feed true \ 45 | -a description 'pushnotifications feed' \ 46 | -a parameters '[ {"name":"appGuid", "required":true, "bindTime":true, "description":"Bluemix application GUID"}, {"name":"appSecret", "required":true, "bindTime":true, "type":"password", "description":"Bluemix Push Service Secret"},{"name":"events", "required":true, "description":"Name of the event user want to subscribe"} ]' \ 47 | -a sampleInput '{"appGuid":"xxx-xxx-xx", "appSecret":"yyy-yyy-yyy", "events":"onDeviceRegister"}' \ 48 | -a sampleOutput '{"tagName": "tagName","eventType": "onDeviceRegister","applicationId": "xxx-xxx-xx"}' 49 | 50 | 51 | $WSK_CLI -i --apihost "$APIHOST" action update --kind nodejs:6 --auth "$AUTH" "pushnotifications/sendMessage" "$PACKAGE_HOME/actions/sendMessage.js" \ 52 | -a description 'Send push notification to all application users or to a specific set of devices' \ 53 | -a parameters '[ {"name":"appGuid", "required":true, "bindTime":true, "description":"Bluemix application GUID"}, {"name":"appSecret", "required":true, "bindTime":true, "type":"password", "description":"Bluemix Push Service Secret"}, {"name":"text", "required":true, "description":"The notification message to be shown to the user"}, {"name":"url", "required":false, "description":"An optional URL that can be sent along with the alert"}, {"name":"apiHost", "required":false, "description":"API host"}, {"name":"deviceIds", "required":false, "description":"Array of device IDs"}, {"name":"platforms", "required":false, "description":"Array of device platform"},{"name":"userIds", "required":false, "description":"Array of UserIds"},{"name":"tagNames", "required":false, "description":"Array of tag names"},{"name":"gcmCollapseKey", "required":false, "description":"This parameter identifies a group of messages"},{"name":"gcmCategory", "required":false, "description":"The category identifier to be used for the interactive push notifications"},{"name":"gcmIcon", "required":false, "description":"Specify the name of the icon to be displayed for the notification"},{"name":"gcmDelayWhileIdle", "required":false, "description":"Send message when device is active"}, {"name":"gcmSync", "required":false, "description":"Device group messaging"}, {"name":"gcmVisibility", "required":false, "description":"private/public - Visibility of notification"},{"name":"gcmPayload", "required":false, "description":"Additional payload"}, {"name":"gcmPriority", "required":false, "description":"Sets the priority of the message"},{"name":"gcmSound", "required":false, "description":"Sound file name"}, {"name":"gcmTimeToLive", "required":false, "description":"Time limit for message to be delivered"}, {"name":"gcmStyleType", "required":false, "description":"Specifies the type of expandable notifications"}, {"name":"gcmStyleTitle", "required":false, "description":"Specifies the title of the notification"}, {"name":"gcmStyleUrl", "required":false, "description":"An URL from which the picture has to be obtained for the notification"}, {"name":"gcmStyleText", "required":false, "description":"The big text in bigtext_notification"}, {"name":"gcmStyleLines", "required":false, "description":"An array of strings for inbox_notification"},{"name":"gcmLightsLedArgb", "required":false, "description":"The color of the led. The hardware will do its best approximation"},{"name":"gcmLightsLedOnMs", "required":false, "description":"The number of milliseconds for the LED to be on while it is flashing. The hardware will do its best approximation"},{"name":"gcmLightsLedOffMs", "required":false, "description":"The number of milliseconds for the LED to be off while it iss flashing. The hardware will do its best approximation"},{"name":"apnsBadge", "required":false, "description":"Value for Badge"}, {"name":"apnsCategory", "required":false, "description":"The category name"}, {"name":"apnsIosActionKey", "required":false, "description":"Title for the push notification action Key"},{"name":"apnsPayload", "required":false, "description":"Additional payload"},{"name":"apnsType", "required":false, "description":"Push notification type name"},{"name":"apnsSound", "required":false, "description":"APNS sound name"}, {"name":"apnsTitleLocKey", "required":false, "description":"The key to a title string in the Localizable.strings file for the current localization"},{"name":"apnsLocKey", "required":false, "description":"A key to an alert-message string in a Localizable.strings file for the current localization"},{"name":"apnsLaunchImage", "required":false, "description":"The filename of an image file in the app bundle, with or without the filename extension"},{"name":"apnsTitleLocArgs", "required":false, "description":"Variable string values to appear in place of the format specifiers in title-loc-key"},{"name":"apnsLocArgs", "required":false, "description":"Variable string values to appear in place of the format specifiers in locKey"},{"name":"apnstitle", "required":false, "description":"The title of Rich Push notifications"},{"name":"apnsSubtitle", "required":false, "description":"The subtitle of the Rich Notifications"},{"name":"apnsAttachmentUrl", "required":false, "description":"The link to the iOS notifications media"},{"name":"fireFoxTitle", "required":false, "description":"Specifies the title to be set for the WebPush Notification"}, {"name":"fireFoxIconUrl", "required":false, "description":"The URL of the icon to be set for the WebPush Notification."}, {"name":"fireFoxTimeToLive", "required":false, "description":"This parameter specifies how long (in seconds) the message should be kept in GCM storage if the device is offline."}, {"name":"fireFoxPayload", "required":false, "description":"Custom JSON payload"}, {"name":"chromeTitle", "required":false, "description":"Specifies the title to be set for the WebPush Notification"}, {"name":"chromeIconUrl", "required":false, "description":"The URL of the icon to be set for the WebPush Notification"}, {"name":"chromeTimeToLive", "required":false, "description":"This parameter specifies how long (in seconds) the message should be kept in GCM storage if the device is offline."}, {"name":"chromePayload", "required":false, "description":"Custom JSON payload"},{"name":"safariTitle", "required":false, "description":"Specifies the title to be set for the Safari Push Notifications"},{"name":"safariUrlArgs", "required":false, "description":"The URL arguments that need to be used with this notification. This has to provided in the form of a JSON Array"},{"name":"safariAction", "required":false, "description":"The label of the action button"},{"name":"chromeAppExtTitle", "required":false, "description":"Specifies the title to be set for the WebPush Notification"}, {"name":"chromeAppExtCollapseKey", "required":false, "description":"This parameter identifies a group of messages"},{"name":"chromeAppExtDelayWhileIdle", "required":false, "description":"When this parameter is set to true, it indicates that the message should not be sent until the device becomes active"}, {"name":"chromeAppExtIconUrl", "required":false, "description":"The URL of the icon to be set for the WebPush Notification"}, {"name":"chromeAppExtTimeToLive", "required":false, "description":"This parameter specifies how long (in seconds) the message should be kept in GCM storage if the device is offline"}, {"name":"chromeAppExtPayload", "required":false, "description":"Custom JSON payload"}]' \ 54 | -a sampleInput '{"appGuid":"xxx-xxx-xx", "appSecret":"yyy-yyy-yyy", "text":"hi there"}' \ 55 | -a sampleOutput '{"pushResponse": {"messageId":"11111s","message":{"message":{"alert":"register for tag"}}}}' 56 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'tests' 2 | 3 | rootProject.name = 'openwhisk-package-pushnotifications' 4 | 5 | gradle.ext.openwhisk = [ 6 | version: '1.0.0-SNAPSHOT' 7 | ] 8 | 9 | gradle.ext.scala = [ 10 | version: '2.12.7', 11 | compileFlags: ['-feature', '-unchecked', '-deprecation', '-Xfatal-warnings', '-Ywarn-unused-import'] 12 | ] 13 | -------------------------------------------------------------------------------- /tests/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'scala' 2 | apply plugin: 'eclipse' 3 | compileTestScala.options.encoding = 'UTF-8' 4 | 5 | repositories { 6 | mavenCentral() 7 | mavenLocal() 8 | } 9 | 10 | tasks.withType(Test) { 11 | testLogging { 12 | events "passed", "skipped", "failed" 13 | showStandardStreams = true 14 | exceptionFormat = 'full' 15 | } 16 | outputs.upToDateWhen { false } // force tests to run every time 17 | } 18 | 19 | dependencies { 20 | compile "org.scala-lang:scala-library:${gradle.scala.version}" 21 | compile "org.apache.openwhisk:openwhisk-tests:${gradle.openwhisk.version}:tests" 22 | compile "org.apache.openwhisk:openwhisk-tests:${gradle.openwhisk.version}:test-sources" 23 | } 24 | 25 | tasks.withType(ScalaCompile) { 26 | scalaCompileOptions.additionalParameters = gradle.scala.compileFlags 27 | } 28 | -------------------------------------------------------------------------------- /tests/credentials.json.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/openwhisk-package-pushnotifications/9e7a81eb3d8e94f40fb150372643194c740434c1/tests/credentials.json.enc -------------------------------------------------------------------------------- /tests/src/test/scala/packages/PushNotificationsTests.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package packages 18 | 19 | import common.{TestHelpers, Wsk, WskProps, WskTestHelpers, _} 20 | import org.junit.runner.RunWith 21 | import org.scalatest.junit.JUnitRunner 22 | import spray.json.DefaultJsonProtocol._ 23 | import spray.json._ 24 | 25 | @RunWith(classOf[JUnitRunner]) 26 | class PushNotificationsTests 27 | extends TestHelpers 28 | with WskTestHelpers{ 29 | implicit val wskprops = WskProps() 30 | val wsk = new Wsk() 31 | val credentials = TestUtils.getVCAPcredentials("imfpush") 32 | val appSecret = credentials.get("appSecret").toJson; 33 | val credentialsUrl = credentials.get("url"); 34 | val adminURL = credentials.get("admin_url"); 35 | val apiHost = adminURL.split("/")(2); 36 | val appGuid = credentialsUrl.split("/").last.toJson; 37 | val url = "www.google.com".toJson; 38 | 39 | val messageText = "This is pushnotifications Testing".toJson; 40 | val unicodeMessage = "\ue04a".toJson; 41 | val accentMessage = "Máxima de 33 C and Mínima de 26 C".toJson; 42 | 43 | behavior of "Push Package" 44 | 45 | it should "Send Notification action" in { 46 | val name = "/whisk.system/pushnotifications/sendMessage" 47 | withActivation(wsk.activation,wsk.action.invoke(name, Map("appSecret" -> appSecret, "appGuid" -> appGuid, "text" -> messageText))){ 48 | _.response.result.get.toString should include ("message") 49 | } 50 | } 51 | 52 | it should "Send Notification action with unicode message" in { 53 | val name = "/whisk.system/pushnotifications/sendMessage" 54 | withActivation(wsk.activation,wsk.action.invoke(name, Map("appSecret" -> appSecret, "appGuid" -> appGuid, "text" -> unicodeMessage))){ 55 | _.response.result.get.toString should include ("message") 56 | } 57 | } 58 | 59 | it should "Send Notification action with accent message" in { 60 | val name = "/whisk.system/pushnotifications/sendMessage" 61 | withActivation(wsk.activation,wsk.action.invoke(name, Map("appSecret" -> appSecret, "appGuid" -> appGuid, "text" -> accentMessage))){ 62 | _.response.result.get.toString should include ("message") 63 | } 64 | } 65 | 66 | it should "Send Notification action with url" in { 67 | val name = "/whisk.system/pushnotifications/sendMessage" 68 | withActivation(wsk.activation,wsk.action.invoke(name, Map("appSecret" -> appSecret, "appGuid" -> appGuid, "text" -> messageText, "url"-> url))){ 69 | _.response.result.get.toString should include ("message") 70 | } 71 | } 72 | 73 | it should "Send Notification action using admin_url" in { 74 | val name = "/whisk.system/pushnotifications/sendMessage" 75 | withActivation(wsk.activation,wsk.action.invoke(name, Map("appSecret" -> appSecret, "appGuid" -> appGuid, "text" -> messageText, "admin_url"-> adminURL.toJson))){ 76 | _.response.result.get.toString should include ("message") 77 | } 78 | } 79 | 80 | it should "Send Notification action using bad admin_url" in { 81 | val name = "/whisk.system/pushnotifications/sendMessage" 82 | withActivation(wsk.activation,wsk.action.invoke(name, Map("appSecret" -> appSecret, "appGuid" -> appGuid, "text" -> messageText, "admin_url"-> "//mobile.bad.host/pathname".toJson))){ 83 | _.response.success shouldBe false 84 | } 85 | } 86 | 87 | it should "Send Notification action using apiHost" in { 88 | val name = "/whisk.system/pushnotifications/sendMessage" 89 | withActivation(wsk.activation,wsk.action.invoke(name, Map("appSecret" -> appSecret, "appGuid" -> appGuid, "text" -> messageText, "apiHost"-> apiHost.toJson))){ 90 | _.response.result.get.toString should include ("message") 91 | } 92 | } 93 | 94 | it should "Send Notification action using bad apiHost" in { 95 | val name = "/whisk.system/pushnotifications/sendMessage" 96 | withActivation(wsk.activation,wsk.action.invoke(name, Map("appSecret" -> appSecret, "appGuid" -> appGuid, "text" -> messageText, "apiHost"-> "mobile.bad.host".toJson))){ 97 | _.response.success shouldBe false 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /tests/template_credentials.json: -------------------------------------------------------------------------------- 1 | { 2 | "template_service": [{ 3 | "name": "Service x", 4 | "label": "service-x", 5 | "credentials": { 6 | "apiKey": "XXXXXXXX", 7 | "apiToken": "YYYYYYY", 8 | "base_uri": "https://openwhisk.ng.bluemix.net/api/v1" 9 | } 10 | }], 11 | "another_service": [{ 12 | "name": "Service y", 13 | "label": "service-y", 14 | "credentials": { 15 | "apiKey": "ZZZZZZZZZZ", 16 | "apiToken": "MMMMMMMMMM", 17 | "base_uri": "https://openwhisk.ng.bluemix.net/api/v1" 18 | } 19 | }] 20 | } 21 | -------------------------------------------------------------------------------- /tools/travis/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Build script for Travis-CI. 3 | 4 | SCRIPTDIR=$(cd $(dirname "$0") && pwd) 5 | ROOTDIR="$SCRIPTDIR/../.." 6 | WHISKDIR="$ROOTDIR/openwhisk" 7 | 8 | cd $WHISKDIR 9 | 10 | tools/build/scanCode.py $ROOTDIR 11 | 12 | # No point to continue with PRs, since encryption is on 13 | if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then exit 0; fi 14 | 15 | cd $WHISKDIR/ansible 16 | 17 | ANSIBLE_CMD="ansible-playbook -i environments/local" 18 | 19 | $ANSIBLE_CMD setup.yml 20 | $ANSIBLE_CMD prereq.yml 21 | $ANSIBLE_CMD couchdb.yml 22 | $ANSIBLE_CMD initdb.yml 23 | $ANSIBLE_CMD properties.yml 24 | 25 | cd $WHISKDIR 26 | 27 | TERM=dumb ./gradlew \ 28 | :common:scala:install \ 29 | :core:controller:install \ 30 | :core:invoker:install \ 31 | :tests:install \ 32 | :tools:admin:install \ 33 | distDocker 34 | 35 | cd $WHISKDIR/ansible 36 | 37 | $ANSIBLE_CMD wipe.yml 38 | $ANSIBLE_CMD openwhisk.yml 39 | 40 | cd $WHISKDIR 41 | 42 | VCAP_SERVICES_FILE="$(readlink -f $WHISKDIR/../tests/credentials.json)" 43 | 44 | #update whisk.properties to add tests/credentials.json file to vcap.services.file, which is needed in tests 45 | WHISKPROPS_FILE="$WHISKDIR/whisk.properties" 46 | sed -i 's:^[ \t]*vcap.services.file[ \t]*=\([ \t]*.*\)$:vcap.services.file='$VCAP_SERVICES_FILE':' $WHISKPROPS_FILE 47 | cat whisk.properties 48 | 49 | WSK_CLI=$WHISKDIR/bin/wsk 50 | AUTH_KEY=$(cat $WHISKDIR/ansible/files/auth.whisk.system) 51 | EDGE_HOST=$(grep '^edge.host=' $WHISKPROPS_FILE | cut -d'=' -f2) 52 | 53 | # Set Environment 54 | export OPENWHISK_HOME=$WHISKDIR 55 | 56 | # Install the package 57 | source $ROOTDIR/packages/installCatalog.sh $AUTH_KEY $EDGE_HOST $WSK_CLI 58 | 59 | # Test 60 | cd $ROOTDIR 61 | ./gradlew :tests:test 62 | 63 | --------------------------------------------------------------------------------