From 50f926bce418e294f7ab9da047e9a7adaf10b24f Mon Sep 17 00:00:00 2001 From: akirilyuk Date: Fri, 4 Feb 2022 08:21:53 +0100 Subject: [PATCH] add customizer for merging arrays --- lib/tasks/cognigy/speech-config.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/tasks/cognigy/speech-config.js b/lib/tasks/cognigy/speech-config.js index ad12cfd8..f83a51e6 100644 --- a/lib/tasks/cognigy/speech-config.js +++ b/lib/tasks/cognigy/speech-config.js @@ -1,4 +1,6 @@ +const obj = require('drachtio-fsmrf/lib/utils'); const Emitter = require('events'); +const { isArray } = require('lodash'); const lodash = require('lodash'); const hasKeys = (obj) => typeof obj === 'object' && Object.keys(obj) > 0; @@ -18,11 +20,17 @@ class SpeechConfig extends Emitter { _mergeConfig(changedConfig = {}) { const merged = lodash.merge( - {}, this.sessionConfig, - changedConfig + changedConfig, + (objValue, sourceValue) => { + if(isArray(objValue)){ + if(isArray(sourceValue)){ + return sourceValue; + } + return objValue; + } + } ); - merged.bargein.enable = changedConfig.bargein?.enable?.length === 0 ? [] : changedConfig.bargein?.enable; this.logger.debug({merged, sessionConfig: this.sessionConfig, changedConfig}, 'merged config'); // should we override hints with empty array or leave it as it is once saved? // merged.recognizer.hints = changedConfig.recognizer?.hints