/
send-push-notification.js
67 lines (55 loc) · 1.66 KB
/
send-push-notification.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
63
64
65
66
67
'use strict';
var Sender = require('../lib/Sender');
module.exports = {
friendlyName: 'Send push notification',
description: 'Send a push notification using APN or GCM',
extendedDescription: '',
inputs: {
message: {
example: {
},
description: 'The notification object (https://www.npmjs.com/package/apn or https://www.npmjs.com/package/node-gcm)',
required: true
},
deviceToken: {
example: '5gxadhy6 6zmtxfl6 5zpbcxmw ez3w7ksf qscpr55t trknkzap 7yyt45sc g6jrw7qz',
description: 'The token device or an array of device tokens',
required: true
},
connectionOptions: {
example: {},
description: 'The connection options (https://www.npmjs.com/package/apn or https://www.npmjs.com/package/node-gcm)',
required: true
},
type: {
example: 0,
description: 'The type of push notification (0: Google, 1: Apple)',
required: true
}
},
defaultExit: 'success',
exits: {
error: {
description: 'Unexpected error occurred.',
},
success: {
description: 'Notification sent.',
},
},
fn: function (inputs, exits) {
var sender;
try {
sender = new Sender(inputs.type, inputs.connectionOptions);
}
catch (ex) {
return exits.error(ex);
}
try {
sender.send(inputs.message, inputs.deviceToken);
}
catch (ex) {
return exits.error(ex);
}
return exits.success();
},
};