-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (50 loc) · 1.19 KB
/
index.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
'use strict';
var AWS = require('aws-sdk');
module.exports = Interface;
function Interface(opts)
{
if (!(this instanceof Interface)) return new Interface(opts);
this.sns = new AWS.SNS({
region: opts.region,
apiVersion: opts.apiVersion || '2010-03-31',
accessKeyId: opts.accessKeyId,
secretAccessKey: opts.secretAccessKey
});
}
Interface.prototype.sendNotification = function(type, arn, message, url, callback)
{
var messageJson = "";
switch(type) {
case 'ios': messageJson = _messageForTypeIos(message, url); break;
case 'android': messageJson = _messageForTypeAndroid(message, url); break;
default: throw new Error('Wrong or missing Type. Expecting "ios" or "android".');
}
this.sns.publish({
TargetArn: arn,
Message: messageJson,
MessageStructure: 'json'
}, callback);
}
function _messageForTypeIos(message, url)
{
var apnsJSON = {
aps: {
alert: message,
//badge: 1,
sound: 'notice.mp3'
},
foyer: {
'url': url
}
};
var messageJson = JSON.stringify(apnsJSON);
return JSON.stringify({
default: message,
APNS: messageJson,
APNS_SANDBOX: messageJson
});
}
function _messageForTypeAndroid(message, url)
{
throw new Error('Not implemented yet.');
}