diff --git a/Call_Automation_GCCH/.gitignore b/Call_Automation_GCCH/.gitignore new file mode 100644 index 00000000..12f72ce6 --- /dev/null +++ b/Call_Automation_GCCH/.gitignore @@ -0,0 +1,18 @@ +# Ignore all bin and obj folders (C# projects) +bin/ +obj/ + +# Ignore user-specific Visual Studio files +.vscode/ +*.user +*.suo + +# Ignore compiled code +*.dll +*.exe + +# Ignore log files +*.log + +# Ignore environment-specific files +.env \ No newline at end of file diff --git a/Call_Automation_GCCH/Call_Automation_GCCH.sln b/Call_Automation_GCCH/Call_Automation_GCCH.sln new file mode 100644 index 00000000..e90b7712 --- /dev/null +++ b/Call_Automation_GCCH/Call_Automation_GCCH.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35728.132 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Call_Automation_GCCH", "Call_Automation_GCCH\Call_Automation_GCCH.csproj", "{1094CA30-3CC4-4B93-92D4-0F313B241B3F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1094CA30-3CC4-4B93-92D4-0F313B241B3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1094CA30-3CC4-4B93-92D4-0F313B241B3F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1094CA30-3CC4-4B93-92D4-0F313B241B3F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1094CA30-3CC4-4B93-92D4-0F313B241B3F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Call_Automation_GCCH/Call_Automation_GCCH/Call_Automation_GCCH.csproj b/Call_Automation_GCCH/Call_Automation_GCCH/Call_Automation_GCCH.csproj new file mode 100644 index 00000000..5762bd3a --- /dev/null +++ b/Call_Automation_GCCH/Call_Automation_GCCH/Call_Automation_GCCH.csproj @@ -0,0 +1,14 @@ + + + + net8.0 + enable + enable + + + + + + + + diff --git a/Call_Automation_GCCH/Call_Automation_GCCH/ConfigurationRequest.cs b/Call_Automation_GCCH/Call_Automation_GCCH/ConfigurationRequest.cs new file mode 100644 index 00000000..70058a7a --- /dev/null +++ b/Call_Automation_GCCH/Call_Automation_GCCH/ConfigurationRequest.cs @@ -0,0 +1,12 @@ +namespace Call_Automation_GCCH +{ + public class ConfigurationRequest + { + public string AcsConnectionString { get; set; } = string.Empty; + public string AcsPhoneNumber { get; set; } = string.Empty; + public string CongnitiveServiceEndpoint { get; set; } = string.Empty; + public string CallbackUriHost { get; set; } = string.Empty; + public Dictionary BotRouting { get; set; } = new(); + public string DefaultBotId { get; set; } = string.Empty; + } +} diff --git a/Call_Automation_GCCH/Call_Automation_GCCH/Helper.cs b/Call_Automation_GCCH/Call_Automation_GCCH/Helper.cs new file mode 100644 index 00000000..a5d95fb1 --- /dev/null +++ b/Call_Automation_GCCH/Call_Automation_GCCH/Helper.cs @@ -0,0 +1,100 @@ +using Azure.Communication.CallAutomation; +using System.Net.WebSockets; +using System.Text; +using System.Text.Json; + +namespace Call_Automation_GCCH +{ + public static class Helper + { + public static async Task ProcessRequest(WebSocket webSocket) + { + try + { + var buffer = new byte[1024 * 4]; + var cancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(60)).Token; + WebSocketReceiveResult receiveResult = await webSocket.ReceiveAsync(new ArraySegment(buffer), cancellationToken); + + while (!receiveResult.CloseStatus.HasValue) + { + string msg = Encoding.UTF8.GetString(buffer, 0, receiveResult.Count); + + var response = StreamingData.Parse(msg); + + if (response != null) + { + if (response is AudioMetadata audioMetadata) + { + Console.WriteLine("***************************************************************************************"); + Console.WriteLine("MEDIA SUBSCRIPTION ID-->" + audioMetadata.MediaSubscriptionId); + Console.WriteLine("ENCODING-->" + audioMetadata.Encoding); + Console.WriteLine("SAMPLE RATE-->" + audioMetadata.SampleRate); + Console.WriteLine("CHANNELS-->" + audioMetadata.Channels); + Console.WriteLine("LENGTH-->" + audioMetadata.Length); + Console.WriteLine("***************************************************************************************"); + } + if (response is AudioData audioData) + { + Console.WriteLine("***************************************************************************************"); + Console.WriteLine("DATA-->" + JsonSerializer.Serialize(audioData.Data)); + Console.WriteLine("TIMESTAMP-->" + audioData.Timestamp); + Console.WriteLine("IS SILENT-->" + audioData.IsSilent); + if (audioData.Participant != null && audioData.Participant.RawId != null) + { + Console.WriteLine("Participant Id-->" + audioData.Participant.RawId); + } + + Console.WriteLine("***************************************************************************************"); + } + + if (response is TranscriptionMetadata transcriptionMetadata) + { + Console.WriteLine("***************************************************************************************"); + Console.WriteLine("TRANSCRIPTION SUBSCRIPTION ID-->" + transcriptionMetadata.TranscriptionSubscriptionId); + Console.WriteLine("LOCALE-->" + transcriptionMetadata.Locale); + Console.WriteLine("CALL CONNECTION ID--?" + transcriptionMetadata.CallConnectionId); + Console.WriteLine("CORRELATION ID-->" + transcriptionMetadata.CorrelationId); + Console.WriteLine("***************************************************************************************"); + } + if (response is TranscriptionData transcriptionData) + { + Console.WriteLine("***************************************************************************************"); + Console.WriteLine("TEXT-->" + transcriptionData.Text); + Console.WriteLine("FORMAT-->" + transcriptionData.Format); + Console.WriteLine("OFFSET-->" + transcriptionData.Offset); + Console.WriteLine("DURATION-->" + transcriptionData.Duration); + Console.WriteLine("PARTICIPANT-->" + transcriptionData.Participant.RawId); + Console.WriteLine("CONFIDENCE-->" + transcriptionData.Confidence); + //Console.WriteLine("RESULT STATUS-->" + transcriptionData.ResultStatus); + foreach (var word in transcriptionData.Words) + { + Console.WriteLine("WORDS TEXT-->" + word.Text); + Console.WriteLine("WORDS OFFSET-->" + word.Offset); + Console.WriteLine("WORDS DURATION-->" + word.Duration); + } + Console.WriteLine("***************************************************************************************"); + } + } + + await webSocket.SendAsync( + new ArraySegment(buffer, 0, receiveResult.Count), + receiveResult.MessageType, + receiveResult.EndOfMessage, + CancellationToken.None); + + receiveResult = await webSocket.ReceiveAsync( + new ArraySegment(buffer), CancellationToken.None); + } + + await webSocket.CloseAsync(receiveResult.CloseStatus.Value, receiveResult.CloseStatusDescription, CancellationToken.None); + } + catch (Exception ex) + { + Console.WriteLine($"Exception -> {ex}"); + } + finally + { + } + } + } +} diff --git a/Call_Automation_GCCH/Call_Automation_GCCH/InstructionToDeploy.txt b/Call_Automation_GCCH/Call_Automation_GCCH/InstructionToDeploy.txt new file mode 100644 index 00000000..a7ce206a --- /dev/null +++ b/Call_Automation_GCCH/Call_Automation_GCCH/InstructionToDeploy.txt @@ -0,0 +1,16 @@ +Install Git Bash + +Open Git Bash + +Navigate to deployment file location + +://Call_Automation_GCCH/Call_Automation_GCCH + +Execute following command to create executable. +chmod +x gcchDeploy.sh + +Execute following command to deploy +./gcchDeploy.sh + +https://.scm.azurewebsites.net/swagger/index.html + diff --git a/Call_Automation_GCCH/Call_Automation_GCCH/Program.cs b/Call_Automation_GCCH/Call_Automation_GCCH/Program.cs new file mode 100644 index 00000000..1bb1058d --- /dev/null +++ b/Call_Automation_GCCH/Call_Automation_GCCH/Program.cs @@ -0,0 +1,2775 @@ +using Azure.Communication; +using Azure.Communication.CallAutomation; +using Azure.Messaging; +using Azure.Messaging.EventGrid; +using Azure.Messaging.EventGrid.SystemEvents; +using Call_Automation_GCCH; +using Microsoft.Extensions.FileProviders; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllers(); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); +var app = builder.Build(); + +app.UseSwagger(); +app.UseSwaggerUI(); + +string acsConnectionString = string.Empty; +string cognitiveServicesEndpoint = string.Empty; +string acsPhoneNumber = string.Empty; +string callbackUriHost = string.Empty; +string fileSourceUri = string.Empty; + +string callConnectionId = string.Empty; +string recordingId = string.Empty; +string recordingLocation = string.Empty; +string recordingFileFormat = string.Empty; +Uri eventCallbackUri = null!; +string callerId = string.Empty; +string calleeId = string.Empty; +Dictionary botRouting = new(); +string defaultBotId = string.Empty; +ConfigurationRequest configuration = new(); +CallAutomationClient client = null!; + +app.MapPost("/setConfigurations", (ConfigurationRequest configurationRequest, ILogger logger) => +{ + acsConnectionString = string.Empty; + cognitiveServicesEndpoint = string.Empty; + acsPhoneNumber = string.Empty; + callbackUriHost = string.Empty; + fileSourceUri = string.Empty; + + if (configurationRequest != null) + { + configuration.AcsConnectionString = !string.IsNullOrEmpty(configurationRequest.AcsConnectionString) ? configurationRequest.AcsConnectionString : throw new ArgumentNullException(nameof(configurationRequest.AcsConnectionString)); + configuration.CongnitiveServiceEndpoint = !string.IsNullOrEmpty(configurationRequest.CongnitiveServiceEndpoint) ? configurationRequest.CongnitiveServiceEndpoint : throw new ArgumentNullException(nameof(configurationRequest.CongnitiveServiceEndpoint)); + configuration.AcsPhoneNumber = !string.IsNullOrEmpty(configurationRequest.AcsPhoneNumber) ? configurationRequest.AcsPhoneNumber : throw new ArgumentNullException(nameof(configurationRequest.AcsPhoneNumber)); + configuration.CallbackUriHost = !string.IsNullOrEmpty(configurationRequest.CallbackUriHost) ? configurationRequest.CallbackUriHost : throw new ArgumentNullException(nameof(configurationRequest.CallbackUriHost)); + configuration.BotRouting = configurationRequest.BotRouting ?? new Dictionary(); + configuration.DefaultBotId = !string.IsNullOrEmpty(configurationRequest.DefaultBotId) + ? configurationRequest.DefaultBotId + : throw new ArgumentNullException(nameof(configurationRequest.DefaultBotId)); + + } + + acsConnectionString = configuration.AcsConnectionString; + cognitiveServicesEndpoint = configuration.CongnitiveServiceEndpoint; + acsPhoneNumber = configuration.AcsPhoneNumber; + callbackUriHost = configuration.CallbackUriHost; + botRouting = configuration.BotRouting; + defaultBotId = configuration.DefaultBotId; + fileSourceUri = "https://sample-videos.com/audio/mp3/crowd-cheering.mp3"; + + client = new CallAutomationClient(connectionString: acsConnectionString); + logger.LogInformation("Initialized call automation client."); + return Results.Ok("Configurtion set successfully. Initialized call automation client."); +}).WithTags("1. Add Connection string and configuration settings."); + +app.MapPost("/api/events", async (EventGridEvent[] eventGridEvents, ILogger logger) => +{ + foreach (var eventGridEvent in eventGridEvents) + { + logger.LogInformation($"Recording event received:{eventGridEvent.EventType}"); + if (eventGridEvent.TryGetSystemEventData(out object eventData)) + { + if (eventData is SubscriptionValidationEventData subscriptionValidationEventData) + { + var responseData = new SubscriptionValidationResponse + { + ValidationResponse = subscriptionValidationEventData.ValidationCode + }; + return Results.Ok(responseData); + } + if (eventData is AcsIncomingCallEventData incomingCallEventData) + { + callerId = incomingCallEventData.FromCommunicationIdentifier.RawId; + Console.WriteLine("Caller Id--> " + callerId); + var callbackUri = new Uri(new Uri(callbackUriHost), $"/api/callbacks"); + logger.LogInformation($"Incoming call - correlationId: {incomingCallEventData.CorrelationId}, " + + $"Callback url: {callbackUri}"); + + eventCallbackUri = callbackUri; + + var options = new AnswerCallOptions(incomingCallEventData.IncomingCallContext, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) } + }; + + AnswerCallResult answerCallResult = await client.AnswerCallAsync(options); + var callConnectionMedia = answerCallResult.CallConnection.GetCallMedia(); + + } + if (eventData is AcsRecordingFileStatusUpdatedEventData statusUpdated) + { + recordingLocation = statusUpdated.RecordingStorageInfo.RecordingChunks[0].ContentLocation; + logger.LogInformation($"The recording location is : {recordingLocation}"); + } + } + } + return Results.Ok(); +}); + +app.MapPost("/api/callbacks", (CloudEvent[] cloudEvents, ILogger logger) => +{ + foreach (var cloudEvent in cloudEvents) + { + CallAutomationEventBase parsedEvent = CallAutomationEventParser.Parse(cloudEvent); + logger.LogInformation( + "Received call event: {type}, callConnectionID: {connId}, serverCallId: {serverId}", + parsedEvent.GetType(), + parsedEvent.CallConnectionId, + parsedEvent.ServerCallId); + + if (parsedEvent is CallConnected callConnected) + { + logger.LogInformation($"Received call event: {callConnected.GetType()}"); + callConnectionId = callConnected.CallConnectionId; + CallConnectionProperties callConnectionProperties = GetCallConnectionProperties(); + logger.LogInformation("************************************************************"); + logger.LogInformation($"CORRELATION ID: {callConnectionProperties.CorrelationId}"); + logger.LogInformation("************************************************************"); + } + else if (parsedEvent is ConnectFailed connectFailed) + { + callConnectionId = connectFailed.CallConnectionId; + logger.LogInformation($"Received call event: {connectFailed.GetType()}, CorrelationId: {connectFailed.CorrelationId}, " + + $"subCode: {connectFailed.ResultInformation?.SubCode}, message: {connectFailed.ResultInformation?.Message}, context: {connectFailed.OperationContext}"); + } + else if (parsedEvent is RecognizeCompleted recognizeCompleted) + { + logger.LogInformation($"Received call event: {recognizeCompleted.GetType()}"); + callConnectionId = recognizeCompleted.CallConnectionId; + + switch (recognizeCompleted.RecognizeResult) + { + case DtmfResult dtmfResult: + var tones = dtmfResult.Tones; + logger.LogInformation("Recognize completed succesfully, tones={tones}", tones); + break; + case ChoiceResult choiceResult: + var labelDetected = choiceResult.Label; + var phraseDetected = choiceResult.RecognizedPhrase; + logger.LogInformation("Recognize completed succesfully, labelDetected={labelDetected}, phraseDetected={phraseDetected}", labelDetected, phraseDetected); + break; + case SpeechResult speechResult: + var text = speechResult.Speech; + logger.LogInformation("Recognize completed succesfully, text={text}", text); + break; + default: + logger.LogInformation("Recognize completed succesfully, recognizeResult={recognizeResult}", recognizeCompleted.RecognizeResult); + break; + } + } + else if (parsedEvent is RecognizeFailed recognizeFailed) + { + callConnectionId = recognizeFailed.CallConnectionId; + logger.LogInformation($"Received call event: {recognizeFailed.GetType()}, CorrelationId: {recognizeFailed.CorrelationId}, " + + $"subCode: {recognizeFailed.ResultInformation?.SubCode}, message: {recognizeFailed.ResultInformation?.Message}, context: {recognizeFailed.OperationContext}"); + } + else if (parsedEvent is PlayCompleted playCompleted) + { + logger.LogInformation($"Received call event: {playCompleted.GetType()}"); + callConnectionId = playCompleted.CallConnectionId; + } + else if (parsedEvent is PlayFailed playFailed) + { + callConnectionId = playFailed.CallConnectionId; + logger.LogInformation($"Received call event: {playFailed.GetType()}, CorrelationId: {playFailed.CorrelationId}, " + + $"subCode: {playFailed.ResultInformation?.SubCode}, message: {playFailed.ResultInformation?.Message}, context: {playFailed.OperationContext}"); + } + else if (parsedEvent is PlayCanceled playCanceled) + { + logger.LogInformation($"Received call event: {playCanceled.GetType()}"); + callConnectionId = playCanceled.CallConnectionId; + } + else if (parsedEvent is RecognizeCanceled recognizeCanceled) + { + logger.LogInformation($"Received call event: {recognizeCanceled.GetType()}"); + callConnectionId = recognizeCanceled.CallConnectionId; + } + else if (parsedEvent is AddParticipantSucceeded addParticipantSucceeded) + { + logger.LogInformation($"Received call event: {addParticipantSucceeded.GetType()}"); + callConnectionId = addParticipantSucceeded.CallConnectionId; + } + else if (parsedEvent is AddParticipantFailed addParticipantFailed) + { + callConnectionId = addParticipantFailed.CallConnectionId; + logger.LogInformation($"Received call event: {addParticipantFailed.GetType()}, CorrelationId: {addParticipantFailed.CorrelationId}, " + + $"subCode: {addParticipantFailed.ResultInformation?.SubCode}, message: {addParticipantFailed.ResultInformation?.Message}, context: {addParticipantFailed.OperationContext}"); + } + else if (parsedEvent is RemoveParticipantSucceeded removeParticipantSucceeded) + { + logger.LogInformation($"Received call event: {removeParticipantSucceeded.GetType()}"); + callConnectionId = removeParticipantSucceeded.CallConnectionId; + } + else if (parsedEvent is RemoveParticipantFailed removeParticipantFailed) + { + callConnectionId = removeParticipantFailed.CallConnectionId; + logger.LogInformation($"Received call event: {removeParticipantFailed.GetType()}, CorrelationId: {removeParticipantFailed.CorrelationId}, " + + $"subCode: {removeParticipantFailed.ResultInformation?.SubCode}, message: {removeParticipantFailed.ResultInformation?.Message}, context: {removeParticipantFailed.OperationContext}"); + } + else if (parsedEvent is CancelAddParticipantSucceeded cancelAddParticipantSucceeded) + { + logger.LogInformation($"Received call event: {cancelAddParticipantSucceeded.GetType()}"); + callConnectionId = cancelAddParticipantSucceeded.CallConnectionId; + } + else if (parsedEvent is CancelAddParticipantFailed cancelAddParticipantFailed) + { + callConnectionId = cancelAddParticipantFailed.CallConnectionId; + logger.LogInformation($"Received call event: {cancelAddParticipantFailed.GetType()}, CorrelationId: {cancelAddParticipantFailed.CorrelationId}, " + + $"subCode: {cancelAddParticipantFailed.ResultInformation?.SubCode}, message: {cancelAddParticipantFailed.ResultInformation?.Message}, context: {cancelAddParticipantFailed.OperationContext}"); + } + else if (parsedEvent is SendDtmfTonesCompleted sendDtmfTonesCompleted) + { + logger.LogInformation($"Received call event: {sendDtmfTonesCompleted.GetType()}"); + callConnectionId = sendDtmfTonesCompleted.CallConnectionId; + } + else if (parsedEvent is SendDtmfTonesFailed sendDtmfTonesFailed) + { + callConnectionId = sendDtmfTonesFailed.CallConnectionId; + logger.LogInformation($"Received call event: {sendDtmfTonesFailed.GetType()}, CorrelationId: {sendDtmfTonesFailed.CorrelationId}, " + + $"subCode: {sendDtmfTonesFailed.ResultInformation?.SubCode}, message: {sendDtmfTonesFailed.ResultInformation?.Message}, context: {sendDtmfTonesFailed.OperationContext}"); + } + else if (parsedEvent is ContinuousDtmfRecognitionToneReceived continuousDtmfRecognitionToneReceived) + { + logger.LogInformation($"Received call event: {continuousDtmfRecognitionToneReceived.GetType()}"); + callConnectionId = continuousDtmfRecognitionToneReceived.CallConnectionId; + logger.LogInformation("Tone?detected:?sequenceId={sequenceId},?tone={tone}", + continuousDtmfRecognitionToneReceived.SequenceId, + continuousDtmfRecognitionToneReceived.Tone); + } + else if (parsedEvent is ContinuousDtmfRecognitionStopped continuousDtmfRecognitionStopped) + { + logger.LogInformation($"Received call event: {continuousDtmfRecognitionStopped.GetType()}"); + callConnectionId = continuousDtmfRecognitionStopped.CallConnectionId; + } + else if (parsedEvent is ContinuousDtmfRecognitionToneFailed continuousDtmfRecognitionToneFailed) + { + callConnectionId = continuousDtmfRecognitionToneFailed.CallConnectionId; + logger.LogInformation($"Received call event: {continuousDtmfRecognitionToneFailed.GetType()}, CorrelationId: {continuousDtmfRecognitionToneFailed.CorrelationId}, " + + $"subCode: {continuousDtmfRecognitionToneFailed.ResultInformation?.SubCode}, message: {continuousDtmfRecognitionToneFailed.ResultInformation?.Message}, context: {continuousDtmfRecognitionToneFailed.OperationContext}"); + } + else if (parsedEvent is HoldAudioStarted holdAudioStarted) + { + logger.LogInformation($"Received call event: {holdAudioStarted.GetType()}"); + callConnectionId = holdAudioStarted.CallConnectionId; + } + else if (parsedEvent is HoldAudioPaused holdAudioPaused) + { + logger.LogInformation($"Received call event: {holdAudioPaused.GetType()}"); + callConnectionId = holdAudioPaused.CallConnectionId; + } + else if (parsedEvent is HoldAudioResumed holdAudioResumed) + { + logger.LogInformation($"Received call event: {holdAudioResumed.GetType()}"); + callConnectionId = holdAudioResumed.CallConnectionId; + } + else if (parsedEvent is HoldAudioCompleted holdAudioCompleted) + { + logger.LogInformation($"Received call event: {holdAudioCompleted.GetType()}"); + callConnectionId = holdAudioCompleted.CallConnectionId; + } + else if (parsedEvent is HoldFailed holdFailed) + { + callConnectionId = holdFailed.CallConnectionId; + logger.LogInformation($"Received call event: {holdFailed.GetType()}, CorrelationId: {holdFailed.CorrelationId}, " + + $"subCode: {holdFailed.ResultInformation?.SubCode}, message: {holdFailed.ResultInformation?.Message}, context: {holdFailed.OperationContext}"); + } + else if (parsedEvent is TranscriptionStarted transcriptionStarted) + { + logger.LogInformation($"Received call event: {transcriptionStarted.GetType()}"); + logger.LogInformation($"Operation context: {transcriptionStarted.OperationContext}"); + callConnectionId = transcriptionStarted.CallConnectionId; + } + else if (parsedEvent is TranscriptionStopped transcriptionStopped) + { + logger.LogInformation($"Received call event: {transcriptionStopped.GetType()}"); + logger.LogInformation($"Operation context: {transcriptionStopped.OperationContext}"); + callConnectionId = transcriptionStopped.CallConnectionId; + } + else if (parsedEvent is TranscriptionUpdated transcriptionUpdated) + { + logger.LogInformation($"Received call event: {transcriptionUpdated.GetType()}"); + logger.LogInformation($"Operation context: {transcriptionUpdated.OperationContext}"); + callConnectionId = transcriptionUpdated.CallConnectionId; + } + else if (parsedEvent is TranscriptionFailed transcriptionFailed) + { + callConnectionId = transcriptionFailed.CallConnectionId; + logger.LogInformation($"Received call event: {transcriptionFailed.GetType()}, CorrelationId: {transcriptionFailed.CorrelationId}, " + + $"subCode: {transcriptionFailed.ResultInformation?.SubCode}, message: {transcriptionFailed.ResultInformation?.Message}, context: {transcriptionFailed.OperationContext}"); + } + else if (parsedEvent is MediaStreamingStarted mediaStreamingStarted) + { + logger.LogInformation($"Received call event: {mediaStreamingStarted.GetType()}"); + logger.LogInformation($"Operation context: {mediaStreamingStarted.OperationContext}"); + callConnectionId = mediaStreamingStarted.CallConnectionId; + } + else if (parsedEvent is MediaStreamingStopped mediaStreamingStopped) + { + logger.LogInformation($"Received call event: {mediaStreamingStopped.GetType()}"); + logger.LogInformation($"Operation context: {mediaStreamingStopped.OperationContext}"); + callConnectionId = mediaStreamingStopped.CallConnectionId; + } + else if (parsedEvent is MediaStreamingFailed mediaStreamingFailed) + { + callConnectionId = mediaStreamingFailed.CallConnectionId; + logger.LogInformation($"Received call event: {mediaStreamingFailed.GetType()}, CorrelationId: {mediaStreamingFailed.CorrelationId}, " + + $"subCode: {mediaStreamingFailed.ResultInformation?.SubCode}, message: {mediaStreamingFailed.ResultInformation?.Message}, context: {mediaStreamingFailed.OperationContext}"); + } + else if (parsedEvent is CallDisconnected callDisconnected) + { + logger.LogInformation($"Received call event: {callDisconnected.GetType()}"); + } + else if (parsedEvent is CreateCallFailed createCallFailed) + { + callConnectionId = createCallFailed.CallConnectionId; + logger.LogInformation($"Received call event: {createCallFailed.GetType()}, CorrelationId: {createCallFailed.CorrelationId}, " + + $"subCode: {createCallFailed.ResultInformation?.SubCode}, message: {createCallFailed.ResultInformation?.Message}, context: {createCallFailed.OperationContext}"); + } + else if (parsedEvent is CallTransferAccepted callTransferAccepted) + { + logger.LogInformation($"Received call event: {callTransferAccepted.GetType()}"); + callConnectionId = callTransferAccepted.CallConnectionId; + } + else if (parsedEvent is CallTransferFailed callTransferFailed) + { + callConnectionId = callTransferFailed.CallConnectionId; + logger.LogInformation($"Received call event: {callTransferFailed.GetType()}, CorrelationId: {callTransferFailed.CorrelationId}, " + + $"subCode: {callTransferFailed.ResultInformation?.SubCode}, message: {callTransferFailed.ResultInformation?.Message}, context: {callTransferFailed.OperationContext}"); + } + else if (parsedEvent is RecordingStateChanged recordingStateChanged) + { + logger.LogInformation($"Received call event: {recordingStateChanged.GetType()}"); + logger.LogInformation($"Recording State: {recordingStateChanged.State}"); + } + else if (parsedEvent is DialogStarted { OperationContext: "DialogStart" } dialogStarted) + { + logger.LogInformation($"Dialog started. DialogId: {dialogStarted.DialogId}, CallConnectionId: {dialogStarted.CallConnectionId}, CorrelationId: {dialogStarted.CorrelationId}"); + // Verify the start of dialog here + } + else if (parsedEvent is DialogFailed { OperationContext: "DialogStart" } dialogFailed) + { + logger.LogWarning($"Dialog failed to start. DialogId: {dialogFailed.DialogId}, Error: {dialogFailed.ResultInformation?.Message}, CorrelationId: {dialogFailed.CorrelationId}"); + } + else if (parsedEvent is DialogTransfer dialogTransfer) + { + logger.LogInformation($"Dialog transfer requested. DialogId: {dialogTransfer.DialogId}, TransferTarget: {dialogTransfer.TransferDestination}"); + var callDialog = GetConnection().GetCallDialog(); + callDialog.StopDialogAsync(dialogTransfer.DialogId); + GetConnection().TransferCallToParticipantAsync(new PhoneNumberIdentifier(dialogTransfer.TransferDestination)); + } + else if (parsedEvent is DialogHangup dialogHangup) + { + logger.LogInformation($"Dialog hangup requested. DialogId: {dialogHangup.DialogId}"); + var callDialog = GetConnection().GetCallDialog(); + callDialog.StopDialogAsync(dialogHangup.DialogId); + GetConnection().HangUpAsync(true); // Hang up the call for everyone + } + else if (parsedEvent is DialogConsent { OperationContext: "DialogStart" } dialogConsent) + { + logger.LogInformation($"Dialog consent event received. DialogId: {dialogConsent.DialogId}, ConsentType: {dialogConsent}"); + } + else if (parsedEvent is DialogCompleted { OperationContext: "DialogStop" } dialogCompleted) + { + logger.LogInformation($"Dialog completed. DialogId: {dialogCompleted.DialogId}, Result: {dialogCompleted.ResultInformation?.Message}"); + } + + } + return Results.Ok(); +}).Produces(StatusCodes.Status200OK); + +#region Outbound Call + +app.MapPost("/outboundCallToPstnAsync", async (string targetPhoneNumber, ILogger logger) => +{ + PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); + PhoneNumberIdentifier caller = new PhoneNumberIdentifier(acsPhoneNumber); + + + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(target, caller); + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + + }; + + CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); + + logger.LogInformation($"Created async pstn call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Create Outbound Call APIs"); + +app.MapPost("/outboundCallToPstn", (string targetPhoneNumber, ILogger logger) => +{ + PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); + PhoneNumberIdentifier caller = new PhoneNumberIdentifier(acsPhoneNumber); + + + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(target, caller); + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + + }; + + CreateCallResult createCallResult = client.CreateCall(createCallOptions); + + logger.LogInformation($"Created call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Create Outbound Call APIs"); + +app.MapPost("/outboundCallToAcsAsync", async (string acsTarget, ILogger logger) => +{ + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(new CommunicationUserIdentifier(acsTarget)); + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + + }; + + CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); + + logger.LogInformation($"Created async acs call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Create Outbound Call APIs"); + +app.MapPost("/outboundCallToAcs", (string acsTarget, ILogger logger) => +{ + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(new CommunicationUserIdentifier(acsTarget)); + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + + }; + + CreateCallResult createCallResult = client.CreateCall(createCallOptions); + + logger.LogInformation($"Created acs call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Create Outbound Call APIs"); + +app.MapPost("/outboundCallToTeamsAsync", async (string teamsObjectId, ILogger logger) => +{ + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(new MicrosoftTeamsUserIdentifier(teamsObjectId)); + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + + }; + + CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); + + logger.LogInformation($"Created async teams call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Create Outbound Call APIs"); + +app.MapPost("/outboundCallToTeams", (string teamsObjectId, ILogger logger) => +{ + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(new MicrosoftTeamsUserIdentifier(teamsObjectId)); + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + + }; + + CreateCallResult createCallResult = client.CreateCall(createCallOptions); + + logger.LogInformation($"Created teams call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Create Outbound Call APIs"); + +#endregion + +#region Group Call + +app.MapPost("/createGroupCallAsync", async (string targetPhoneNumber, ILogger logger) => +{ + PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); + PhoneNumberIdentifier sourceCallerId = new PhoneNumberIdentifier(acsPhoneNumber); + + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, false); + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", false, TranscriptionTransport.Websocket); + + IEnumerable targets = new List() + { + target + }; + + var createGroupCallOptions = new CreateGroupCallOptions(targets, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + SourceCallerIdNumber = sourceCallerId, + MediaStreamingOptions = mediaStreamingOptions, + TranscriptionOptions = transcriptionOptions + }; + + CreateCallResult createCallResult = await client.CreateGroupCallAsync(createGroupCallOptions); + + logger.LogInformation($"Created async group call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Create Group Call APIs"); + +app.MapPost("/createGroupCall", (string targetPhoneNumber, ILogger logger) => +{ + PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); + PhoneNumberIdentifier sourceCallerId = new PhoneNumberIdentifier(acsPhoneNumber); + + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, false); + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", false, TranscriptionTransport.Websocket); + + IEnumerable targets = new List() + { + target + }; + + var createGroupCallOptions = new CreateGroupCallOptions(targets, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + SourceCallerIdNumber = sourceCallerId, + MediaStreamingOptions = mediaStreamingOptions, + TranscriptionOptions = transcriptionOptions + }; + + CreateCallResult createCallResult = client.CreateGroupCall(createGroupCallOptions); + + logger.LogInformation($"Created group call with id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Create Group Call APIs"); + +#endregion + +#region Connect Api + +app.MapPost("/ConnectRoomCallAsync", async (string roomId, ILogger logger) => +{ + RoomCallLocator roomCallLocator = !string.IsNullOrEmpty(roomId) ? new RoomCallLocator(roomId) : throw new ArgumentNullException(nameof(roomId)); + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, false); + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", false, TranscriptionTransport.Websocket); + ConnectCallOptions connectCallOptions = new ConnectCallOptions(roomCallLocator, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + OperationContext = "ConnectRoomCallContext", + MediaStreamingOptions = mediaStreamingOptions, + TranscriptionOptions = transcriptionOptions + }; + ConnectCallResult connectCallResult = await client.ConnectCallAsync(connectCallOptions); + logger.LogInformation($"Connected room async call with connection id: {connectCallResult.CallConnectionProperties.CallConnectionId}"); + return Results.Ok(); +}).WithTags("Connect Call APIs"); + +app.MapPost("/ConnectRoomCall", (string roomId, ILogger logger) => +{ + RoomCallLocator roomCallLocator = !string.IsNullOrEmpty(roomId) ? new RoomCallLocator(roomId) : throw new ArgumentNullException(nameof(roomId)); + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, false); + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", false, TranscriptionTransport.Websocket); + + ConnectCallOptions connectCallOptions = new ConnectCallOptions(roomCallLocator, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + OperationContext = "ConnectRoomCallContext", + MediaStreamingOptions = mediaStreamingOptions, + TranscriptionOptions = transcriptionOptions + }; + ConnectCallResult connectCallResult = client.ConnectCall(connectCallOptions); + logger.LogInformation($"Connected room call with connection id: {connectCallResult.CallConnectionProperties.CallConnectionId}"); + return Results.Ok(); +}).WithTags("Connect Call APIs"); + +app.MapPost("/ConnectGroupCallAsync", async (string groupId, ILogger logger) => +{ + GroupCallLocator groupCallLocator = !string.IsNullOrEmpty(groupId) ? new GroupCallLocator(groupId) : throw new ArgumentNullException(nameof(groupId)); + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, false); + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", false, TranscriptionTransport.Websocket); + + ConnectCallOptions connectCallOptions = new ConnectCallOptions(groupCallLocator, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + OperationContext = "ConnectRoomCallContext", + MediaStreamingOptions = mediaStreamingOptions, + TranscriptionOptions = transcriptionOptions + }; + ConnectCallResult connectCallResult = await client.ConnectCallAsync(connectCallOptions); + logger.LogInformation($"Connected group async call with connection id: {connectCallResult.CallConnectionProperties.CallConnectionId}"); + return Results.Ok(); +}).WithTags("Connect Call APIs"); + +app.MapPost("/ConnectGroupCall", (string groupId, ILogger logger) => +{ + GroupCallLocator groupCallLocator = !string.IsNullOrEmpty(groupId) ? new GroupCallLocator(groupId) : throw new ArgumentNullException(nameof(groupId)); + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, false); + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", false, TranscriptionTransport.Websocket); + + ConnectCallOptions connectCallOptions = new ConnectCallOptions(groupCallLocator, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + OperationContext = "ConnectGroupCallContext", + MediaStreamingOptions = mediaStreamingOptions, + TranscriptionOptions = transcriptionOptions + }; + ConnectCallResult connectCallResult = client.ConnectCall(connectCallOptions); + logger.LogInformation($"Connected group call with connection id: {connectCallResult.CallConnectionProperties.CallConnectionId}"); + return Results.Ok(); +}).WithTags("Connect Call APIs"); + +app.MapPost("/ConnectOneToNCallAsync", async (string serverCallId, ILogger logger) => +{ + ServerCallLocator serverCallLocator = !string.IsNullOrEmpty(serverCallId) ? new ServerCallLocator(serverCallId) : throw new ArgumentNullException(nameof(serverCallId)); + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, false); + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", false, TranscriptionTransport.Websocket); + + ConnectCallOptions connectCallOptions = new ConnectCallOptions(serverCallLocator, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + OperationContext = "ConnectOneToNCallContext", + MediaStreamingOptions = mediaStreamingOptions, + TranscriptionOptions = transcriptionOptions + }; + ConnectCallResult connectCallResult = await client.ConnectCallAsync(connectCallOptions); + logger.LogInformation($"Connected 1 to N async call with connection id: {connectCallResult.CallConnectionProperties.CallConnectionId}"); + return Results.Ok(); +}).WithTags("Connect Call APIs"); + +app.MapPost("/ConnectOneToNCall", (string serverCallId, ILogger logger) => +{ + ServerCallLocator serverCallLocator = !string.IsNullOrEmpty(serverCallId) ? new ServerCallLocator(serverCallId) : throw new ArgumentNullException(nameof(serverCallId)); + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, false); + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", false, TranscriptionTransport.Websocket); + ConnectCallOptions connectCallOptions = new ConnectCallOptions(serverCallLocator, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + OperationContext = "ConnectOneToNCallContext", + MediaStreamingOptions = mediaStreamingOptions, + TranscriptionOptions = transcriptionOptions + }; + ConnectCallResult connectCallResult = client.ConnectCall(connectCallOptions); + logger.LogInformation($"Connected 1 to N call with connection id: {connectCallResult.CallConnectionProperties.CallConnectionId}"); + return Results.Ok(); +}).WithTags("Connect Call APIs"); + +#endregion + +#region Add Remove Participant + +app.MapPost("/addPstnParticipantAsync", async (string pstnParticipant, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + CallInvite callInvite = new CallInvite(new PhoneNumberIdentifier(pstnParticipant), + new PhoneNumberIdentifier(acsPhoneNumber)); + var addParticipantOptions = new AddParticipantOptions(callInvite) + { + OperationContext = "addPstnUserContext", + InvitationTimeoutInSeconds = 30, + }; + + var result = await callConnection.AddParticipantAsync(addParticipantOptions); + return Results.Ok(result); +}).WithTags("Add/Remove Participant APIs"); + +app.MapPost("/addPstnParticipant", (string pstnParticipant, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + CallInvite callInvite = new CallInvite(new PhoneNumberIdentifier(pstnParticipant), + new PhoneNumberIdentifier(acsPhoneNumber)); + var addParticipantOptions = new AddParticipantOptions(callInvite) + { + OperationContext = "addPstnUserContext", + InvitationTimeoutInSeconds = 30, + }; + + var result = callConnection.AddParticipant(addParticipantOptions); + return Results.Ok(result); +}).WithTags("Add/Remove Participant APIs"); + +app.MapPost("/addAcsParticipantAsync", async (string acsParticipant, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + CallInvite callInvite = new CallInvite(new CommunicationUserIdentifier(acsParticipant)); + var addParticipantOptions = new AddParticipantOptions(callInvite) + { + OperationContext = "addAcsUserContext", + InvitationTimeoutInSeconds = 30, + }; + + var result = await callConnection.AddParticipantAsync(addParticipantOptions); + return Results.Ok(result); +}).WithTags("Add/Remove Participant APIs"); + +app.MapPost("/addAcsParticipant", (string acsParticipant, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + CallInvite callInvite = new CallInvite(new CommunicationUserIdentifier(acsParticipant)); + var addParticipantOptions = new AddParticipantOptions(callInvite) + { + OperationContext = "addPstnUserContext", + InvitationTimeoutInSeconds = 30, + }; + + var result = callConnection.AddParticipant(addParticipantOptions); + return Results.Ok(result); +}).WithTags("Add/Remove Participant APIs"); + +app.MapPost("/addTeamsParticipantAsync", async (string teamsObjectId, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + CallInvite callInvite = new CallInvite(new MicrosoftTeamsUserIdentifier(teamsObjectId)); + var addParticipantOptions = new AddParticipantOptions(callInvite) + { + OperationContext = "addTeamsUserContext", + InvitationTimeoutInSeconds = 30, + }; + + var result = await callConnection.AddParticipantAsync(addParticipantOptions); + return Results.Ok(result); +}).WithTags("Add/Remove Participant APIs"); + +app.MapPost("/addTeamsParticipant", (string teamsObjectId, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + CallInvite callInvite = new CallInvite(new MicrosoftTeamsUserIdentifier(teamsObjectId)); + var addParticipantOptions = new AddParticipantOptions(callInvite) + { + OperationContext = "addTeamsUserContext", + InvitationTimeoutInSeconds = 30, + }; + + var result = callConnection.AddParticipant(addParticipantOptions); + return Results.Ok(result); +}).WithTags("Add/Remove Participant APIs"); + +app.MapPost("/removePstnParticipantAsync", async (string pstnTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + RemoveParticipantOptions removeParticipantOptions = new RemoveParticipantOptions(new PhoneNumberIdentifier(pstnTarget)) + { + OperationContext = "removePstnParticipantContext" + }; + + await callConnection.RemoveParticipantAsync(removeParticipantOptions); + return Results.Ok(); +}).WithTags("Add/Remove Participant APIs"); + +app.MapPost("/removePstnParticipant", (string pstnTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + RemoveParticipantOptions removeParticipantOptions = new RemoveParticipantOptions(new PhoneNumberIdentifier(pstnTarget)) + { + OperationContext = "removePstnParticipantContext" + }; + + callConnection.RemoveParticipant(removeParticipantOptions); + return Results.Ok(); +}).WithTags("Add/Remove Participant APIs"); + +app.MapPost("/removeAcsParticipantAsync", async (string acsTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + RemoveParticipantOptions removeParticipantOptions = new RemoveParticipantOptions(new CommunicationUserIdentifier(acsTarget)) + { + OperationContext = "removeAcsParticipantContext" + }; + + await callConnection.RemoveParticipantAsync(removeParticipantOptions); + return Results.Ok(); +}).WithTags("Add/Remove Participant APIs"); + +app.MapPost("/removeAcsParticipant", (string acsTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + RemoveParticipantOptions removeParticipantOptions = new RemoveParticipantOptions(new CommunicationUserIdentifier(acsTarget)) + { + OperationContext = "removeAcsParticipantContext" + }; + + callConnection.RemoveParticipant(removeParticipantOptions); + return Results.Ok(); +}).WithTags("Add/Remove Participant APIs"); + +app.MapPost("/removeTeamsParticipantAsync", async (string teamsObjectId, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + RemoveParticipantOptions removeParticipantOptions = new RemoveParticipantOptions(new MicrosoftTeamsUserIdentifier(teamsObjectId)) + { + OperationContext = "removeTeamsParticipantContext" + }; + + await callConnection.RemoveParticipantAsync(removeParticipantOptions); + return Results.Ok(); +}).WithTags("Add/Remove Participant APIs"); + +app.MapPost("/removeTeamsParticipant", (string teamsObjectId, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + RemoveParticipantOptions removeParticipantOptions = new RemoveParticipantOptions(new MicrosoftTeamsUserIdentifier(teamsObjectId)) + { + OperationContext = "removeTeamsParticipantContext" + }; + + callConnection.RemoveParticipantAsync(removeParticipantOptions); + return Results.Ok(); +}).WithTags("Add/Remove Participant APIs"); + +app.MapPost("/cancelAddParticipantAsync", async (string invitationId, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + CancelAddParticipantOperationOptions cancelAddParticipantOperationOptions = new CancelAddParticipantOperationOptions(invitationId) + { + OperationContext = "CancelAddingParticipantContext" + }; + var result = await callConnection.CancelAddParticipantOperationAsync(cancelAddParticipantOperationOptions); + + return Results.Ok(result); +}).WithTags("Add/Remove Participant APIs"); + +app.MapPost("/cancelAddParticipant", (string invitationId, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + CancelAddParticipantOperationOptions cancelAddParticipantOperationOptions = new CancelAddParticipantOperationOptions(invitationId) + { + OperationContext = "CancelAddingParticipantContext" + }; + var result = callConnection.CancelAddParticipantOperationAsync(cancelAddParticipantOperationOptions); + return Results.Ok(result); +}).WithTags("Add/Remove Participant APIs"); + +#endregion + +# region Play Media with text Source + +app.MapPost("/playTextSourceToPstnTargetAsync", async (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + + TextSource textSource = new TextSource("Hi, this is test source played through play source thanks. Goodbye!.") + { + VoiceName = "en-US-NancyNeural" + }; + + List playTo = new List { new PhoneNumberIdentifier(pstnTarget) }; + PlayOptions playToOptions = new PlayOptions(textSource, playTo) + { + OperationContext = "playToContext" + }; + + await callMedia.PlayAsync(playToOptions); + + return Results.Ok(); +}).WithTags("Play TextSource Media APIs"); + +app.MapPost("/playTextSourceToPstnTarget", (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + + TextSource textSource = new TextSource("Hi, this is test source played through play source thanks. Goodbye!.") + { + VoiceName = "en-US-NancyNeural" + }; + + List playTo = new List { new PhoneNumberIdentifier(pstnTarget) }; + PlayOptions playToOptions = new PlayOptions(textSource, playTo) + { + OperationContext = "playToContext" + }; + + callMedia.Play(playToOptions); + + return Results.Ok(); +}).WithTags("Play TextSource Media APIs"); + +app.MapPost("/playTextSourceAcsTargetAsync", async (string acsTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + + TextSource textSource = new TextSource("Hi, this is test source played through play source thanks. Goodbye!.") + { + VoiceName = "en-US-NancyNeural" + }; + + List playTo = new List { new CommunicationUserIdentifier(acsTarget) }; + PlayOptions playToOptions = new PlayOptions(textSource, playTo) + { + OperationContext = "playToContext" + }; + + await callMedia.PlayAsync(playToOptions); + + return Results.Ok(); +}).WithTags("Play TextSource Media APIs"); + +app.MapPost("/playTextSourceToAcsTarget", (string acsTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + + TextSource textSource = new TextSource("Hi, this is test source played through play source thanks. Goodbye!.") + { + VoiceName = "en-US-NancyNeural" + }; + + List playTo = new List { new CommunicationUserIdentifier(acsTarget) }; + PlayOptions playToOptions = new PlayOptions(textSource, playTo) + { + OperationContext = "playToContext" + }; + + callMedia.Play(playToOptions); + + return Results.Ok(); +}).WithTags("Play TextSource Media APIs"); + +app.MapPost("/playTextSourceToTeamsTargetAsync", async (string teamsObjectId, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + + TextSource textSource = new TextSource("Hi, this is test source played through play source thanks. Goodbye!.") + { + VoiceName = "en-US-NancyNeural" + }; + + List playTo = new List { new MicrosoftTeamsUserIdentifier(teamsObjectId) }; + PlayOptions playToOptions = new PlayOptions(textSource, playTo) + { + OperationContext = "playToContext" + }; + + await callMedia.PlayAsync(playToOptions); + + return Results.Ok(); +}).WithTags("Play TextSource Media APIs"); + +app.MapPost("/playTextSourceToTeamsTarget", (string teamsObjectId, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + + TextSource textSource = new TextSource("Hi, this is test source played through play source thanks. Goodbye!.") + { + VoiceName = "en-US-NancyNeural" + }; + + List playTo = new List { new MicrosoftTeamsUserIdentifier(teamsObjectId) }; + PlayOptions playToOptions = new PlayOptions(textSource, playTo) + { + OperationContext = "playToContext" + }; + + callMedia.Play(playToOptions); + + return Results.Ok(); +}).WithTags("Play TextSource Media APIs"); + +app.MapPost("/playTextSourceToAllAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + + TextSource textSource = new TextSource("Hi, this is test source played through play source thanks. Goodbye!.") + { + VoiceName = "en-US-NancyNeural" + }; + + PlayToAllOptions playToAllOptions = new PlayToAllOptions(textSource) + { + OperationContext = "playToAllContext" + }; + await callMedia.PlayToAllAsync(playToAllOptions); + + return Results.Ok(); +}).WithTags("Play TextSource Media APIs"); + +app.MapPost("/playTextSourceToAll", (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + + TextSource textSource = new TextSource("Hi, this is test source played through play source thanks. Goodbye!.") + { + VoiceName = "en-US-NancyNeural" + }; + + PlayToAllOptions playToAllOptions = new PlayToAllOptions(textSource) + { + OperationContext = "playToAllContext" + }; + callMedia.PlayToAll(playToAllOptions); + + return Results.Ok(); +}).WithTags("Play TextSource Media APIs"); + +app.MapPost("/playTextSourceBargeInAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + + TextSource textSource = new TextSource("Hi, this is barge in test played through play source thanks. Goodbye!.") + { + VoiceName = "en-US-NancyNeural" + }; + + PlayToAllOptions playToAllOptions = new PlayToAllOptions(textSource) + { + OperationContext = "playToAllContext", + InterruptCallMediaOperation = true + }; + await callMedia.PlayToAllAsync(playToAllOptions); + + return Results.Ok(); +}).WithTags("Play TextSource Media APIs"); + +#endregion + +# region Play Media with Ssml Source + +app.MapPost("/playSsmlSourceToPstnTargetAsync", async (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + + SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); + + List playTo = new List { new PhoneNumberIdentifier(pstnTarget) }; + PlayOptions playToOptions = new PlayOptions(ssmlSource, playTo) + { + OperationContext = "playToContext" + }; + + await callMedia.PlayAsync(playToOptions); + + return Results.Ok(); +}).WithTags("Play SsmlSource Media APIs"); + +app.MapPost("/playSsmlSourceToPstnTarget", (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); + List playTo = new List { new PhoneNumberIdentifier(pstnTarget) }; + PlayOptions playToOptions = new PlayOptions(ssmlSource, playTo) + { + OperationContext = "playToContext" + }; + + callMedia.Play(playToOptions); + + return Results.Ok(); +}).WithTags("Play SsmlSource Media APIs"); + +app.MapPost("/playSsmlSourceAcsTargetAsync", async (string acsTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); + List playTo = new List { new CommunicationUserIdentifier(acsTarget) }; + PlayOptions playToOptions = new PlayOptions(ssmlSource, playTo) + { + OperationContext = "playToContext" + }; + + await callMedia.PlayAsync(playToOptions); + + return Results.Ok(); +}).WithTags("Play SsmlSource Media APIs"); + +app.MapPost("/playSsmlSourceToAcsTarget", (string acsTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); + + List playTo = new List { new CommunicationUserIdentifier(acsTarget) }; + PlayOptions playToOptions = new PlayOptions(ssmlSource, playTo) + { + OperationContext = "playToContext" + }; + + callMedia.Play(playToOptions); + + return Results.Ok(); +}).WithTags("Play SsmlSource Media APIs"); + +app.MapPost("/playSsmlSourceToTeamsTargetAsync", async (string teamsObjectId, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); + List playTo = new List { new MicrosoftTeamsUserIdentifier(teamsObjectId) }; + PlayOptions playToOptions = new PlayOptions(ssmlSource, playTo) + { + OperationContext = "playToContext" + }; + + await callMedia.PlayAsync(playToOptions); + + return Results.Ok(); +}).WithTags("Play SsmlSource Media APIs"); + +app.MapPost("/playSsmlSourceToTeamsTarget", (string teamsObjectId, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); + List playTo = new List { new MicrosoftTeamsUserIdentifier(teamsObjectId) }; + PlayOptions playToOptions = new PlayOptions(ssmlSource, playTo) + { + OperationContext = "playToContext" + }; + + callMedia.Play(playToOptions); + + return Results.Ok(); +}).WithTags("Play SsmlSource Media APIs"); + +app.MapPost("/playSsmlSourceToAllAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); + PlayToAllOptions playToAllOptions = new PlayToAllOptions(ssmlSource) + { + OperationContext = "playToAllContext" + }; + await callMedia.PlayToAllAsync(playToAllOptions); + + return Results.Ok(); +}).WithTags("Play SsmlSource Media APIs"); + +app.MapPost("/playSsmlSourceToAll", (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); + + PlayToAllOptions playToAllOptions = new PlayToAllOptions(ssmlSource) + { + OperationContext = "playToAllContext" + }; + callMedia.PlayToAll(playToAllOptions); + + return Results.Ok(); +}).WithTags("Play SsmlSource Media APIs"); + +app.MapPost("/playSsmlSourceBargeInAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml barge in test played through ssml source thanks. Goodbye!"); + PlayToAllOptions playToAllOptions = new PlayToAllOptions(ssmlSource) + { + OperationContext = "playBargeInContext", + InterruptCallMediaOperation = true + }; + await callMedia.PlayToAllAsync(playToAllOptions); + + return Results.Ok(); +}).WithTags("Play SsmlSource Media APIs"); + +#endregion + +# region Play Media with File Source + +app.MapPost("/playFileSourceToPstnTargetAsync", async (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + FileSource fileSource = new FileSource(new Uri(fileSourceUri)); + List playTo = new List { new PhoneNumberIdentifier(pstnTarget) }; + PlayOptions playToOptions = new PlayOptions(fileSource, playTo) + { + OperationContext = "playToContext" + }; + + await callMedia.PlayAsync(playToOptions); + + return Results.Ok(); +}).WithTags("Play FileSource Media APIs"); + +app.MapPost("/playFileSourceToPstnTarget", (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + FileSource fileSource = new FileSource(new Uri(fileSourceUri)); + List playTo = new List { new PhoneNumberIdentifier(pstnTarget) }; + PlayOptions playToOptions = new PlayOptions(fileSource, playTo) + { + OperationContext = "playToContext" + }; + + callMedia.Play(playToOptions); + + return Results.Ok(); +}).WithTags("Play FileSource Media APIs"); + +app.MapPost("/playFileSourceAcsTargetAsync", async (string acsTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + FileSource fileSource = new FileSource(new Uri(fileSourceUri)); + List playTo = new List { new CommunicationUserIdentifier(acsTarget) }; + PlayOptions playToOptions = new PlayOptions(fileSource, playTo) + { + OperationContext = "playToContext" + }; + + await callMedia.PlayAsync(playToOptions); + + return Results.Ok(); +}).WithTags("Play FileSource Media APIs"); + +app.MapPost("/playFileSourceToAcsTarget", (string acsTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + FileSource fileSource = new FileSource(new Uri(fileSourceUri)); + + List playTo = new List { new CommunicationUserIdentifier(acsTarget) }; + PlayOptions playToOptions = new PlayOptions(fileSource, playTo) + { + OperationContext = "playToContext" + }; + + callMedia.Play(playToOptions); + + return Results.Ok(); +}).WithTags("Play FileSource Media APIs"); + +app.MapPost("/playFileSourceToTeamsTargetAsync", async (string teamsObjectId, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + FileSource fileSource = new FileSource(new Uri(fileSourceUri)); + List playTo = new List { new MicrosoftTeamsUserIdentifier(teamsObjectId) }; + PlayOptions playToOptions = new PlayOptions(fileSource, playTo) + { + OperationContext = "playToContext" + }; + + await callMedia.PlayAsync(playToOptions); + + return Results.Ok(); +}).WithTags("Play FileSource Media APIs"); + +app.MapPost("/playFileSourceToTeamsTarget", (string teamsObjectId, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + FileSource fileSource = new FileSource(new Uri(fileSourceUri)); + List playTo = new List { new MicrosoftTeamsUserIdentifier(teamsObjectId) }; + PlayOptions playToOptions = new PlayOptions(fileSource, playTo) + { + OperationContext = "playToContext" + }; + + callMedia.Play(playToOptions); + + return Results.Ok(); +}).WithTags("Play FileSource Media APIs"); + +app.MapPost("/playFileSourceToAllAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + FileSource fileSource = new FileSource(new Uri(fileSourceUri)); + PlayToAllOptions playToAllOptions = new PlayToAllOptions(fileSource) + { + OperationContext = "playToAllContext" + }; + await callMedia.PlayToAllAsync(playToAllOptions); + + return Results.Ok(); +}).WithTags("Play FileSource Media APIs"); + +app.MapPost("/playFileSourceToAll", (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + FileSource fileSource = new FileSource(new Uri(fileSourceUri)); + + PlayToAllOptions playToAllOptions = new PlayToAllOptions(fileSource) + { + OperationContext = "playToAllContext" + }; + callMedia.PlayToAll(playToAllOptions); + + return Results.Ok(); +}).WithTags("Play FileSource Media APIs"); + +app.MapPost("/playFileSourceBargeInAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + FileSource fileSource = new FileSource(new Uri(fileSourceUri)); + PlayToAllOptions playToAllOptions = new PlayToAllOptions(fileSource) + { + OperationContext = "playBargeInContext", + InterruptCallMediaOperation = true + }; + await callMedia.PlayToAllAsync(playToAllOptions); + + return Results.Ok(); +}).WithTags("Play FileSource Media APIs"); + +#endregion + +#region Recognization + +app.MapPost("/recognizeDTMFAsync", async (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + TextSource textSource = new TextSource("Hi, this is recognize test. please provide input thanks!.") + { + VoiceName = "en-US-NancyNeural" + }; + + var target = new PhoneNumberIdentifier(pstnTarget); + + var recognizeOptions = + new CallMediaRecognizeDtmfOptions( + targetParticipant: target, maxTonesToCollect: 4) + { + InterruptPrompt = false, + InterToneTimeout = TimeSpan.FromSeconds(5), + OperationContext = "DtmfContext", + InitialSilenceTimeout = TimeSpan.FromSeconds(15), + Prompt = textSource + }; + + await callMedia.StartRecognizingAsync(recognizeOptions); + + return Results.Ok(); +}).WithTags("Start Recognization APIs"); + +app.MapPost("/recognizeDTMF", (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + TextSource textSource = new TextSource("Hi, this is recognize test. please provide input thanks!.") + { + VoiceName = "en-US-NancyNeural" + }; + + var target = new PhoneNumberIdentifier(pstnTarget); + + var recognizeOptions = + new CallMediaRecognizeDtmfOptions( + targetParticipant: target, maxTonesToCollect: 4) + { + InterruptPrompt = false, + InterToneTimeout = TimeSpan.FromSeconds(5), + OperationContext = "DtmfContext", + InitialSilenceTimeout = TimeSpan.FromSeconds(15), + Prompt = textSource + }; + + callMedia.StartRecognizing(recognizeOptions); + + return Results.Ok(); +}).WithTags("Start Recognization APIs"); + + +app.MapPost("/recognizeSpeechAsync", async (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + TextSource textSource = new TextSource("Hi, this is recognize test. please provide input thanks!.") + { + VoiceName = "en-US-NancyNeural" + }; + + var target = new PhoneNumberIdentifier(pstnTarget); + + var recognizeOptions = new CallMediaRecognizeSpeechOptions(targetParticipant: target) + { + InterruptPrompt = false, + OperationContext = "SpeechContext", + InitialSilenceTimeout = TimeSpan.FromSeconds(15), + Prompt = textSource, + EndSilenceTimeout = TimeSpan.FromSeconds(15) + }; + + await callMedia.StartRecognizingAsync(recognizeOptions); + + return Results.Ok(); +}).WithTags("Start Recognization APIs"); + +app.MapPost("/recognizeSpeech", (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + TextSource textSource = new TextSource("Hi, this is recognize test. please provide input thanks!.") + { + VoiceName = "en-US-NancyNeural" + }; + + var target = new PhoneNumberIdentifier(pstnTarget); + + var recognizeOptions = new CallMediaRecognizeSpeechOptions(targetParticipant: target) + { + InterruptPrompt = false, + OperationContext = "SpeechContext", + InitialSilenceTimeout = TimeSpan.FromSeconds(15), + Prompt = textSource, + EndSilenceTimeout = TimeSpan.FromSeconds(15) + }; + + callMedia.StartRecognizing(recognizeOptions); + + return Results.Ok(); +}).WithTags("Start Recognization APIs"); + +app.MapPost("/recognizeSpeechOrDtmfAsync", async (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + TextSource textSource = new TextSource("Hi, this is recognize test. please provide input thanks!.") + { + VoiceName = "en-US-NancyNeural" + }; + + var target = new PhoneNumberIdentifier(pstnTarget); + + var recognizeOptions = + new CallMediaRecognizeSpeechOrDtmfOptions( + targetParticipant: target, maxTonesToCollect: 4) + { + InterruptPrompt = false, + OperationContext = "SpeechOrDTMFContext", + InitialSilenceTimeout = TimeSpan.FromSeconds(15), + Prompt = textSource, + EndSilenceTimeout = TimeSpan.FromSeconds(5) + }; + await callMedia.StartRecognizingAsync(recognizeOptions); + + return Results.Ok(); +}).WithTags("Start Recognization APIs"); + +app.MapPost("/recognizeSpeechOrDtmf", (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + TextSource textSource = new TextSource("Hi, this is recognize test. please provide input thanks!.") + { + VoiceName = "en-US-NancyNeural" + }; + + var target = new PhoneNumberIdentifier(pstnTarget); + + var recognizeOptions = + new CallMediaRecognizeSpeechOrDtmfOptions( + targetParticipant: target, maxTonesToCollect: 4) + { + InterruptPrompt = false, + OperationContext = "SpeechOrDTMFContext", + InitialSilenceTimeout = TimeSpan.FromSeconds(15), + Prompt = textSource, + EndSilenceTimeout = TimeSpan.FromSeconds(5) + }; + callMedia.StartRecognizingAsync(recognizeOptions); + + return Results.Ok(); +}).WithTags("Start Recognization APIs"); + +app.MapPost("/recognizeChoiceAsync", async (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + TextSource textSource = new TextSource("Hi, this is recognize test. please provide input thanks!.") + { + VoiceName = "en-US-NancyNeural" + }; + + var target = new PhoneNumberIdentifier(pstnTarget); + + + var recognizeOptions = + new CallMediaRecognizeChoiceOptions(targetParticipant: target, GetChoices()) + { + InterruptCallMediaOperation = false, + InterruptPrompt = false, + InitialSilenceTimeout = TimeSpan.FromSeconds(10), + Prompt = textSource, + OperationContext = "ChoiceContext" + }; + + + await callMedia.StartRecognizingAsync(recognizeOptions); + + return Results.Ok(); +}).WithTags("Start Recognization APIs"); + +app.MapPost("/recognizeChoice", (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + TextSource textSource = new TextSource("Hi, this is recognize test. please provide input thanks!.") + { + VoiceName = "en-US-NancyNeural" + }; + + var target = new PhoneNumberIdentifier(pstnTarget); + + + var recognizeOptions = + new CallMediaRecognizeChoiceOptions(targetParticipant: target, GetChoices()) + { + InterruptCallMediaOperation = false, + InterruptPrompt = false, + InitialSilenceTimeout = TimeSpan.FromSeconds(10), + Prompt = textSource, + OperationContext = "ChoiceContext" + }; + + callMedia.StartRecognizingAsync(recognizeOptions); + + return Results.Ok(); +}).WithTags("Start Recognization APIs"); + +#endregion + +# region DTMF + +app.MapPost("/sendDTMFTonesAsync", async (string pstnTarget, ILogger logger) => +{ + CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); + + List tones = new List + { + DtmfTone.Zero, + DtmfTone.One + }; + + CallMedia callMedia = GetCallMedia(); + + await callMedia.SendDtmfTonesAsync(tones, target); + return Results.Ok(); +}).WithTags("Send or Start DTMF APIs"); + +app.MapPost("/sendDTMFTones", (string pstnTarget, ILogger logger) => +{ + CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); + + List tones = new List + { + DtmfTone.Zero, + DtmfTone.One + }; + + CallMedia callMedia = GetCallMedia(); + + callMedia.SendDtmfTones(tones, target); + return Results.Ok(); +}).WithTags("Send or Start DTMF APIs"); + +app.MapPost("/startContinuousDTMFTonesAsync", async (string pstnTarget, ILogger logger) => +{ + CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); + + CallMedia callMedia = GetCallMedia(); + + await callMedia.StartContinuousDtmfRecognitionAsync(target); + return Results.Ok(); +}).WithTags("Send or Start DTMF APIs"); + +app.MapPost("/startContinuousDTMFTones", (string pstnTarget, ILogger logger) => +{ + CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); + + CallMedia callMedia = GetCallMedia(); + + callMedia.StartContinuousDtmfRecognition(target); + return Results.Ok(); +}).WithTags("Send or Start DTMF APIs"); + +app.MapPost("/stopContinuousDTMFTonesAsync", async (string pstnTarget, ILogger logger) => +{ + CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); + + CallMedia callMedia = GetCallMedia(); + + await callMedia.StopContinuousDtmfRecognitionAsync(target); + return Results.Ok(); +}).WithTags("Send or Start DTMF APIs"); + +app.MapPost("/stopContinuousDTMFTones", (string pstnTarget, ILogger logger) => +{ + CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); + + CallMedia callMedia = GetCallMedia(); + + callMedia.StopContinuousDtmfRecognition(target); + return Results.Ok(); +}).WithTags("Send or Start DTMF APIs"); + +# endregion + +# region Hold/Unhold + +app.MapPost("/holdParticipantAsync", async (string pstnTarget, bool isPlaySource, ILogger logger) => +{ + CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); + + CallMedia callMedia = GetCallMedia(); + TextSource textSource = new TextSource("You are on hold please wait..") + { + VoiceName = "en-US-NancyNeural" + }; + + if (isPlaySource) + { + HoldOptions holdOptions = new HoldOptions(target) + { + PlaySource = textSource, + OperationContext = "holdUserContext" + }; + await callMedia.HoldAsync(holdOptions); + } + else + { + HoldOptions holdOptions = new HoldOptions(target) + { + OperationContext = "holdUserContext" + }; + await callMedia.HoldAsync(holdOptions); + } + + return Results.Ok(); +}).WithTags("Hold Participant APIs"); + +app.MapPost("/holdParticipant", (string pstnTarget, bool isPlaySource, ILogger logger) => +{ + CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); + + CallMedia callMedia = GetCallMedia(); + TextSource textSource = new TextSource("You are on hold please wait..") + { + VoiceName = "en-US-NancyNeural" + }; + + if (isPlaySource) + { + HoldOptions holdOptions = new HoldOptions(target) + { + PlaySource = textSource, + OperationContext = "holdUserContext" + }; + callMedia.Hold(holdOptions); + } + else + { + HoldOptions holdOptions = new HoldOptions(target) + { + OperationContext = "holdUserContext" + }; + callMedia.Hold(holdOptions); + } + + return Results.Ok(); +}).WithTags("Hold Participant APIs"); + +app.MapPost("/interrupAudioAndAnnounceAsync", async (string pstnTarget, ILogger logger) => +{ + CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); + + CallMedia callMedia = GetCallMedia(); + + TextSource textSource = new TextSource("Hi, This is interrup audio and announcement test") + { + VoiceName = "en-US-NancyNeural" + }; + + InterruptAudioAndAnnounceOptions interruptAudio = new InterruptAudioAndAnnounceOptions(textSource, target) + { + OperationContext = "innterruptContext" + }; + + await callMedia.InterruptAudioAndAnnounceAsync(interruptAudio); + + return Results.Ok(); +}).WithTags("Hold Participant APIs"); + +app.MapPost("/interrupAudioAndAnnounce", (string pstnTarget, ILogger logger) => +{ + CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); + + CallMedia callMedia = GetCallMedia(); + + TextSource textSource = new TextSource("Hi, This is interrupt audio and announcement test.") + { + VoiceName = "en-US-NancyNeural" + }; + + InterruptAudioAndAnnounceOptions interruptAudio = new InterruptAudioAndAnnounceOptions(textSource, target) + { + OperationContext = "innterruptContext" + }; + + callMedia.InterruptAudioAndAnnounce(interruptAudio); + + return Results.Ok(); +}).WithTags("Hold Participant APIs"); + + +app.MapPost("/unholdParticipantAsync", async (string pstnTarget, ILogger logger) => +{ + CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); + + CallMedia callMedia = GetCallMedia(); + + UnholdOptions unholdOptions = new UnholdOptions(target) + { + OperationContext = "unholdUserContext" + }; + + await callMedia.UnholdAsync(unholdOptions); + return Results.Ok(); +}).WithTags("Hold Participant APIs"); + +app.MapPost("/unholdParticipant", (string pstnTarget, ILogger logger) => +{ + CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); + + CallMedia callMedia = GetCallMedia(); + + UnholdOptions unholdOptions = new UnholdOptions(target) + { + OperationContext = "unholdUserContext" + }; + + callMedia.Unhold(unholdOptions); + return Results.Ok(); +}).WithTags("Hold Participant APIs"); + +app.MapPost("/interruptHoldWithPlay", (string pstnTarget, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + + TextSource textSource = new TextSource("Hi, This is interrupt audio and announcement test.") + { + VoiceName = "en-US-NancyNeural" + }; + + List playTo = new List { new PhoneNumberIdentifier(pstnTarget) }; + PlayOptions playToOptions = new PlayOptions(textSource, playTo) + { + OperationContext = "playToContext", + InterruptHoldAudio = true + }; + + callMedia.Play(playToOptions); + + return Results.Ok(); +}).WithTags("Hold Participant APIs"); + +# endregion + +#region Disconnect call + +app.MapPost("/hangupAsync", async (bool isForEveryOne, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + await callConnection.HangUpAsync(isForEveryOne); + return Results.Ok(); +}).WithTags("Disconnect call APIs"); + +app.MapPost("/hangup", (bool isForEveryOne, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + callConnection.HangUp(isForEveryOne); + return Results.Ok(); +}).WithTags("Disconnect call APIs"); + +#endregion + +# region Mute Particiapant + +app.MapPost("/muteAcsParticipantAsync", async (string acsTarget, ILogger logger) => +{ + CommunicationIdentifier target = new CommunicationUserIdentifier(acsTarget); + + CallConnection callConnection = GetConnection(); + + await callConnection.MuteParticipantAsync(target); + + return Results.Ok(); +}).WithTags("Mute Participant APIs"); + +app.MapPost("/muteAcsParticipant", (string acsTarget, ILogger logger) => +{ + CommunicationIdentifier target = new CommunicationUserIdentifier(acsTarget); + + CallConnection callConnection = GetConnection(); + + callConnection.MuteParticipant(target); + + return Results.Ok(); +}).WithTags("Mute Participant APIs"); + +#endregion + +# region Media streaming + +app.MapPost("/createCallToPstnWithMediaStreamingAsync", async (string targetPhoneNumber, bool isEnableBidirectional, bool isPcm24kMono, ILogger logger) => +{ + PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); + PhoneNumberIdentifier caller = new PhoneNumberIdentifier(acsPhoneNumber); + + + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(target, caller); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, true); + mediaStreamingOptions.EnableBidirectional = isEnableBidirectional; + mediaStreamingOptions.AudioFormat = isPcm24kMono ? AudioFormat.Pcm24KMono : AudioFormat.Pcm16KMono; + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + MediaStreamingOptions = mediaStreamingOptions + }; + + CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); + + logger.LogInformation($"Created async pstn media streaming call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Media streaming APIs"); + +app.MapPost("/createCallToPstnWithMediaStreaming", (string targetPhoneNumber, bool isEnableBidirectional, bool isPcm24kMono, ILogger logger) => +{ + PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); + PhoneNumberIdentifier caller = new PhoneNumberIdentifier(acsPhoneNumber); + + + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(target, caller); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, true); + mediaStreamingOptions.EnableBidirectional = isEnableBidirectional; + mediaStreamingOptions.AudioFormat = isPcm24kMono ? AudioFormat.Pcm24KMono : AudioFormat.Pcm16KMono; + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + MediaStreamingOptions = mediaStreamingOptions + }; + + CreateCallResult createCallResult = client.CreateCall(createCallOptions); + + logger.LogInformation($"Created async pstn media streaming call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Media streaming APIs"); + +app.MapPost("/createCallToAcsWithMediaStreamingAsync", async (string acsTarget, bool isEnableBidirectional, bool isPcm24kMono, ILogger logger) => +{ + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(new CommunicationUserIdentifier(acsTarget)); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, true); + mediaStreamingOptions.EnableBidirectional = isEnableBidirectional; + mediaStreamingOptions.AudioFormat = isPcm24kMono ? AudioFormat.Pcm24KMono : AudioFormat.Pcm16KMono; + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + MediaStreamingOptions = mediaStreamingOptions + }; + + CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); + + logger.LogInformation($"Created async acs call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Media streaming APIs"); + +app.MapPost("/createCallToAcsWithMediaStreaming", (string acsTarget, bool isEnableBidirectional, bool isPcm24kMono, ILogger logger) => +{ + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(new CommunicationUserIdentifier(acsTarget)); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, true); + mediaStreamingOptions.EnableBidirectional = isEnableBidirectional; + mediaStreamingOptions.AudioFormat = isPcm24kMono ? AudioFormat.Pcm24KMono : AudioFormat.Pcm16KMono; + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + MediaStreamingOptions = mediaStreamingOptions + }; + + CreateCallResult createCallResult = client.CreateCall(createCallOptions); + + logger.LogInformation($"Created acs call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Media streaming APIs"); + +app.MapPost("/createCallToTeamsWithMediaStreamingAsync", async (string teamsObjectId, bool isEnableBidirectional, bool isPcm24kMono, ILogger logger) => +{ + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(new MicrosoftTeamsUserIdentifier(teamsObjectId)); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, true); + mediaStreamingOptions.EnableBidirectional = isEnableBidirectional; + mediaStreamingOptions.AudioFormat = isPcm24kMono ? AudioFormat.Pcm24KMono : AudioFormat.Pcm16KMono; + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + MediaStreamingOptions = mediaStreamingOptions + }; + + CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); + + logger.LogInformation($"Created async teams call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Media streaming APIs"); + +app.MapPost("/createCallToTeamsWithMediaStreaming", (string teamsObjectId, bool isEnableBidirectional, bool isPcm24kMono, ILogger logger) => +{ + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(new MicrosoftTeamsUserIdentifier(teamsObjectId)); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(new Uri(websocketUri), MediaStreamingContent.Audio, + MediaStreamingAudioChannel.Unmixed, MediaStreamingTransport.Websocket, true); + mediaStreamingOptions.EnableBidirectional = isEnableBidirectional; + mediaStreamingOptions.AudioFormat = isPcm24kMono ? AudioFormat.Pcm24KMono : AudioFormat.Pcm16KMono; + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + MediaStreamingOptions = mediaStreamingOptions + }; + + CreateCallResult createCallResult = client.CreateCall(createCallOptions); + + logger.LogInformation($"Created teams call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Media streaming APIs"); + + +app.MapPost("/startMediaStreamingAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + await callMedia.StartMediaStreamingAsync(); + return Results.Ok(); +}).WithTags("Media streaming APIs"); + +app.MapPost("/startMediaStreaming", (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + callMedia.StartMediaStreaming(); + return Results.Ok(); +}).WithTags("Media streaming APIs"); + +app.MapPost("/stopMediaStreamingAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + await callMedia.StopMediaStreamingAsync(); + return Results.Ok(); +}).WithTags("Media streaming APIs"); + +app.MapPost("/stopMediaStreaming", (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + callMedia.StopMediaStreaming(); + return Results.Ok(); +}).WithTags("Media streaming APIs"); + +app.MapPost("/startMediaStreamingWithOptionsAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + StartMediaStreamingOptions startMediaStreamingOptions = new() + { + OperationContext = "StartMediaStreamingContext", + OperationCallbackUri = eventCallbackUri + }; + await callMedia.StartMediaStreamingAsync(startMediaStreamingOptions); + return Results.Ok(); +}).WithTags("Media streaming APIs"); + +app.MapPost("/startMediaStreamingWithOptions", (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + StartMediaStreamingOptions startMediaStreamingOptions = new() + { + OperationContext = "StartMediaStreamingContext", + OperationCallbackUri = eventCallbackUri + }; + callMedia.StartMediaStreaming(startMediaStreamingOptions); + return Results.Ok(); +}).WithTags("Media streaming APIs"); + +app.MapPost("/stopMediaStreamingWithOptionsAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + StopMediaStreamingOptions stopMediaStreamingOptions = new() + { + OperationContext = "StopMediaStreamingContext", + OperationCallbackUri = eventCallbackUri + }; + await callMedia.StopMediaStreamingAsync(); + return Results.Ok(); +}).WithTags("Media streaming APIs"); + +app.MapPost("/stopMediaStreamingWithOptions", (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + StopMediaStreamingOptions stopMediaStreamingOptions = new() + { + OperationContext = "StopMediaStreamingContext", + OperationCallbackUri = eventCallbackUri + }; + callMedia.StopMediaStreaming(stopMediaStreamingOptions); + return Results.Ok(); +}).WithTags("Media streaming APIs"); + +#endregion + +#region Transcription + +app.MapPost("/createCallToPstnWithTranscriptionAsync", async (string targetPhoneNumber, ILogger logger) => +{ + PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); + PhoneNumberIdentifier caller = new PhoneNumberIdentifier(acsPhoneNumber); + + + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(target, caller); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", false, TranscriptionTransport.Websocket); + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + TranscriptionOptions = transcriptionOptions + }; + + CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); + + logger.LogInformation($"Created async pstn transcription call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Transcription APIs"); + +app.MapPost("/createCallToPstnWithTranscription", (string targetPhoneNumber, ILogger logger) => +{ + PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); + PhoneNumberIdentifier caller = new PhoneNumberIdentifier(acsPhoneNumber); + + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(target, caller); + + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", true, TranscriptionTransport.Websocket); + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + TranscriptionOptions = transcriptionOptions + }; + + CreateCallResult createCallResult = client.CreateCall(createCallOptions); + + logger.LogInformation($"Created pstn transcription call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Transcription APIs"); + +app.MapPost("/createCallToAcsWithTranscriptionAsync", async (string acsTarget, ILogger logger) => +{ + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(new CommunicationUserIdentifier(acsTarget)); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", true, TranscriptionTransport.Websocket); + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + TranscriptionOptions = transcriptionOptions + }; + + CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); + + logger.LogInformation($"Created async acs transcription call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Transcription APIs"); + +app.MapPost("/createCallToAcsWithTranscription", (string acsTarget, ILogger logger) => +{ + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(new CommunicationUserIdentifier(acsTarget)); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", true, TranscriptionTransport.Websocket); + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + TranscriptionOptions = transcriptionOptions + }; + + CreateCallResult createCallResult = client.CreateCall(createCallOptions); + + logger.LogInformation($"Created acs transcription call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Transcription APIs"); + +app.MapPost("/createCallToTeamsWithTranscriptionAsync", async (string teamsObjectId, ILogger logger) => +{ + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(new MicrosoftTeamsUserIdentifier(teamsObjectId)); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", true, TranscriptionTransport.Websocket); + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + TranscriptionOptions = transcriptionOptions + }; + + CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); + + logger.LogInformation($"Created async teams transcription call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Transcription APIs"); + +app.MapPost("/createCallToTeamsWithTranscription", (string teamsObjectId, ILogger logger) => +{ + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + eventCallbackUri = callbackUri; + CallInvite callInvite = new CallInvite(new MicrosoftTeamsUserIdentifier(teamsObjectId)); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + TranscriptionOptions transcriptionOptions = new TranscriptionOptions(new Uri(websocketUri), + "en-us", true, TranscriptionTransport.Websocket); + + var createCallOptions = new CreateCallOptions(callInvite, callbackUri) + { + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + TranscriptionOptions = transcriptionOptions + }; + + CreateCallResult createCallResult = client.CreateCall(createCallOptions); + + logger.LogInformation($"Created teams transcription call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +}).WithTags("Transcription APIs"); + +app.MapPost("/startTranscriptionAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + await callMedia.StartTranscriptionAsync(); + return Results.Ok(); +}).WithTags("Transcription APIs"); + +app.MapPost("/startTranscription", (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + callMedia.StartTranscription(); + return Results.Ok(); +}).WithTags("Transcription APIs"); + +app.MapPost("/updateTranscriptionAsync", async (string locale, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + await callMedia.UpdateTranscriptionAsync(locale); + return Results.Ok(); +}).WithTags("Transcription APIs"); + +app.MapPost("/updateTranscription", (string locale, ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + callMedia.UpdateTranscription(locale); + return Results.Ok(); +}).WithTags("Transcription APIs"); + +app.MapPost("/stopTranscriptionAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + await callMedia.StopTranscriptionAsync(); + return Results.Ok(); +}).WithTags("Transcription APIs"); + +app.MapPost("/stopTranscription", (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + callMedia.StopTranscription(); + return Results.Ok(); +}).WithTags("Transcription APIs"); + +app.MapPost("/startTranscriptionWithOptionsAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + StartTranscriptionOptions startTranscriptionOptions = new StartTranscriptionOptions() + { + OperationContext = "StartTranscriptionContext", + Locale = "en-us" + }; + await callMedia.StartTranscriptionAsync(startTranscriptionOptions); + return Results.Ok(); +}).WithTags("Transcription APIs"); + +app.MapPost("/startTranscriptionWithOptions", (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + StartTranscriptionOptions startTranscriptionOptions = new StartTranscriptionOptions() + { + OperationContext = "StartTranscriptionContext", + Locale = "en-us" + }; + callMedia.StartTranscription(startTranscriptionOptions); + return Results.Ok(); +}).WithTags("Transcription APIs"); + +app.MapPost("/stopTranscriptionWithOptionsAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + await callMedia.StopTranscriptionAsync(); + return Results.Ok(); +}).WithTags("Transcription APIs"); + +app.MapPost("/stopTranscriptionWithOptions", (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + callMedia.StopTranscription(); + return Results.Ok(); +}).WithTags("Transcription APIs"); + +#endregion + +#region Transfer Call + +app.MapPost("/transferCallToPstnParticipantAsync", async (string pstnTransferTarget, string pstnTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + TransferToParticipantOptions transferToParticipantOptions = new TransferToParticipantOptions(new PhoneNumberIdentifier(pstnTransferTarget)) + { + OperationContext = "TransferCallContext", + Transferee = new PhoneNumberIdentifier(pstnTarget), + }; + + await callConnection.TransferCallToParticipantAsync(transferToParticipantOptions); + return Results.Ok(); +}).WithTags("Transfer Call APIs"); + +app.MapPost("/transferCallToPstnParticipant", (string pstnTransferTarget, string pstnTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + TransferToParticipantOptions transferToParticipantOptions = new TransferToParticipantOptions(new PhoneNumberIdentifier(pstnTransferTarget)) + { + OperationContext = "TransferCallContext", + Transferee = new PhoneNumberIdentifier(pstnTarget), + }; + + callConnection.TransferCallToParticipant(transferToParticipantOptions); + return Results.Ok(); +}).WithTags("Transfer Call APIs"); + +#endregion + +#region Get Participant + +app.MapPost("/getPstnParticipantAsync", async (string pstnTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + CallParticipant participant = await callConnection.GetParticipantAsync(new PhoneNumberIdentifier(pstnTarget)); + + if (participant != null) + { + Console.WriteLine("Participant:-->" + participant.Identifier.RawId.ToString()); + Console.WriteLine("Is Participant on hold:-->" + participant.IsOnHold); + } + return Results.Ok(); +}).WithTags("Get Participant APIs"); + +app.MapPost("/getPstnParticipant", (string pstnTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + CallParticipant participant = callConnection.GetParticipant(new PhoneNumberIdentifier(pstnTarget)); + + if (participant != null) + { + Console.WriteLine("Participant:-->" + participant.Identifier.RawId.ToString()); + Console.WriteLine("Is Participant on hold:-->" + participant.IsOnHold); + } + return Results.Ok(); +}).WithTags("Get Participant APIs"); + +app.MapPost("/getAcsParticipantAsync", async (string acsTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + CallParticipant participant = await callConnection.GetParticipantAsync(new CommunicationUserIdentifier(acsTarget)); + + if (participant != null) + { + Console.WriteLine("Participant:-->" + participant.Identifier.RawId.ToString()); + Console.WriteLine("Is Participant on hold:-->" + participant.IsOnHold); + } + return Results.Ok(); +}).WithTags("Get Participant APIs"); + +app.MapPost("/getAcsParticipant", (string acsTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + CallParticipant participant = callConnection.GetParticipant(new CommunicationUserIdentifier(acsTarget)); + + if (participant != null) + { + Console.WriteLine("Participant:-->" + participant.Identifier.RawId.ToString()); + Console.WriteLine("Is Participant on hold:-->" + participant.IsOnHold); + } + return Results.Ok(); +}).WithTags("Get Participant APIs"); + +app.MapPost("/getTeamsParticipantAsync", async (string teamsObjectId, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + CallParticipant participant = await callConnection.GetParticipantAsync(new MicrosoftTeamsUserIdentifier(teamsObjectId)); + + if (participant != null) + { + Console.WriteLine("Participant:-->" + participant.Identifier.RawId.ToString()); + Console.WriteLine("Is Participant on hold:-->" + participant.IsOnHold); + } + return Results.Ok(); +}).WithTags("Get Participant APIs"); + +app.MapPost("/getTeamsParticipant", (string teamsObjectId, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + CallParticipant participant = callConnection.GetParticipant(new MicrosoftTeamsUserIdentifier(teamsObjectId)); + + if (participant != null) + { + Console.WriteLine("Participant:-->" + participant.Identifier.RawId.ToString()); + Console.WriteLine("Is Participant on hold:-->" + participant.IsOnHold); + } + return Results.Ok(); +}).WithTags("Get Participant APIs"); + +app.MapPost("/getParticipantListAsync", async (ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + var list = await callConnection.GetParticipantsAsync(); + + foreach (var participant in list.Value) + { + Console.WriteLine("----------------------------------------------------------------------"); + Console.WriteLine("Participant:-->" + participant.Identifier.RawId.ToString()); + Console.WriteLine("Is Participant on hold:-->" + participant.IsOnHold); + Console.WriteLine("----------------------------------------------------------------------"); + } + return Results.Ok(); +}).WithTags("Get Participant APIs"); + +app.MapPost("/getParticipantList", (ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + var list = callConnection.GetParticipants(); + + foreach (var participant in list.Value) + { + Console.WriteLine("----------------------------------------------------------------------"); + Console.WriteLine("Participant:-->" + participant.Identifier.RawId.ToString()); + Console.WriteLine("Is Participant on hold:-->" + participant.IsOnHold); + Console.WriteLine("----------------------------------------------------------------------"); + } + return Results.Ok(); +}).WithTags("Get Participant APIs"); + +#endregion + +#region Recording + +app.MapPost("/startRecordingWithVideoMp4MixedAsync", async (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +{ + CallConnectionProperties callConnectionProperties = GetCallConnectionProperties(); + var serverCallId = callConnectionProperties.ServerCallId; + CallLocator callLocator = new ServerCallLocator(serverCallId); + var recordingOptions = isRecordingWithCallConnectionId ? new StartRecordingOptions(callConnectionProperties.CallConnectionId) : new StartRecordingOptions(callLocator); + recordingOptions.RecordingContent = RecordingContent.AudioVideo; + recordingOptions.RecordingFormat = RecordingFormat.Mp4; + recordingOptions.RecordingChannel = RecordingChannel.Mixed; + recordingOptions.RecordingStateCallbackUri = eventCallbackUri; + recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingFileFormat = "mp4"; + var recordingResult = await client.GetCallRecording().StartAsync(recordingOptions); + recordingId = recordingResult.Value.RecordingId; + logger.LogInformation($"Recording started. RecordingId: {recordingId}"); + return Results.Ok(); +}).WithTags("Recording APIs"); + +app.MapPost("/startRecordingWithVideoMp4Mixed", (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +{ + CallConnectionProperties callConnectionProperties = GetCallConnectionProperties(); + var serverCallId = callConnectionProperties.ServerCallId; + CallLocator callLocator = new ServerCallLocator(serverCallId); + var recordingOptions = isRecordingWithCallConnectionId ? new StartRecordingOptions(callConnectionProperties.CallConnectionId) : new StartRecordingOptions(callLocator); + recordingOptions.RecordingContent = RecordingContent.AudioVideo; + recordingOptions.RecordingFormat = RecordingFormat.Mp4; + recordingOptions.RecordingChannel = RecordingChannel.Mixed; + recordingOptions.RecordingStateCallbackUri = eventCallbackUri; + recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingFileFormat = "mp4"; + + var recordingResult = client.GetCallRecording().Start(recordingOptions); + recordingId = recordingResult.Value.RecordingId; + logger.LogInformation($"Recording started. RecordingId: {recordingId}"); + return Results.Ok(); +}).WithTags("Recording APIs"); + +app.MapPost("/startRecordingWithAudioMp3MixedAsync", async (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +{ + CallConnectionProperties callConnectionProperties = GetCallConnectionProperties(); + var serverCallId = callConnectionProperties.ServerCallId; + CallLocator callLocator = new ServerCallLocator(serverCallId); + var recordingOptions = isRecordingWithCallConnectionId ? new StartRecordingOptions(callConnectionProperties.CallConnectionId) : new StartRecordingOptions(callLocator); + recordingOptions.RecordingContent = RecordingContent.Audio; + recordingOptions.RecordingFormat = RecordingFormat.Mp3; + recordingOptions.RecordingChannel = RecordingChannel.Mixed; + recordingOptions.RecordingStateCallbackUri = eventCallbackUri; + recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingFileFormat = "mp3"; + + var recordingResult = await client.GetCallRecording().StartAsync(recordingOptions); + recordingId = recordingResult.Value.RecordingId; + logger.LogInformation($"Recording started. RecordingId: {recordingId}"); + return Results.Ok(); +}).WithTags("Recording APIs"); + +app.MapPost("/startRecordingWithAudioMp3Mixed", (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +{ + CallConnectionProperties callConnectionProperties = GetCallConnectionProperties(); + var serverCallId = callConnectionProperties.ServerCallId; + CallLocator callLocator = new ServerCallLocator(serverCallId); + var recordingOptions = isRecordingWithCallConnectionId ? new StartRecordingOptions(callConnectionProperties.CallConnectionId) : new StartRecordingOptions(callLocator); + recordingOptions.RecordingContent = RecordingContent.Audio; + recordingOptions.RecordingFormat = RecordingFormat.Mp3; + recordingOptions.RecordingChannel = RecordingChannel.Mixed; + recordingOptions.RecordingStateCallbackUri = eventCallbackUri; + recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingFileFormat = "mp3"; + + var recordingResult = client.GetCallRecording().Start(recordingOptions); + recordingId = recordingResult.Value.RecordingId; + logger.LogInformation($"Recording started. RecordingId: {recordingId}"); + return Results.Ok(); +}).WithTags("Recording APIs"); + +app.MapPost("/startRecordingWithAudioMp3UnMixedAsync", async (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +{ + CallConnectionProperties callConnectionProperties = GetCallConnectionProperties(); + var serverCallId = callConnectionProperties.ServerCallId; + CallLocator callLocator = new ServerCallLocator(serverCallId); + var recordingOptions = isRecordingWithCallConnectionId ? new StartRecordingOptions(callConnectionProperties.CallConnectionId) : new StartRecordingOptions(callLocator); + recordingOptions.RecordingContent = RecordingContent.Audio; + recordingOptions.RecordingFormat = RecordingFormat.Mp3; + recordingOptions.RecordingChannel = RecordingChannel.Unmixed; + recordingOptions.RecordingStateCallbackUri = eventCallbackUri; + recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingFileFormat = "mp3"; + + var recordingResult = await client.GetCallRecording().StartAsync(recordingOptions); + recordingId = recordingResult.Value.RecordingId; + logger.LogInformation($"Recording started. RecordingId: {recordingId}"); + return Results.Ok(); +}).WithTags("Recording APIs"); + +app.MapPost("/startRecordingWithAudioMp3Unmixed", (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +{ + CallConnectionProperties callConnectionProperties = GetCallConnectionProperties(); + var serverCallId = callConnectionProperties.ServerCallId; + CallLocator callLocator = new ServerCallLocator(serverCallId); + var recordingOptions = isRecordingWithCallConnectionId ? new StartRecordingOptions(callConnectionProperties.CallConnectionId) : new StartRecordingOptions(callLocator); + recordingOptions.RecordingContent = RecordingContent.Audio; + recordingOptions.RecordingFormat = RecordingFormat.Mp3; + recordingOptions.RecordingChannel = RecordingChannel.Unmixed; + recordingOptions.RecordingStateCallbackUri = eventCallbackUri; + recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingFileFormat = "mp3"; + + var recordingResult = client.GetCallRecording().Start(recordingOptions); + recordingId = recordingResult.Value.RecordingId; + logger.LogInformation($"Recording started. RecordingId: {recordingId}"); + return Results.Ok(); +}).WithTags("Recording APIs"); + +app.MapPost("/startRecordingWithAudioWavUnMixedAsync", async (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +{ + CallConnectionProperties callConnectionProperties = GetCallConnectionProperties(); + var serverCallId = callConnectionProperties.ServerCallId; + CallLocator callLocator = new ServerCallLocator(serverCallId); + var recordingOptions = isRecordingWithCallConnectionId ? new StartRecordingOptions(callConnectionProperties.CallConnectionId) : new StartRecordingOptions(callLocator); + recordingOptions.RecordingContent = RecordingContent.Audio; + recordingOptions.RecordingFormat = RecordingFormat.Wav; + recordingOptions.RecordingChannel = RecordingChannel.Unmixed; + recordingOptions.RecordingStateCallbackUri = eventCallbackUri; + recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingFileFormat = "wav"; + + var recordingResult = await client.GetCallRecording().StartAsync(recordingOptions); + recordingId = recordingResult.Value.RecordingId; + logger.LogInformation($"Recording started. RecordingId: {recordingId}"); + return Results.Ok(); +}).WithTags("Recording APIs"); + +app.MapPost("/startRecordingWithAudioWavUnmixed", (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +{ + CallConnectionProperties callConnectionProperties = GetCallConnectionProperties(); + var serverCallId = callConnectionProperties.ServerCallId; + CallLocator callLocator = new ServerCallLocator(serverCallId); + var recordingOptions = isRecordingWithCallConnectionId ? new StartRecordingOptions(callConnectionProperties.CallConnectionId) : new StartRecordingOptions(callLocator); + recordingOptions.RecordingContent = RecordingContent.Audio; + recordingOptions.RecordingFormat = RecordingFormat.Wav; + recordingOptions.RecordingChannel = RecordingChannel.Unmixed; + recordingOptions.RecordingStateCallbackUri = eventCallbackUri; + recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingFileFormat = "wav"; + + var recordingResult = client.GetCallRecording().Start(recordingOptions); + recordingId = recordingResult.Value.RecordingId; + logger.LogInformation($"Recording started. RecordingId: {recordingId}"); + return Results.Ok(); +}).WithTags("Recording APIs"); + + + +app.MapPost("/pauseRecordingAsync", async () => +{ + await client.GetCallRecording().PauseAsync(recordingId); + return Results.Ok(); +}).WithTags("Recording APIs"); + +app.MapPost("/pauseRecording", () => +{ + client.GetCallRecording().Pause(recordingId); + return Results.Ok(); +}).WithTags("Recording APIs"); + +app.MapPost("/resumeRecordingAsync", async () => +{ + await client.GetCallRecording().ResumeAsync(recordingId); + return Results.Ok(); +}).WithTags("Recording APIs"); + +app.MapPost("/resumeRecording", () => +{ + client.GetCallRecording().Resume(recordingId); + return Results.Ok(); +}).WithTags("Recording APIs"); + +app.MapPost("/stopRecordingAsync", async () => +{ + await client.GetCallRecording().StopAsync(recordingId); + return Results.Ok(); +}).WithTags("Recording APIs"); + +app.MapPost("/stopRecording", () => +{ + client.GetCallRecording().Stop(recordingId); + return Results.Ok(); +}).WithTags("Recording APIs"); + +app.MapGet("/downloadRecording", (ILogger logger) => +{ + if (!string.IsNullOrEmpty(recordingLocation)) + { + string downloadsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"); + var date = DateTime.Now.ToString("yyyyMMdd_HHmmss"); + string fileName = $"Recording_{date}.{recordingFileFormat}"; + client.GetCallRecording().DownloadTo(new Uri(recordingLocation), $"{downloadsPath}\\{fileName}"); + } + else + { + logger.LogError("Recording is not available"); + } + return Results.Ok(); +}).WithTags("Recording APIs"); + +#endregion + +#region Cancel All Media Operations + +app.MapPost("/cancelAllMediaOperationAsync", async (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + await callMedia.CancelAllMediaOperationsAsync(); + return Results.Ok(); +}).WithTags("Cancel All Media Opertation APIs"); + +app.MapPost("/cancelAllMediaOperation", (ILogger logger) => +{ + CallMedia callMedia = GetCallMedia(); + callMedia.CancelAllMediaOperations(); + return Results.Ok(); +}).WithTags("Cancel All Media Opertation APIs"); + +#endregion +#region Dialog Call APIs +app.MapPost("/startDialogAsync", async (ILogger logger) => +{ + Dictionary dialogContext = new Dictionary(); + + PhoneNumberIdentifier target = new PhoneNumberIdentifier(calleeId); + PhoneNumberIdentifier sourceCallerId = new PhoneNumberIdentifier(callerId); + + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + CallInvite callInvite = new CallInvite(target, sourceCallerId); + var createCallOptions = new CreateCallOptions(callInvite, callbackUri); + + CreateCallResult createCallResult = client.CreateCall(createCallOptions); + CallConnection callConnection = GetConnection(); + var callDialog = callConnection.GetCallDialog(); + + logger.LogInformation($"Async call created with ID: {createCallResult.CallConnectionProperties.CallConnectionId}"); + + string botAppId = botRouting.ContainsKey(calleeId) ? botRouting[calleeId] : defaultBotId; + + var dialogOptions = new StartDialogOptions(Guid.NewGuid().ToString(), new PowerVirtualAgentsDialog(botAppId, dialogContext)) + { + OperationContext = "DialogStart" + }; + + var response = await callDialog.StartDialogAsync(dialogOptions); + + logger.LogInformation($"Dialog started asynchronously: {response.GetRawResponse().Content.ToString()}"); + + return Results.Ok(); +}).WithTags("2. Dialogs APIs"); + +app.MapPost("/startDialog", (ILogger logger) => +{ + Dictionary dialogContext = new Dictionary(); + + PhoneNumberIdentifier target = new PhoneNumberIdentifier(calleeId); + PhoneNumberIdentifier sourceCallerId = new PhoneNumberIdentifier(callerId); + + var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); + CallInvite callInvite = new CallInvite(target, sourceCallerId); + var createCallOptions = new CreateCallOptions(callInvite, callbackUri); + + CreateCallResult createCallResult = client.CreateCall(createCallOptions); + CallConnection callConnection = GetConnection(); + var callDialog = callConnection.GetCallDialog(); + + logger.LogInformation($"Call created with ID: {createCallResult.CallConnectionProperties.CallConnectionId}"); + + string botAppId = botRouting.ContainsKey(calleeId) ? botRouting[calleeId] : defaultBotId; + + var dialogOptions = new StartDialogOptions(Guid.NewGuid().ToString(), new PowerVirtualAgentsDialog(botAppId, dialogContext)) + { + OperationContext = "DialogStart" + }; + + var response = callDialog.StartDialog(dialogOptions); + + logger.LogInformation($"Dialog started synchronously: {response.GetRawResponse().Content.ToString()}"); + + return Results.Ok(); +}).WithTags("2. Dialogs APIs"); + + +#endregion +CallMedia GetCallMedia() +{ + CallMedia callMedia = !string.IsNullOrEmpty(callConnectionId) ? + client.GetCallConnection(callConnectionId).GetCallMedia() + : throw new ArgumentNullException("Call connection id is empty"); + + return callMedia; +} + +CallConnection GetConnection() +{ + CallConnection callConnection = !string.IsNullOrEmpty(callConnectionId) ? + client.GetCallConnection(callConnectionId) + : throw new ArgumentNullException("Call connection id is empty"); + return callConnection; +} + +CallConnectionProperties GetCallConnectionProperties() +{ + CallConnectionProperties callConnectionProperties = !string.IsNullOrEmpty(callConnectionId) ? + client.GetCallConnection(callConnectionId).GetCallConnectionProperties() + : throw new ArgumentNullException("Call connection id is empty"); + return callConnectionProperties; +} + +List GetChoices() +{ + return new List { + new RecognitionChoice("Confirm", new List { + "Confirm", + "First", + "One" + }) { + Tone = DtmfTone.One + }, + new RecognitionChoice("Cancel", new List { + "Cancel", + "Second", + "Two" + }) { + Tone = DtmfTone.Two + } + }; +} + +app.UseWebSockets(); +app.Use(async (context, next) => +{ + if (context.Request.Path == "/ws") + { + if (context.WebSockets.IsWebSocketRequest) + { + using var webSocket = await context.WebSockets.AcceptWebSocketAsync(); + await Helper.ProcessRequest(webSocket); + } + else + { + context.Response.StatusCode = StatusCodes.Status400BadRequest; + } + } + else + { + await next(context); + } +}); + +//app.UseStaticFiles(new StaticFileOptions +//{ +// FileProvider = new PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath, "wwwroot", "audio")), +// RequestPath = "/audio" +//}); + + +app.Run(); diff --git a/Call_Automation_GCCH/Call_Automation_GCCH/Properties/launchSettings.json b/Call_Automation_GCCH/Call_Automation_GCCH/Properties/launchSettings.json new file mode 100644 index 00000000..688b8a42 --- /dev/null +++ b/Call_Automation_GCCH/Call_Automation_GCCH/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:39947", + "sslPort": 44389 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5142", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7006;http://localhost:5142", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Call_Automation_GCCH/Call_Automation_GCCH/appsettings.Development.json b/Call_Automation_GCCH/Call_Automation_GCCH/appsettings.Development.json new file mode 100644 index 00000000..0c208ae9 --- /dev/null +++ b/Call_Automation_GCCH/Call_Automation_GCCH/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Call_Automation_GCCH/Call_Automation_GCCH/appsettings.json b/Call_Automation_GCCH/Call_Automation_GCCH/appsettings.json new file mode 100644 index 00000000..10f68b8c --- /dev/null +++ b/Call_Automation_GCCH/Call_Automation_GCCH/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Call_Automation_GCCH/Call_Automation_GCCH/gcchDeploy.sh b/Call_Automation_GCCH/Call_Automation_GCCH/gcchDeploy.sh new file mode 100644 index 00000000..7b22d33b --- /dev/null +++ b/Call_Automation_GCCH/Call_Automation_GCCH/gcchDeploy.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +LOCATION='eastus' +RESOURCE_GROUP_NAME='waferwire-gcch-test' + +WEB_APP_NAME='gcch-test-app' +APP_SERVICE_PLAN_NAME='gcch-test-app-service' +RUNTIME='DOTNETCORE|8.0' +SUBSCRIPTION_ID='' + +# Log in to Azure +az login + +# Set the subscription +az account set --subscription $SUBSCRIPTION_ID + +# Build the .NET API +dotnet publish -c Release -o ./publish + +# Check if the publish directory exists +if [ -d "./publish" ]; then + echo "Publish directory exists." +else + echo "Publish directory does not exist." + exit 1 +fi + +# Check if the resource group exists +if ! az group exists --name $RESOURCE_GROUP_NAME; then + az group create --location $LOCATION --name $RESOURCE_GROUP_NAME +else + echo "Resource group $RESOURCE_GROUP_NAME already exists." +fi + +# Check if the app service plan exists +if ! az appservice plan show --name $APP_SERVICE_PLAN_NAME --resource-group $RESOURCE_GROUP_NAME > /dev/null 2>&1; then + az appservice plan create --name $APP_SERVICE_PLAN_NAME --resource-group $RESOURCE_GROUP_NAME --sku B1 --is-linux +else + echo "App service plan $APP_SERVICE_PLAN_NAME already exists." +fi + +# Check if the web app exists +if ! az webapp show --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP_NAME > /dev/null 2>&1; then + az webapp create --name $WEB_APP_NAME --runtime $RUNTIME --plan $APP_SERVICE_PLAN_NAME --resource-group $RESOURCE_GROUP_NAME +else + echo "Web app $WEB_APP_NAME already exists." + +fi +# Zip the published files using PowerShell +powershell.exe -Command "Compress-Archive -Path ./publish/* -DestinationPath ./publish.zip" + +# Check if the zip file was created +if [ -f "./publish.zip" ]; then + echo "Zip file created successfully." +else + echo "Failed to create zip file." + exit 1 +fi + +# Deploy the .NET API +az webapp deployment source config-zip --resource-group $RESOURCE_GROUP_NAME --name $WEB_APP_NAME --src ./publish.zip