-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush.js
62 lines (55 loc) · 1.45 KB
/
push.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
*
* main() will be invoked when you Run This Action.
*
* @param OpenWhisk actions accept a single parameter,
* which must be a JSON object.
*
* In this case, the params variable will look like:
* { "message": "xxxx" }
*
* @return which must be a JSON object.
* It will be the output of this action.
*
*/
/**
*
* main() will be invoked when you Run This Action.
*
* @param OpenWhisk actions accept a single parameter,
* which must be a JSON object.
*
* In this case, the params variable will look like:
* { "message": "xxxx" }
*
* @return which must be a JSON object.
* It will be the output of this action.
*
*/
var openwhisk = require('openwhisk')
function main(params) {
var message = params.value + " This is a message for deviceid " + params.deviceId;
var deviceID = params.deviceId;
var wsk = openwhisk()
var promise = new Promise(function (resolve, reject) {
var devid = [deviceID]
var tags = ["tagsName"]
wsk.actions.invoke({
actionName: "/whisk.system/pushnotifications/sendMessage",
params: {
"appSecret": "appSecret",
"appId": "appId",
"text": message,
"deviceIds": devid,
"tagNames": tags
}
}).then(result => {
console.log('Message Send to device', result)
resolve(result);
}).catch(err => {
console.error('failed to Send message', err)
reject(err);
});
});
return promise;
}