added code to support GetResponse.com as a contacts/lists manager

This commit is contained in:
tigerbot 2017-08-04 11:45:33 -06:00
parent d4674971da
commit f246cf0b93
2 changed files with 58 additions and 0 deletions

View File

@ -3,6 +3,7 @@
module.exports.create = function (xconfx, apiFactories, apiDeps) {
var PromiseA = apiDeps.Promise;
var mkdirpAsync = PromiseA.promisify(require('mkdirp'));
var request = PromiseA.promisify(require('request'));
//var express = require('express');
var express = require('express-lazy');
var fs = PromiseA.promisifyAll(require('fs'));
@ -320,6 +321,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
var _mandrill;
var _mailchimp;
var _twilio;
var _get_response;
myApp.use('/', function preHandler(req, res, next) {
return getSiteConfig(clientUrih).then(function (siteConfig) {
Object.defineProperty(req, 'getSiteMailer', {
@ -435,6 +437,51 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
}
});
Object.defineProperty(req, 'GetResponse', {
enumerable: true
, configurable: false
, get: function () {
if (_get_response) {
return _get_response;
}
_get_response = {
saveSubscriber: function (email, opts) {
var config = siteConfig['getresponse@daplie.com'];
var customFields = [];
Object.keys(config.customFields).forEach(function (name) {
if (typeof opts[name] !== 'undefined') {
customFields.push({
customFieldId: config.customFields[name]
, value: [ String(opts[name]) ]
});
}
});
return request({
method: 'POST'
, url: 'https://api.getresponse.com/v3/contacts'
, headers: { 'X-Auth-Token': 'api-key ' + config.apiKey }
, json: true
, body: {
name: opts.name
, email: email
, ipAddress: opts.ipAddress
, campaign: { campaignId: config.campaignId }
, customFieldValues: customFields
}
}).then(function (resp) {
if (resp.statusCode === 202) {
return;
}
return PromiseA.reject(resp.body.message);
});
}
};
return _get_response;
}
});
var Twilio = require('twilio');
function twilioTel(/*opts*/) {
if (_twilio) {
@ -496,6 +543,9 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
function mailgunMail(/*opts*/) {
return apiDeps.Promise.resolve(req.getSiteMailer());
}
function getResponseList() {
return apiDeps.Promise.resolve(req.GetResponse);
}
// Twilio Parameters are often 26 long
var bodyParserTwilio = require('body-parser').urlencoded({ limit: '4kb', parameterLimit: 100, extended: false });
@ -560,6 +610,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
, 'twilio@daplie.com': twilioTel // specifically twilio
, 'com.daplie.tel.twilio': twilioTel // deprecated alias
, 'getresponse@daplie.com': getResponseList
//
// Webhook Parsers
//
@ -642,6 +693,12 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
if (caps[capname]) {
return caps[capname](opts, b, c);
}
if (siteConfig[capname]) {
var service = siteConfig[capname].service || siteConfig[capname];
if (caps[service]) {
return caps[service](opts, b, c);
}
}
return apiDeps.Promise.reject(
new Error("['" + req.clientApiUri + '/' + pkgId + "'] "
+ "capability '" + capname + "' not implemented")

View File

@ -60,6 +60,7 @@
"nodemailer": "^1.4.0",
"nodemailer-mailgun-transport": "1.x",
"oauthcommon": "git+https://git.daplie.com/node/oauthcommon.git",
"request": "^2.81.0",
"serve-static": "1.x",
"sqlite3-cluster": "git+https://git.daplie.com/coolaj86/sqlite3-cluster.git#v2",
"stripe": "^4.22.0",