From f71d3aed8bc9dbc52e44d960e963294b54dc9ad7 Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Thu, 9 Mar 2023 20:58:19 +0700 Subject: [PATCH] feat: forward PAI from inbound call to dial outbound call (#280) * feat: forward PAI from inbound call to dial outbound call * fix: review comment --------- Co-authored-by: Quan HL --- lib/tasks/dial.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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) {