Skip to content

Commit

Permalink
Richardcho/add correlationid answeredby (Azure#25795)
Browse files Browse the repository at this point in the history
- Add correlationId to CallConnectionProperties 
- Add operationContext to AnswerCallOptions
- Add answeredByIdentifier to CallConnectionProperties

---------

Co-authored-by: juntuchen <[email protected]>
  • Loading branch information
richardcho-msft and juntuchen-msft authored May 10, 2023
1 parent 6726d75 commit 9ab8890
Showing 29 changed files with 1,030 additions and 879 deletions.
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@
"uuid": "^8.3.0"
},
"devDependencies": {
"@azure-tools/test-credential": "^1.0.0",
"@azure-tools/test-credential": "^1.0.1",
"@azure-tools/test-recorder": "^3.0.0",
"@azure/communication-identity": "^1.1.0-beta.2",
"@azure/core-util": "^1.0.0",

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@ export interface AddParticipantSucceeded extends Omit<RestAddParticipantSucceede
export interface AnswerCallOptions extends OperationOptions {
azureCognitiveServicesEndpointUrl?: string;
mediaStreamingConfiguration?: MediaStreamingConfiguration;
operationContext?: string;
}

// Warning: (ae-forgotten-export) The symbol "CallResult" needs to be exported by the entry point index.d.ts
@@ -104,9 +105,11 @@ export class CallConnection {

// @public
export interface CallConnectionProperties {
answeredByIdentifier?: CommunicationUserIdentifier;
callbackUrl?: string;
callConnectionId?: string;
callConnectionState?: CallConnectionStateModel;
correlationId?: string;
mediaSubscriptionId?: string;
serverCallId?: string;
sourceCallerIdNumber?: PhoneNumberIdentifier;
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import { SDK_VERSION } from "./models/constants";
import {
AnswerCallRequest,
CallAutomationApiClient,
CommunicationIdentifierModel,
CommunicationUserIdentifierModel,
CreateCallRequest,
RedirectCallRequest,
RejectCallRequest,
@@ -33,6 +33,8 @@ import { CallConnectionProperties, CallInvite } from "./models/models";
import {
communicationIdentifierConverter,
communicationIdentifierModelConverter,
communicationUserIdentifierConverter,
communicationUserIdentifierModelConverter,
phoneNumberIdentifierConverter,
PhoneNumberIdentifierModelConverter,
} from "./utli/converters";
@@ -61,7 +63,7 @@ const isCallAutomationClientOptions = (options: any): options is CallAutomationC
*/
export class CallAutomationClient {
private readonly callAutomationApiClient: CallAutomationApiClient;
private readonly sourceIdentity?: CommunicationIdentifierModel;
private readonly sourceIdentity?: CommunicationUserIdentifierModel;
private readonly credential: TokenCredential | KeyCredential;
private readonly internalPipelineOptions: InternalPipelineOptions;
/**
@@ -119,9 +121,7 @@ export class CallAutomationClient {
this.credential = credential;
this.callAutomationApiClient = new CallAutomationApiClient(url, this.internalPipelineOptions);
this.callAutomationApiClient.pipeline.addPolicy(authPolicy);
this.sourceIdentity = options.sourceIdentity
? communicationIdentifierModelConverter(options.sourceIdentity)
: undefined;
this.sourceIdentity = communicationUserIdentifierModelConverter(options.sourceIdentity);
}

/**
@@ -152,9 +152,7 @@ export class CallAutomationClient {
* Get Source Identity that is used for create and answer call
*/
public getSourceIdentity(): CommunicationUserIdentifier | undefined {
return this.sourceIdentity
? (communicationIdentifierConverter(this.sourceIdentity) as CommunicationUserIdentifier)
: undefined;
return communicationUserIdentifierConverter(this.sourceIdentity);
}

private async createCallInternal(
@@ -166,23 +164,32 @@ export class CallAutomationClient {
repeatabilityFirstSent: new Date().toUTCString(),
repeatabilityRequestID: uuidv4(),
};
const result = await this.callAutomationApiClient.createCall(request, optionsInternal);
const {
callConnectionId,
answeredByIdentifier,
targets,
sourceCallerIdNumber,
sourceIdentity,
...result
} = await this.callAutomationApiClient.createCall(request, optionsInternal);

if (result?.callConnectionId) {
if (callConnectionId) {
const callConnectionPropertiesDto: CallConnectionProperties = {
...result,
sourceIdentity: result.sourceIdentity
? communicationIdentifierConverter(result.sourceIdentity)
callConnectionId: callConnectionId,
sourceIdentity: sourceIdentity
? communicationIdentifierConverter(sourceIdentity)
: undefined,
targetParticipants: result.targets?.map((returnedTarget) =>
answeredByIdentifier: communicationUserIdentifierConverter(answeredByIdentifier),
targetParticipants: targets?.map((returnedTarget) =>
communicationIdentifierConverter(returnedTarget)
),
sourceCallerIdNumber: result.sourceCallerIdNumber
? phoneNumberIdentifierConverter(result.sourceCallerIdNumber)
sourceCallerIdNumber: sourceCallerIdNumber
? phoneNumberIdentifierConverter(sourceCallerIdNumber)
: undefined,
};
const callConnection = new CallConnection(
result.callConnectionId,
callConnectionId,
this.callAutomationApiClient.endpoint,
this.credential,
this.internalPipelineOptions
@@ -267,34 +274,49 @@ export class CallAutomationClient {
callbackUrl: string,
options: AnswerCallOptions = {}
): Promise<AnswerCallResult> {
const {
mediaStreamingConfiguration,
azureCognitiveServicesEndpointUrl,
operationContext,
...operationOptions
} = options;
const request: AnswerCallRequest = {
incomingCallContext: incomingCallContext,
incomingCallContext,
mediaStreamingConfiguration,
azureCognitiveServicesEndpointUrl,
operationContext,
callbackUri: callbackUrl,
mediaStreamingConfiguration: options.mediaStreamingConfiguration,
azureCognitiveServicesEndpointUrl: options.azureCognitiveServicesEndpointUrl,
answeredByIdentifier: this.sourceIdentity,
};
const optionsInternal = {
...options,
...operationOptions,
repeatabilityFirstSent: new Date().toUTCString(),
repeatabilityRequestID: uuidv4(),
};
const result = await this.callAutomationApiClient.answerCall(request, optionsInternal);
const {
callConnectionId,
targets,
sourceCallerIdNumber,
answeredByIdentifier,
sourceIdentity,
...result
} = await this.callAutomationApiClient.answerCall(request, optionsInternal);

if (result?.callConnectionId) {
if (callConnectionId) {
const callConnectionProperties: CallConnectionProperties = {
...result,
sourceIdentity: result.sourceIdentity
? communicationIdentifierConverter(result.sourceIdentity)
callConnectionId: callConnectionId,
sourceIdentity: sourceIdentity
? communicationIdentifierConverter(sourceIdentity)
: undefined,
targetParticipants: result.targets?.map((target) =>
communicationIdentifierConverter(target)
),
sourceCallerIdNumber: result.sourceCallerIdNumber
? phoneNumberIdentifierConverter(result.sourceCallerIdNumber)
answeredByIdentifier: communicationUserIdentifierConverter(answeredByIdentifier),
targetParticipants: targets?.map((target) => communicationIdentifierConverter(target)),
sourceCallerIdNumber: sourceCallerIdNumber
? phoneNumberIdentifierConverter(sourceCallerIdNumber)
: undefined,
};
const callConnection = new CallConnection(
result.callConnectionId,
callConnectionId,
this.callAutomationApiClient.endpoint,
this.credential,
this.internalPipelineOptions
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ import {
callParticipantConverter,
communicationIdentifierConverter,
communicationIdentifierModelConverter,
communicationUserIdentifierConverter,
phoneNumberIdentifierConverter,
PhoneNumberIdentifierModelConverter,
} from "./utli/converters";
@@ -83,15 +84,15 @@ export class CallConnection {
public async getCallConnectionProperties(
options: GetCallConnectionPropertiesOptions = {}
): Promise<CallConnectionProperties> {
const result = await this.callConnection.getCall(this.callConnectionId, options);
const { targets, sourceCallerIdNumber, answeredByIdentifier, sourceIdentity, ...result } =
await this.callConnection.getCall(this.callConnectionId, options);
const callConnectionProperties: CallConnectionProperties = {
...result,
sourceIdentity: result.sourceIdentity
? communicationIdentifierConverter(result.sourceIdentity)
: undefined,
targetParticipants: result.targets?.map((target) => communicationIdentifierConverter(target)),
sourceCallerIdNumber: result.sourceCallerIdNumber
? phoneNumberIdentifierConverter(result.sourceCallerIdNumber)
sourceIdentity: sourceIdentity ? communicationIdentifierConverter(sourceIdentity) : undefined,
answeredByIdentifier: communicationUserIdentifierConverter(answeredByIdentifier),
targetParticipants: targets?.map((target) => communicationIdentifierConverter(target)),
sourceCallerIdNumber: sourceCallerIdNumber
? phoneNumberIdentifierConverter(sourceCallerIdNumber)
: undefined,
};
return callConnectionProperties;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -44,6 +44,10 @@ export interface CallConnectionProperties {
callbackUrl?: string;
/** SubscriptionId for media streaming */
mediaSubscriptionId?: string;
/** The correlation ID. */
correlationId?: string;
/** Identity of the answering entity. Only populated when identity is provided in the request. */
answeredByIdentifier?: CommunicationUserIdentifier;
}

/** Contract model of an ACS call participant */
Original file line number Diff line number Diff line change
@@ -63,6 +63,8 @@ export interface AnswerCallOptions extends OperationOptions {
azureCognitiveServicesEndpointUrl?: string;
/** Configuration of Media streaming. */
mediaStreamingConfiguration?: MediaStreamingConfiguration;
/** The operation context. */
operationContext?: string;
}

/**
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import {
CallParticipantInternal,
CommunicationIdentifierModel,
CommunicationIdentifierModelKind,
CommunicationUserIdentifierModel,
KnownCommunicationIdentifierModelKind,
PhoneNumberIdentifierModel,
} from "../generated/src";
@@ -150,3 +151,25 @@ export function callParticipantConverter(
};
return callParticipant;
}

/** Convert CommunicationUserIdentifier to CommunicationUserIdentifierModel (Internal usage class) */
export function communicationUserIdentifierModelConverter(
identifier: CommunicationUserIdentifier | undefined
): CommunicationUserIdentifierModel | undefined {
if (!identifier || !identifier.communicationUserId) {
return undefined;
}

return { id: identifier.communicationUserId };
}

/** Convert CommunicationUserIdentifierModel to CommunicationUserIdentifier (Public usage class) */
export function communicationUserIdentifierConverter(
identifier: CommunicationUserIdentifierModel | undefined
): CommunicationUserIdentifier | undefined {
if (!identifier || !identifier.id) {
return undefined;
}

return { communicationUserId: identifier.id };
}
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ generate-metadata: false
license-header: MICROSOFT_MIT_NO_VERSION
output-folder: ../src/generated
tag: V2023-01-15-preview
input-file: https://raw.githubusercontent.com/williamzhao87/azure-rest-api-specs/a37e7e55b3aa6174e83e425b31015bda6d65de06/specification/communication/data-plane/CallAutomation/preview/2023-01-15-preview/communicationservicescallautomation.json
input-file: https://raw.githubusercontent.com/williamzhao87/azure-rest-api-specs/366f31cb260cb6c0ef4c8964440e9fee25bdf39f/specification/communication/data-plane/CallAutomation/preview/2023-01-15-preview/communicationservicescallautomation.json
package-version: 1.0.0-beta.1
model-date-time-as-string: false
optional-response-headers: true
Loading

0 comments on commit 9ab8890

Please sign in to comment.