Fix/env vars rest dial (#1225)

* rest dial needs to support env vars

* wip
This commit is contained in:
Dave Horton
2025-05-30 10:14:44 -04:00
committed by GitHub
parent e975511df5
commit 8e9ab83ca4
3 changed files with 12 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ const HttpRequestor = require('../../utils/http-requestor');
const WsRequestor = require('../../utils/ws-requestor');
const RootSpan = require('../../utils/call-tracer');
const dbUtils = require('../../utils/db-utils');
const { decrypt } = require('../../utils/encrypt-decrypt');
const { mergeSdpMedia, extractSdpMedia } = require('../../utils/sdp-utils');
const { createCallSchema, customSanitizeFunction } = require('../schemas/create-call');
const { selectHostPort } = require('../../utils/network');
@@ -212,6 +213,13 @@ router.post('/',
* we merge the inbound call application,
* with the provided app params from the request body
*/
try {
if (application?.env_vars && Object.keys(application.env_vars).length > 0) {
restDial.env_vars = JSON.parse(decrypt(application.env_vars));
}
} catch (err) {
logger.info({err}, 'Unable to set env_vars');
}
const app = {
...application,
...req.body
@@ -224,7 +232,7 @@ router.post('/',
if ('WS' === app.call_hook?.method || /^wss?:/.test(app.call_hook.url)) {
logger.debug({call_hook: app.call_hook}, 'creating websocket for call hook');
app.requestor = new WsRequestor(logger, account.account_sid, app.call_hook, account.webhook_secret) ;
if (app.call_hook.url === app.call_status_hook.url || !app.call_status_hook?.url) {
if (app.call_hook.url === app.call_status_hook?.url || !app.call_status_hook?.url) {
logger.debug('reusing websocket for call status hook');
app.notifier = app.requestor;
}

View File

@@ -424,8 +424,8 @@ module.exports = function(srf, logger) {
logger.info(`Setting env_vars: ${Object.keys(d_env_vars)}`); // Only log the keys not the values
env_vars = d_env_vars;
}
} catch (error) {
logger.info('Unable to set env_vars', error);
} catch (err) {
logger.info({err}, 'Unable to set env_vars');
}
const params = Object.assign(['POST', 'WS'].includes(app.call_hook.method) ? { sip: req.msg } : {},
req.locals.callInfo,

View File

@@ -77,6 +77,7 @@ class TaskRestDial extends Task {
const httpHeaders = b3 && {b3};
const params = {
...(cs.callInfo.toJSON()),
...(this.env_vars && {env_vars: this.env_vars}),
defaults: {
synthesizer: {
vendor: cs.speechSynthesisVendor,