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

Added custom calling context in answer api. #32046

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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 @@ -334,6 +334,9 @@ export class CallAutomationClient {
operationContext: operationContext,
callbackUri: callbackUrl,
answeredBy: this.sourceIdentity,
customCallingContext: this.createCustomCallingContextInternal(
options.customCallingContext!,
),
};
const optionsInternal = {
...operationOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ export interface AnswerCallOptions extends OperationOptions {
transcriptionConfiguration?: TranscriptionConfiguration;
/** The operation context. */
operationContext?: string;
/** The Custom Context. */
customCallingContext?: CustomCallingContext;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,54 @@ describe("Call Automation Main Client Live Tests", { skip: !isNodeLike }, () =>
assert.isDefined(callDisconnectedEvent);
});

it("answer call with custom context and hangup", { timeout: 60000 }, async (ctx) => {
const fullTitle: string | undefined =
ctx.task.suite && ctx.task.suite.name && ctx.task.name
? `${ctx.task.suite.name} ${ctx.task.name}`
: undefined;

testName = fullTitle ? fullTitle.replace(/ /g, "_") : "answer_call_with_custom_context_and_hang_up";
await loadPersistedEvents(testName);

const callInvite: CallInvite = { targetParticipant: testUser2 };
const uniqueId = await serviceBusWithNewCall(testUser, testUser2);
const callBackUrl: string = dispatcherCallback + `?q=${uniqueId}`;
const createCallOption: CreateCallOptions = { operationContext: "operationContextCreateCall" };

const result = await callerCallAutomationClient.createCall(
callInvite,
callBackUrl,
createCallOption,
);
const incomingCallContext = await waitForIncomingCallContext(uniqueId, 8000);
const callConnectionId: string = result.callConnectionProperties.callConnectionId
? result.callConnectionProperties.callConnectionId
: "";
assert.isDefined(incomingCallContext);

if (incomingCallContext) {
const answerCallOptions: AnswerCallOptions = {
operationContext: "operationContextAnswerCall",
customCallingContext : [{ kind: "voip", key: "foo", value: "bar" }]
};
await receiverCallAutomationClient.answerCall(
incomingCallContext,
callBackUrl,
answerCallOptions,
);
}

const callConnectedEvent = await waitForEvent("CallConnected", callConnectionId, 8000);

assert.isDefined(callConnectedEvent);
callConnection = result.callConnection;

await callConnection.hangUp(true);

const callDisconnectedEvent = await waitForEvent("CallDisconnected", callConnectionId, 8000);
assert.isDefined(callDisconnectedEvent);
});

it("Reject call", { timeout: 60000 }, async (ctx) => {
const fullTitle: string | undefined =
ctx.task.suite && ctx.task.suite.name && ctx.task.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
CommunicationIdentifier,
MicrosoftTeamsAppIdentifier,
} from "@azure/communication-common";
import type { CallInvite, CallConnection } from "../../src/index.js";
import type { CallInvite, CallConnection, AnswerCallOptions } from "../../src/index.js";
import type {
AnswerCallEventResult,
CreateCallEventResult,
Expand Down Expand Up @@ -198,6 +198,30 @@ describe("Call Automation Client Unit Tests", () => {
assert.equal(result, answerCallResultMock);
});

it("AnswerCall with custom context", async () => {
// mocks
const answerCallResultMock: AnswerCallResult = {
callConnectionProperties: {} as CallConnectionProperties,
callConnection: {} as CallConnection,
waitForEventProcessor: async () => {
return {} as AnswerCallEventResult;
},
};
vi.spyOn(client, "answerCall").mockResolvedValue(answerCallResultMock);
const answerCallOptions: AnswerCallOptions = {
operationContext: "operationContextAnswerCall",
customCallingContext : [{ kind: "voip", key: "foo", value: "bar" }]
};
const promiseResult = client.answerCall(CALL_INCOMING_CALL_CONTEXT, CALL_CALLBACK_URL, answerCallOptions);

// asserts
const result = await promiseResult;

assert.isNotNull(result);
expect(client.answerCall).toHaveBeenCalledWith(CALL_INCOMING_CALL_CONTEXT, CALL_CALLBACK_URL);
assert.equal(result, answerCallResultMock);
});

it("RedirectCall", async () => {
// mocks
vi.spyOn(client, "redirectCall").mockReturnValue(
Expand Down
Loading