Add capability to use mailchimp back to the mix

This commit is contained in:
Drew Warren 2017-10-25 16:57:40 -06:00
parent 903bd3cead
commit 26c0ed66cf
1 changed files with 36 additions and 2 deletions

View File

@ -431,8 +431,38 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
enumerable: true
, configurable: false
, get: function () {
var Mailchimp = require('mailchimp-api-v3');
_mailchimp = _mailchimp || new Mailchimp(siteConfig['mailchimp.com'].apiKey);
if (_mailchimp) {
return _mailchimp;
}
var Mailchimp = new (require('mailchimp-api-v3'))(siteConfig['mailchimp@daplie.com'].apiKey);
_mailchimp = {
saveSubscriber: function (email, opts) {
var config = siteConfig['mailchimp@daplie.com'];
var interests = {};
Object.keys(config.defaultInterests).forEach(function (name) {
interests[config.defaultInterests[name]] = true;
});
Object.keys(config.optionalInterests).forEach(function (name) {
if (opts[name]) {
interests[config.optionalInterests[name]] = true;
}
});
Mailchimp.post({
// Daplie Updates list
path: '/lists/' + config.listId + '/members'
, body: {
'email_address': email
, 'status_if_new': 'subscribed'
, 'status': 'subscribed'
, 'interests': interests
}
}).catch(function (err) {
console.error("mailchimp failure", email, JSON.stringify(opts));
console.error(err);
});
}
};
return _mailchimp;
}
});
@ -543,6 +573,9 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
function mailgunMail(/*opts*/) {
return apiDeps.Promise.resolve(req.getSiteMailer());
}
function mailchimpList() {
return apiDeps.Promise.resolve(req.Mailchimp);
}
function getResponseList() {
return apiDeps.Promise.resolve(req.GetResponse);
}
@ -611,6 +644,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
, 'com.daplie.tel.twilio': twilioTel // deprecated alias
, 'getresponse@daplie.com': getResponseList
, 'mailchimp@daplie.com': mailchimpList
//
// Webhook Parsers
//