mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
include fs_sip_address and api_base_url in webhook paylods
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
const {CallDirection, CallStatus} = require('../utils/constants');
|
const {CallDirection, CallStatus} = require('../utils/constants');
|
||||||
const parseUri = require('drachtio-srf').parseUri;
|
const parseUri = require('drachtio-srf').parseUri;
|
||||||
const { v4: uuidv4 } = require('uuid');
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc Represents the common information for all calls
|
* @classdesc Represents the common information for all calls
|
||||||
* that is provided in call status webhooks
|
* that is provided in call status webhooks
|
||||||
@@ -9,6 +8,7 @@ const { v4: uuidv4 } = require('uuid');
|
|||||||
class CallInfo {
|
class CallInfo {
|
||||||
constructor(opts) {
|
constructor(opts) {
|
||||||
let from ;
|
let from ;
|
||||||
|
let srf;
|
||||||
this.direction = opts.direction;
|
this.direction = opts.direction;
|
||||||
if (opts.req) {
|
if (opts.req) {
|
||||||
const u = opts.req.getParsedHeader('from');
|
const u = opts.req.getParsedHeader('from');
|
||||||
@@ -19,6 +19,7 @@ class CallInfo {
|
|||||||
if (this.direction === CallDirection.Inbound) {
|
if (this.direction === CallDirection.Inbound) {
|
||||||
// inbound call
|
// inbound call
|
||||||
const {app, req} = opts;
|
const {app, req} = opts;
|
||||||
|
srf = req.srf;
|
||||||
this.callSid = req.locals.callSid,
|
this.callSid = req.locals.callSid,
|
||||||
this.accountSid = app.account_sid,
|
this.accountSid = app.account_sid,
|
||||||
this.applicationSid = app.application_sid;
|
this.applicationSid = app.application_sid;
|
||||||
@@ -33,6 +34,7 @@ class CallInfo {
|
|||||||
else if (opts.parentCallInfo) {
|
else if (opts.parentCallInfo) {
|
||||||
// outbound call that is a child of an existing call
|
// outbound call that is a child of an existing call
|
||||||
const {req, parentCallInfo, to, callSid} = opts;
|
const {req, parentCallInfo, to, callSid} = opts;
|
||||||
|
srf = req.srf;
|
||||||
this.callSid = callSid || uuidv4();
|
this.callSid = callSid || uuidv4();
|
||||||
this.parentCallSid = parentCallInfo.callSid;
|
this.parentCallSid = parentCallInfo.callSid;
|
||||||
this.accountSid = parentCallInfo.accountSid;
|
this.accountSid = parentCallInfo.accountSid;
|
||||||
@@ -47,6 +49,7 @@ class CallInfo {
|
|||||||
else if (this.direction === CallDirection.None) {
|
else if (this.direction === CallDirection.None) {
|
||||||
// outbound SMS
|
// outbound SMS
|
||||||
const {messageSid, accountSid, applicationSid, res} = opts;
|
const {messageSid, accountSid, applicationSid, res} = opts;
|
||||||
|
srf = res.srf;
|
||||||
this.messageSid = messageSid;
|
this.messageSid = messageSid;
|
||||||
this.accountSid = accountSid;
|
this.accountSid = accountSid;
|
||||||
this.applicationSid = applicationSid;
|
this.applicationSid = applicationSid;
|
||||||
@@ -55,6 +58,7 @@ class CallInfo {
|
|||||||
else {
|
else {
|
||||||
// outbound call triggered by REST
|
// outbound call triggered by REST
|
||||||
const {req, callSid, accountSid, applicationSid, to, tag} = opts;
|
const {req, callSid, accountSid, applicationSid, to, tag} = opts;
|
||||||
|
srf = req.srf;
|
||||||
this.callSid = callSid;
|
this.callSid = callSid;
|
||||||
this.accountSid = accountSid;
|
this.accountSid = accountSid;
|
||||||
this.applicationSid = applicationSid;
|
this.applicationSid = applicationSid;
|
||||||
@@ -65,6 +69,8 @@ class CallInfo {
|
|||||||
this.to = to;
|
this.to = to;
|
||||||
if (tag) this._customerData = tag;
|
if (tag) this._customerData = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.localSipAddress = srf.locals.localSipAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,7 +106,8 @@ class CallInfo {
|
|||||||
callStatus: this.callStatus,
|
callStatus: this.callStatus,
|
||||||
callerId: this.callerId,
|
callerId: this.callerId,
|
||||||
accountSid: this.accountSid,
|
accountSid: this.accountSid,
|
||||||
applicationSid: this.applicationSid
|
applicationSid: this.applicationSid,
|
||||||
|
fsSipAddress: this.localSipAddress
|
||||||
};
|
};
|
||||||
['parentCallSid', 'originatingSipIp', 'originatingSipTrunkName'].forEach((prop) => {
|
['parentCallSid', 'originatingSipIp', 'originatingSipTrunkName'].forEach((prop) => {
|
||||||
if (this[prop]) obj[prop] = this[prop];
|
if (this[prop]) obj[prop] = this[prop];
|
||||||
@@ -110,6 +117,10 @@ class CallInfo {
|
|||||||
if (this._customerData) {
|
if (this._customerData) {
|
||||||
Object.assign(obj, {customerData: 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;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user