-
Notifications
You must be signed in to change notification settings - Fork 20
/
bounces.js
50 lines (42 loc) · 1.73 KB
/
bounces.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
/**
* Created by ejf3 on 1/13/14.
*/
var c = require('../constants');
var Bounces = function (sns, ses, dynamoEmails) {
this.sns = sns;
this.ses = ses;
this.dynamoEmails = dynamoEmails;
var self = this;
this.confirmSubscription = function(token){
var params = {
TopicArn: "arn:aws:sns:us-east-1:492000747399:aws-node-angular-demos",
Token: token
};
self.sns.confirmSubscription(params, function(err, data){
console.log("confirmed?",data,err);
});
};
this.handleBounce = function(request){
if ("SubscriptionConfirmation" === request.Type && !!request.Token){
self.confirmSubscription(request.Token);
return;
}
if (!!request.Message && !!request.Type && "Notification" === request.Type){
request = JSON.parse(request.Message);
}
if ("Bounce" === request.notificationType && !!request.bounce){
if (!!request.bounce.bouncedRecipients && !!request.bounce.bouncedRecipients.length > 0){
for (var i=0; i<request.bounce.bouncedRecipients.length; i++){
self.dynamoEmails.silentUnsubscribe(request.bounce.bouncedRecipients[i].emailAddress);
}
}
} else if ("Complaint" === request.notificationType && !!request.complaint){
if (!!request.complaint.complainedRecipients && !!request.complaint.complainedRecipients.length > 0){
for (var i=0; i<request.complaint.complainedRecipients.length; i++){
self.dynamoEmails.silentUnsubscribe(request.complaint.complainedRecipients[i].emailAddress);
}
}
}
};
};
module.exports = Bounces;