added initial support for REST-initiated outdials

This commit is contained in:
Dave Horton
2020-02-01 16:16:00 -05:00
parent 44a1b45357
commit 2525b8c70a
28 changed files with 985 additions and 127 deletions

View File

@@ -1,27 +1,26 @@
const request = require('request');
require('request-debug')(request);
//require('request-debug')(request);
const retrieveApp = require('./retrieve-app');
function hooks(logger, callInfo) {
logger.debug({callInfo}, 'creating action hook');
function actionHook(hook, obj = {}, expectResponse = true) {
const method = hook.method.toUpperCase();
const method = (hook.method || 'POST').toUpperCase();
const auth = (hook.username && hook.password) ?
{username: hook.username, password: hook.password} :
null;
const data = Object.assign({}, obj, callInfo);
logger.debug({data}, `actionhook sending to ${hook.url}`);
if ('GET' === method) {
// remove customer data - only for POSTs since it might be quite complex
delete data.customerData;
}
const data = Object.assign({}, obj, callInfo.toJSON());
logger.debug({hook, data, auth}, 'actionhook');
/* customer data only on POSTs */
if ('GET' === method) delete data.customerData;
const opts = {
url: hook.url,
method,
json: 'POST' === method || expectResponse
};
if (auth) obj.auth = auth;
if (auth) opts.auth = auth;
if ('POST' === method) opts.body = data;
else opts.qs = data;
@@ -40,8 +39,8 @@ function hooks(logger, callInfo) {
});
}
function notifyHook(url, method, auth, opts = {}) {
return actionHook(url, method, auth, opts, false);
function notifyHook(hook, opts = {}) {
return actionHook(hook, opts, false);
}
return {