diff --git a/config/default.json.example b/config/default.json.example index a4ef6929..f6a3f6d0 100644 --- a/config/default.json.example +++ b/config/default.json.example @@ -3,13 +3,11 @@ "port": 3010, "secret": "cymru" }, - "freeswitch: [ - { - "address": "127.0.0.1", - "port": 8021, - "secret": "ClueCon" - } - ], + "freeswitch: { + "address": "127.0.0.1", + "port": 8021, + "secret": "ClueCon" + }, "logging": { "level": "info" }, diff --git a/lib/middleware.js b/lib/middleware.js index 6c535639..22795eaa 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -83,12 +83,12 @@ module.exports = function(srf, logger) { baseUrl: `${u.protocol}://${u.resource}${myPort}`, auth }; - logger.debug({originalRequest: app.originalRequest}, 'invokeWebCallback'); - const obj = req.locals.callInfo; + logger.debug({url: call_hook.url, method}, 'invokeWebCallback'); + const obj = Object.assign({}, req.locals.callInfo); // if the call hook is a POST add the entire SIP message to the payload - if (method === 'POST') Object.assign(obj, {sip: req.msg}); - app.tasks = await retrieveApp(logger, app.call_hook, method, auth, obj); + if (method === 'POST') obj.sip = req.msg; + app.tasks = await retrieveApp(logger, call_hook.url, method, auth, obj); next(); } catch (err) { logger.error(err, 'Error retrieving or parsing application'); diff --git a/lib/session/call-info.js b/lib/session/call-info.js index 0eb045d4..5b1ac3d8 100644 --- a/lib/session/call-info.js +++ b/lib/session/call-info.js @@ -18,7 +18,8 @@ class CallInfo { this.originatingSipIP = req.get('X-Forwarded-For'); this.originatingSipTrunkName = req.get('X-Originating-Carrier'); } - else if (opts.parentCallInfo instanceof CallInfo) { + else if (opts.parentCallInfo) { + console.log(`is opts.parentCallInfo a CallInfo ${opts.parentCallInfo instanceof CallInfo}`); const {req, parentCallInfo} = opts; this.callSid = uuidv4(); this.parentCallSid = parentCallInfo.callSid; diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 011b1c0e..b57cd5b8 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -198,7 +198,7 @@ class CallSession extends Emitter { } _notifyCallStatusChange({callStatus, sipStatus}) { this.logger.debug(`CallSession:_notifyCallStatusChange: ${callStatus} ${sipStatus}`); - this.callInfo.updateStatus(callStatus, sipStatus); + this.callInfo.updateCallStatus(callStatus, sipStatus); try { this.notifyHook(this.application.call_status_hook); } catch (err) { diff --git a/lib/tasks/dial.js b/lib/tasks/dial.js index 88f80304..4815c339 100644 --- a/lib/tasks/dial.js +++ b/lib/tasks/dial.js @@ -130,12 +130,6 @@ class TaskDial extends Task { callingNumber: this.callerId || req.callingNumber }; - // construct bare-bones callInfo for the new outbound call attempt - const callInfo = Object.assign({}, cs.callInfo); - callInfo.parentCallSid = cs.callSid; - callInfo.direction = CallDirection.Outbound; - ['callSid', 'callID', 'from', 'to', 'callerId', 'sipStatus', 'callStatus'].forEach((k) => delete callInfo[k]); - const ms = await cs.getMS(); const timerRing = setTimeout(() => { this.logger.info(`Dial:_attemptCall: ring no answer timer ${this.timeout}s exceeded`); @@ -154,7 +148,7 @@ class TaskDial extends Task { sbcAddress, target: t, opts, - callInfo + callInfo: cs.callInfo }); this.dials.set(sd.callSid, sd); diff --git a/lib/utils/notifiers.js b/lib/utils/notifiers.js index 01135484..cf3b2c11 100644 --- a/lib/utils/notifiers.js +++ b/lib/utils/notifiers.js @@ -3,13 +3,15 @@ require('request-debug')(request); const retrieveApp = require('./retrieve-app'); function hooks(logger, callInfo) { - function actionHook(hook, obj, expectResponse = true) { + logger.debug({callInfo}, 'creating action hook'); + function actionHook(hook, obj = {}, expectResponse = true) { const method = hook.method.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; @@ -20,8 +22,8 @@ function hooks(logger, callInfo) { json: 'POST' === method || expectResponse }; if (auth) obj.auth = auth; - if ('POST' === method) obj.body = data; - else obj.qs = data; + if ('POST' === method) opts.body = data; + else opts.qs = data; return new Promise((resolve, reject) => { request(opts, (err, response, body) => { diff --git a/lib/utils/place-outdial.js b/lib/utils/place-outdial.js index de89782b..ec3e9af5 100644 --- a/lib/utils/place-outdial.js +++ b/lib/utils/place-outdial.js @@ -95,6 +95,7 @@ class SingleDialer extends Emitter { * (a) create a logger for this call * (b) augment this.callInfo with additional call info */ + this.logger.debug(`call sent, creating CallInfo parentCallInfo is CallInfo? ${this.parentCallInfo instanceof CallInfo}`); this.callInfo = new CallInfo({ direction: CallDirection.Outbound, parentCallInfo: this.parentCallInfo, @@ -221,7 +222,7 @@ class SingleDialer extends Emitter { _notifyCallStatusChange({callStatus, sipStatus}) { this.logger.debug(`SingleDialer:_notifyCallStatusChange: ${callStatus} ${sipStatus}`); - this.callInfo.updateStatus(callStatus, sipStatus); + this.callInfo.updateCallStatus(callStatus, sipStatus); try { this.notifyHook(this.application.call_status_hook); } catch (err) {