huston, we've got texts

This commit is contained in:
AJ ONeal 2017-07-06 18:52:19 +00:00
parent f4c41150b3
commit bc970b4ffe
1 changed files with 53 additions and 4 deletions

View File

@ -341,6 +341,10 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
, configurable: false , configurable: false
, writable: false , writable: false
, value: function getSiteConfigProp(section) { , value: function getSiteConfigProp(section) {
// deprecated
if ('com.daplie.tel' === section) {
section = 'tel@daplie.com';
}
return PromiseA.resolve((siteConfig || {})[section]); return PromiseA.resolve((siteConfig || {})[section]);
} }
}); });
@ -494,7 +498,8 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
// Twilio Parameters are often 26 long // Twilio Parameters are often 26 long
var bodyParserTwilio = require('body-parser').urlencoded({ limit: '4kb', parameterLimit: 100, extended: false }); var bodyParserTwilio = require('body-parser').urlencoded({ limit: '4kb', parameterLimit: 100, extended: false });
var bodyParserMailgun = require('body-parser').urlencoded({ limit: '100kb', parameterLimit: 500, extended: false }); // Mailgun has something like 50 parameters
var bodyParserMailgun = require('body-parser').urlencoded({ limit: '1024kb', parameterLimit: 500, extended: false });
function bodyMultiParserMailgun (req, res, next) { function bodyMultiParserMailgun (req, res, next) {
var multiparty = require('multiparty'); var multiparty = require('multiparty');
var form = new multiparty.Form(); var form = new multiparty.Form();
@ -520,13 +525,36 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
}); });
} }
function daplieTel() {
return twilioTel().then(function (twilio) {
function sms(opts) {
// opts = { to, from, body }
return new apiDeps.Promise(function (resolve, reject) {
twilio.sendSms(opts, function (err, resp) {
if (err) {
reject(err);
return;
}
resolve(resp);
});
});
}
return {
sms: sms
, mms: function () { throw new Error('MMS Not Implemented'); }
};
});
}
var caps = { var caps = {
// //
// Capabilities for APIs // Capabilities for APIs
// //
'mailer@daplie.com': mailgunMail // whichever mailer 'mailer@daplie.com': mailgunMail // whichever mailer
, 'mailgun@daplie.com': mailgunMail // specifically mailgun , 'mailgun@daplie.com': mailgunMail // specifically mailgun
, 'tel@daplie.com': twilioTel // whichever telephony service , 'tel@daplie.com': daplieTel // whichever telephony service
, 'twilio@daplie.com': twilioTel // specifically twilio , 'twilio@daplie.com': twilioTel // specifically twilio
, 'com.daplie.tel.twilio': twilioTel // deprecated alias , 'com.daplie.tel.twilio': twilioTel // deprecated alias
@ -535,15 +563,33 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
// //
//, 'mailgun.urlencoded@daplie.com': function (req, res, next) { ... } //, 'mailgun.urlencoded@daplie.com': function (req, res, next) { ... }
, 'mailgun.parsers@daplie.com': function (req, res, next) { , 'mailgun.parsers@daplie.com': function (req, res, next) {
console.log('mailgun parser req.headers'); var chunks = [];
console.log(req.headers);
req.on('data', function (chunk) {
chunks.push(chunk);
});
req.on('end', function () {
});
function verify() { function verify() {
var body = req.body; var body = req.body;
var mailconf = siteConfig['mailgun.org']; var mailconf = siteConfig['mailgun.org'];
if (!body.timestamp) {
console.log('mailgun parser req.headers');
console.log(req.headers);
chunks.forEach(function (datum) {
console.log('Length:', datum.length);
//console.log(datum.toString('utf8'));
});
console.log('weird body');
console.log(body);
}
if (!validateMailgun(mailconf.apiKey, body.timestamp, body.token, body.signature)) { if (!validateMailgun(mailconf.apiKey, body.timestamp, body.token, body.signature)) {
console.error('Request came, but not from Mailgun'); console.error('Request came, but not from Mailgun');
console.error(req.url);
console.error(req.headers);
res.send({ error: { message: 'Invalid signature. Are you even Mailgun?' } }); res.send({ error: { message: 'Invalid signature. Are you even Mailgun?' } });
return; return;
} }
@ -552,12 +598,15 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
} }
if (/urlencoded/.test(req.headers['content-type'])) { if (/urlencoded/.test(req.headers['content-type'])) {
console.log('urlencoded');
bodyParserMailgun(req, res, verify); bodyParserMailgun(req, res, verify);
} }
else if (/multipart/.test(req.headers['content-type'])) { else if (/multipart/.test(req.headers['content-type'])) {
console.log('multipart');
bodyMultiParserMailgun(req, res, verify); bodyMultiParserMailgun(req, res, verify);
} }
else { else {
console.log('no parser');
next(); next();
} }
} }