From 9df18fd4ed2a15eb28c9825d8c4f16b32495502f Mon Sep 17 00:00:00 2001 From: Juntu Chen Date: Fri, 25 Oct 2024 16:29:59 -0400 Subject: [PATCH 1/5] updated swagger --- .../communication-call-automation/swagger/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/communication/communication-call-automation/swagger/README.md b/sdk/communication/communication-call-automation/swagger/README.md index 951fc4ae04f0..8323c607fa9f 100644 --- a/sdk/communication/communication-call-automation/swagger/README.md +++ b/sdk/communication/communication-call-automation/swagger/README.md @@ -13,7 +13,7 @@ license-header: MICROSOFT_MIT_NO_VERSION output-folder: ../src/generated tag: package-2023-10-03-preview require: - - https://github.com/Azure/azure-rest-api-specs/blob/156ff363e44f764ddd8a0a6adcd371610240ba15/specification/communication/data-plane/CallAutomation/readme.md + - https://github.com/Azure/azure-rest-api-specs/blob/be2a0fa68829fcb15c4e6b47aa6bc4bdd566c1cf/specification/communication/data-plane/CallAutomation/readme.md package-version: 1.3.0-beta.1 model-date-time-as-string: false optional-response-headers: true From 9d024d5b6867eb7ad36b4db8d8f11d2f8711f80f Mon Sep 17 00:00:00 2001 From: Juntu Chen Date: Mon, 28 Oct 2024 18:14:48 -0400 Subject: [PATCH 2/5] updated ops outgoing call --- .../communication-call-automation.api.md | 1 + .../src/callAutomationClient.ts | 11 +++ .../src/generated/src/models/index.ts | 7 +- .../src/generated/src/models/mappers.ts | 14 ++++ .../generated/src/operations/callDialog.ts | 5 +- .../src/operationsInterfaces/callDialog.ts | 5 +- .../src/utli/converters.ts | 23 +++++++ .../test/callAutomationClient.spec.ts | 68 ++++++++++++++++++- 8 files changed, 125 insertions(+), 9 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 7d7a6c60e86a..34543c0571f3 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 @@ -113,6 +113,7 @@ export class CallAutomationClient { // @public export interface CallAutomationClientOptions extends CommonClientOptions { + oPSSourceIdentity?: MicrosoftTeamsAppIdentifier; sourceIdentity?: CommunicationUserIdentifier; } diff --git a/sdk/communication/communication-call-automation/src/callAutomationClient.ts b/sdk/communication/communication-call-automation/src/callAutomationClient.ts index f5a8a3881111..2d6144261007 100644 --- a/sdk/communication/communication-call-automation/src/callAutomationClient.ts +++ b/sdk/communication/communication-call-automation/src/callAutomationClient.ts @@ -8,12 +8,14 @@ import { isKeyCredential, CommunicationIdentifier, CommunicationUserIdentifier, + MicrosoftTeamsAppIdentifier, } from "@azure/communication-common"; import { logger } from "./models/logger"; import { AnswerCallRequest, CallAutomationApiClient, CommunicationUserIdentifierModel, + MicrosoftTeamsAppIdentifierModel, CreateCallRequest, RedirectCallRequest, RejectCallRequest, @@ -34,6 +36,7 @@ import { communicationIdentifierModelConverter, communicationUserIdentifierConverter, communicationUserIdentifierModelConverter, + microsoftTeamsAppIdentifierModelConverter, phoneNumberIdentifierConverter, PhoneNumberIdentifierModelConverter, } from "./utli/converters"; @@ -49,6 +52,10 @@ export interface CallAutomationClientOptions extends CommonClientOptions { * The identifier of the source of the call for call creating/answering/inviting operation. */ sourceIdentity?: CommunicationUserIdentifier; + /** + * The identifier of the OPS of the call for call creating operation. + */ + oPSSourceIdentity?: MicrosoftTeamsAppIdentifier; } /** @@ -65,6 +72,7 @@ const isCallAutomationClientOptions = (options: any): options is CallAutomationC export class CallAutomationClient { private readonly callAutomationApiClient: CallAutomationApiClient; private readonly sourceIdentity?: CommunicationUserIdentifierModel; + private readonly oPSSourceIdentity?: MicrosoftTeamsAppIdentifierModel; private readonly credential: TokenCredential | KeyCredential; private readonly internalPipelineOptions: InternalPipelineOptions; private readonly callAutomationEventProcessor: CallAutomationEventProcessor; @@ -127,6 +135,7 @@ export class CallAutomationClient { ); this.sourceIdentity = communicationUserIdentifierModelConverter(options.sourceIdentity); + this.oPSSourceIdentity = microsoftTeamsAppIdentifierModelConverter(options.oPSSourceIdentity); } /** @@ -245,6 +254,7 @@ export class CallAutomationClient { ): Promise { const request: CreateCallRequest = { source: this.sourceIdentity, + opsSource: this.oPSSourceIdentity, targets: [communicationIdentifierModelConverter(targetParticipant.targetParticipant)], callbackUri: callbackUrl, operationContext: options.operationContext, @@ -277,6 +287,7 @@ export class CallAutomationClient { ): Promise { const request: CreateCallRequest = { source: this.sourceIdentity, + opsSource: this.oPSSourceIdentity, targets: targetParticipants.map((target) => communicationIdentifierModelConverter(target)), callbackUri: callbackUrl, operationContext: options.operationContext, diff --git a/sdk/communication/communication-call-automation/src/generated/src/models/index.ts b/sdk/communication/communication-call-automation/src/generated/src/models/index.ts index 8033a147ae4d..ecc485f622b0 100644 --- a/sdk/communication/communication-call-automation/src/generated/src/models/index.ts +++ b/sdk/communication/communication-call-automation/src/generated/src/models/index.ts @@ -27,6 +27,8 @@ export interface CreateCallRequest { sourceDisplayName?: string; /** The identifier of the source of the call */ source?: CommunicationUserIdentifierModel; + /** The identifier of the source in an OPS call */ + opsSource?: MicrosoftTeamsAppIdentifierModel; /** A customer set value used to track the answering of a call. */ operationContext?: string; /** The callback URI. */ @@ -194,6 +196,8 @@ export interface AnswerCallRequest { incomingCallContext: string; /** The callback uri. */ callbackUri: string; + /** Used by customer to send custom calling context to targets when answering On-Behalf-Of call */ + customCallingContext?: CustomCallingContextInternal; /** A customer set value used to track the answering of a call. */ operationContext?: string; /** Media Streaming Configuration. */ @@ -711,7 +715,7 @@ export interface StartCallRecordingRequest { pauseOnStart?: boolean; } -/** The locator used for joining or taking action on a call. */ +/** The locator used for joining or taking action on a call */ export interface CallLocator { /** The group call id */ groupCallId?: string; @@ -3064,7 +3068,6 @@ export type CallDialogStartDialogResponse = DialogStateResponse; /** Optional parameters. */ export interface CallDialogStopDialogOptionalParams extends coreClient.OperationOptions { - /** Operation callback URI. */ operationCallbackUri?: string; } diff --git a/sdk/communication/communication-call-automation/src/generated/src/models/mappers.ts b/sdk/communication/communication-call-automation/src/generated/src/models/mappers.ts index 0e121e804a3f..d5b306a6efc6 100644 --- a/sdk/communication/communication-call-automation/src/generated/src/models/mappers.ts +++ b/sdk/communication/communication-call-automation/src/generated/src/models/mappers.ts @@ -46,6 +46,13 @@ export const CreateCallRequest: coreClient.CompositeMapper = { className: "CommunicationUserIdentifierModel", }, }, + opsSource: { + serializedName: "opsSource", + type: { + name: "Composite", + className: "MicrosoftTeamsAppIdentifierModel", + }, + }, operationContext: { serializedName: "operationContext", type: { @@ -522,6 +529,13 @@ export const AnswerCallRequest: coreClient.CompositeMapper = { name: "String", }, }, + customCallingContext: { + serializedName: "customCallingContext", + type: { + name: "Composite", + className: "CustomCallingContextInternal", + }, + }, operationContext: { serializedName: "operationContext", type: { diff --git a/sdk/communication/communication-call-automation/src/generated/src/operations/callDialog.ts b/sdk/communication/communication-call-automation/src/generated/src/operations/callDialog.ts index ed2a0cf76d98..02330c389d27 100644 --- a/sdk/communication/communication-call-automation/src/generated/src/operations/callDialog.ts +++ b/sdk/communication/communication-call-automation/src/generated/src/operations/callDialog.ts @@ -52,9 +52,8 @@ export class CallDialogImpl implements CallDialog { } /** - * Stop a dialog. - * @param callConnectionId The call connection id - * @param dialogId The dialog id + * @param callConnectionId + * @param dialogId * @param options The options parameters. */ stopDialog( diff --git a/sdk/communication/communication-call-automation/src/generated/src/operationsInterfaces/callDialog.ts b/sdk/communication/communication-call-automation/src/generated/src/operationsInterfaces/callDialog.ts index 731b8415380f..4fccc524812b 100644 --- a/sdk/communication/communication-call-automation/src/generated/src/operationsInterfaces/callDialog.ts +++ b/sdk/communication/communication-call-automation/src/generated/src/operationsInterfaces/callDialog.ts @@ -31,9 +31,8 @@ export interface CallDialog { options?: CallDialogStartDialogOptionalParams, ): Promise; /** - * Stop a dialog. - * @param callConnectionId The call connection id - * @param dialogId The dialog id + * @param callConnectionId + * @param dialogId * @param options The options parameters. */ stopDialog( diff --git a/sdk/communication/communication-call-automation/src/utli/converters.ts b/sdk/communication/communication-call-automation/src/utli/converters.ts index b25f5d168f5c..e36fe04b394d 100644 --- a/sdk/communication/communication-call-automation/src/utli/converters.ts +++ b/sdk/communication/communication-call-automation/src/utli/converters.ts @@ -25,6 +25,7 @@ import { KnownCommunicationIdentifierModelKind, PhoneNumberIdentifierModel, CommunicationUserIdentifierModel, + MicrosoftTeamsAppIdentifierModel, } from "../generated/src"; import { CallParticipant } from "../models/models"; @@ -219,3 +220,25 @@ export function communicationUserIdentifierConverter( return { communicationUserId: identifier.id }; } + +/** Convert MicrosoftTeamsAppIdentifier to MicrosoftTeamsAppIdentifierModel (Internal usage class) */ +export function microsoftTeamsAppIdentifierModelConverter( + identifier: MicrosoftTeamsAppIdentifier | undefined, +): MicrosoftTeamsAppIdentifierModel | undefined { + if (!identifier || !identifier.teamsAppId) { + return undefined; + } + + return { appId: identifier.teamsAppId }; +} + +/** Convert MicrosoftTeamsAppIdentifierModel to MicrosoftTeamsAppIdentifier (Public usage class) */ +export function microsoftTeamsAppIdentifierConverter( + identifier: MicrosoftTeamsAppIdentifierModel | undefined, +): MicrosoftTeamsAppIdentifier | undefined { + if (!identifier || !identifier.appId) { + return undefined; + } + + return { teamsAppId: identifier.appId }; +} diff --git a/sdk/communication/communication-call-automation/test/callAutomationClient.spec.ts b/sdk/communication/communication-call-automation/test/callAutomationClient.spec.ts index 5ba0c3e06f4e..f1f922a68272 100644 --- a/sdk/communication/communication-call-automation/test/callAutomationClient.spec.ts +++ b/sdk/communication/communication-call-automation/test/callAutomationClient.spec.ts @@ -11,7 +11,11 @@ import { CALL_TARGET_ID, CALL_TARGET_ID_2, } from "./utils/connectionUtils"; -import { CommunicationIdentifier, CommunicationUserIdentifier } from "@azure/communication-common"; +import { + CommunicationIdentifier, + CommunicationUserIdentifier, + MicrosoftTeamsAppIdentifier, +} from "@azure/communication-common"; import { assert } from "chai"; import { Context } from "mocha"; import { @@ -37,6 +41,17 @@ import { } from "./utils/recordedClient"; import { AnswerCallEventResult, CreateCallEventResult } from "../src/eventprocessor/eventResponses"; import { randomUUID } from "@azure/core-util"; +import { KnownCommunicationCloudEnvironmentModel } from "../src/generated/src"; + +function createOPSCallAutomationClient( + oPSSourceIdentity: MicrosoftTeamsAppIdentifier, +): CallAutomationClient { + const connectionString = "endpoint=https://redacted.communication.azure.com/;accesskey=redacted"; + + return new CallAutomationClient(connectionString, { + oPSSourceIdentity, + }); +} describe("Call Automation Client Unit Tests", () => { let targets: CommunicationIdentifier[]; @@ -130,6 +145,57 @@ describe("Call Automation Client Unit Tests", () => { .catch((error) => console.error(error)); }); + it("CreateOPSCall", async () => { + // defined dummy variables + const appId = "28:acs:redacted"; + const appCloud = KnownCommunicationCloudEnvironmentModel.Public; + const oPSSouceStub = { + teamsAppId: appId, + cloud: appCloud, + }; + + // stub an OPS CallAutomationClient + const createOPSClientStub = Sinon.stub().callsFake(() => + createOPSCallAutomationClient(oPSSouceStub), + ); + + // Use the stubbed factory function to create the client + const oPSClient: SinonStubbedInstance & CallAutomationClient = + createOPSClientStub(); + + // Explicitly stub the createCall method + oPSClient.createCall = Sinon.stub(); + + // mocks + const createCallResultMock: CreateCallResult = { + callConnectionProperties: { + source: { + rawId: appId, + teamsAppId: appId, + cloud: appCloud, + } as MicrosoftTeamsAppIdentifier, + } as CallConnectionProperties, + callConnection: {} as CallConnection, + waitForEventProcessor: async () => { + return {} as CreateCallEventResult; + }, + }; + + (oPSClient.createCall as Sinon.SinonStub).returns(Promise.resolve(createCallResultMock)); + + const promiseResult = oPSClient.createCall(target, CALL_CALLBACK_URL); + + // asserts + promiseResult + .then((result: CreateCallResult) => { + assert.isNotNull(result); + assert.isTrue(oPSClient.createCall.calledWith(target, CALL_CALLBACK_URL)); + assert.equal(result, createCallResultMock); + return; + }) + .catch((error) => console.error(error)); + }); + it("AnswerCall", async () => { // mocks const answerCallResultMock: AnswerCallResult = { From 239436712126fdc1dfd85101c289b5875e23f2ef Mon Sep 17 00:00:00 2001 From: Juntu Chen Date: Wed, 6 Nov 2024 17:24:02 -0500 Subject: [PATCH 3/5] updated naming --- .../review/communication-call-automation.api.md | 2 +- .../communication-call-automation/src/callAutomationClient.ts | 4 ++-- .../test/callAutomationClient.spec.ts | 2 +- 3 files changed, 4 insertions(+), 4 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 34543c0571f3..b99df487e230 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 @@ -113,7 +113,7 @@ export class CallAutomationClient { // @public export interface CallAutomationClientOptions extends CommonClientOptions { - oPSSourceIdentity?: MicrosoftTeamsAppIdentifier; + opsSourceIdentity?: MicrosoftTeamsAppIdentifier; sourceIdentity?: CommunicationUserIdentifier; } diff --git a/sdk/communication/communication-call-automation/src/callAutomationClient.ts b/sdk/communication/communication-call-automation/src/callAutomationClient.ts index 2d6144261007..3488c15f57d4 100644 --- a/sdk/communication/communication-call-automation/src/callAutomationClient.ts +++ b/sdk/communication/communication-call-automation/src/callAutomationClient.ts @@ -55,7 +55,7 @@ export interface CallAutomationClientOptions extends CommonClientOptions { /** * The identifier of the OPS of the call for call creating operation. */ - oPSSourceIdentity?: MicrosoftTeamsAppIdentifier; + opsSourceIdentity?: MicrosoftTeamsAppIdentifier; } /** @@ -135,7 +135,7 @@ export class CallAutomationClient { ); this.sourceIdentity = communicationUserIdentifierModelConverter(options.sourceIdentity); - this.oPSSourceIdentity = microsoftTeamsAppIdentifierModelConverter(options.oPSSourceIdentity); + this.oPSSourceIdentity = microsoftTeamsAppIdentifierModelConverter(options.opsSourceIdentity); } /** diff --git a/sdk/communication/communication-call-automation/test/callAutomationClient.spec.ts b/sdk/communication/communication-call-automation/test/callAutomationClient.spec.ts index f1f922a68272..3ba556ff9d5b 100644 --- a/sdk/communication/communication-call-automation/test/callAutomationClient.spec.ts +++ b/sdk/communication/communication-call-automation/test/callAutomationClient.spec.ts @@ -49,7 +49,7 @@ function createOPSCallAutomationClient( const connectionString = "endpoint=https://redacted.communication.azure.com/;accesskey=redacted"; return new CallAutomationClient(connectionString, { - oPSSourceIdentity, + opsSourceIdentity: oPSSourceIdentity, }); } From 8c788e430081665c342e9b19a4876d91bf9d552c Mon Sep 17 00:00:00 2001 From: Juntu Chen Date: Fri, 8 Nov 2024 14:01:40 -0500 Subject: [PATCH 4/5] updated PR based on comments --- .../src/callAutomationClient.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sdk/communication/communication-call-automation/src/callAutomationClient.ts b/sdk/communication/communication-call-automation/src/callAutomationClient.ts index eba911a8e90e..a2ea6255acd5 100644 --- a/sdk/communication/communication-call-automation/src/callAutomationClient.ts +++ b/sdk/communication/communication-call-automation/src/callAutomationClient.ts @@ -53,7 +53,7 @@ export interface CallAutomationClientOptions extends CommonClientOptions { */ sourceIdentity?: CommunicationUserIdentifier; /** - * The identifier of the OPS of the call for call creating operation. + * The identifier of the One Phone System bot for call creating operation. */ opsSourceIdentity?: MicrosoftTeamsAppIdentifier; } @@ -72,7 +72,7 @@ const isCallAutomationClientOptions = (options: any): options is CallAutomationC export class CallAutomationClient { private readonly callAutomationApiClient: CallAutomationApiClient; private readonly sourceIdentity?: CommunicationUserIdentifierModel; - private readonly oPSSourceIdentity?: MicrosoftTeamsAppIdentifierModel; + private readonly opsSourceIdentity?: MicrosoftTeamsAppIdentifierModel; private readonly credential: TokenCredential | KeyCredential; private readonly internalPipelineOptions: InternalPipelineOptions; private readonly callAutomationEventProcessor: CallAutomationEventProcessor; @@ -135,7 +135,7 @@ export class CallAutomationClient { ); this.sourceIdentity = communicationUserIdentifierModelConverter(options.sourceIdentity); - this.oPSSourceIdentity = microsoftTeamsAppIdentifierModelConverter(options.opsSourceIdentity); + this.opsSourceIdentity = microsoftTeamsAppIdentifierModelConverter(options.opsSourceIdentity); } /** @@ -254,7 +254,7 @@ export class CallAutomationClient { ): Promise { const request: CreateCallRequest = { source: this.sourceIdentity, - opsSource: this.oPSSourceIdentity, + opsSource: this.opsSourceIdentity, targets: [communicationIdentifierModelConverter(targetParticipant.targetParticipant)], callbackUri: callbackUrl, operationContext: options.operationContext, @@ -287,7 +287,7 @@ export class CallAutomationClient { ): Promise { const request: CreateCallRequest = { source: this.sourceIdentity, - opsSource: this.oPSSourceIdentity, + opsSource: this.opsSourceIdentity, targets: targetParticipants.map((target) => communicationIdentifierModelConverter(target)), callbackUri: callbackUrl, operationContext: options.operationContext, From 0ec6f64107f492f3287fb6b86d92df6f5a08563f Mon Sep 17 00:00:00 2001 From: Juntu Chen Date: Fri, 8 Nov 2024 14:20:01 -0500 Subject: [PATCH 5/5] updated comment --- .../communication-call-automation/src/callAutomationClient.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/communication/communication-call-automation/src/callAutomationClient.ts b/sdk/communication/communication-call-automation/src/callAutomationClient.ts index a2ea6255acd5..a5cfb3ff7849 100644 --- a/sdk/communication/communication-call-automation/src/callAutomationClient.ts +++ b/sdk/communication/communication-call-automation/src/callAutomationClient.ts @@ -54,6 +54,7 @@ export interface CallAutomationClientOptions extends CommonClientOptions { sourceIdentity?: CommunicationUserIdentifier; /** * The identifier of the One Phone System bot for call creating operation. + * Should be mutually exclusive with sourceIdentity. */ opsSourceIdentity?: MicrosoftTeamsAppIdentifier; }