diff --git a/Call_Automation_GCCH/Call_Automation_GCCH/Controllers/CallController.cs b/Call_Automation_GCCH/Call_Automation_GCCH/Controllers/CallController.cs index b2628d0..1efc976 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 ///