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

@@ -56,16 +56,26 @@ class Task extends Emitter {
return this._completionPromise;
}
async performAction(method, auth, results) {
if (this.action) {
let action = this.action;
if (action.startsWith('/')) {
const or = this.callSession.originalRequest;
action = `${or.baseUrl}${this.action}`;
this.logger.debug({originalUrl: this.action, normalizedUrl: action}, 'Task:performAction normalized url');
if (!auth && or.auth) auth = or.auth;
normalizeUrl(url, method, auth) {
const hook = {url, method};
if (auth && auth.username && auth.password) Object.assign(hook, auth);
if (url.startsWith('/')) {
const or = this.callSession.originalRequest;
if (or) {
hook.url = `${or.baseUrl}${url}`;
hook.method = hook.method || or.method || 'POST';
if (!hook.auth && or.auth) Object.assign(hook, or.auth);
}
const tasks = await this.actionHook(action, method, auth, results);
}
this.logger.debug({hook}, 'Task:normalizeUrl');
return hook;
}
async performAction(method, auth, results, expectResponse = true) {
if (this.action) {
const hook = this.normalizeUrl(this.action, method, auth);
const tasks = await this.actionHook(hook, results, expectResponse);
if (tasks && Array.isArray(tasks)) {
this.logger.debug({tasks: tasks}, `${this.name} replacing application with ${tasks.length} tasks`);
this.callSession.replaceApplication(tasks);