UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

153 lines 6.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.play = void 0; /** Helper Modules */ const setSessionConfig_mapper_1 = require("../mappers/setSessionConfig.mapper"); const paramUtils_1 = require("../../voicegateway/utils/paramUtils"); const strip_nulls_1 = require("../../voicegateway2/utils/strip-nulls"); const setSessionConfig_mapper_2 = require("../mappers/setSessionConfig.mapper"); exports.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_mapper_1.setSessionConfig.handleVGInput((0, setSessionConfig_mapper_2.voiceConfigParamsToVoiceSettings)(config, api)); const activityConfig = (0, setSessionConfig_mapper_2.vg2PayloadToActivityParams)(vg2Payload); if (url && Object.keys(activityConfig).length) { voiceGateway2Payload.play.activityConfig = activityConfig; } } if (sessionParams) { voiceGateway2Payload.play.sessionParams = sessionParams; } const verb = (0, strip_nulls_1.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) { (0, paramUtils_1.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) { (0, paramUtils_1.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