Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Juntuchen/ops outgoing call #31567

Merged
merged 7 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class CallAutomationClient {

// @public
export interface CallAutomationClientOptions extends CommonClientOptions {
opsSourceIdentity?: MicrosoftTeamsAppIdentifier;
sourceIdentity?: CommunicationUserIdentifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import type { InternalPipelineOptions } from "@azure/core-rest-pipeline";
import type {
CommunicationIdentifier,
CommunicationUserIdentifier,
MicrosoftTeamsAppIdentifier,
} from "@azure/communication-common";
import { parseClientArguments, isKeyCredential } from "@azure/communication-common";
import { logger } from "./models/logger";
import type {
AnswerCallRequest,
CallAutomationApiClient,
CommunicationUserIdentifierModel,
MicrosoftTeamsAppIdentifierModel,
CreateCallRequest,
RedirectCallRequest,
RejectCallRequest,
Expand All @@ -34,6 +36,7 @@ import {
communicationIdentifierModelConverter,
communicationUserIdentifierConverter,
communicationUserIdentifierModelConverter,
microsoftTeamsAppIdentifierModelConverter,
phoneNumberIdentifierConverter,
PhoneNumberIdentifierModelConverter,
} from "./utli/converters";
Expand All @@ -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.
jeremymeng marked this conversation as resolved.
Show resolved Hide resolved
*/
opsSourceIdentity?: MicrosoftTeamsAppIdentifier;
}

/**
Expand All @@ -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;
jeremymeng marked this conversation as resolved.
Show resolved Hide resolved
private readonly credential: TokenCredential | KeyCredential;
private readonly internalPipelineOptions: InternalPipelineOptions;
private readonly callAutomationEventProcessor: CallAutomationEventProcessor;
Expand Down Expand Up @@ -127,6 +135,7 @@ export class CallAutomationClient {
);

this.sourceIdentity = communicationUserIdentifierModelConverter(options.sourceIdentity);
this.oPSSourceIdentity = microsoftTeamsAppIdentifierModelConverter(options.opsSourceIdentity);
}

/**
Expand Down Expand Up @@ -245,6 +254,7 @@ export class CallAutomationClient {
): Promise<CreateCallResult> {
const request: CreateCallRequest = {
source: this.sourceIdentity,
opsSource: this.oPSSourceIdentity,
targets: [communicationIdentifierModelConverter(targetParticipant.targetParticipant)],
callbackUri: callbackUrl,
operationContext: options.operationContext,
Expand Down Expand Up @@ -277,6 +287,7 @@ export class CallAutomationClient {
): Promise<CreateCallResult> {
const request: CreateCallRequest = {
source: this.sourceIdentity,
opsSource: this.oPSSourceIdentity,
targets: targetParticipants.map((target) => communicationIdentifierModelConverter(target)),
callbackUri: callbackUrl,
operationContext: options.operationContext,
Expand Down

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.

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
Expand Up @@ -26,6 +26,7 @@ import type {
KnownCommunicationCloudEnvironmentModel,
PhoneNumberIdentifierModel,
CommunicationUserIdentifierModel,
MicrosoftTeamsAppIdentifierModel,
} from "../generated/src";
import { KnownCommunicationIdentifierModelKind } from "../generated/src";
import type { CallParticipant } from "../models/models";
Expand Down Expand Up @@ -221,3 +222,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 };
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import type {
CommunicationIdentifier,
CommunicationUserIdentifier,
MicrosoftTeamsAppIdentifier,
} from "@azure/communication-common";
import { assert } from "chai";
import type { Context } from "mocha";
Expand All @@ -39,6 +40,17 @@ import type {
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: oPSSourceIdentity,
});
}

describe("Call Automation Client Unit Tests", () => {
let targets: CommunicationIdentifier[];
Expand Down Expand Up @@ -132,6 +144,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> & 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 = {
Expand Down
Loading