UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

651 lines 32.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setSessionConfig = exports.vg2PayloadToActivityParams = exports.voiceConfigParamsToVoiceSettings = void 0; /* Node modules */ const base_mapper_1 = require("./base.mapper"); const strip_nulls_1 = require("../../voicegateway2/utils/strip-nulls"); const helper_1 = require("../utils/helper"); class SessionConfigMapper extends base_mapper_1.BaseMapper { buildUser(sessionParams, userNoInput) { const { userNoInputRetries, userNoInputMode, userNoInputSpeech, userNoInputTimeout, userNoInputUrl, userNoInputTimeoutEnable } = userNoInput || {}; const { user: sessionParamsUser } = sessionParams || {}; const { noInputSpeech, noInputUrl, noInputRetries, noInputTimeout, noInputMode } = sessionParamsUser || {}; const user = {}; /* verify if there are No User Input Configs to set */ if (userNoInput || sessionParamsUser) { /* Either userNoInputTimeoutEnable is true, or the 'user' object is defined in the session params */ if (userNoInputTimeoutEnable === true || this.has(sessionParamsUser)) { user.noInputMode = noInputMode || userNoInputMode; switch (user.noInputMode) { case "speech": user.noInputSpeech = noInputSpeech || userNoInputSpeech; break; case "play": user.noInputUrl = noInputUrl || userNoInputUrl; break; default: break; } const retries = Number(noInputRetries) || Number(userNoInputRetries); /* User No Input Retries. min: 0, max: 999 - if invalid range: set to 1 */ if (retries < 0 || retries > 999 || isNaN(retries)) { user.noInputRetries = 1; } else { user.noInputRetries = retries; } const timeout = Number(noInputTimeout) || Number(userNoInputTimeout); if (timeout < 0 || isNaN(timeout)) { user.noInputTimeout = 10; } else { user.noInputTimeout = timeout / 1000; } } else if (userNoInputTimeoutEnable === false && !this.has(sessionParamsUser)) { user.noInputTimeout = 0; } } return user; } buildFlow(sessionParams, flowNoInput) { const { flowNoInputMode, flowNoInputRetries, flowNoInputSpeech, flowNoInputTimeout, flowNoInputTimeoutEnable, flowNoInputUrl, flowNoInputFail } = flowNoInput || {}; const { flow: sessionParamsFlow } = sessionParams || {}; const { flowNoInputEnable: spEnable, flowNoInputFail: spFail, flowNoInputMode: spMode, flowNoInputRetries: spRetries, flowNoInputSpeech: spSpeech, flowNoInputTimeout: spTimeout, flowNoInputUrl: spUrl } = sessionParamsFlow || {}; const flow = {}; // verify if there are No Flow Input Configs to set if (flowNoInput || sessionParamsFlow) { const enabled = spEnable === true || flowNoInputTimeoutEnable === true; flow.flowNoInputEnable = enabled; if (!enabled) return flow; if (enabled) { flow.flowNoInputMode = spMode || flowNoInputMode; flow.flowNoInputFail = spFail || flowNoInputFail; switch (flow.flowNoInputMode) { case "speech": flow.flowNoInputSpeech = spSpeech || flowNoInputSpeech; break; case "play": flow.flowNoInputUrl = spUrl || flowNoInputUrl; break; default: break; } const retries = Number(spRetries) || Number(flowNoInputRetries); /* User No Input Retries. min: 0, max: 999 - if invalid range: set to 1 */ if (retries <= 1 || retries > 999 || isNaN(retries)) { flow.flowNoInputRetries = 1; } else { flow.flowNoInputRetries = retries; } const timeout = Number(spTimeout) || Number(flowNoInputTimeout); if (timeout < 0 || isNaN(timeout)) { flow.flowNoInputTimeout = 10; } else { flow.flowNoInputTimeout = timeout / 1000; } } else if (!enabled && !this.has(sessionParamsFlow)) { flow.flowNoInputTimeout = 0; } } return flow; } buildBarge(sessionParams, dtmf, bargeIn) { const { dtmf: sessionParamsDtmf, bargeIn: sessionParamsBargeIn } = sessionParams || {}; const { bargeInOnSpeech, bargeInOnDtmf, bargeInMinimumWords } = bargeIn || {}; const { bargeInOnSpeech: spSpeech, bargeInOnDtmf: spDtmf, bargeInMinimumWords: spMinWordCount } = sessionParamsBargeIn || {}; const { dtmfEnable, dtmfInterDigitTimeout, dtmfMaxDigits, dtmfMinDigits, dtmfSubmitDigit } = dtmf || {}; const { dtmfEnable: spEnable, dtmfInterDigitTimeout: spTimeout, dtmfMaxDigits: spMaxDigits, dtmfMinDigits: spMinDigits, dtmfSubmitDigit: spSubmitDigit } = sessionParamsDtmf || {}; let barge = {}; if (this.has(bargeIn) || this.has(sessionParamsBargeIn)) { const speechEnabled = spSpeech || bargeInOnSpeech; const dtmfEnabled = spDtmf || bargeInOnDtmf; barge = { enable: speechEnabled || bargeInOnDtmf, actionHook: "voice", dtmfBargein: dtmfEnabled, input: [], }; if (dtmfEnabled) { barge.input.push("digits"); } if (speechEnabled) { const minWords = spMinWordCount || bargeInMinimumWords || 1; /* Barge in minimum words. min: 1, max: 5, default: 1 */ if (minWords >= 1 && minWords <= 5) { barge.minBargeinWordCount = minWords; } barge.input.push("speech"); } } if (dtmfEnable || spEnable) { barge = Object.assign(Object.assign({}, barge), { maxDigits: 1, minDigits: Number(spMinDigits) || Number(dtmfMinDigits) || 1, finishOnKey: spSubmitDigit || dtmfSubmitDigit }); const timeout = Number(spTimeout) || Number(dtmfInterDigitTimeout) || 0; if (timeout > 0) { barge.interDigitTimeout = timeout / 1000; } /* Max digits. min: 1, max: - default: 1 */ const max = Number(spMaxDigits) || Number(dtmfMaxDigits); if (max >= 1) { barge.maxDigits = max; } } return barge; } recognizerApplyContinuousAsr(sessionParams, recognizer, continuousAsr) { const { continuousAsr: sessionParamsContinuousAsr } = sessionParams || {}; const { asrEnabled, asrDigit, asrTimeout = 0 } = continuousAsr || {}; const { asrDigit: spAsrDigit, asrEnabled: spAsrEnabled, asrTimeout: spAsrTimeout = 0 } = sessionParamsContinuousAsr || {}; // verify if there are Continuous ASR Configs to set if (spAsrEnabled || asrEnabled) { recognizer.asrDtmfTerminationDigit = spAsrDigit || asrDigit; const timeout = Number(spAsrTimeout || asrTimeout); recognizer.asrTimeout = timeout / 1000 || undefined; } return recognizer; } isDtmfEnabled(sessionParams, dtmf) { const { dtmf: sessionParamsDtmf } = sessionParams || {}; const { dtmfEnable } = dtmf || {}; const { dtmfEnable: spEnable } = sessionParamsDtmf || {}; if (dtmf && (typeof dtmfEnable === "boolean" || typeof spEnable === "boolean")) { return dtmfEnable === true || spEnable === true; } return undefined; } buildSynthesizer(sessionParams, tts) { const { synthesizer: sessionParamsTts } = sessionParams || {}; const { vendor: spVendor, language: spLanguage, voice: spVoice, label: spLabel, model: spModel, azureServiceEndpoint: spAzureServiceEndpoint } = sessionParamsTts || {}; const { azureServiceEndpoint, ttsLabel, ttsLanguage, ttsModel, ttsVendor, ttsVoice } = tts || {}; const synthesizer = {}; if (this.has(tts) || this.has(sessionParamsTts)) { synthesizer.vendor = spVendor || ttsVendor; synthesizer.language = spLanguage || ttsLanguage; synthesizer.voice = spVoice || ttsVoice; synthesizer.label = spLabel || ttsLabel; synthesizer.azureServiceEndpoint = ""; if (spAzureServiceEndpoint || azureServiceEndpoint) { synthesizer.azureServiceEndpoint = spAzureServiceEndpoint || azureServiceEndpoint; } if (spModel || ttsModel) { synthesizer.options = { model_id: spModel || ttsModel }; } return synthesizer; } } buildRecognizer(sessionParams, stt, vad, azureConfig) { var _a, _b, _c; const { recognizer: sessionParamsRecognizer } = sessionParams || {}; const { vendor: spVendor, language: spLanguage, hints: spHints, label: spLabel, model: spModel, azureSttEndpointId: spAzureSttEndpointId, audioLogging: spAudioLogging, hintsBoost: spHintsBoost, punctuation: spPunctuation, altLanguages: spAltLanguages = [], deepgramOptions: spDeepgramOptions, vad: spVad, profanityOption: spProfanityOption } = sessionParamsRecognizer || {}; const { sttVendor, sttLanguage, sttHints, sttLabel, sttHintsBoost, sttDisablePunctuation, googleModel, deepgramEndpointing, deepgramEndpointingValue, sttDeepgramModel, deepgramSmartFormatting, deepgramShortUtterance, altLanguages = [] } = stt || {}; const recognizer = {}; recognizer.language = spLanguage || sttLanguage || undefined; recognizer.hints = spHints || sttHints || undefined; recognizer.label = spLabel || sttLabel || undefined; recognizer.vendor = spVendor || sttVendor || undefined; if (recognizer.hints) { recognizer.hintsBoost = spHintsBoost || sttHintsBoost || 20; } recognizer.punctuation = spPunctuation || sttDisablePunctuation; recognizer.azureSttEndpointId = spAzureSttEndpointId || (azureConfig === null || azureConfig === void 0 ? void 0 : azureConfig.azureSttContextId) || ""; recognizer.audioLogging = spAudioLogging || (azureConfig === null || azureConfig === void 0 ? void 0 : azureConfig.azureEnableAudioLogging); if (recognizer.vendor) { if (recognizer.vendor === "microsoft") { recognizer.profanityOption = spProfanityOption || (azureConfig === null || azureConfig === void 0 ? void 0 : azureConfig.azureProfanityOption) || "raw"; } if (recognizer.vendor === "microsoft" || recognizer.vendor === "google") { if (this.has(spAltLanguages)) { recognizer.altLanguages = spAltLanguages; } else if (this.has(altLanguages)) { recognizer.altLanguages = altLanguages; } } const model = spModel || googleModel; if (recognizer.vendor === "google" && model) { recognizer.model = model; } if (recognizer.vendor === 'deepgram') { const { model: spModel, endpointing: spEndpointing, shortUtterance: spShortUtterance, smartFormatting: spSmartFormatting, } = spDeepgramOptions || {}; /* * session params: 'endpointing' is a number * ssc node: 'deepgramEndpointing' => boolean, 'deepgramEndpointingValue' => number */ const isDeepgramEndpointingEnabled = (_a = (typeof spEndpointing === "number" || deepgramEndpointing)) !== null && _a !== void 0 ? _a : false; recognizer.model = spModel || sttDeepgramModel; const deepgramOptions = { endpointing: false, punctuate: recognizer.punctuation, shortUtterance: spShortUtterance || deepgramShortUtterance, model: recognizer.model, smartFormatting: (_b = (spSmartFormatting || deepgramSmartFormatting)) !== null && _b !== void 0 ? _b : false }; if (isDeepgramEndpointingEnabled) { deepgramOptions.endpointing = (_c = (spEndpointing || deepgramEndpointingValue)) !== null && _c !== void 0 ? _c : 250; } recognizer.deepgramOptions = deepgramOptions; } } if (this.has(spVad) || this.has(vad)) { const { enable: spEnable, mode: spMode, voiceMs: spVoiceMs } = spVad || {}; const vadConfig = { enable: spEnable || (vad === null || vad === void 0 ? void 0 : vad.enable) }; const mode = Number(spMode) || (vad === null || vad === void 0 ? void 0 : vad.mode); if (vadConfig.enable) { /* mode must be a nuber between 0-3 - default is 1 */ if (mode < 0 || mode > 3 || isNaN(mode)) { vadConfig.mode = 1; } else { vadConfig.mode = mode; } vadConfig.voiceMs = spVoiceMs || (vad === null || vad === void 0 ? void 0 : vad.voiceMs); } recognizer.vad = vadConfig; } return recognizer; } buildFillerNoise(sessionParams, silenceOverlay) { const { fillerNoise: sessionParamsFillerNoise } = sessionParams || {}; const { enable: spEnable, startDelaySecs: spStartDelaySecs, url: spUrl } = sessionParamsFillerNoise || {}; const { enable, startDelaySecs, url } = silenceOverlay || {}; if (!(this.has(sessionParamsFillerNoise) || this.has(silenceOverlay))) { return; } const fillerNoise = { enable: spEnable || enable, }; if (fillerNoise.enable) { fillerNoise.url = spUrl || url; const startDelay = Number(spStartDelaySecs) || Number(startDelaySecs); /* start delay secs mst be a value between 0 and 60. default: 0 */ if (startDelay < 0 || startDelay > 60 || isNaN(startDelaySecs)) { fillerNoise.startDelaySecs = 0; } else { fillerNoise.startDelaySecs = startDelay; } } return fillerNoise; } disableTtsCache(sessionParams, tts) { const { ttsDisableCache } = tts || {}; const { synthesizer } = sessionParams || {}; const { disableCache: spDisableCache } = synthesizer || {}; let disableTtsCache = false; /* this will be applied to 'say' verb 'disableTtsCache' * say: { * text: "Hello World", * disableTtsCache: true * } */ if (typeof spDisableCache === "boolean") { disableTtsCache = spDisableCache; } else if (typeof ttsDisableCache === "boolean") { disableTtsCache = ttsDisableCache; } return disableTtsCache; } } const mapper = new SessionConfigMapper("voiceGateway2"); function voiceConfigParamsToVoiceSettings(config, api) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; let voiceSettings = {}; if (config.sttVendor === 'none') { delete config.sttVendor; delete config.sttLabel; } if (config.ttsVendor === 'none') { delete config.ttsVendor; delete config.ttsLabel; } if (typeof config.bargeInOnDtmf === 'boolean' || typeof config.bargeInOnSpeech === 'boolean') { voiceSettings.bargeIn = { bargeInEnable: false, bargeInOnDtmf: (_a = config.bargeInOnDtmf) !== null && _a !== void 0 ? _a : false, bargeInOnSpeech: (_b = config.bargeInOnSpeech) !== null && _b !== void 0 ? _b : false, bargeInMinimumWords: config.bargeInMinWordCount, }; } // vad voiceSettings.vad = { enable: config.sttVadEnabled, mode: config.sttVadMode, voiceMs: config.sttVadVoiceMs, }; let hints = []; if (config.sttHintsDynamicHints) { if (Array.isArray(config.sttHintsDynamicHints) && ((_c = config.sttHintsDynamicHints) === null || _c === void 0 ? void 0 : _c.length)) { hints = [...config.sttHintsDynamicHints]; } else { throw new Error(`Error adding dynamic hints. Context or input is not an array`); } } if (config.sttHints && config.sttHints.length) { hints = [...hints, ...config.sttHints]; } const deepgramEndpointing = (_d = config.deepgramEndpointing) !== null && _d !== void 0 ? _d : true; const deepgramShortUtterance = deepgramEndpointing ? false : true; // stt (recognizer) voiceSettings.stt = { sttVendor: config.sttVendor, sttLanguage: config.sttLanguage, sttHints: hints, sttLabel: (_e = config.sttLabel) !== null && _e !== void 0 ? _e : undefined, sttDisablePunctuation: config.sttDisablePunctuation !== undefined && config.sttDisablePunctuation !== null ? !config.sttDisablePunctuation : undefined, googleModel: (_f = config.googleModel) !== null && _f !== void 0 ? _f : undefined, /* by default we enable endpointing - it is only undefined via SAP */ deepgramEndpointing, deepgramEndpointingValue: (_g = config.deepgramEndpointingValue) !== null && _g !== void 0 ? _g : 250, sttDeepgramModel: (_h = config.sttDeepgramModel) !== null && _h !== void 0 ? _h : "nova-2", deepgramSmartFormatting: (_j = config.deepgramSmartFormatting) !== null && _j !== void 0 ? _j : undefined, deepgramShortUtterance, listenDuringPrompt: (_k = config.sttListenDuringPrompt) !== null && _k !== void 0 ? _k : undefined, }; // tts (synthesizer) voiceSettings.tts = { ttsVendor: config.ttsVendor, ttsLanguage: config.ttsLanguage, ttsVoice: config.ttsVoice, ttsDisableCache: config.ttsDisableCache, ttsLabel: config.ttsLabel, }; if (config.sttVendor === "microsoft") { voiceSettings.azureConfig = { azureSttContextId: config.azureSttContextId ? config.azureSttContextId.trim() : undefined, azureEnableAudioLogging: config.azureEnableAudioLogging || undefined, azureProfanityOption: config.azureProfanityOption || "raw", }; if (config.recognizeLanguagesAzure) { voiceSettings.stt.altLanguages = []; const languages = [config.sttAzureLang1, config.sttAzureLang2, config.sttAzureLang3]; languages.map(language => { var _a, _b; if (language && (language === null || language === void 0 ? void 0 : language.length) > 0) { (_b = (_a = voiceSettings.stt) === null || _a === void 0 ? void 0 : _a.altLanguages) === null || _b === void 0 ? void 0 : _b.push(language); } }); } else { voiceSettings.stt.altLanguages = []; } } if (config.sttVendor === "google") { if (config.recognizeLanguagesGoogle) { voiceSettings.stt.altLanguages = []; const languages = [config.sttGoogleLang1, config.sttGoogleLang2, config.sttGoogleLang3]; languages.map(language => { var _a, _b; if (language && (language === null || language === void 0 ? void 0 : language.length) > 0) { (_b = (_a = voiceSettings.stt) === null || _a === void 0 ? void 0 : _a.altLanguages) === null || _b === void 0 ? void 0 : _b.push(language); } }); } else { voiceSettings.stt.altLanguages = []; } } if (config.ttsVendor === "elevenlabs") { voiceSettings.tts.ttsModel = config.ttsModel; } // userNoInput voiceSettings.userNoInput = { userNoInputMode: config.userNoInputMode, userNoInputTimeout: config.userNoInputTimeout, userNoInputRetries: config.userNoInputRetries, userNoInputSpeech: config.userNoInputSpeech, userNoInputUrl: config.userNoInputUrl, userNoInputTimeoutEnable: config.userNoInputTimeoutEnable }; voiceSettings.flowNoInput = { flowNoInputMode: config.flowNoInputMode, flowNoInputTimeout: config.flowNoInputTimeout, flowNoInputRetries: config.flowNoInputRetries, flowNoInputSpeech: config.flowNoInputSpeech, flowNoInputUrl: config.flowNoInputUrl, flowNoInputTimeoutEnable: config.flowNoInputTimeoutEnable, flowNoInputFail: config.flowNoInputFail }; // Check if userNoInputTimeout has a value and userNoInputTimeoutEnable is null or undefined to cover generic nodes if (((_l = voiceSettings === null || voiceSettings === void 0 ? void 0 : voiceSettings.userNoInput) === null || _l === void 0 ? void 0 : _l.userNoInputTimeout) && (voiceSettings.userNoInput.userNoInputTimeoutEnable === null || voiceSettings.userNoInput.userNoInputTimeoutEnable === undefined)) { voiceSettings.userNoInput.userNoInputTimeoutEnable = true; } voiceSettings.dtmf = { dtmfEnable: config.dtmfEnable, dtmfInterDigitTimeout: config.dtmfInterDigitTimeout, dtmfMaxDigits: config.dtmfMaxDigits, dtmfMinDigits: config.dtmfMinDigits, dtmfSubmitDigit: (_m = config.dtmfSubmitDigit) === null || _m === void 0 ? void 0 : _m.trim(), }; if (config === null || config === void 0 ? void 0 : config.dtmfEnable) { if (voiceSettings.dtmf.dtmfSubmitDigit && !(0, helper_1.isValidDTMF)(voiceSettings.dtmf.dtmfSubmitDigit)) { if (api) api.log("error", "Invalid DTMF Submit Digit"); delete voiceSettings.dtmf.dtmfSubmitDigit; } if (config === null || config === void 0 ? void 0 : config.dtmfEnable) { if ((!config.dtmfInterDigitTimeout || typeof config.dtmfInterDigitTimeout !== "number") && (!config.dtmfMaxDigits || typeof config.dtmfMaxDigits !== "number") && (!config.dtmfSubmitDigit || config.dtmfSubmitDigit === "")) voiceSettings.dtmf.dtmfInterDigitTimeout = 2000; } } // continuousAsr voiceSettings.continuousAsr = { asrEnabled: config.asrEnabled, asrDigit: config.asrDigit, asrTimeout: config.asrTimeout, }; if (config === null || config === void 0 ? void 0 : config.asrEnabled) { if (config.asrDigit) voiceSettings.continuousAsr.asrDigit = config.asrDigit.trim(); if (!config.asrTimeout || typeof config.asrTimeout !== "number") voiceSettings.continuousAsr.asrTimeout = 3000; if (voiceSettings.continuousAsr.asrDigit && !(0, helper_1.isValidDTMF)(voiceSettings.continuousAsr.asrDigit)) { if (api) api.log("error", "Invalid DTMF Submit Digit"); delete voiceSettings.continuousAsr.asrDigit; } } // atmosphere sounds if (config.atmosphereAction) { if ((_o = config.atmosphereUrl) === null || _o === void 0 ? void 0 : _o.length) { if (!(0, helper_1.isValidUrl)(config.atmosphereUrl)) { throw new Error(`Audio file URL is invalid ${config.atmosphereUrl}`); } } voiceSettings.atmosphereNoise = { action: config.atmosphereAction, url: config.atmosphereUrl || undefined, volume: config.atmosphereVolume || undefined, loop: config.atmosphereLoop || undefined }; } // silence overlay if (typeof config.silenceOverlayAction === "boolean") { voiceSettings.silenceOverlay = { enable: config.silenceOverlayAction, url: config.silenceOverlayURL || undefined, startDelaySecs: config.silenceOverlayDelay || undefined }; } return (0, strip_nulls_1.stripNulls)(voiceSettings); } exports.voiceConfigParamsToVoiceSettings = voiceConfigParamsToVoiceSettings; function vg2PayloadToActivityParams(payload) { var _a, _b, _c, _d, _e; const vg2Config = payload._voiceGateway2.json; return (0, strip_nulls_1.stripNulls)({ synthesizer: (_a = vg2Config.voiceGateway2Config) === null || _a === void 0 ? void 0 : _a.synthesizer, recognizer: (_b = vg2Config.voiceGateway2Config) === null || _b === void 0 ? void 0 : _b.recognizer, bargeIn: (_c = vg2Config.voiceGateway2Config) === null || _c === void 0 ? void 0 : _c.bargeIn, user: (_d = vg2Config.cognigyConfig) === null || _d === void 0 ? void 0 : _d.user, dtmf: (_e = vg2Config.cognigyConfig) === null || _e === void 0 ? void 0 : _e.dtmf, }); } exports.vg2PayloadToActivityParams = vg2PayloadToActivityParams; exports.setSessionConfig = { handleInput(endpointType, voiceSettings) { switch (endpointType) { case "bandwidth": return this.handleAudioCodesInput(voiceSettings, endpointType); case "audioCodes": return this.handleAudioCodesInput(voiceSettings, endpointType); case "voiceGateway2": default: return this.handleVGInput(voiceSettings); } }, handleVGInput(voiceSettings, sessionParams, api) { var _a; const { bargeIn, continuousAsr, stt, tts, userNoInput, dtmf, vad, azureConfig, atmosphereNoise, silenceOverlay, flowNoInput } = voiceSettings; try { const recognizer = mapper.buildRecognizer(sessionParams, stt, vad, azureConfig) || undefined; mapper.recognizerApplyContinuousAsr(sessionParams, recognizer, continuousAsr); // Check if there are configs for synthesizer, recognizer and bargeIn const voiceConfig = { synthesizer: mapper.buildSynthesizer(sessionParams, tts) || undefined, recognizer, bargeIn: mapper.buildBarge(sessionParams, dtmf, bargeIn) || undefined, fillerNoise: mapper.buildFillerNoise(sessionParams, silenceOverlay) || undefined, }; (0, strip_nulls_1.stripNulls)(voiceConfig); // Check if there are configs for No User Input and DTMF const cognigyConfig = { user: mapper.buildUser(sessionParams, userNoInput) || undefined, flow: mapper.buildFlow(sessionParams, flowNoInput) || undefined, dtmf: mapper.isDtmfEnabled(sessionParams, dtmf), disableTtsCache: mapper.disableTtsCache(sessionParams, tts), listenDuringPrompt: (_a = stt === null || stt === void 0 ? void 0 : stt.listenDuringPrompt) !== null && _a !== void 0 ? _a : undefined, }; (0, strip_nulls_1.stripNulls)(cognigyConfig); const prePayload = { cognigyConfig: Object.keys(cognigyConfig).length ? cognigyConfig : undefined, voiceGateway2Config: Object.keys(voiceConfig).length ? voiceConfig : undefined, }; if (atmosphereNoise) { prePayload.voiceGateway2Atmosphere = (0, strip_nulls_1.stripNulls)(atmosphereNoise); } if (prePayload.cognigyConfig === undefined) { delete prePayload.cognigyConfig; } if (prePayload.voiceGateway2Config === undefined) { delete prePayload.voiceGateway2Config; } const payload = { _voiceGateway2: { json: Object.assign({}, prePayload), }, }; return payload; } catch (error) { console.error("Error in setSessionConfig.handleVGInput: ", error); } }, handleAudioCodesInput(voiceSettings, endpointType = "audioCodes") { const { bargeIn, continuousAsr, stt, tts, userNoInput, dtmf, azureConfig } = voiceSettings; const sessionParams = {}; if (stt) { sessionParams.sttLanguage = stt.sttLanguage; if (stt.sttHints && stt.sttHints.length > 0) { const hints = []; stt.sttHints.forEach((element) => { hints.push({ phrases: [element], boost: 20 }); }); sessionParams.sttSpeechContexts = hints; } sessionParams.sttDisablePunctuation = !stt.sttDisablePunctuation; if (stt.googleModel) { sessionParams.sttModel = stt.googleModel; } } if (tts) { sessionParams.ttsLanguage = tts.ttsLanguage; sessionParams.voiceName = tts.ttsVoice; if (tts.azureServiceEndpoint) { sessionParams.ttsDeploymentId = tts.azureServiceEndpoint; } ; } if (dtmf) { sessionParams.sendDTMF = dtmf.dtmfEnable; sessionParams.dtmfCollect = dtmf.dtmfEnable; if (sessionParams.dtmfCollect) { if (dtmf.dtmfInterDigitTimeout && dtmf.dtmfInterDigitTimeout >= 0) sessionParams.dtmfCollectInterDigitTimeoutMS = dtmf.dtmfInterDigitTimeout; sessionParams.dtmfCollectSubmitDigit = dtmf.dtmfSubmitDigit; if (dtmf.dtmfMaxDigits && dtmf.dtmfMaxDigits > 0) sessionParams.dtmfCollectMaxDigits = dtmf.dtmfMaxDigits; } } if (bargeIn) { sessionParams.bargeIn = bargeIn.bargeInOnSpeech; sessionParams.bargeInOnDTMF = bargeIn.bargeInOnDtmf; if (bargeIn.bargeInMinimumWords >= 1 && bargeIn.bargeInMinimumWords <= 5) { sessionParams.bargeInMinWordCount = bargeIn.bargeInMinimumWords || 1; } if (sessionParams.bargeInOnDTMF) sessionParams.sendDTMF = true; } if (continuousAsr) { sessionParams.continuousASR = continuousAsr.asrEnabled; sessionParams.continuousASRDigits = continuousAsr.asrDigit; sessionParams.continuousASRTimeoutInMS = continuousAsr.asrTimeout; } if (userNoInput) { sessionParams.userNoInputRetries = userNoInput.userNoInputRetries || 0; sessionParams.userNoInputTimeoutMS = userNoInput.userNoInputTimeout; sessionParams.userNoInputAutoHangup = true; sessionParams.userNoInputSendEvent = true; if (userNoInput.userNoInputMode === "speech" && sessionParams.userNoInputRetries > 0) sessionParams.userNoInputSpeech = userNoInput.userNoInputSpeech; if (userNoInput.userNoInputMode === "play" && sessionParams.userNoInputRetries > 0) sessionParams.userNoInputUrl = userNoInput.userNoInputUrl; } if (azureConfig === null || azureConfig === void 0 ? void 0 : azureConfig.azureSttContextId) { sessionParams.sttContextId = azureConfig.azureSttContextId; if (azureConfig.azureEnableAudioLogging) { sessionParams.azureEnableAudioLogging = azureConfig.azureEnableAudioLogging; } } const activities = { type: "event", name: "config", sessionParams: sessionParams || {}, }; const contentKey = endpointType === "bandwidth" ? "_bandwidth" : "_voiceGateway"; const payload = { [contentKey]: { json: { activities: [activities], }, }, }; return payload; }, }; //# sourceMappingURL=setSessionConfig.mapper.js.map