From 3c693ee2fc53319286fdfa5ac1bf195a414c7d67 Mon Sep 17 00:00:00 2001 From: kvsksraman <159804461+kvsksraman@users.noreply.github.com> Date: Thu, 24 Apr 2025 17:25:19 -0700 Subject: [PATCH] Add sync and async endpoints for ACS call transfer - Introduced new test endpoints in Call Controller to validate synchronous and asynchronous call transfer flows between ACS participants and target endpoints. --- .../Controllers/CallController.cs | 86 ++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/Call_Automation_GCCH/Call_Automation_GCCH/Controllers/CallController.cs b/Call_Automation_GCCH/Call_Automation_GCCH/Controllers/CallController.cs index b2628d03..1efc976e 100644 --- a/Call_Automation_GCCH/Call_Automation_GCCH/Controllers/CallController.cs +++ b/Call_Automation_GCCH/Call_Automation_GCCH/Controllers/CallController.cs @@ -131,7 +131,91 @@ public async Task CreateOutboundCallToAcsAsync(string acsTarget) return Problem($"Failed to create outbound ACS call: {ex.Message}"); } } - + /// + /// Transfers a call to an ACS participant asynchronously + /// + /// The call connection ID + /// The ACS user identifier to transfer to + /// The ACS target identifier + /// Call connection status + [HttpPost("/transferCallToAcsParticipantAsync")] + [Tags("Transfer Call APIs")] + public async Task TransferCallToAcsParticipantAsync(string callConnectionId, string acsTransferTarget, string acsTarget) + { + try + { + _logger.LogInformation($"Starting async call transfer to ACS user: {acsTransferTarget} for call {callConnectionId}"); + + CallConnection callConnection = _service.GetCallConnection(callConnectionId); + var correlationId = _service.GetCallConnectionProperties(callConnectionId).CorrelationId; + + TransferToParticipantOptions transferToParticipantOptions = new TransferToParticipantOptions(new CommunicationUserIdentifier(acsTransferTarget)) + { + OperationContext = "TransferCallContext", + Transferee = new CommunicationUserIdentifier(acsTarget), + }; + + var transferResult = await callConnection.TransferCallToParticipantAsync(transferToParticipantOptions); + var status = transferResult.GetRawResponse().Status.ToString(); + + _logger.LogInformation($"Call transferred successfully. CallConnectionId: {callConnectionId}, correlation id: {correlationId}, status: {status}"); + + return Ok(new CallConnectionResponse + { + CallConnectionId = callConnectionId, + CorrelationId = correlationId, + Status = status + }); + } + catch (Exception ex) + { + _logger.LogError($"Error transferring call: {ex.Message}. CallConnectionId: {callConnectionId}"); + return Problem($"Failed to transfer call: {ex.Message}"); + } + } + + /// + /// Transfers a call to an ACS participant synchronously + /// + /// The call connection ID + /// The ACS user identifier to transfer to + /// The ACS target identifier + /// Call connection status + [HttpPost("/transferCallToAcsParticipant")] + [Tags("Transfer Call APIs")] + public IActionResult TransferCallToAcsParticipant(string callConnectionId, string acsTransferTarget, string acsTarget) + { + try + { + _logger.LogInformation($"Starting call transfer to ACS user: {acsTransferTarget} for call {callConnectionId}"); + + CallConnection callConnection = _service.GetCallConnection(callConnectionId); + var correlationId = _service.GetCallConnectionProperties(callConnectionId).CorrelationId; + + TransferToParticipantOptions transferToParticipantOptions = new TransferToParticipantOptions(new CommunicationUserIdentifier(acsTransferTarget)) + { + OperationContext = "TransferCallContext", + Transferee = new CommunicationUserIdentifier(acsTarget), + }; + + var transferResult = callConnection.TransferCallToParticipant(transferToParticipantOptions); + var status = transferResult.GetRawResponse().Status.ToString(); + + _logger.LogInformation($"Call transferred successfully. CallConnectionId: {callConnectionId}, correlation id: {correlationId}, status: {status}"); + + return Ok(new CallConnectionResponse + { + CallConnectionId = callConnectionId, + CorrelationId = correlationId, + Status = status + }); + } + catch (Exception ex) + { + _logger.LogError($"Error transferring call: {ex.Message}. CallConnectionId: {callConnectionId}"); + return Problem($"Failed to transfer call: {ex.Message}"); + } + } /// /// Hangs up a call asynchronously ///