UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

103 lines 4.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RecordMapper = void 0; /* Custom modules */ const logger_1 = require("../../../../helper/logger"); const base_mapper_1 = require("./base.mapper"); class RecordMapper extends base_mapper_1.BaseMapper { handleInput(input, api, isGenericNode = false) { try { switch (this.endpointType) { case "bandwidth": { const output = this.handleBandwidthInput(input, api); return this.buildPayload(output); } case "audioCodes": { const output = this.handleAudioCodesInput(input, api); return this.buildPayload(output); } case "voiceGateway2": default: { const output = this.handleVGInput(input, api); return this.buildPayload(output); } } } catch (err) { const errorMessage = `Error in RecordMapper handleInput: ${err.message}`; api.log("error", errorMessage); throw Error(errorMessage); } } handleVGInput(input, api) { const { action, recordingId, siprecServerURL } = input; /* base record options */ const recordOptions = { action, }; const storedActivity = api.getSystemContext("vgRecordAction"); if (recordingId) { recordOptions.recordingID = recordingId; } switch (action) { case "startCallRecording": if (process.env.TMP_ENDPOINT_CALL_RECORDING_ENABLE_GLOBALLY !== "true") { if (storedActivity === "startCallRecording") { const errorText = "Cannot start recording when recording is already started"; logger_1.default.error({}, errorText, {}, true); throw new Error(errorText); } else if (storedActivity === "resumeCallRecording") { const errorText = "Cannot start recording when recording is already resumed"; logger_1.default.error({}, errorText, {}, true); throw new Error(errorText); } recordOptions.siprecServerURL = siprecServerURL; } break; case "pauseCallRecording": if (storedActivity !== "startCallRecording" && process.env.TMP_ENDPOINT_CALL_RECORDING_ENABLE_GLOBALLY !== "true") { const errorText = "Cannot pause recording when recording is not started"; logger_1.default.error({}, errorText, {}, true); throw new Error(errorText); } break; case "stopCallRecording": if (storedActivity !== "startCallRecording" && storedActivity !== "resumeCallRecording" && process.env.TMP_ENDPOINT_CALL_RECORDING_ENABLE_GLOBALLY !== "true") { const errorText = "Cannot stop recording when recording is not started or paused"; logger_1.default.error({}, errorText, {}, true); throw new Error(errorText); } break; case "resumeCallRecording": if (storedActivity === "resumeCallRecording") { const warnText = "Cannot resume recording when recording is already resumed"; logger_1.default.warn({}, warnText, {}, true); } else if (storedActivity !== "pauseCallRecording") { const errorText = "Cannot resume recording when recording is not paused"; logger_1.default.error({}, errorText, {}, true); throw new Error(errorText); } break; default: throw new Error(`Call Recording - invalid action: ${action}`); } /* Store the action in the context to send proper warnings */ api.setSystemContext("vgRecordAction", action); const output = { config: { record: recordOptions } }; return output; } handleAudioCodesInput(input, api) { return {}; } handleBandwidthInput(input, api) { return {}; } } exports.RecordMapper = RecordMapper; //# sourceMappingURL=record.mapper.js.map