UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

68 lines 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendMetadata = void 0; const helper_1 = require("../../voicegateway2/utils/helper"); exports.sendMetadata = { handleInput(endpointType, metadata) { if (!(0, helper_1.isValidJSON)(metadata)) { throw new Error("Invalid JSON in Metadata Field"); } if (JSON.stringify(metadata) === '{}') { throw new Error("Nothing is set in Metadata Field"); } switch (endpointType) { case "bandwidth": return this.handleBandwidthInput(metadata); case "audioCodes": return this.handleAudioCodesInput(metadata); case "voiceGateway2": default: return this.handleVGInput(metadata); } }, handleVGInput(metadata) { const voiceGateway2Payload = { "sip:request": { headers: { "Content-Type": "application/json", }, body: "", method: "INFO", actionHook: "/info", }, }; voiceGateway2Payload["sip:request"].body = JSON.stringify(metadata); return { _voiceGateway2: { json: Object.assign({}, voiceGateway2Payload) } }; }, handleAudioCodesInput(metadata) { return { _voiceGateway: { json: { activities: [{ type: "event", name: "sendMetaData", value: metadata }] } } }; }, handleBandwidthInput(metadata) { return { _bandwidth: { json: { activities: [{ type: "event", name: "sendMetaData", value: metadata }] } } }; } }; //# sourceMappingURL=sendMetadata.mapper.js.map