diff --git a/lib/session/call-info.js b/lib/session/call-info.js index 600ec213..ea29a0c4 100644 --- a/lib/session/call-info.js +++ b/lib/session/call-info.js @@ -1,7 +1,6 @@ const {CallDirection, CallStatus} = require('../utils/constants'); const parseUri = require('drachtio-srf').parseUri; const { v4: uuidv4 } = require('uuid'); - /** * @classdesc Represents the common information for all calls * that is provided in call status webhooks @@ -9,6 +8,7 @@ const { v4: uuidv4 } = require('uuid'); class CallInfo { constructor(opts) { let from ; + let srf; this.direction = opts.direction; if (opts.req) { const u = opts.req.getParsedHeader('from'); @@ -19,6 +19,7 @@ class CallInfo { if (this.direction === CallDirection.Inbound) { // inbound call const {app, req} = opts; + srf = req.srf; this.callSid = req.locals.callSid, this.accountSid = app.account_sid, this.applicationSid = app.application_sid; @@ -33,6 +34,7 @@ class CallInfo { else if (opts.parentCallInfo) { // outbound call that is a child of an existing call const {req, parentCallInfo, to, callSid} = opts; + srf = req.srf; this.callSid = callSid || uuidv4(); this.parentCallSid = parentCallInfo.callSid; this.accountSid = parentCallInfo.accountSid; @@ -47,6 +49,7 @@ class CallInfo { else if (this.direction === CallDirection.None) { // outbound SMS const {messageSid, accountSid, applicationSid, res} = opts; + srf = res.srf; this.messageSid = messageSid; this.accountSid = accountSid; this.applicationSid = applicationSid; @@ -55,6 +58,7 @@ class CallInfo { else { // outbound call triggered by REST const {req, callSid, accountSid, applicationSid, to, tag} = opts; + srf = req.srf; this.callSid = callSid; this.accountSid = accountSid; this.applicationSid = applicationSid; @@ -65,6 +69,8 @@ class CallInfo { this.to = to; if (tag) this._customerData = tag; } + + this.localSipAddress = srf.locals.localSipAddress; } /** @@ -100,7 +106,8 @@ class CallInfo { callStatus: this.callStatus, callerId: this.callerId, accountSid: this.accountSid, - applicationSid: this.applicationSid + applicationSid: this.applicationSid, + fsSipAddress: this.localSipAddress }; ['parentCallSid', 'originatingSipIp', 'originatingSipTrunkName'].forEach((prop) => { if (this[prop]) obj[prop] = this[prop]; @@ -110,6 +117,10 @@ class CallInfo { if (this._customerData) { Object.assign(obj, {customerData: this._customerData}); } + + if (process.env.JAMBONES_API_BASE_URL) { + Object.assign(obj, {apiBaseUrl: process.env.JAMBONES_API_BASE_URL}); + } return obj; }