@azure/communication-call-automation
Version:
Azure client library for Azure Communication Call Automation services
202 lines (201 loc) • 8.12 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var callAutomationEventParser_exports = {};
__export(callAutomationEventParser_exports, {
parseCallAutomationEvent: () => parseCallAutomationEvent
});
module.exports = __toCommonJS(callAutomationEventParser_exports);
var import_core_client = require("@azure/core-client");
var import_converters = require("./utli/converters.js");
var import_mapper = require("./models/mapper.js");
const serializer = (0, import_core_client.createSerializer)();
function parseCallAutomationEvent(encodedEvents) {
const decodedInput = parseAndWrap(encodedEvents);
const deserialized = serializer.deserialize(import_mapper.CloudEventMapper, decodedInput, "");
const data = deserialized.data;
const eventType = deserialized.type;
let callbackEvent;
let parsed = data;
switch (eventType) {
case "Microsoft.Communication.AddParticipantSucceeded":
callbackEvent = { kind: "AddParticipantSucceeded" };
parsed.participant = (0, import_converters.communicationIdentifierConverter)(data.participant);
break;
case "Microsoft.Communication.AddParticipantFailed":
callbackEvent = { kind: "AddParticipantFailed" };
parsed.participant = (0, import_converters.communicationIdentifierConverter)(data.participant);
break;
case "Microsoft.Communication.RemoveParticipantSucceeded":
callbackEvent = { kind: "RemoveParticipantSucceeded" };
parsed.participant = (0, import_converters.communicationIdentifierConverter)(data.participant);
break;
case "Microsoft.Communication.RemoveParticipantFailed":
callbackEvent = { kind: "RemoveParticipantFailed" };
parsed.participant = (0, import_converters.communicationIdentifierConverter)(data.participant);
break;
case "Microsoft.Communication.MoveParticipantSucceeded":
callbackEvent = { kind: "MoveParticipantSucceeded" };
parsed.participant = (0, import_converters.communicationIdentifierConverter)(data.participant);
break;
case "Microsoft.Communication.MoveParticipantFailed":
callbackEvent = { kind: "MoveParticipantFailed" };
parsed.participant = (0, import_converters.communicationIdentifierConverter)(data.participant);
break;
case "Microsoft.Communication.CallConnected":
callbackEvent = { kind: "CallConnected" };
break;
case "Microsoft.Communication.CallDisconnected":
callbackEvent = { kind: "CallDisconnected" };
break;
case "Microsoft.Communication.CallTransferAccepted":
callbackEvent = { kind: "CallTransferAccepted" };
break;
case "Microsoft.Communication.CallTransferFailed":
callbackEvent = { kind: "CallTransferFailed" };
break;
case "Microsoft.Communication.ParticipantsUpdated":
callbackEvent = { kind: "ParticipantsUpdated" };
parsed = participantsParserForEvent(data);
break;
case "Microsoft.Communication.RecordingStateChanged":
callbackEvent = { kind: "RecordingStateChanged" };
break;
case "Microsoft.Communication.PlayCompleted":
callbackEvent = { kind: "PlayCompleted" };
break;
case "Microsoft.Communication.PlayFailed":
callbackEvent = { kind: "PlayFailed" };
break;
case "Microsoft.Communication.PlayCanceled":
callbackEvent = { kind: "PlayCanceled" };
break;
case "Microsoft.Communication.RecognizeCompleted":
callbackEvent = { kind: "RecognizeCompleted" };
break;
case "Microsoft.Communication.RecognizeCanceled":
callbackEvent = { kind: "RecognizeCanceled" };
break;
case "Microsoft.Communication.RecognizeFailed":
callbackEvent = { kind: "RecognizeFailed" };
break;
case "Microsoft.Communication.ContinuousDtmfRecognitionToneReceived":
callbackEvent = {
kind: "ContinuousDtmfRecognitionToneReceived"
};
break;
case "Microsoft.Communication.ContinuousDtmfRecognitionToneFailed":
callbackEvent = {
kind: "ContinuousDtmfRecognitionToneFailed"
};
break;
case "Microsoft.Communication.ContinuousDtmfRecognitionStopped":
callbackEvent = {
kind: "ContinuousDtmfRecognitionStopped"
};
break;
case "Microsoft.Communication.SendDtmfTonesCompleted":
callbackEvent = { kind: "SendDtmfTonesCompleted" };
break;
case "Microsoft.Communication.SendDtmfTonesFailed":
callbackEvent = { kind: "SendDtmfTonesFailed" };
break;
case "Microsoft.Communication.CancelAddParticipantSucceeded":
callbackEvent = { kind: "CancelAddParticipantSucceeded" };
break;
case "Microsoft.Communication.CancelAddParticipantFailed":
callbackEvent = { kind: "CancelAddParticipantFailed" };
break;
case "Microsoft.Communication.TranscriptionStarted":
callbackEvent = { kind: "TranscriptionStarted" };
break;
case "Microsoft.Communication.TranscriptionStopped":
callbackEvent = { kind: "TranscriptionStopped" };
break;
case "Microsoft.Communication.TranscriptionUpdated":
callbackEvent = { kind: "TranscriptionUpdated" };
break;
case "Microsoft.Communication.TranscriptionFailed":
callbackEvent = { kind: "TranscriptionFailed" };
break;
case "Microsoft.Communication.CreateCallFailed":
callbackEvent = { kind: "CreateCallFailed" };
break;
case "Microsoft.Communication.AnswerFailed":
callbackEvent = { kind: "AnswerFailed" };
break;
case "Microsoft.Communication.HoldFailed":
callbackEvent = { kind: "HoldFailed" };
break;
case "Microsoft.Communication.ConnectFailed":
callbackEvent = { kind: "ConnectFailed" };
break;
case "Microsoft.Communication.MediaStreamingStarted":
callbackEvent = { kind: "MediaStreamingStarted" };
break;
case "Microsoft.Communication.MediaStreamingStopped":
callbackEvent = { kind: "MediaStreamingStopped" };
break;
case "Microsoft.Communication.MediaStreamingFailed":
callbackEvent = { kind: "MediaStreamingFailed" };
break;
case "Microsoft.Communication.PlayStarted":
callbackEvent = { kind: "PlayStarted" };
break;
case "Microsoft.Communication.StartRecordingFailed":
callbackEvent = { kind: "StartRecordingFailed" };
break;
default:
throw new TypeError(`Unknown Call Automation Event type: ${eventType}`);
}
return { ...parsed, ...callbackEvent };
}
function parseAndWrap(jsonStringOrObject) {
if (typeof jsonStringOrObject === "string") {
const o = JSON.parse(jsonStringOrObject);
if (Array.isArray(o)) {
if (o.length === 0) {
throw Error("Empty event array.");
}
return o[0];
} else {
return o;
}
}
if (Array.isArray(jsonStringOrObject)) {
if (jsonStringOrObject.length === 0) {
throw Error("Empty event array.");
}
return jsonStringOrObject[0];
} else {
return jsonStringOrObject;
}
}
function participantsParserForEvent(data) {
const { participants, ...rest } = data;
return {
...rest,
participants: participants?.map(
(participant) => (0, import_converters.callParticipantConverter)(participant)
)
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
parseCallAutomationEvent
});
//# sourceMappingURL=callAutomationEventParser.js.map