add twilio capability

This commit is contained in:
AJ ONeal 2017-06-14 02:26:16 +00:00
parent b9551e7b8a
commit bd497902f0
1 changed files with 22 additions and 0 deletions

View File

@ -318,6 +318,7 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
var _stripe_test;
var _mandrill;
var _mailchimp;
var _twilio;
myApp.use('/', function preHandler(req, res, next) {
return getSiteConfig(clientUrih).then(function (siteConfig) {
Object.defineProperty(req, 'getSiteMailer', {
@ -429,6 +430,27 @@ module.exports.create = function (xconfx, apiFactories, apiDeps) {
}
});
var caps = {
'com.daplie.tel.twilio': function (/*opts*/) {
if (_twilio) {
return _twilio;
}
var Twilio = require('twilio');
_twilio = new Twilio.RestClient(siteConfig['twilio.com'].id, siteConfig['twilio.com'].auth);
return apiDeps.Promise.resolve(_twilio);
}
};
req.getSiteCapability = function (capname, opts) {
if (caps[capname]) {
return caps[capname](opts);
}
return apiDeps.Promise.reject(
new Error("['" + req.clientApiUri + '/' + pkgId + "'] "
+ "capability '" + capname + "' not implemented")
);
};
req._walnutOriginalUrl = req.url;
// "/path/api/com.example/hello".replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/') => '/hello'
req.url = req.url.replace(/\/api\//, '').replace(/.*\/api\//, '').replace(/([^\/]*\/+)/, '/');