-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
35 lines (30 loc) · 1.19 KB
/
Copy pathserver.js
File metadata and controls
35 lines (30 loc) · 1.19 KB
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
"use strict";
var MailChimpWebhook = require('mailchimp').MailChimpWebhook,
config = require("./config"),
webhook = new MailChimpWebhook({
port: config.port,
secret: config.secret,
}),
sendgrid = require('sendgrid')(config.sendgrid.user, config.sendgrid.password),
receipients = config.receipients,
sender = config.sender,
list = config.list;
function send(subject, text) {
sendgrid.send({
to: receipients,
from: sender,
subject: subject,
text: text
}, function(err, json) {
if (err) { return console.error(err); }
});
}
webhook.on('error', function (error) {
console.log(error.message);
});
webhook.on('subscribe', function (data, meta) {
send(data.email + " subscribed to " + list.name, "Hi, \n\n Good News!\n " + data.email + " joined your mailing list '" + list.name + "'. \n\n Isn't it the best? Cheers! \n\n Manage your list here: " + list.url);
});
webhook.on('unsubscribe', function (data, meta) {
send(data.email + " unsubscribed from " + list.name, "Hi, \n\n So " + data.email + " left your mailing list '" + list.name + "'. \nSad story.\n\n Manage your list here: " + list.url);
});