From 208f9b8e5815aa5b587a42787d08a8c600d1a7b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Min=20Woo=20Lee=20=F0=9F=A7=8A?= <77083090+minwoolee-ms@users.noreply.github.com> Date: Thu, 2 Mar 2023 17:10:22 -0800 Subject: [PATCH] Event parser updated to accomodate latest changes such as naming update on AddParticipantFailed --- .../communication-call-automation.api.md | 32 +++++++++---------- .../src/callAutomationEventParser.ts | 31 ++++++++++-------- .../src/models/events.ts | 29 +++++++++-------- 3 files changed, 48 insertions(+), 44 deletions(-) diff --git a/sdk/communication/communication-call-automation/review/communication-call-automation.api.md b/sdk/communication/communication-call-automation/review/communication-call-automation.api.md index 8eb24ad242d5..470d48aa46b5 100644 --- a/sdk/communication/communication-call-automation/review/communication-call-automation.api.md +++ b/sdk/communication/communication-call-automation/review/communication-call-automation.api.md @@ -15,35 +15,35 @@ import { PhoneNumberIdentifier } from '@azure/communication-common'; import { TokenCredential } from '@azure/core-auth'; // @public -export interface AddParticipantOptions extends OperationOptions { - invitationTimeoutInSeconds?: number; +export interface AddParticipantFailed { + callConnectionId?: string; + correlationId?: string; + kind: "AddParticipantFailed"; operationContext?: string; + participant?: CommunicationIdentifier; + resultInformation?: ResultInformation; + serverCallId?: string; } // @public -export interface AddParticipantResult { +export interface AddParticipantOptions extends OperationOptions { + invitationTimeoutInSeconds?: number; operationContext?: string; - participant?: CallParticipant; } // @public -export interface AddParticipantsFailed { - callConnectionId?: string; - correlationId?: string; - kind: "AddParticipantsFailed"; +export interface AddParticipantResult { operationContext?: string; - participants?: CommunicationIdentifier[]; - resultInformation?: ResultInformation; - serverCallId?: string; + participant?: CallParticipant; } // @public -export interface AddParticipantsSucceeded { +export interface AddParticipantSucceeded { callConnectionId?: string; correlationId?: string; - kind: "AddParticipantsSucceeded"; + kind: "AddParticipantSucceeded"; operationContext?: string; - participants?: CommunicationIdentifier[]; + participant?: CommunicationIdentifier; resultInformation?: ResultInformation; serverCallId?: string; } @@ -79,7 +79,7 @@ export interface CallAutomationClientOptions extends CommonClientOptions { } // @public -export type CallAutomationEvent = AddParticipantsSucceeded | AddParticipantsFailed | CallConnected | CallDisconnected | CallTransferAccepted | CallTransferFailed | ParticipantsUpdated | RecordingStateChanged | PlayCompleted | PlayFailed | PlayCanceled | RecognizeCompleted | RecognizeCanceled | RecognizeFailed; +export type CallAutomationEvent = AddParticipantSucceeded | AddParticipantFailed | CallConnected | CallDisconnected | CallTransferAccepted | CallTransferFailed | ParticipantsUpdated | RecordingStateChanged | PlayCompleted | PlayFailed | PlayCanceled | RecognizeCompleted | RecognizeCanceled | RecognizeFailed; // @public export class CallAutomationEventParser { @@ -342,7 +342,7 @@ export interface ParticipantsUpdated { callConnectionId?: string; correlationId?: string; kind: "ParticipantsUpdated"; - participants?: CommunicationIdentifier[]; + participants?: CallParticipant[]; serverCallId?: string; } diff --git a/sdk/communication/communication-call-automation/src/callAutomationEventParser.ts b/sdk/communication/communication-call-automation/src/callAutomationEventParser.ts index 980759a83dcf..e0d25d16aa0e 100644 --- a/sdk/communication/communication-call-automation/src/callAutomationEventParser.ts +++ b/sdk/communication/communication-call-automation/src/callAutomationEventParser.ts @@ -3,12 +3,15 @@ import { createSerializer } from "@azure/core-client"; -import { communicationIdentifierConverter } from "./utli/converters"; +import { + communicationIdentifierConverter, + callParticipantConverter + } from "./utli/converters"; import { CallAutomationEvent, - AddParticipantsSucceeded, - AddParticipantsFailed, + AddParticipantSucceeded, + AddParticipantFailed, CallConnected, CallDisconnected, CallTransferAccepted, @@ -24,7 +27,7 @@ import { } from "./models/events"; import { CloudEventMapper } from "./models/mapper"; -import { CommunicationIdentifierModel } from "./generated/src"; +import { CallParticipantInternal } from "./generated/src"; const serializer = createSerializer(); @@ -56,13 +59,13 @@ export class CallAutomationEventParser { let callbackEvent: CallAutomationEvent; let parsed: any = data; switch (eventType) { - case "Microsoft.Communication.AddParticipantsSucceeded": - callbackEvent = { kind: "AddParticipantsSucceeded" } as AddParticipantsSucceeded; - parsed = communicationIdentifierParserForEvent(data); + case "Microsoft.Communication.AddParticipantSucceeded": + callbackEvent = { kind: "AddParticipantSucceeded" } as AddParticipantSucceeded; + data.participant = communicationIdentifierConverter(data.participant) break; - case "Microsoft.Communication.AddParticipantsFailed": - callbackEvent = { kind: "AddParticipantsFailed" } as AddParticipantsFailed; - parsed = communicationIdentifierParserForEvent(data); + case "Microsoft.Communication.AddParticipantFailed": + callbackEvent = { kind: "AddParticipantFailed" } as AddParticipantFailed; + data.participant = communicationIdentifierConverter(data.participant) break; case "Microsoft.Communication.CallConnected": callbackEvent = { kind: "CallConnected" } as CallConnected; @@ -78,7 +81,7 @@ export class CallAutomationEventParser { break; case "Microsoft.Communication.ParticipantsUpdated": callbackEvent = { kind: "ParticipantsUpdated" } as ParticipantsUpdated; - parsed = communicationIdentifierParserForEvent(data); + parsed = participantsParserForEvent(data); break; case "Microsoft.Communication.RecordingStateChanged": callbackEvent = { kind: "RecordingStateChanged" } as RecordingStateChanged; @@ -134,13 +137,13 @@ function parseAndWrap( } } -function communicationIdentifierParserForEvent(data: any): any { +function participantsParserForEvent(data: any): any { const { participants, ...rest } = data; return { ...rest, participants: participants?.map( - (participant: CommunicationIdentifierModel) => - communicationIdentifierConverter(participant) + (participant: CallParticipantInternal) => + callParticipantConverter(participant) ), }; } diff --git a/sdk/communication/communication-call-automation/src/models/events.ts b/sdk/communication/communication-call-automation/src/models/events.ts index f833e5acdec7..a3e073ccbf0b 100644 --- a/sdk/communication/communication-call-automation/src/models/events.ts +++ b/sdk/communication/communication-call-automation/src/models/events.ts @@ -15,14 +15,15 @@ import { RecognizeCompleted as RestRecognizeCompleted, RecognizeFailed as RestRecognizeFailed, RecognizeCanceled as RestRecognizeCanceled, - ResultInformation, + ResultInformation } from "../generated/src/models"; +import { CallParticipant } from "./models"; /** Callback events for Call Automation */ export type CallAutomationEvent = - | AddParticipantsSucceeded - | AddParticipantsFailed + | AddParticipantSucceeded + | AddParticipantFailed | CallConnected | CallDisconnected | CallTransferAccepted @@ -51,8 +52,8 @@ export { ResultInformation }; -/** The participants successfully added event. */ -export interface AddParticipantsSucceeded { +/** The participant successfully added event. */ +export interface AddParticipantSucceeded { /** Call connection ID. */ callConnectionId?: string; /** Server call ID. */ @@ -63,14 +64,14 @@ export interface AddParticipantsSucceeded { operationContext?: string; /** Contains the resulting SIP code/sub-code and message from NGC services. */ resultInformation?: ResultInformation; - /** The list of participants in the call. */ - participants?: CommunicationIdentifier[]; + /** The participant in the call. */ + participant?: CommunicationIdentifier; /** kind of this event. */ - kind: "AddParticipantsSucceeded"; + kind: "AddParticipantSucceeded"; } -/** The failed to add participants event. */ -export interface AddParticipantsFailed { +/** The failed to add participant event. */ +export interface AddParticipantFailed { /** Call connection ID. */ callConnectionId?: string; /** Server call ID. */ @@ -81,10 +82,10 @@ export interface AddParticipantsFailed { operationContext?: string; /** Contains the resulting SIP code/sub-code and message from NGC services. */ resultInformation?: ResultInformation; - /** The list of participants in the call. */ - participants?: CommunicationIdentifier[]; + /** The participant in the call. */ + participant?: CommunicationIdentifier; /** kind of this event. */ - kind: "AddParticipantsFailed"; + kind: "AddParticipantFailed"; } /** Event when call was established. */ @@ -120,7 +121,7 @@ export interface ParticipantsUpdated { /** Correlation ID for event to call correlation. Also called ChainId for skype chain ID. */ correlationId?: string; /** The list of participants in the call. */ - participants?: CommunicationIdentifier[]; + participants?: CallParticipant[]; /** kind of this event. */ kind: "ParticipantsUpdated"; }