UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

150 lines 6.6 kB
/** Helper Modules */ import { setSessionConfig } from "../mappers/setSessionConfig.mapper"; import { compileParams } from "../../voicegateway/utils/paramUtils"; import { stripNulls } from "../../voicegateway2/utils/strip-nulls"; import { voiceConfigParamsToVoiceSettings, vg2PayloadToActivityParams } from "../mappers/setSessionConfig.mapper"; export const play = { handleInput(params) { const { endpointType, config } = params; switch (endpointType) { case "bandwidth": return this.handleBandwidthInput(config); case "audioCodes": return this.handleAudioCodesInput(config); case "voiceGateway2": default: return this.handleVGInput(params); } }, handleVGInput(params) { const { config, api } = params; const { url, loop, setActivityParams, sessionParams } = config; const voiceGateway2Payload = { play: { url, loop } }; if (setActivityParams) { const vg2Payload = setSessionConfig.handleVGInput(voiceConfigParamsToVoiceSettings(config, api)); const activityConfig = vg2PayloadToActivityParams(vg2Payload); if (url && Object.keys(activityConfig).length) { voiceGateway2Payload.play.activityConfig = activityConfig; } } if (sessionParams) { voiceGateway2Payload.play.sessionParams = sessionParams; } const verb = stripNulls(voiceGateway2Payload); return { _voiceGateway2: { json: verb } }; }, handleAudioCodesInput(config) { let { playUrlUrl, playUrlMediaFormat, playUrlAltText, setActivityParams, activityParams, playUrlCaching } = config; // set up default if the config is not present (from generic play node) if (playUrlCaching === undefined) playUrlCaching = true; if (playUrlMediaFormat === undefined) playUrlMediaFormat = "wav/lpcm16"; let compiledParams = Object.assign(activityParams || {}, { playUrlUrl, playUrlMediaFormat }); if (playUrlAltText) compiledParams["playUrlAltText"] = playUrlAltText; if (playUrlCaching !== null) compiledParams["playUrlCaching"] = !!playUrlCaching; if (setActivityParams) { compileParams(config, compiledParams); } // translate config of generic node into AudioCodes if (compiledParams.bargeInOnSpeech !== undefined) compiledParams.bargeIn = compiledParams.bargeInOnSpeech; if (compiledParams.bargeInOnDtmf !== undefined) compiledParams.bargeInOnDTMF = compiledParams.bargeInOnDtmf; if (compiledParams.dtmfEnable !== undefined) compiledParams.sendDTMF = compiledParams.dtmfEnable; if (compiledParams.dtmfInterDigitTimeout !== undefined) compiledParams.dtmfCollectInterDigitTimeoutMS = compiledParams.dtmfInterDigitTimeout; if (compiledParams.dtmfMaxDigits !== undefined) compiledParams.dtmfCollectMaxDigits = compiledParams.dtmfMaxDigits; if (compiledParams.dtmfSubmitDigit !== undefined) compiledParams.dtmfCollectSubmitDigit = compiledParams.dtmfSubmitDigit; // remove the configurations from VG2 delete compiledParams.url; delete compiledParams.bargeInOnSpeech; delete compiledParams.bargeInOnDtmf; delete compiledParams.dtmfEnable; delete compiledParams.dtmfInterDigitTimeout; delete compiledParams.dtmfMaxDigits; delete compiledParams.dtmfMinDigits; delete compiledParams.dtmfSubmitDigit; return { _voiceGateway: { json: { activities: [{ type: "event", name: "playUrl", activityParams: compiledParams }] } } }; }, handleBandwidthInput(config) { let { playUrlUrl, playUrlMediaFormat, playUrlAltText, setActivityParams, activityParams, playUrlCaching } = config; // set up default if the config is not present (from generic play node) if (playUrlCaching === undefined) playUrlCaching = true; if (playUrlMediaFormat === undefined) playUrlMediaFormat = "wav/lpcm16"; let compiledParams = Object.assign(activityParams || {}, { playUrlUrl, playUrlMediaFormat }); if (playUrlAltText) compiledParams["playUrlAltText"] = playUrlAltText; if (playUrlCaching !== null) compiledParams["playUrlCaching"] = !!playUrlCaching; if (setActivityParams) { compileParams(config, compiledParams); } // translate config of generic node into Bandwidth if (compiledParams.bargeInOnSpeech !== undefined) compiledParams.bargeIn = compiledParams.bargeInOnSpeech; if (compiledParams.bargeInOnDtmf !== undefined) compiledParams.bargeInOnDTMF = compiledParams.bargeInOnDtmf; if (compiledParams.dtmfEnable !== undefined) compiledParams.sendDTMF = compiledParams.dtmfEnable; if (compiledParams.dtmfInterDigitTimeout !== undefined) compiledParams.dtmfCollectInterDigitTimeoutMS = compiledParams.dtmfInterDigitTimeout; if (compiledParams.dtmfMaxDigits !== undefined) compiledParams.dtmfCollectMaxDigits = compiledParams.dtmfMaxDigits; if (compiledParams.dtmfSubmitDigit !== undefined) compiledParams.dtmfCollectSubmitDigit = compiledParams.dtmfSubmitDigit; // remove the configurations from VG2 delete compiledParams.url; delete compiledParams.bargeInOnSpeech; delete compiledParams.bargeInOnDtmf; delete compiledParams.dtmfEnable; delete compiledParams.dtmfInterDigitTimeout; delete compiledParams.dtmfMaxDigits; delete compiledParams.dtmfMinDigits; delete compiledParams.dtmfSubmitDigit; return { _bandwidth: { json: { activities: [{ type: "event", name: "playUrl", activityParams: compiledParams }] } } }; } }; //# sourceMappingURL=play.mapper.js.map