diff --git a/lib/tasks/dial.js b/lib/tasks/dial.js index 2fa32534..4b4415f4 100644 --- a/lib/tasks/dial.js +++ b/lib/tasks/dial.js @@ -400,15 +400,19 @@ class TaskDial extends Task { let fqdn; if (!sbcAddress) throw new Error('no SBC found for outbound call'); + this.headers = { + 'X-Account-Sid': cs.accountSid, + ...(req && req.has('X-CID') && {'X-CID': req.get('X-CID')}), + ...(req && req.has('P-Asserted-Identity') && {'P-Asserted-Identity': req.get('P-Asserted-Identity')}), + // Put headers at the end to make sure opt.headers override all default behavior. + ...this.headers + }; + const opts = { - headers: req && req.has('X-CID') ? Object.assign(this.headers, {'X-CID': req.get('X-CID')}) : this.headers, + headers: this.headers, proxy: `sip:${sbcAddress}`, callingNumber: this.callerId || req.callingNumber }; - opts.headers = { - ...opts.headers, - 'X-Account-Sid': cs.accountSid - }; const t = this.target.find((t) => t.type === 'teams'); if (t) {