From 9bcc1026239c82187a942918bd0119c691348499 Mon Sep 17 00:00:00 2001 From: Pilli Vamshi Date: Thu, 10 Apr 2025 12:01:49 +0530 Subject: [PATCH 1/3] addd beta6 test sample. --- .../CallAutomation_Beta6_Test_sample.csproj | 23 + .../CallAutomation_Beta6_Test_sample.sln | 25 + .../ConfigurationRequest.cs | 10 + CallAutomation_Beta6_Test_sample/Helper.cs | 99 + CallAutomation_Beta6_Test_sample/Program.cs | 2573 +++++++++++++++++ .../Properties/launchSettings.json | 41 + .../appsettings.Development.json | 8 + .../appsettings.json | 9 + 8 files changed, 2788 insertions(+) create mode 100644 CallAutomation_Beta6_Test_sample/CallAutomation_Beta6_Test_sample.csproj create mode 100644 CallAutomation_Beta6_Test_sample/CallAutomation_Beta6_Test_sample.sln create mode 100644 CallAutomation_Beta6_Test_sample/ConfigurationRequest.cs create mode 100644 CallAutomation_Beta6_Test_sample/Helper.cs create mode 100644 CallAutomation_Beta6_Test_sample/Program.cs create mode 100644 CallAutomation_Beta6_Test_sample/Properties/launchSettings.json create mode 100644 CallAutomation_Beta6_Test_sample/appsettings.Development.json create mode 100644 CallAutomation_Beta6_Test_sample/appsettings.json diff --git a/CallAutomation_Beta6_Test_sample/CallAutomation_Beta6_Test_sample.csproj b/CallAutomation_Beta6_Test_sample/CallAutomation_Beta6_Test_sample.csproj new file mode 100644 index 00000000..3a12e8a5 --- /dev/null +++ b/CallAutomation_Beta6_Test_sample/CallAutomation_Beta6_Test_sample.csproj @@ -0,0 +1,23 @@ + + + + net8.0 + enable + enable + + + + + + + + + + ..\..\..\SDK\azure-sdk-for-net\artifacts\bin\Azure.Communication.CallAutomation\Debug\netstandard2.0\Azure.Communication.CallAutomation.dll + + + ..\..\..\SDK\azure-sdk-for-net\artifacts\bin\Azure.Communication.Common\Debug\netstandard2.0\Azure.Communication.Common.dll + + + + diff --git a/CallAutomation_Beta6_Test_sample/CallAutomation_Beta6_Test_sample.sln b/CallAutomation_Beta6_Test_sample/CallAutomation_Beta6_Test_sample.sln new file mode 100644 index 00000000..23389da8 --- /dev/null +++ b/CallAutomation_Beta6_Test_sample/CallAutomation_Beta6_Test_sample.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35913.81 d17.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CallAutomation_Beta6_Test_sample", "CallAutomation_Beta6_Test_sample.csproj", "{F12FD9EE-4816-40A6-94EA-3DF5075E42E7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F12FD9EE-4816-40A6-94EA-3DF5075E42E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F12FD9EE-4816-40A6-94EA-3DF5075E42E7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F12FD9EE-4816-40A6-94EA-3DF5075E42E7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F12FD9EE-4816-40A6-94EA-3DF5075E42E7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {069D5CC6-E42C-4791-BCF3-7138896EDD10} + EndGlobalSection +EndGlobal diff --git a/CallAutomation_Beta6_Test_sample/ConfigurationRequest.cs b/CallAutomation_Beta6_Test_sample/ConfigurationRequest.cs new file mode 100644 index 00000000..d8e53084 --- /dev/null +++ b/CallAutomation_Beta6_Test_sample/ConfigurationRequest.cs @@ -0,0 +1,10 @@ +namespace CallAutomation_Beta6_Test_sample +{ + 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; + } +} \ No newline at end of file diff --git a/CallAutomation_Beta6_Test_sample/Helper.cs b/CallAutomation_Beta6_Test_sample/Helper.cs new file mode 100644 index 00000000..830f5903 --- /dev/null +++ b/CallAutomation_Beta6_Test_sample/Helper.cs @@ -0,0 +1,99 @@ +using Azure.Communication.CallAutomation; +using System.Net.WebSockets; +using System.Text; +using System.Text.Json; + +namespace CallAutomation_Beta6_Test_sample +{ + 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); + 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 + { + } + } + } +} \ No newline at end of file diff --git a/CallAutomation_Beta6_Test_sample/Program.cs b/CallAutomation_Beta6_Test_sample/Program.cs new file mode 100644 index 00000000..8f24d336 --- /dev/null +++ b/CallAutomation_Beta6_Test_sample/Program.cs @@ -0,0 +1,2573 @@ +using Azure.Communication; +using Azure.Communication.CallAutomation; +using Azure.Messaging; +using Azure.Messaging.EventGrid; +using Azure.Messaging.EventGrid.SystemEvents; +using CallAutomation_Beta6_Test_sample; +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; +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)); + } + + acsConnectionString = configuration.AcsConnectionString; + cognitiveServicesEndpoint = configuration.CongnitiveServiceEndpoint; + acsPhoneNumber = configuration.AcsPhoneNumber; + callbackUriHost = configuration.CallbackUriHost; + 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 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}"); + } + } + 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("/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"); + +# 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", 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 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 + +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(); \ No newline at end of file diff --git a/CallAutomation_Beta6_Test_sample/Properties/launchSettings.json b/CallAutomation_Beta6_Test_sample/Properties/launchSettings.json new file mode 100644 index 00000000..370280c7 --- /dev/null +++ b/CallAutomation_Beta6_Test_sample/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:6043", + "sslPort": 44349 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5072", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7286;http://localhost:5072", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/CallAutomation_Beta6_Test_sample/appsettings.Development.json b/CallAutomation_Beta6_Test_sample/appsettings.Development.json new file mode 100644 index 00000000..0c208ae9 --- /dev/null +++ b/CallAutomation_Beta6_Test_sample/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/CallAutomation_Beta6_Test_sample/appsettings.json b/CallAutomation_Beta6_Test_sample/appsettings.json new file mode 100644 index 00000000..10f68b8c --- /dev/null +++ b/CallAutomation_Beta6_Test_sample/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} From 8f522e18b92e79101120cebe3422801e597af9b7 Mon Sep 17 00:00:00 2001 From: Pilli Vamshi Date: Thu, 21 Aug 2025 21:06:52 +0530 Subject: [PATCH 2/3] Added changes. --- CallAutomation_Beta6_Test_sample/Helper.cs | 30 +- CallAutomation_Beta6_Test_sample/Program.cs | 3436 ++++++++++++------- 2 files changed, 2262 insertions(+), 1204 deletions(-) diff --git a/CallAutomation_Beta6_Test_sample/Helper.cs b/CallAutomation_Beta6_Test_sample/Helper.cs index 830f5903..7c091a73 100644 --- a/CallAutomation_Beta6_Test_sample/Helper.cs +++ b/CallAutomation_Beta6_Test_sample/Helper.cs @@ -30,7 +30,6 @@ public static async Task ProcessRequest(WebSocket webSocket) 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) @@ -39,7 +38,9 @@ public static async Task ProcessRequest(WebSocket webSocket) 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) + if (audioData.Participant != null + && !(audioData.Participant.RawId).Contains("87123")) + //&& !(audioData.Participant.RawId).Contains("2f6f-45f7-3a3a0d009a2d")) { Console.WriteLine("Participant Id-->" + audioData.Participant.RawId); } @@ -47,6 +48,18 @@ public static async Task ProcessRequest(WebSocket webSocket) Console.WriteLine("***************************************************************************************"); } + //if (response is DtmfData dtmfData) + //{ + // Console.WriteLine("***************************************************************************************"); + // Console.WriteLine("DATA-->" + dtmfData.Data); + // Console.WriteLine("TIMESTAMP-->" + dtmfData.Timestamp); + // if (dtmfData.Participant != null && dtmfData.Participant.RawId != null) + // { + // Console.WriteLine("Participant Id-->" + dtmfData.Participant.RawId); + // } + + // Console.WriteLine("***************************************************************************************"); + //} if (response is TranscriptionMetadata transcriptionMetadata) { Console.WriteLine("***************************************************************************************"); @@ -65,11 +78,16 @@ public static async Task ProcessRequest(WebSocket webSocket) Console.WriteLine("DURATION-->" + transcriptionData.Duration); Console.WriteLine("PARTICIPANT-->" + transcriptionData.Participant.RawId); Console.WriteLine("CONFIDENCE-->" + transcriptionData.Confidence); - foreach (var word in transcriptionData.Words) + + if (transcriptionData.Words != null) { - Console.WriteLine("WORDS TEXT-->" + word.Text); - Console.WriteLine("WORDS OFFSET-->" + word.Offset); - Console.WriteLine("WORDS DURATION-->" + word.Duration); + + 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("***************************************************************************************"); } diff --git a/CallAutomation_Beta6_Test_sample/Program.cs b/CallAutomation_Beta6_Test_sample/Program.cs index 8f24d336..e96db78e 100644 --- a/CallAutomation_Beta6_Test_sample/Program.cs +++ b/CallAutomation_Beta6_Test_sample/Program.cs @@ -5,6 +5,10 @@ using Azure.Messaging.EventGrid.SystemEvents; using CallAutomation_Beta6_Test_sample; using Microsoft.Extensions.FileProviders; +using System.Buffers.Text; +using System.Text; +using static System.Net.WebRequestMethods; +using static System.Runtime.InteropServices.JavaScript.JSType; var builder = WebApplication.CreateBuilder(args); @@ -16,47 +20,24 @@ 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 acsConnectionString = ""; +string cognitiveServicesEndpoint = ""; +string acsPhoneNumber = ""; + +string callbackUriHost = "https://9675p4k5-7286.inc1.devtunnels.ms"; +string fileSourceUri = "https://pixabay.com/sound-effects/countdown-from-10-190389/"; string callConnectionId = string.Empty; string recordingId = string.Empty; string recordingLocation = string.Empty; +string metadataLocation = string.Empty; string recordingFileFormat = string.Empty; Uri eventCallbackUri = null!; string callerId = string.Empty; +string roomCallId = 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)); - } - - acsConnectionString = configuration.AcsConnectionString; - cognitiveServicesEndpoint = configuration.CongnitiveServiceEndpoint; - acsPhoneNumber = configuration.AcsPhoneNumber; - callbackUriHost = configuration.CallbackUriHost; - 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."); +CallAutomationClient client = new CallAutomationClient(new Uri("https://uswe-03.sdf.pma.teams.microsoft.com"), connectionString: acsConnectionString); +//CallAutomationClient client = new CallAutomationClient(connectionString: acsConnectionString); app.MapPost("/api/events", async (EventGridEvent[] eventGridEvents, ILogger logger) => { @@ -82,10 +63,25 @@ $"Callback url: {callbackUri}"); eventCallbackUri = callbackUri; - + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + var mediaStreamingOptions = new MediaStreamingOptions( + MediaStreamingAudioChannel.Unmixed, StreamingTransport.Websocket) + { + StartMediaStreaming = false, + TransportUri = new Uri(websocketUri), + MediaStreamingContent = MediaStreamingContent.Audio, + }; + TranscriptionOptions transcriptionOptions = new TranscriptionOptions("en-us", StreamingTransport.Websocket) + { + StartTranscription = false, + TransportUri = new Uri(websocketUri) + }; var options = new AnswerCallOptions(incomingCallEventData.IncomingCallContext, callbackUri) { - CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) } + CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + //IsLoopbackAudioEnabled = true, + MediaStreamingOptions = mediaStreamingOptions, + TranscriptionOptions = transcriptionOptions }; AnswerCallResult answerCallResult = await client.AnswerCallAsync(options); @@ -95,7 +91,9 @@ if (eventData is AcsRecordingFileStatusUpdatedEventData statusUpdated) { recordingLocation = statusUpdated.RecordingStorageInfo.RecordingChunks[0].ContentLocation; + metadataLocation = statusUpdated.RecordingStorageInfo.RecordingChunks[0].MetadataLocation; logger.LogInformation($"The recording location is : {recordingLocation}"); + logger.LogInformation($"The recording metadata location is : {metadataLocation}"); } } } @@ -120,6 +118,7 @@ CallConnectionProperties callConnectionProperties = GetCallConnectionProperties(); logger.LogInformation("************************************************************"); logger.LogInformation($"CORRELATION ID: {callConnectionProperties.CorrelationId}"); + logger.LogInformation($"CALL CONNECTION ID: {callConnectionProperties.CallConnectionId}"); logger.LogInformation("************************************************************"); } else if (parsedEvent is ConnectFailed connectFailed) @@ -137,19 +136,27 @@ { case DtmfResult dtmfResult: var tones = dtmfResult.Tones; - logger.LogInformation("Recognize completed succesfully, tones={tones}", tones); + logger.LogInformation("Recognize completed successfully, 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); + //var languageIdentified = choiceResult.LanguageIdentified; + //var sentimentAnalysisResult = choiceResult.SentimentAnalysisResult.Sentiment; + //logger.LogInformation("Recognize completed successfully, labelDetected={labelDetected}, phraseDetected={phraseDetected}", labelDetected, phraseDetected); + //logger.LogInformation("Recognize Language Identified: {languageIdentified}", languageIdentified); + //logger.LogInformation("Recognize Sentiment Analysis: {sentimentAnalysisResult}", sentimentAnalysisResult); break; case SpeechResult speechResult: var text = speechResult.Speech; - logger.LogInformation("Recognize completed succesfully, text={text}", text); + //var identifiedLanguage = speechResult.LanguageIdentified; + //var sentimentAnalysis = speechResult.SentimentAnalysisResult.Sentiment; + logger.LogInformation("Recognize completed successfully, text={text}", text); + //logger.LogInformation("Recognize Language Identified: {identifiedLanguage}", identifiedLanguage); + //logger.LogInformation("Recognize Sentiment Analysis: {sentimentAnalysis}", sentimentAnalysis); break; default: - logger.LogInformation("Recognize completed succesfully, recognizeResult={recognizeResult}", recognizeCompleted.RecognizeResult); + logger.LogInformation("Recognize completed successfully, recognizeResult={recognizeResult}", recognizeCompleted.RecognizeResult); break; } } @@ -243,12 +250,42 @@ 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()}"); + // logger.LogInformation($"Operation Context: {holdAudioStarted.OperationContext}"); + // callConnectionId = holdAudioStarted.CallConnectionId; + //} + //else if (parsedEvent is HoldAudioPaused holdAudioPaused) + //{ + // logger.LogInformation($"Received call event: {holdAudioPaused.GetType()}"); + // logger.LogInformation($"Operation Context: {holdAudioPaused.OperationContext}"); + // callConnectionId = holdAudioPaused.CallConnectionId; + //} + //else if (parsedEvent is HoldAudioResumed holdAudioResumed) + //{ + // logger.LogInformation($"Received call event: {holdAudioResumed.GetType()}"); + // logger.LogInformation($"Operation Context: {holdAudioResumed.OperationContext}"); + // callConnectionId = holdAudioResumed.CallConnectionId; + //} + //else if (parsedEvent is HoldAudioCompleted holdAudioCompleted) + //{ + // logger.LogInformation($"Received call event: {holdAudioCompleted.GetType()}"); + // logger.LogInformation($"Operation Context: {holdAudioCompleted.OperationContext}"); + // 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 ParticipantsUpdated participantsUpdated) + { + logger.LogInformation($"Received call event: {participantsUpdated.GetType()}"); + logger.LogInformation($"Operation Context: {participantsUpdated.OperationContext}"); + callConnectionId = participantsUpdated.CallConnectionId; + } else if (parsedEvent is TranscriptionStarted transcriptionStarted) { logger.LogInformation($"Received call event: {transcriptionStarted.GetType()}"); @@ -294,6 +331,9 @@ else if (parsedEvent is CallDisconnected callDisconnected) { logger.LogInformation($"Received call event: {callDisconnected.GetType()}"); + logger.LogInformation("************************************************************"); + logger.LogInformation($"CORRELATION ID: {callDisconnected.CorrelationId}"); + logger.LogInformation("************************************************************"); } else if (parsedEvent is CreateCallFailed createCallFailed) { @@ -323,28 +363,40 @@ #region Outbound Call -app.MapPost("/outboundCallToPstnAsync", async (string targetPhoneNumber, ILogger logger) => +app.MapPost("/outboundCallToTeamsExtensionAsync", async (string userId, string tenantId, string resourceId, string teamsAppId, ILogger logger) => { - PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); - PhoneNumberIdentifier caller = new PhoneNumberIdentifier(acsPhoneNumber); - + var target = new TeamsExtensionUserIdentifier(userId: userId, tenantId: tenantId, resourceId: resourceId); var callbackUri = new Uri(new Uri(callbackUriHost), "/api/callbacks"); eventCallbackUri = callbackUri; - CallInvite callInvite = new CallInvite(target, caller); - + CallInvite callInvite = new CallInvite(target); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + var mediaStreamingOptions = new MediaStreamingOptions( + MediaStreamingAudioChannel.Unmixed, StreamingTransport.Websocket) + { + StartMediaStreaming = false, + TransportUri = new Uri(websocketUri), + MediaStreamingContent = MediaStreamingContent.Audio, + }; + TranscriptionOptions transcriptionOptions = new TranscriptionOptions("en-us", StreamingTransport.Websocket) + { + StartTranscription = false, + TransportUri = new Uri(websocketUri) + }; var createCallOptions = new CreateCallOptions(callInvite, callbackUri) { CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, - + TeamsAppSource = new MicrosoftTeamsAppIdentifier(teamsAppId), + MediaStreamingOptions = mediaStreamingOptions, + TranscriptionOptions = transcriptionOptions }; - CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); - logger.LogInformation($"Created async pstn call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); + logger.LogInformation($"Created async call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); + }).WithTags("Create Outbound Call APIs"); -app.MapPost("/outboundCallToPstn", (string targetPhoneNumber, ILogger logger) => +app.MapPost("/outboundCallToPstnAsync", async (string targetPhoneNumber, bool isEnableLoopbackAudio, ILogger < Program> logger) => { PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); PhoneNumberIdentifier caller = new PhoneNumberIdentifier(acsPhoneNumber); @@ -354,27 +406,92 @@ eventCallbackUri = callbackUri; CallInvite callInvite = new CallInvite(target, caller); + var websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + var mediaStreamingOptions = new MediaStreamingOptions( + MediaStreamingAudioChannel.Unmixed, StreamingTransport.Websocket) + { + StartMediaStreaming = false, + TransportUri = new Uri(websocketUri), + MediaStreamingContent = MediaStreamingContent.Audio, + }; + TranscriptionOptions transcriptionOptions = new TranscriptionOptions("en-us", StreamingTransport.Websocket) + { + StartTranscription = false, + TransportUri = new Uri(websocketUri) + }; var createCallOptions = new CreateCallOptions(callInvite, callbackUri) { CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, - + TranscriptionOptions = transcriptionOptions, + MediaStreamingOptions = mediaStreamingOptions, + //IsLoopbackAudioEnabled = isEnableLoopbackAudio, }; - CreateCallResult createCallResult = client.CreateCall(createCallOptions); + CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); - logger.LogInformation($"Created call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); + logger.LogInformation($"Created async pstn call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); }).WithTags("Create Outbound Call APIs"); + + +//app.MapPost("/outboundCallToPstn", (string targetPhoneNumber, bool isEnableLoopbackAudio, 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"; +// var mediaStreamingOptions = new MediaStreamingOptions( +// MediaStreamingAudioChannel.Unmixed, StreamingTransport.Websocket) +// { +// StartMediaStreaming = false, +// TransportUri = new Uri(websocketUri), +// MediaStreamingContent = MediaStreamingContent.Audio, +// }; +// TranscriptionOptions transcriptionOptions = new TranscriptionOptions("en-us", StreamingTransport.Websocket) +// { +// StartTranscription = false, +// TransportUri = new Uri(websocketUri) +// }; + +// var createCallOptions = new CreateCallOptions(callInvite, callbackUri) +// { +// CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, +// //EnableLoopbackAudio = isEnableLoopbackAudio +// }; + +// 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 websocketUri = callbackUriHost.Replace("https", "wss") + "/ws"; + var mediaStreamingOptions = new MediaStreamingOptions( + MediaStreamingAudioChannel.Unmixed, StreamingTransport.Websocket) + { + StartMediaStreaming = true, + TransportUri = new Uri(websocketUri), + MediaStreamingContent = MediaStreamingContent.Audio, + }; + TranscriptionOptions transcriptionOptions = new TranscriptionOptions("en-us", StreamingTransport.Websocket) + { + StartTranscription = false, + TransportUri = new Uri(websocketUri) + }; var createCallOptions = new CreateCallOptions(callInvite, callbackUri) { CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, - + //MediaStreamingOptions = mediaStreamingOptions, + //TranscriptionOptions = transcriptionOptions, + OperationContext = "OutboundCallToAcsAsync" }; CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); @@ -382,22 +499,22 @@ 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)); +//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) }, +// var createCallOptions = new CreateCallOptions(callInvite, callbackUri) +// { +// CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, - }; +// }; - CreateCallResult createCallResult = client.CreateCall(createCallOptions); +// CreateCallResult createCallResult = client.CreateCall(createCallOptions); - logger.LogInformation($"Created acs call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); -}).WithTags("Create Outbound Call APIs"); +// logger.LogInformation($"Created acs call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +//}).WithTags("Create Outbound Call APIs"); app.MapPost("/outboundCallToTeamsAsync", async (string teamsObjectId, ILogger logger) => { @@ -437,27 +554,39 @@ #region Group Call -app.MapPost("/createGroupCallAsync", async (string targetPhoneNumber, ILogger logger) => +app.MapPost("/createGroupCallAsync", async (string targetPhoneNumber, string acsTarget, bool isEnableLoopbackAudio, ILogger logger) => { PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); PhoneNumberIdentifier sourceCallerId = new PhoneNumberIdentifier(acsPhoneNumber); + CommunicationUserIdentifier acsTargetIdentifier = new CommunicationUserIdentifier(acsTarget); 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 + target, + acsTargetIdentifier }; + var mediaStreamingOptions = new MediaStreamingOptions( + MediaStreamingAudioChannel.Unmixed, StreamingTransport.Websocket) + { + StartMediaStreaming = false, + TransportUri = new Uri(websocketUri), + MediaStreamingContent = MediaStreamingContent.Audio, + }; + TranscriptionOptions transcriptionOptions = new TranscriptionOptions("en-us", StreamingTransport.Websocket) + { + StartTranscription = false, + TransportUri = new Uri(websocketUri) + }; var createGroupCallOptions = new CreateGroupCallOptions(targets, callbackUri) { CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, SourceCallerIdNumber = sourceCallerId, + //IsLoopbackAudioEnabled = isEnableLoopbackAudio, MediaStreamingOptions = mediaStreamingOptions, TranscriptionOptions = transcriptionOptions }; @@ -467,21 +596,32 @@ logger.LogInformation($"Created async group call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); }).WithTags("Create Group Call APIs"); -app.MapPost("/createGroupCall", (string targetPhoneNumber, ILogger logger) => +app.MapPost("/createGroupCall", (string targetPhoneNumber, string acsTarget, bool isEnableLoopbackAudio, ILogger logger) => { PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); PhoneNumberIdentifier sourceCallerId = new PhoneNumberIdentifier(acsPhoneNumber); + CommunicationUserIdentifier acsTargetIdentifier = new CommunicationUserIdentifier(acsTarget); 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); + var mediaStreamingOptions = new MediaStreamingOptions( + MediaStreamingAudioChannel.Unmixed, StreamingTransport.Websocket) + { + StartMediaStreaming = false, + TransportUri = new Uri(websocketUri), + MediaStreamingContent = MediaStreamingContent.Audio, + }; + TranscriptionOptions transcriptionOptions = new TranscriptionOptions("en-us", StreamingTransport.Websocket) + { + StartTranscription = false, + TransportUri = new Uri(websocketUri) + }; IEnumerable targets = new List() { - target + target, + acsTargetIdentifier }; var createGroupCallOptions = new CreateGroupCallOptions(targets, callbackUri) @@ -489,7 +629,8 @@ CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, SourceCallerIdNumber = sourceCallerId, MediaStreamingOptions = mediaStreamingOptions, - TranscriptionOptions = transcriptionOptions + TranscriptionOptions = transcriptionOptions, + //IsLoopbackAudioEnabled = isEnableLoopbackAudio }; CreateCallResult createCallResult = client.CreateGroupCall(createGroupCallOptions); @@ -503,53 +644,23 @@ app.MapPost("/ConnectRoomCallAsync", async (string roomId, ILogger logger) => { + roomCallId = roomId; RoomCallLocator roomCallLocator = !string.IsNullOrEmpty(roomId) ? new RoomCallLocator(roomId) : throw new ArgumentNullException(nameof(roomId)); 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); - ConnectCallOptions connectCallOptions = new ConnectCallOptions(roomCallLocator, callbackUri) + MediaStreamingOptions mediaStreamingOptions = new MediaStreamingOptions(MediaStreamingAudioChannel.Unmixed, StreamingTransport.Websocket) { - CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, - OperationContext = "ConnectRoomCallContext", - MediaStreamingOptions = mediaStreamingOptions, - TranscriptionOptions = transcriptionOptions + TransportUri = new Uri(websocketUri), + MediaStreamingContent = MediaStreamingContent.Audio, + StartMediaStreaming = false }; - 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) + TranscriptionOptions transcriptionOptions = new TranscriptionOptions("en-us", StreamingTransport.Websocket) { - CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, - OperationContext = "ConnectRoomCallContext", - MediaStreamingOptions = mediaStreamingOptions, - TranscriptionOptions = transcriptionOptions + TransportUri = new Uri(websocketUri), + StartTranscription = false }; - 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) + ConnectCallOptions connectCallOptions = new ConnectCallOptions(roomCallLocator, callbackUri) { CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, OperationContext = "ConnectRoomCallContext", @@ -557,69 +668,109 @@ 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}"); + logger.LogInformation($"Connected room 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"); +//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 @@ -627,191 +778,236 @@ 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, - }; +CallConnection callConnection = GetConnection(); +//CallInvite callInvite = new CallInvite(new PhoneNumberIdentifier(pstnParticipant), new PhoneNumberIdentifier(acsPhoneNumber)); - var result = await callConnection.AddParticipantAsync(addParticipantOptions); - return Results.Ok(result); +//ops +CallInvite callInvite = new CallInvite(new PhoneNumberIdentifier(pstnParticipant), null); +var addParticipantOptions = new AddParticipantOptions(callInvite) +{ +OperationContext = "addPstnUserContext", +InvitationTimeoutInSeconds = 60, +OperationCallbackUri = eventCallbackUri + +}; + +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, - }; +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); +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, - }; +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); +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, - }; +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); +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, - }; +CallConnection callConnection = GetConnection(); +CallInvite callInvite = new CallInvite(new MicrosoftTeamsUserIdentifier(teamsObjectId)); +callInvite.CustomCallingContext.AddSipUui("OBOuuivalue"); +callInvite.CustomCallingContext.AddSipX("XheaderOBO", "value"); + +// Create TeamsPhoneCallerDetails +var teamsPhoneCallerDetails = new TeamsPhoneCallerDetails(new MicrosoftTeamsUserIdentifier(teamsObjectId), name: "John Doe", phoneNumber: "+14256451678"); +teamsPhoneCallerDetails.AdditionalCallerInformation.Add("Department", "Sales"); +teamsPhoneCallerDetails.AdditionalCallerInformation.Add("Priority", "High"); + +// Create TeamsPhoneSourceDetails +var teamsPhoneSourceDetails = new TeamsPhoneSourceDetails(new MicrosoftTeamsUserIdentifier(teamsObjectId), language: "en-US", status: "Active"); + +// Create TeamsPhoneCallDetails +var teamsPhoneCallDetails = new TeamsPhoneCallDetails() +{ +TeamsPhoneCallerDetails = teamsPhoneCallerDetails, +TeamsPhoneSourceDetails = teamsPhoneSourceDetails, +SessionId = "session-123-abc", +Intent = "Sales Inquiry", +CallTopic = "New Product Information", +CallContext = "Customer is interested in our latest product line", +CallSentiment = "Positive", +SuggestedActions = "Offer product demo, Schedule follow-up" +}; + +callInvite.CustomCallingContext.SetTeamsPhoneCallDetails(teamsPhoneCallDetails); - var result = await callConnection.AddParticipantAsync(addParticipantOptions); - return Results.Ok(result); +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("/addDuelPersonaParticipantAsync", async (string userId, string tenantId, string ResourceId, ILogger logger) => +{ +CallConnection callConnection = GetConnection(); +CallInvite callInvite = new CallInvite(new TeamsExtensionUserIdentifier(userId, tenantId, ResourceId)); +var addParticipantOptions = new AddParticipantOptions(callInvite) +{ +OperationContext = "addDuelPersonaUserContext", +InvitationTimeoutInSeconds = 30, +}; + +var result = await callConnection.AddParticipantAsync(addParticipantOptions); +logger.LogInformation($"Added Duel Persona participant with user id: {userId}"); +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, - }; +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); +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" - }; +CallConnection callConnection = GetConnection(); +RemoveParticipantOptions removeParticipantOptions = new RemoveParticipantOptions(new PhoneNumberIdentifier(pstnTarget)) +{ +OperationContext = "removePstnParticipantContext" +}; - await callConnection.RemoveParticipantAsync(removeParticipantOptions); - return Results.Ok(); +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 callConnection = GetConnection(); +RemoveParticipantOptions removeParticipantOptions = new RemoveParticipantOptions(new PhoneNumberIdentifier(pstnTarget)) +{ +OperationContext = "removePstnParticipantContext" +}; - callConnection.RemoveParticipant(removeParticipantOptions); - return Results.Ok(); +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" - }; +CallConnection callConnection = GetConnection(); +RemoveParticipantOptions removeParticipantOptions = new RemoveParticipantOptions(new CommunicationUserIdentifier(acsTarget)) +{ +OperationContext = "removeAcsParticipantContext" +}; - await callConnection.RemoveParticipantAsync(removeParticipantOptions); - return Results.Ok(); +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 callConnection = GetConnection(); +RemoveParticipantOptions removeParticipantOptions = new RemoveParticipantOptions(new CommunicationUserIdentifier(acsTarget)) +{ +OperationContext = "removeAcsParticipantContext" +}; - callConnection.RemoveParticipant(removeParticipantOptions); - return Results.Ok(); +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" - }; +CallConnection callConnection = GetConnection(); +RemoveParticipantOptions removeParticipantOptions = new RemoveParticipantOptions(new MicrosoftTeamsUserIdentifier(teamsObjectId)) +{ +OperationContext = "removeTeamsParticipantContext" +}; - await callConnection.RemoveParticipantAsync(removeParticipantOptions); - return Results.Ok(); +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 callConnection = GetConnection(); +RemoveParticipantOptions removeParticipantOptions = new RemoveParticipantOptions(new MicrosoftTeamsUserIdentifier(teamsObjectId)) +{ +OperationContext = "removeTeamsParticipantContext" +}; - callConnection.RemoveParticipantAsync(removeParticipantOptions); - return Results.Ok(); +callConnection.RemoveParticipantAsync(removeParticipantOptions); +return Results.Ok(); }).WithTags("Add/Remove Participant APIs"); app.MapPost("/cancelAddParticipantAsync", async (string invitationId, ILogger logger) => { - CallConnection callConnection = GetConnection(); +CallConnection callConnection = GetConnection(); - CancelAddParticipantOperationOptions cancelAddParticipantOperationOptions = new CancelAddParticipantOperationOptions(invitationId) - { - OperationContext = "CancelAddingParticipantContext" - }; - var result = await callConnection.CancelAddParticipantOperationAsync(cancelAddParticipantOperationOptions); +CancelAddParticipantOperationOptions cancelAddParticipantOperationOptions = new CancelAddParticipantOperationOptions(invitationId) +{ +OperationContext = "CancelAddingParticipantContext" +}; +var result = await callConnection.CancelAddParticipantOperationAsync(cancelAddParticipantOperationOptions); - return Results.Ok(result); +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); +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) => +app.MapPost("/playTextSourceToPstnTargetAsync", async (string pstnTarget, bool isLoop, ILogger logger) => { CallMedia callMedia = GetCallMedia(); @@ -823,7 +1019,9 @@ List playTo = new List { new PhoneNumberIdentifier(pstnTarget) }; PlayOptions playToOptions = new PlayOptions(textSource, playTo) { - OperationContext = "playToContext" + OperationContext = "playToContext", + OperationCallbackUri = eventCallbackUri, // Set the callback URI for operation events + Loop = isLoop, // Set Loop to true or false based on the input parameter, }; await callMedia.PlayAsync(playToOptions); @@ -831,7 +1029,7 @@ return Results.Ok(); }).WithTags("Play TextSource Media APIs"); -app.MapPost("/playTextSourceToPstnTarget", (string pstnTarget, ILogger logger) => +app.MapPost("/playTextSourceToPstnTarget", (string pstnTarget, bool isLoop, ILogger logger) => { CallMedia callMedia = GetCallMedia(); @@ -843,7 +1041,9 @@ List playTo = new List { new PhoneNumberIdentifier(pstnTarget) }; PlayOptions playToOptions = new PlayOptions(textSource, playTo) { - OperationContext = "playToContext" + OperationContext = "playToContext", + OperationCallbackUri = eventCallbackUri, + Loop = isLoop // Set Loop to true or false based on the input parameter }; callMedia.Play(playToOptions); @@ -851,7 +1051,87 @@ return Results.Ok(); }).WithTags("Play TextSource Media APIs"); -app.MapPost("/playTextSourceAcsTargetAsync", async (string acsTarget, ILogger logger) => +//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 (bool isLoop, bool isInterruptCallMediaOperation, ILogger logger) => { CallMedia callMedia = GetCallMedia(); @@ -860,18 +1140,19 @@ VoiceName = "en-US-NancyNeural" }; - List playTo = new List { new CommunicationUserIdentifier(acsTarget) }; - PlayOptions playToOptions = new PlayOptions(textSource, playTo) + PlayToAllOptions playToAllOptions = new PlayToAllOptions(textSource) { - OperationContext = "playToContext" + OperationContext = "playToAllContext", + OperationCallbackUri = eventCallbackUri, // Set the callback URI for operation events + Loop = isLoop, // Set Loop to true or false based on the input parameter + InterruptCallMediaOperation = isInterruptCallMediaOperation // Set to true if you want to allow barge-in }; - - await callMedia.PlayAsync(playToOptions); + await callMedia.PlayToAllAsync(playToAllOptions); return Results.Ok(); }).WithTags("Play TextSource Media APIs"); -app.MapPost("/playTextSourceToAcsTarget", (string acsTarget, ILogger logger) => +app.MapPost("/playTextSourceToAll", (bool isLoop, bool isInterruptCallMediaOperation, ILogger logger) => { CallMedia callMedia = GetCallMedia(); @@ -880,671 +1161,1022 @@ VoiceName = "en-US-NancyNeural" }; - List playTo = new List { new CommunicationUserIdentifier(acsTarget) }; - PlayOptions playToOptions = new PlayOptions(textSource, playTo) + PlayToAllOptions playToAllOptions = new PlayToAllOptions(textSource) { - OperationContext = "playToContext" + OperationContext = "playToAllContext", + OperationCallbackUri = eventCallbackUri, + Loop = isLoop, + InterruptCallMediaOperation = isInterruptCallMediaOperation // Set to true if you want to allow barge-in }; - - callMedia.Play(playToOptions); + callMedia.PlayToAll(playToAllOptions); 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); +//app.MapPost("/playTextSourceBargeInAsync", async (ILogger logger) => +//{ +// CallMedia callMedia = GetCallMedia(); - return Results.Ok(); -}).WithTags("Play FileSource Media APIs"); +// TextSource textSource = new TextSource("Hi, this is barge in test played through play source thanks. Goodbye!.") +// { +// VoiceName = "en-US-NancyNeural" +// }; -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); +// PlayToAllOptions playToAllOptions = new PlayToAllOptions(textSource) +// { +// OperationContext = "playToAllContext", +// InterruptCallMediaOperation = true +// }; +// await callMedia.PlayToAllAsync(playToAllOptions); - return Results.Ok(); -}).WithTags("Play FileSource Media APIs"); +// return Results.Ok(); +//}).WithTags("Play TextSource 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); +//# 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 Play Media With Multiple Play Source + +//app.MapPost("/playMultipleSourceToPstnTargetAsync", async (string pstnTarget, bool isLoop, ILogger logger) => +//{ +// CallMedia callMedia = GetCallMedia(); + +// TextSource textSource = new TextSource("Hi, this is test source played through play source thanks. Goodbye!.") +// { +// VoiceName = "en-US-NancyNeural" +// }; +// SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); +// FileSource fileSource = new FileSource(new Uri(fileSourceUri)); +// List playTo = new List { new PhoneNumberIdentifier(pstnTarget) }; +// List playSources = new List +// { +// textSource, +// ssmlSource, +// //fileSource +// }; +// PlayOptions playToOptions = new PlayOptions(playSources, playTo) +// { +// OperationContext = "playToContext", +// OperationCallbackUri = eventCallbackUri, // Set the callback URI for operation events +// Loop = isLoop // Set Loop to true or false based on the input parameter + +// }; + +// await callMedia.PlayAsync(playToOptions); + +// return Results.Ok(); +//}).WithTags("Play Multiple Source Media APIs"); + +//app.MapPost("/playMultipleSourceToPstnTarget", (string pstnTarget, bool isLoop, ILogger logger) => +//{ +// CallMedia callMedia = GetCallMedia(); + +// TextSource textSource = new TextSource("Hi, this is test source played through play source thanks. Goodbye!.") +// { +// VoiceName = "en-US-NancyNeural" +// }; +// SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); +// FileSource fileSource = new FileSource(new Uri(fileSourceUri)); +// List playSources = new List +// { +// textSource, +// ssmlSource, +// //fileSource +// }; +// List playTo = new List { new PhoneNumberIdentifier(pstnTarget) }; +// PlayOptions playToOptions = new PlayOptions(playSources, playTo) +// { +// OperationContext = "playToContext", +// OperationCallbackUri = eventCallbackUri, +// Loop = isLoop // Set Loop to true or false based on the input parameter +// }; + +// callMedia.Play(playToOptions); + +// return Results.Ok(); +//}).WithTags("Play Multiple Source Media APIs"); + +//app.MapPost("/playMultipleSourceToAllAsync", async (bool isLoop, ILogger logger) => +//{ +// CallMedia callMedia = GetCallMedia(); + +// TextSource textSource = new TextSource("Hi, this is test source played through play source thanks. Goodbye!.") +// { +// VoiceName = "en-US-NancyNeural" +// }; +// SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); +// FileSource fileSource = new FileSource(new Uri(fileSourceUri)); +// List playSources = new List +//{ +// textSource, +// ssmlSource, +// //fileSource +//}; +// PlayToAllOptions playToAllOptions = new PlayToAllOptions(playSources) +// { +// OperationContext = "playToAllContext", +// OperationCallbackUri = eventCallbackUri, // Set the callback URI for operation events +// Loop = isLoop // Set Loop to true or false based on the input parameter +// }; +// await callMedia.PlayToAllAsync(playToAllOptions); + +// return Results.Ok(); +//}).WithTags("Play Multiple Source Media APIs"); + +//app.MapPost("/playMultipleSourceToAll", (bool isLoop, ILogger logger) => +//{ +// CallMedia callMedia = GetCallMedia(); + +// TextSource textSource = new TextSource("Hi, this is test source played through play source thanks. Goodbye!.") +// { +// VoiceName = "en-US-NancyNeural" +// }; +// SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); +// FileSource fileSource = new FileSource(new Uri(fileSourceUri)); +// List playSources = new List +//{ +// textSource, +// ssmlSource, +// //fileSource +//}; +// PlayToAllOptions playToAllOptions = new PlayToAllOptions(playSources) +// { +// OperationContext = "playToAllContext", +// OperationCallbackUri = eventCallbackUri, +// Loop = isLoop +// }; +// callMedia.PlayToAll(playToAllOptions); + +// return Results.Ok(); +//}).WithTags("Play Multiple Source 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 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); +// var target = new CommunicationUserIdentifier(pstnTarget); - return Results.Ok(); -}).WithTags("Start Recognization APIs"); +// var recognizeOptions = +// new CallMediaRecognizeDtmfOptions( +// targetParticipant: target, maxTonesToCollect: 4) +// { +// InterruptPrompt = false, +// InterToneTimeout = TimeSpan.FromSeconds(5), +// OperationContext = "DtmfContext", +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// Prompt = textSource +// }; -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" - }; +// callMedia.StartRecognizing(recognizeOptions); - var target = new PhoneNumberIdentifier(pstnTarget); +// return Results.Ok(); +//}).WithTags("Start Recognization APIs"); - 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("/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 CommunicationUserIdentifier(pstnTarget); + +// var recognizeOptions = new CallMediaRecognizeSpeechOptions(targetParticipant: target) +// { +// InterruptPrompt = false, +// OperationContext = "SpeechContext", +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// Prompt = textSource, +// EndSilenceTimeout = TimeSpan.FromSeconds(5), +// IsSentimentAnalysisEnabled = true, +// SpeechLanguages = new List { "en-US", "en-IN" }, +// OperationCallbackUri = eventCallbackUri +// }; + +// 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 CommunicationUserIdentifier(pstnTarget); + +// var recognizeOptions = new CallMediaRecognizeSpeechOptions(targetParticipant: target) +// { +// InterruptPrompt = false, +// OperationContext = "SpeechContext", +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// Prompt = textSource, +// EndSilenceTimeout = TimeSpan.FromSeconds(5), +// IsSentimentAnalysisEnabled = true, +// SpeechLanguages = new List { "en-US", "en-IN" }, +// OperationCallbackUri = eventCallbackUri +// }; + +// 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 CommunicationUserIdentifier(pstnTarget); + +// var recognizeOptions = +// new CallMediaRecognizeSpeechOrDtmfOptions( +// targetParticipant: target, maxTonesToCollect: 4) +// { +// InterruptPrompt = false, +// OperationContext = "SpeechOrDTMFContext", +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// Prompt = textSource, +// EndSilenceTimeout = TimeSpan.FromSeconds(5), +// IsSentimentAnalysisEnabled = true, +// SpeechLanguages = new List { "en-US", "en-IN" }, +// OperationCallbackUri = eventCallbackUri +// }; +// 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 CommunicationUserIdentifier(pstnTarget); + +// var recognizeOptions = +// new CallMediaRecognizeSpeechOrDtmfOptions( +// targetParticipant: target, maxTonesToCollect: 4) +// { +// InterruptPrompt = false, +// OperationContext = "SpeechOrDTMFContext", +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// Prompt = textSource, +// EndSilenceTimeout = TimeSpan.FromSeconds(5), +// IsSentimentAnalysisEnabled = true, +// SpeechLanguages = new List { "en-US", "en-IN" }, +// OperationCallbackUri = eventCallbackUri +// }; +// 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" +// }; -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 CommunicationUserIdentifier(pstnTarget); - var target = new PhoneNumberIdentifier(pstnTarget); +// var recognizeOptions = +// new CallMediaRecognizeChoiceOptions(targetParticipant: target, GetChoices()) +// { +// InterruptCallMediaOperation = false, +// InterruptPrompt = false, +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// Prompt = textSource, +// OperationContext = "ChoiceContext", +// IsSentimentAnalysisEnabled = true, +// SpeechLanguages = new List { "en-US", "en-IN" }, +// OperationCallbackUri = eventCallbackUri +// }; - var recognizeOptions = - new CallMediaRecognizeChoiceOptions(targetParticipant: target, GetChoices()) - { - InterruptCallMediaOperation = false, - InterruptPrompt = false, - InitialSilenceTimeout = TimeSpan.FromSeconds(10), - Prompt = textSource, - OperationContext = "ChoiceContext" - }; +// await callMedia.StartRecognizingAsync(recognizeOptions); - await callMedia.StartRecognizingAsync(recognizeOptions); +// return Results.Ok(); +//}).WithTags("Start Recognization APIs"); - 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" +// }; -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 CommunicationUserIdentifier(pstnTarget); - var target = new PhoneNumberIdentifier(pstnTarget); +// var recognizeOptions = +// new CallMediaRecognizeChoiceOptions(targetParticipant: target, GetChoices()) +// { +// InterruptCallMediaOperation = false, +// InterruptPrompt = false, +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// Prompt = textSource, +// OperationContext = "ChoiceContext", +// IsSentimentAnalysisEnabled = true, +// SpeechLanguages = new List { "en-US", "en-IN" }, +// OperationCallbackUri = eventCallbackUri +// }; - var recognizeOptions = - new CallMediaRecognizeChoiceOptions(targetParticipant: target, GetChoices()) - { - InterruptCallMediaOperation = false, - InterruptPrompt = false, - InitialSilenceTimeout = TimeSpan.FromSeconds(10), - Prompt = textSource, - OperationContext = "ChoiceContext" - }; +// callMedia.StartRecognizingAsync(recognizeOptions); - callMedia.StartRecognizingAsync(recognizeOptions); +// return Results.Ok(); +//}).WithTags("Start Recognization APIs"); - return Results.Ok(); -}).WithTags("Start Recognization APIs"); +//#endregion -#endregion -# region DTMF +//#region Recognization multiple play sources -app.MapPost("/sendDTMFTonesAsync", async (string pstnTarget, ILogger logger) => -{ - CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); +//app.MapPost("/recognizeDTMFWithMultiplePlaySourcesAsync", 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" +// }; +// SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); +// FileSource fileSource = new FileSource(new Uri(fileSourceUri)); +// List playSources = new List +// { +// textSource, +// //fileSource, +// ssmlSource +// }; +// var target = new CommunicationUserIdentifier(pstnTarget); + +// var recognizeOptions = +// new CallMediaRecognizeDtmfOptions( +// targetParticipant: target, maxTonesToCollect: 4) +// { +// InterruptPrompt = false, +// InterToneTimeout = TimeSpan.FromSeconds(5), +// OperationContext = "DtmfContext", +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// //Prompt = textSource, +// PlayPrompts = playSources, +// }; + +// await callMedia.StartRecognizingAsync(recognizeOptions); + +// return Results.Ok(); +//}).WithTags("Start Recognization APIs"); + +//app.MapPost("/recognizeDTMFWithMultiplePlaySources", (string pstnTarget, ILogger logger) => +//{ +// CallMedia callMedia = GetCallMedia(); +// TextSource textSource = new TextSource("Hi, this is recognize test. please provide input thanks!.") +// { +// VoiceName = "en-US-NancyNeural" +// }; +// SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); +// FileSource fileSource = new FileSource(new Uri(fileSourceUri)); +// List playSources = new List +// { +// textSource, +// //fileSource, +// ssmlSource +// }; +// var target = new CommunicationUserIdentifier(pstnTarget); + +// var recognizeOptions = +// new CallMediaRecognizeDtmfOptions( +// targetParticipant: target, maxTonesToCollect: 4) +// { +// InterruptPrompt = false, +// InterToneTimeout = TimeSpan.FromSeconds(5), +// OperationContext = "DtmfContext", +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// //Prompt = textSource, +// PlayPrompts = playSources, +// }; + +// callMedia.StartRecognizing(recognizeOptions); + +// return Results.Ok(); +//}).WithTags("Start Recognize with multiple play sources APIs"); + + +//app.MapPost("/recognizeSpeechWithMultiplePlaySourcesAsync", 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" +// }; +// SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); +// FileSource fileSource = new FileSource(new Uri(fileSourceUri)); +// List playSources = new List +// { +// textSource, +// //fileSource, +// ssmlSource +// }; +// var target = new CommunicationUserIdentifier(pstnTarget); + +// var recognizeOptions = new CallMediaRecognizeSpeechOptions(targetParticipant: target) +// { +// InterruptPrompt = false, +// OperationContext = "SpeechContext", +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// //Prompt = textSource, +// PlayPrompts = playSources, +// EndSilenceTimeout = TimeSpan.FromSeconds(5), +// IsSentimentAnalysisEnabled = true, +// SpeechLanguages = new List { "en-US", "en-IN" }, +// OperationCallbackUri = eventCallbackUri +// }; + +// await callMedia.StartRecognizingAsync(recognizeOptions); + +// return Results.Ok(); +//}).WithTags("Start Recognize with multiple play sources APIs"); + +//app.MapPost("/recognizeSpeechWithMultiplePlaySources", (string pstnTarget, ILogger logger) => +//{ +// CallMedia callMedia = GetCallMedia(); +// TextSource textSource = new TextSource("Hi, this is recognize test. please provide input thanks!.") +// { +// VoiceName = "en-US-NancyNeural" +// }; +// SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); +// FileSource fileSource = new FileSource(new Uri(fileSourceUri)); +// List playSources = new List +// { +// textSource, +// //fileSource, +// ssmlSource +// }; +// var target = new CommunicationUserIdentifier(pstnTarget); + +// var recognizeOptions = new CallMediaRecognizeSpeechOptions(targetParticipant: target) +// { +// InterruptPrompt = false, +// OperationContext = "SpeechContext", +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// //Prompt = textSource, +// PlayPrompts = playSources, +// EndSilenceTimeout = TimeSpan.FromSeconds(5), +// IsSentimentAnalysisEnabled = true, +// SpeechLanguages = new List { "en-US", "en-IN" }, +// OperationCallbackUri = eventCallbackUri +// }; + +// callMedia.StartRecognizing(recognizeOptions); + +// return Results.Ok(); +//}).WithTags("Start Recognize with multiple play sources APIs"); + +//app.MapPost("/recognizeSpeechOrDtmfWithMultiplePlaySourcesAsync", 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" +// }; +// SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); +// FileSource fileSource = new FileSource(new Uri(fileSourceUri)); +// List playSources = new List +// { +// textSource, +// //fileSource, +// ssmlSource +// }; +// var target = new CommunicationUserIdentifier(pstnTarget); + +// var recognizeOptions = +// new CallMediaRecognizeSpeechOrDtmfOptions( +// targetParticipant: target, maxTonesToCollect: 4) +// { +// InterruptPrompt = false, +// OperationContext = "SpeechOrDTMFContext", +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// //Prompt = textSource, +// PlayPrompts = playSources, +// EndSilenceTimeout = TimeSpan.FromSeconds(5), +// IsSentimentAnalysisEnabled = true, +// SpeechLanguages = new List { "en-US", "en-IN" }, +// OperationCallbackUri = eventCallbackUri +// }; +// await callMedia.StartRecognizingAsync(recognizeOptions); + +// return Results.Ok(); +//}).WithTags("Start Recognize with multiple play sources APIs"); + +//app.MapPost("/recognizeSpeechOrDtmfWithMultiplePlaySources", (string pstnTarget, ILogger logger) => +//{ +// CallMedia callMedia = GetCallMedia(); +// TextSource textSource = new TextSource("Hi, this is recognize test. please provide input thanks!.") +// { +// VoiceName = "en-US-NancyNeural" +// }; +// SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); +// FileSource fileSource = new FileSource(new Uri(fileSourceUri)); +// List playSources = new List +// { +// textSource, +// //fileSource, +// ssmlSource +// }; +// var target = new CommunicationUserIdentifier(pstnTarget); + +// var recognizeOptions = +// new CallMediaRecognizeSpeechOrDtmfOptions( +// targetParticipant: target, maxTonesToCollect: 4) +// { +// InterruptPrompt = false, +// OperationContext = "SpeechOrDTMFContext", +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// //Prompt = textSource, +// PlayPrompts = playSources, +// EndSilenceTimeout = TimeSpan.FromSeconds(5), +// IsSentimentAnalysisEnabled = true, +// SpeechLanguages = new List { "en-US", "en-IN" }, +// OperationCallbackUri = eventCallbackUri +// }; +// callMedia.StartRecognizingAsync(recognizeOptions); + +// return Results.Ok(); +//}).WithTags("Start Recognize with multiple play sources APIs"); + +//app.MapPost("/recognizeChoiceWithMultiplePlaySourcesAsync", 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" +// }; +// SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); +// FileSource fileSource = new FileSource(new Uri(fileSourceUri)); +// List playSources = new List +// { +// textSource, +// //fileSource, +// ssmlSource +// }; +// var target = new CommunicationUserIdentifier(pstnTarget); + + +// var recognizeOptions = +// new CallMediaRecognizeChoiceOptions(targetParticipant: target, GetChoices()) +// { +// InterruptCallMediaOperation = false, +// InterruptPrompt = false, +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// //Prompt = textSource, +// PlayPrompts = playSources, +// OperationContext = "ChoiceContext", +// IsSentimentAnalysisEnabled = true, +// SpeechLanguages = new List { "en-US", "en-IN" }, +// OperationCallbackUri = eventCallbackUri +// }; + + +// await callMedia.StartRecognizingAsync(recognizeOptions); + +// return Results.Ok(); +//}).WithTags("Start Recognize with multiple play sources APIs"); + +//app.MapPost("/recognizeChoiceWithMultiplePlaySources", (string pstnTarget, ILogger logger) => +//{ +// CallMedia callMedia = GetCallMedia(); +// TextSource textSource = new TextSource("Hi, this is recognize test. please provide input thanks!.") +// { +// VoiceName = "en-US-NancyNeural" +// }; +// SsmlSource ssmlSource = new SsmlSource("Hi, this is ssml test played through ssml source thanks. Goodbye!"); +// FileSource fileSource = new FileSource(new Uri(fileSourceUri)); +// List playSources = new List +// { +// textSource, +// //fileSource, +// ssmlSource +// }; +// var target = new CommunicationUserIdentifier(pstnTarget); + + +// var recognizeOptions = +// new CallMediaRecognizeChoiceOptions(targetParticipant: target, GetChoices()) +// { +// InterruptCallMediaOperation = false, +// InterruptPrompt = false, +// InitialSilenceTimeout = TimeSpan.FromSeconds(15), +// //Prompt = textSource, +// PlayPrompts = playSources, +// OperationContext = "ChoiceContext", +// IsSentimentAnalysisEnabled = true, +// SpeechLanguages = new List { "en-US", "en-IN" }, +// OperationCallbackUri = eventCallbackUri +// }; + +// callMedia.StartRecognizingAsync(recognizeOptions); + +// return Results.Ok(); +//}).WithTags("Start Recognize with multiple play sources 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 - }; +// List tones = new List +// { +// DtmfTone.Zero, +// DtmfTone.One +// }; - CallMedia callMedia = GetCallMedia(); +// CallMedia callMedia = GetCallMedia(); - await callMedia.SendDtmfTonesAsync(tones, target); - return Results.Ok(); -}).WithTags("Send or Start DTMF APIs"); +// 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); +//app.MapPost("/sendDTMFTones", (string pstnTarget, ILogger logger) => +//{ +// CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); - List tones = new List - { - DtmfTone.Zero, - DtmfTone.One - }; +// List tones = new List +// { +// DtmfTone.Zero, +// DtmfTone.One +// }; - CallMedia callMedia = GetCallMedia(); +// CallMedia callMedia = GetCallMedia(); - callMedia.SendDtmfTones(tones, target); - return Results.Ok(); -}).WithTags("Send or Start DTMF APIs"); +// 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); +//app.MapPost("/startContinuousDTMFTonesAsync", async (string pstnTarget, ILogger logger) => +//{ +// CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); - CallMedia callMedia = GetCallMedia(); +// CallMedia callMedia = GetCallMedia(); - await callMedia.StartContinuousDtmfRecognitionAsync(target); - return Results.Ok(); -}).WithTags("Send or Start DTMF APIs"); +// 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); +//app.MapPost("/startContinuousDTMFTones", (string pstnTarget, ILogger logger) => +//{ +// CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); - CallMedia callMedia = GetCallMedia(); +// CallMedia callMedia = GetCallMedia(); - callMedia.StartContinuousDtmfRecognition(target); - return Results.Ok(); -}).WithTags("Send or Start DTMF APIs"); +// 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); +//app.MapPost("/stopContinuousDTMFTonesAsync", async (string pstnTarget, ILogger logger) => +//{ +// CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); - CallMedia callMedia = GetCallMedia(); +// CallMedia callMedia = GetCallMedia(); - await callMedia.StopContinuousDtmfRecognitionAsync(target); - return Results.Ok(); -}).WithTags("Send or Start DTMF APIs"); +// 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); +//app.MapPost("/stopContinuousDTMFTones", (string pstnTarget, ILogger logger) => +//{ +// CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); - CallMedia callMedia = GetCallMedia(); +// CallMedia callMedia = GetCallMedia(); - callMedia.StopContinuousDtmfRecognition(target); - return Results.Ok(); -}).WithTags("Send or Start DTMF APIs"); +// callMedia.StopContinuousDtmfRecognition(target); +// return Results.Ok(); +//}).WithTags("Send or Start DTMF APIs"); -# endregion +//# endregion # region Hold/Unhold @@ -1579,9 +2211,40 @@ return Results.Ok(); }).WithTags("Hold Participant APIs"); -app.MapPost("/holdParticipant", (string pstnTarget, bool isPlaySource, ILogger logger) => -{ - CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); +////app.MapPost("/holdTeamsParticipantAsync", async (string teamsId, bool isPlaySource, ILogger logger) => +////{ +//// CommunicationIdentifier target = new MicrosoftTeamsUserIdentifier(teamsId); + +//// 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("/holdTPEParticipantAsync", async (string userId, string tenantId, string resourceId, bool isPlaySource, ILogger logger) => +{ + CommunicationIdentifier target = new TeamsExtensionUserIdentifier(userId, tenantId, resourceId); CallMedia callMedia = GetCallMedia(); TextSource textSource = new TextSource("You are on hold please wait..") @@ -1596,7 +2259,7 @@ PlaySource = textSource, OperationContext = "holdUserContext" }; - callMedia.Hold(holdOptions); + await callMedia.HoldAsync(holdOptions); } else { @@ -1604,12 +2267,43 @@ { OperationContext = "holdUserContext" }; - callMedia.Hold(holdOptions); + 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("/unholdParticipantAsync", async (string pstnTarget, ILogger logger) => { CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); @@ -1625,9 +2319,24 @@ return Results.Ok(); }).WithTags("Hold Participant APIs"); -app.MapPost("/unholdParticipant", (string pstnTarget, ILogger logger) => +////app.MapPost("/unholdTeamsParticipantAsync", async (string teamsId, ILogger logger) => +////{ +//// CommunicationIdentifier target = new MicrosoftTeamsUserIdentifier(teamsId); + +//// CallMedia callMedia = GetCallMedia(); + +//// UnholdOptions unholdOptions = new UnholdOptions(target) +//// { +//// OperationContext = "unholdUserContext" +//// }; + +//// await callMedia.UnholdAsync(unholdOptions); +//// return Results.Ok(); +////}).WithTags("Hold Participant APIs"); + +app.MapPost("/unholdTPEParticipantAsync", async (string userId, string tenantId, string resourceId, ILogger logger) => { - CommunicationIdentifier target = new PhoneNumberIdentifier(pstnTarget); + CommunicationIdentifier target = new TeamsExtensionUserIdentifier(userId, tenantId, resourceId); CallMedia callMedia = GetCallMedia(); @@ -1636,10 +2345,206 @@ OperationContext = "unholdUserContext" }; - callMedia.Unhold(unholdOptions); + 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("/holdParticipantWithoutOptionsAsync", 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) +// { +// await callMedia.HoldAsync(target, textSource); +// } +// else +// { +// await callMedia.HoldAsync(target, textSource); +// } + +// return Results.Ok(); +//}).WithTags("Hold Participant APIs"); + +////app.MapPost("/holdParticipantWithoutOptions", (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) +//// { +//// callMedia.Hold(target, textSource); +//// } +//// else +//// { +//// callMedia.Hold(target); +//// } + +//// return Results.Ok(); +////}).WithTags("Hold Participant APIs"); + + +//app.MapPost("/holdACSParticipantAsync", async (string acsTarget, bool isPlaySource, ILogger logger) => +//{ +// CommunicationIdentifier target = new CommunicationUserIdentifier(acsTarget); + +// 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("/holdACSParticipant", (string acsTarget, bool isPlaySource, ILogger logger) => +////{ +//// CommunicationIdentifier target = new CommunicationUserIdentifier(acsTarget); + +//// 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("/unholdACSParticipantAsync", async (string acsTarget, ILogger logger) => +//{ +// CommunicationIdentifier target = new CommunicationUserIdentifier(acsTarget); + +// CallMedia callMedia = GetCallMedia(); + +// UnholdOptions unholdOptions = new UnholdOptions(target) +// { +// OperationContext = "unholdUserContext" +// }; + +// await callMedia.UnholdAsync(unholdOptions); +// return Results.Ok(); +//}).WithTags("Hold Participant APIs"); + +////app.MapPost("/unholdACSParticipant", (string acsTarget, ILogger logger) => +////{ +//// CommunicationIdentifier target = new CommunicationUserIdentifier(acsTarget); + +//// CallMedia callMedia = GetCallMedia(); + +//// UnholdOptions unholdOptions = new UnholdOptions(target) +//// { +//// OperationContext = "unholdUserContext" +//// }; + +//// callMedia.Unhold(unholdOptions); +//// return Results.Ok(); +////}).WithTags("Hold Participant APIs"); + +//app.MapPost("/holdACSParticipantWithoutOptionsAsync", async (string acsTarget, bool isPlaySource, ILogger logger) => +//{ +// CommunicationIdentifier target = new CommunicationUserIdentifier(acsTarget); + +// CallMedia callMedia = GetCallMedia(); +// TextSource textSource = new TextSource("You are on hold please wait..") +// { +// VoiceName = "en-US-NancyNeural" +// }; + +// if (isPlaySource) +// { +// await callMedia.HoldAsync(target, textSource); +// } +// else +// { +// await callMedia.HoldAsync(target, textSource); +// } + +// return Results.Ok(); +//}).WithTags("Hold Participant APIs"); + +////app.MapPost("/holdAcsParticipantWithoutOptions", (string acsTarget, bool isPlaySource, ILogger logger) => +////{ +//// CommunicationIdentifier target = new CommunicationUserIdentifier(acsTarget); + +//// CallMedia callMedia = GetCallMedia(); +//// TextSource textSource = new TextSource("You are on hold please wait..") +//// { +//// VoiceName = "en-US-NancyNeural" +//// }; + +//// if (isPlaySource) +//// { +//// callMedia.Hold(target, textSource); +//// } +//// else +//// { +//// callMedia.Hold(target); +//// } + +//// return Results.Ok(); +////}).WithTags("Hold Participant APIs"); + # endregion #region Disconnect call @@ -1662,9 +2567,9 @@ # region Mute Particiapant -app.MapPost("/muteAcsParticipantAsync", async (string acsTarget, ILogger logger) => +app.MapPost("/muteTeamsParticipantAsync", async (string teamsId, ILogger logger) => { - CommunicationIdentifier target = new CommunicationUserIdentifier(acsTarget); + CommunicationIdentifier target = new MicrosoftTeamsUserIdentifier(teamsId); CallConnection callConnection = GetConnection(); @@ -1673,160 +2578,183 @@ return Results.Ok(); }).WithTags("Mute Participant APIs"); -app.MapPost("/muteAcsParticipant", (string acsTarget, ILogger logger) => + +app.MapPost("/muteDuelPersonaParticipantAsync", async (string userId, string tenantId, string resourceId, ILogger logger) => { - CommunicationIdentifier target = new CommunicationUserIdentifier(acsTarget); + CommunicationIdentifier target = new TeamsExtensionUserIdentifier(userId, tenantId, resourceId); CallConnection callConnection = GetConnection(); - callConnection.MuteParticipant(target); + await callConnection.MuteParticipantAsync(target); return Results.Ok(); }).WithTags("Mute Participant APIs"); -#endregion - -# region Media streaming - -app.MapPost("/createCallToPstnWithMediaStreamingAsync", async (string targetPhoneNumber, bool isEnableBidirectional, bool isPcm24kMono, ILogger logger) => +app.MapPost("/muteAcsParticipantAsync", async (string acsTarget, 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; + CommunicationIdentifier target = new CommunicationUserIdentifier(acsTarget); - var createCallOptions = new CreateCallOptions(callInvite, callbackUri) - { - CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, - MediaStreamingOptions = mediaStreamingOptions - }; + CallConnection callConnection = GetConnection(); - CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); + await callConnection.MuteParticipantAsync(target); - logger.LogInformation($"Created async pstn media streaming call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); -}).WithTags("Media streaming APIs"); + return Results.Ok(); +}).WithTags("Mute Participant APIs"); -app.MapPost("/createCallToPstnWithMediaStreaming", (string targetPhoneNumber, bool isEnableBidirectional, bool isPcm24kMono, ILogger logger) => +app.MapPost("/muteAcsParticipant", (string acsTarget, ILogger logger) => { - PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); - PhoneNumberIdentifier caller = new PhoneNumberIdentifier(acsPhoneNumber); + CommunicationIdentifier target = new CommunicationUserIdentifier(acsTarget); + CallConnection callConnection = GetConnection(); - 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; + callConnection.MuteParticipant(target); - var createCallOptions = new CreateCallOptions(callInvite, callbackUri) - { - CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, - MediaStreamingOptions = mediaStreamingOptions - }; + return Results.Ok(); +}).WithTags("Mute Participant APIs"); - CreateCallResult createCallResult = client.CreateCall(createCallOptions); +#endregion - logger.LogInformation($"Created async pstn media streaming call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); -}).WithTags("Media streaming APIs"); +# region Media streaming -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; +//app.MapPost("/createCallToPstnWithMediaStreamingAsync", async (string targetPhoneNumber, bool isEnableBidirectional, bool isPcm24kMono, ILogger logger) => +//{ +// PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); +// PhoneNumberIdentifier caller = new PhoneNumberIdentifier(acsPhoneNumber); - var createCallOptions = new CreateCallOptions(callInvite, callbackUri) - { - CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, - MediaStreamingOptions = mediaStreamingOptions - }; - CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); +// 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; - logger.LogInformation($"Created async acs call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); -}).WithTags("Media streaming APIs"); +// var createCallOptions = new CreateCallOptions(callInvite, callbackUri) +// { +// CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, +// MediaStreamingOptions = mediaStreamingOptions +// }; -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; +// CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); - var createCallOptions = new CreateCallOptions(callInvite, callbackUri) - { - CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, - MediaStreamingOptions = mediaStreamingOptions - }; +// logger.LogInformation($"Created async pstn media streaming call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +//}).WithTags("Media streaming APIs"); - CreateCallResult createCallResult = client.CreateCall(createCallOptions); +//app.MapPost("/createCallToPstnWithMediaStreaming", (string targetPhoneNumber, bool isEnableBidirectional, bool isPcm24kMono, ILogger logger) => +//{ +// PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); +// PhoneNumberIdentifier caller = new PhoneNumberIdentifier(acsPhoneNumber); - 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 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 - }; +// var createCallOptions = new CreateCallOptions(callInvite, callbackUri) +// { +// CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, +// MediaStreamingOptions = mediaStreamingOptions +// }; - CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); +// CreateCallResult createCallResult = client.CreateCall(createCallOptions); - logger.LogInformation($"Created async teams call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); -}).WithTags("Media streaming APIs"); +// logger.LogInformation($"Created async pstn media streaming 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; +//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 - }; +// var createCallOptions = new CreateCallOptions(callInvite, callbackUri) +// { +// CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, +// MediaStreamingOptions = mediaStreamingOptions +// }; - CreateCallResult createCallResult = client.CreateCall(createCallOptions); +// CreateCallResult createCallResult = client.CreateCall(createCallOptions); - logger.LogInformation($"Created teams call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); -}).WithTags("Media streaming APIs"); +// logger.LogInformation($"Created teams call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +//}).WithTags("Media streaming APIs"); app.MapPost("/startMediaStreamingAsync", async (ILogger logger) => @@ -1909,132 +2837,132 @@ #region Transcription -app.MapPost("/createCallToPstnWithTranscriptionAsync", async (string targetPhoneNumber, ILogger logger) => -{ - PhoneNumberIdentifier target = new PhoneNumberIdentifier(targetPhoneNumber); - PhoneNumberIdentifier caller = new PhoneNumberIdentifier(acsPhoneNumber); +//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", true, TranscriptionTransport.Websocket); +// 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 - }; +// var createCallOptions = new CreateCallOptions(callInvite, callbackUri) +// { +// CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, +// TranscriptionOptions = transcriptionOptions +// }; - CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); +// CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); - logger.LogInformation($"Created async pstn transcription call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); -}).WithTags("Transcription APIs"); +// 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); +//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 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 - }; +// 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); +// CreateCallResult createCallResult = client.CreateCall(createCallOptions); - logger.LogInformation($"Created pstn transcription call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); -}).WithTags("Transcription APIs"); +// 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); +//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 - }; +// var createCallOptions = new CreateCallOptions(callInvite, callbackUri) +// { +// CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, +// TranscriptionOptions = transcriptionOptions +// }; - CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); +// CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); - logger.LogInformation($"Created async acs transcription call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); -}).WithTags("Transcription APIs"); +// 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); +//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 - }; +// var createCallOptions = new CreateCallOptions(callInvite, callbackUri) +// { +// CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, +// TranscriptionOptions = transcriptionOptions +// }; - CreateCallResult createCallResult = client.CreateCall(createCallOptions); +// CreateCallResult createCallResult = client.CreateCall(createCallOptions); - logger.LogInformation($"Created acs transcription call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); -}).WithTags("Transcription APIs"); +// 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); +//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 - }; +// var createCallOptions = new CreateCallOptions(callInvite, callbackUri) +// { +// CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, +// TranscriptionOptions = transcriptionOptions +// }; - CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); +// CreateCallResult createCallResult = await client.CreateCallAsync(createCallOptions); - logger.LogInformation($"Created async teams transcription call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); -}).WithTags("Transcription APIs"); +// 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); +//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 - }; +// var createCallOptions = new CreateCallOptions(callInvite, callbackUri) +// { +// CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, +// TranscriptionOptions = transcriptionOptions +// }; - CreateCallResult createCallResult = client.CreateCall(createCallOptions); +// CreateCallResult createCallResult = client.CreateCall(createCallOptions); - logger.LogInformation($"Created teams transcription call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); -}).WithTags("Transcription APIs"); +// logger.LogInformation($"Created teams transcription call with connection id: {createCallResult.CallConnectionProperties.CallConnectionId}"); +//}).WithTags("Transcription APIs"); app.MapPost("/startTranscriptionAsync", async (ILogger logger) => { @@ -2105,7 +3033,11 @@ app.MapPost("/stopTranscriptionWithOptionsAsync", async (ILogger logger) => { CallMedia callMedia = GetCallMedia(); - await callMedia.StopTranscriptionAsync(); + StopTranscriptionOptions stopTranscriptionOptions = new StopTranscriptionOptions() + { + OperationContext = "StopTranscriptionContext" + }; + await callMedia.StopTranscriptionAsync(stopTranscriptionOptions); return Results.Ok(); }).WithTags("Transcription APIs"); @@ -2120,7 +3052,7 @@ #region Transfer Call -app.MapPost("/transferCallToPstnParticipantAsync", async (string pstnTransferTarget, string pstnTarget, ILogger logger) => +app.MapPost("/transferCallPstnToPstnParticipantAsync", async (string pstnTransferTarget, string pstnTarget, ILogger logger) => { CallConnection callConnection = GetConnection(); @@ -2128,12 +3060,28 @@ { OperationContext = "TransferCallContext", Transferee = new PhoneNumberIdentifier(pstnTarget), + OperationCallbackUri = eventCallbackUri }; await callConnection.TransferCallToParticipantAsync(transferToParticipantOptions); return Results.Ok(); }).WithTags("Transfer Call APIs"); +//app.MapPost("/transferCallPstnToACSParticipantAsync", async (string acsTransferTarget, string pstnTarget, ILogger logger) => +//{ +// CallConnection callConnection = GetConnection(); + +// TransferToParticipantOptions transferToParticipantOptions = new TransferToParticipantOptions(new CommunicationUserIdentifier(acsTransferTarget)) +// { +// OperationContext = "TransferCallContext", +// Transferee = new PhoneNumberIdentifier(pstnTarget), +// OperationCallbackUri = eventCallbackUri +// }; + +// await callConnection.TransferCallToParticipantAsync(transferToParticipantOptions); +// return Results.Ok(); +//}).WithTags("Transfer Call APIs"); + app.MapPost("/transferCallToPstnParticipant", (string pstnTransferTarget, string pstnTarget, ILogger logger) => { CallConnection callConnection = GetConnection(); @@ -2141,13 +3089,73 @@ TransferToParticipantOptions transferToParticipantOptions = new TransferToParticipantOptions(new PhoneNumberIdentifier(pstnTransferTarget)) { OperationContext = "TransferCallContext", - Transferee = new PhoneNumberIdentifier(pstnTarget), + Transferee = new PhoneNumberIdentifier(acsPhoneNumber), + OperationCallbackUri = eventCallbackUri }; callConnection.TransferCallToParticipant(transferToParticipantOptions); return Results.Ok(); }).WithTags("Transfer Call APIs"); +app.MapPost("/transferCallTPEToPSTNParticipantAsync", async (string userId, string tenantId, string resourceId, string pstnTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + TransferToParticipantOptions transferToParticipantOptions = new TransferToParticipantOptions(new PhoneNumberIdentifier(pstnTarget)) + { + OperationContext = "TransferCallContext", + Transferee = new TeamsExtensionUserIdentifier(userId, tenantId, resourceId), + OperationCallbackUri = eventCallbackUri + }; + + await callConnection.TransferCallToParticipantAsync(transferToParticipantOptions); + return Results.Ok(); +}).WithTags("Transfer Call APIs"); + +app.MapPost("/transferCallPSTNToTPEParticipantAsync", async (string userId, string tenantId, string resourceId, string pstnTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + TransferToParticipantOptions transferToParticipantOptions = new TransferToParticipantOptions(new TeamsExtensionUserIdentifier(userId, tenantId, resourceId)) + { + OperationContext = "TransferCallContext", + Transferee = new PhoneNumberIdentifier(pstnTarget), + OperationCallbackUri = eventCallbackUri + }; + + await callConnection.TransferCallToParticipantAsync(transferToParticipantOptions); + return Results.Ok(); +}).WithTags("Transfer Call APIs"); + +app.MapPost("/transferCallPSTNToTeamsParticipantAsync", async (string teamsTransferTarget, string pstnTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + TransferToParticipantOptions transferToParticipantOptions = new TransferToParticipantOptions(new MicrosoftTeamsUserIdentifier(teamsTransferTarget)) + { + OperationContext = "TransferCallContext", + Transferee = new PhoneNumberIdentifier(pstnTarget), + OperationCallbackUri = eventCallbackUri, + }; + + await callConnection.TransferCallToParticipantAsync(transferToParticipantOptions); + return Results.Ok(); +}).WithTags("Transfer Call APIs"); + +app.MapPost("/transferCallTeamsUserToPSTNAsync", async (string pstnTransferTarget, string teamsTarget, ILogger logger) => +{ + CallConnection callConnection = GetConnection(); + + TransferToParticipantOptions transferToParticipantOptions = new TransferToParticipantOptions(new PhoneNumberIdentifier(pstnTransferTarget)) + { + OperationContext = "TransferCallContext", + Transferee = new MicrosoftTeamsUserIdentifier(teamsTarget), + OperationCallbackUri = eventCallbackUri + }; + + await callConnection.TransferCallToParticipantAsync(transferToParticipantOptions); + return Results.Ok(); +}).WithTags("Transfer Call APIs"); #endregion #region Get Participant @@ -2208,33 +3216,33 @@ return Results.Ok(); }).WithTags("Get Participant APIs"); -app.MapPost("/getTeamsParticipantAsync", async (string teamsObjectId, ILogger logger) => -{ - CallConnection callConnection = GetConnection(); +//app.MapPost("/getTeamsParticipantAsync", async (string teamsObjectId, ILogger logger) => +//{ +// CallConnection callConnection = GetConnection(); - CallParticipant participant = await callConnection.GetParticipantAsync(new MicrosoftTeamsUserIdentifier(teamsObjectId)); +// 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"); +// 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(); +//app.MapPost("/getTeamsParticipant", (string teamsObjectId, ILogger logger) => +//{ +// CallConnection callConnection = GetConnection(); - CallParticipant participant = callConnection.GetParticipant(new MicrosoftTeamsUserIdentifier(teamsObjectId)); +// 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"); +// 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) => { @@ -2247,6 +3255,7 @@ Console.WriteLine("----------------------------------------------------------------------"); Console.WriteLine("Participant:-->" + participant.Identifier.RawId.ToString()); Console.WriteLine("Is Participant on hold:-->" + participant.IsOnHold); + Console.WriteLine("Is Participant on mute:-->" + participant.IsMuted); Console.WriteLine("----------------------------------------------------------------------"); } return Results.Ok(); @@ -2263,6 +3272,7 @@ Console.WriteLine("----------------------------------------------------------------------"); Console.WriteLine("Participant:-->" + participant.Identifier.RawId.ToString()); Console.WriteLine("Is Participant on hold:-->" + participant.IsOnHold); + Console.WriteLine("Is Participant on mute:-->" + participant.IsMuted); Console.WriteLine("----------------------------------------------------------------------"); } return Results.Ok(); @@ -2272,17 +3282,18 @@ #region Recording -app.MapPost("/startRecordingWithVideoMp4MixedAsync", async (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +app.MapPost("/startRecordingWithVideoMp4MixedAsync", async (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); + var recordingOptions = new StartRecordingOptions(callConnectionProperties.CallConnectionId); recordingOptions.RecordingContent = RecordingContent.AudioVideo; recordingOptions.RecordingFormat = RecordingFormat.Mp4; recordingOptions.RecordingChannel = RecordingChannel.Mixed; recordingOptions.RecordingStateCallbackUri = eventCallbackUri; - recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingOptions.PauseOnStart = isPauseOnStart; + //recordingOptions.RecordingStorage = RecordingStorage.CreateAzureBlobContainerRecordingStorage(new Uri("https://waferwirestorage.blob.core.windows.net/ga5byos")); recordingFileFormat = "mp4"; var recordingResult = await client.GetCallRecording().StartAsync(recordingOptions); recordingId = recordingResult.Value.RecordingId; @@ -2290,17 +3301,17 @@ return Results.Ok(); }).WithTags("Recording APIs"); -app.MapPost("/startRecordingWithVideoMp4Mixed", (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +app.MapPost("/startRecordingWithVideoMp4Mixed", (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); + var recordingOptions = new StartRecordingOptions(callLocator); recordingOptions.RecordingContent = RecordingContent.AudioVideo; recordingOptions.RecordingFormat = RecordingFormat.Mp4; recordingOptions.RecordingChannel = RecordingChannel.Mixed; recordingOptions.RecordingStateCallbackUri = eventCallbackUri; - recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingOptions.PauseOnStart = isPauseOnStart; recordingFileFormat = "mp4"; var recordingResult = client.GetCallRecording().Start(recordingOptions); @@ -2309,17 +3320,17 @@ return Results.Ok(); }).WithTags("Recording APIs"); -app.MapPost("/startRecordingWithAudioMp3MixedAsync", async (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +app.MapPost("/startRecordingWithAudioMp3MixedAsync", async (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); + var recordingOptions = new StartRecordingOptions(callLocator); recordingOptions.RecordingContent = RecordingContent.Audio; recordingOptions.RecordingFormat = RecordingFormat.Mp3; recordingOptions.RecordingChannel = RecordingChannel.Mixed; recordingOptions.RecordingStateCallbackUri = eventCallbackUri; - recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingOptions.PauseOnStart = isPauseOnStart; recordingFileFormat = "mp3"; var recordingResult = await client.GetCallRecording().StartAsync(recordingOptions); @@ -2328,17 +3339,17 @@ return Results.Ok(); }).WithTags("Recording APIs"); -app.MapPost("/startRecordingWithAudioMp3Mixed", (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +app.MapPost("/startRecordingWithAudioMp3Mixed", (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); + var recordingOptions = new StartRecordingOptions(callLocator); recordingOptions.RecordingContent = RecordingContent.Audio; recordingOptions.RecordingFormat = RecordingFormat.Mp3; recordingOptions.RecordingChannel = RecordingChannel.Mixed; recordingOptions.RecordingStateCallbackUri = eventCallbackUri; - recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingOptions.PauseOnStart = isPauseOnStart; recordingFileFormat = "mp3"; var recordingResult = client.GetCallRecording().Start(recordingOptions); @@ -2347,18 +3358,18 @@ return Results.Ok(); }).WithTags("Recording APIs"); -app.MapPost("/startRecordingWithAudioMp3UnMixedAsync", async (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +app.MapPost("/startRecordingWithAudioWavMixedAsync", async (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); + var recordingOptions = new StartRecordingOptions(callLocator); recordingOptions.RecordingContent = RecordingContent.Audio; - recordingOptions.RecordingFormat = RecordingFormat.Mp3; - recordingOptions.RecordingChannel = RecordingChannel.Unmixed; + recordingOptions.RecordingFormat = RecordingFormat.Wav; + recordingOptions.RecordingChannel = RecordingChannel.Mixed; recordingOptions.RecordingStateCallbackUri = eventCallbackUri; - recordingOptions.PauseOnStart = isPauseOnStart ? true : false; - recordingFileFormat = "mp3"; + recordingOptions.PauseOnStart = isPauseOnStart; + recordingFileFormat = "wav"; var recordingResult = await client.GetCallRecording().StartAsync(recordingOptions); recordingId = recordingResult.Value.RecordingId; @@ -2366,18 +3377,18 @@ return Results.Ok(); }).WithTags("Recording APIs"); -app.MapPost("/startRecordingWithAudioMp3Unmixed", (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +app.MapPost("/startRecordingWithAudioWavMixed", (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); + var recordingOptions = new StartRecordingOptions(callLocator); recordingOptions.RecordingContent = RecordingContent.Audio; - recordingOptions.RecordingFormat = RecordingFormat.Mp3; - recordingOptions.RecordingChannel = RecordingChannel.Unmixed; + recordingOptions.RecordingFormat = RecordingFormat.Wav; + recordingOptions.RecordingChannel = RecordingChannel.Mixed; recordingOptions.RecordingStateCallbackUri = eventCallbackUri; - recordingOptions.PauseOnStart = isPauseOnStart ? true : false; - recordingFileFormat = "mp3"; + recordingOptions.PauseOnStart = isPauseOnStart; + recordingFileFormat = "wav"; var recordingResult = client.GetCallRecording().Start(recordingOptions); recordingId = recordingResult.Value.RecordingId; @@ -2385,17 +3396,17 @@ return Results.Ok(); }).WithTags("Recording APIs"); -app.MapPost("/startRecordingWithAudioWavUnMixedAsync", async (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +app.MapPost("/startRecordingWithAudioWavUnMixedAsync", async (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); + var recordingOptions = new StartRecordingOptions(callLocator); recordingOptions.RecordingContent = RecordingContent.Audio; recordingOptions.RecordingFormat = RecordingFormat.Wav; recordingOptions.RecordingChannel = RecordingChannel.Unmixed; recordingOptions.RecordingStateCallbackUri = eventCallbackUri; - recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingOptions.PauseOnStart = isPauseOnStart; recordingFileFormat = "wav"; var recordingResult = await client.GetCallRecording().StartAsync(recordingOptions); @@ -2404,17 +3415,17 @@ return Results.Ok(); }).WithTags("Recording APIs"); -app.MapPost("/startRecordingWithAudioWavUnmixed", (bool isRecordingWithCallConnectionId, bool isPauseOnStart, ILogger logger) => +app.MapPost("/startRecordingWithAudioWavUnmixed", (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); + var recordingOptions = new StartRecordingOptions(callLocator); recordingOptions.RecordingContent = RecordingContent.Audio; recordingOptions.RecordingFormat = RecordingFormat.Wav; recordingOptions.RecordingChannel = RecordingChannel.Unmixed; recordingOptions.RecordingStateCallbackUri = eventCallbackUri; - recordingOptions.PauseOnStart = isPauseOnStart ? true : false; + recordingOptions.PauseOnStart = isPauseOnStart; recordingFileFormat = "wav"; var recordingResult = client.GetCallRecording().Start(recordingOptions); @@ -2461,14 +3472,21 @@ return Results.Ok(); }).WithTags("Recording APIs"); -app.MapGet("/downloadRecording", (ILogger logger) => +app.MapGet("/downloadRecording", async (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}"); + + logger.LogInformation($"Downloading recording location {recordingLocation}"); + string recordingLocationNew = recordingLocation.Replace("https://as-storage.asm.skype.com/", "https://prod.asyncgw.teams.microsoft.com/"); + logger.LogInformation($"Downloading recording location new {recordingLocationNew}"); + + var response = await client.GetCallRecording().DownloadStreamingAsync(new Uri(recordingLocationNew)); + + //var response2 = await client.GetCallRecording().DownloadToAsync(new Uri(recordingLocationNew), $"{downloadsPath}\\{fileName}"); } else { @@ -2476,6 +3494,28 @@ } return Results.Ok(); }).WithTags("Recording APIs"); +app.MapGet("/downloadRecordingMetadata", async (ILogger logger) => +{ + if (!string.IsNullOrEmpty(metadataLocation)) + { + string downloadsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"); + var recordingDownloadUri = new Uri(metadataLocation); + var date = DateTime.Now.ToString("yyyyMMdd_HHmmss"); + string fileName = $"Recording_{date}.json"; + logger.LogInformation($"Downloading recording location {recordingLocation}"); + string recordingLocationNew = metadataLocation.Replace("https://as-storage.asm.skype.com/", "https://prod.asyncgw.teams.microsoft.com/"); + logger.LogInformation($"Downloading recording location new {recordingLocationNew}"); + + var response = await client.GetCallRecording().DownloadStreamingAsync(new Uri(metadataLocation)); + + //var response2 = await client.GetCallRecording().DownloadToAsync(new Uri(recordingLocationNew), $"{downloadsPath}\\{fileName}"); + } + else + { + logger.LogError("Metadata location is empty."); + } + return Results.Ok(); +}).WithTags("Recording APIs"); #endregion From 1436a040e5e34c7655e6789a18ff17b05b16afcf Mon Sep 17 00:00:00 2001 From: Pilli Vamshi Date: Sat, 23 Aug 2025 00:46:16 +0530 Subject: [PATCH 3/3] added changes for beta7 --- CallAutomation_Beta6_Test_sample/Program.cs | 823 ++++++++++---------- 1 file changed, 414 insertions(+), 409 deletions(-) diff --git a/CallAutomation_Beta6_Test_sample/Program.cs b/CallAutomation_Beta6_Test_sample/Program.cs index e96db78e..3dfd22f9 100644 --- a/CallAutomation_Beta6_Test_sample/Program.cs +++ b/CallAutomation_Beta6_Test_sample/Program.cs @@ -24,7 +24,7 @@ string cognitiveServicesEndpoint = ""; string acsPhoneNumber = ""; -string callbackUriHost = "https://9675p4k5-7286.inc1.devtunnels.ms"; +string callbackUriHost = "https://bvm9l0s9.inc1.devtunnels.ms:8081"; string fileSourceUri = "https://pixabay.com/sound-effects/countdown-from-10-190389/"; string callConnectionId = string.Empty; @@ -39,7 +39,7 @@ CallAutomationClient client = new CallAutomationClient(new Uri("https://uswe-03.sdf.pma.teams.microsoft.com"), connectionString: acsConnectionString); //CallAutomationClient client = new CallAutomationClient(connectionString: acsConnectionString); -app.MapPost("/api/events", async (EventGridEvent[] eventGridEvents, ILogger logger) => +app.MapPost("/api/incomingCall", async (EventGridEvent[] eventGridEvents, ILogger logger) => { foreach (var eventGridEvent in eventGridEvents) { @@ -78,10 +78,10 @@ }; var options = new AnswerCallOptions(incomingCallEventData.IncomingCallContext, callbackUri) { - CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, + //CallIntelligenceOptions = new CallIntelligenceOptions() { CognitiveServicesEndpoint = new Uri(cognitiveServicesEndpoint) }, //IsLoopbackAudioEnabled = true, - MediaStreamingOptions = mediaStreamingOptions, - TranscriptionOptions = transcriptionOptions + //MediaStreamingOptions = mediaStreamingOptions, + //TranscriptionOptions = transcriptionOptions }; AnswerCallResult answerCallResult = await client.AnswerCallAsync(options); @@ -110,7 +110,7 @@ parsedEvent.GetType(), parsedEvent.CallConnectionId, parsedEvent.ServerCallId); - + callConnectionId = parsedEvent.CallConnectionId; if (parsedEvent is CallConnected callConnected) { logger.LogInformation($"Received call event: {callConnected.GetType()}"); @@ -846,7 +846,12 @@ callInvite.CustomCallingContext.AddSipX("XheaderOBO", "value"); // Create TeamsPhoneCallerDetails -var teamsPhoneCallerDetails = new TeamsPhoneCallerDetails(new MicrosoftTeamsUserIdentifier(teamsObjectId), name: "John Doe", phoneNumber: "+14256451678"); +var teamsPhoneCallerDetails = new TeamsPhoneCallerDetails(new MicrosoftTeamsUserIdentifier(teamsObjectId), name: "John Doe", phoneNumber: "+14256451678") +{ + IsAuthenticated = true, + ScreenPopUrl = "abcdef", //prescriptionDetails?.ScreenPopUpUrl, + RecordId = "recordId-12345", +}; teamsPhoneCallerDetails.AdditionalCallerInformation.Add("Department", "Sales"); teamsPhoneCallerDetails.AdditionalCallerInformation.Add("Priority", "High"); @@ -865,7 +870,6 @@ CallSentiment = "Positive", SuggestedActions = "Offer product demo, Schedule follow-up" }; - callInvite.CustomCallingContext.SetTeamsPhoneCallDetails(teamsPhoneCallDetails); var addParticipantOptions = new AddParticipantOptions(callInvite) @@ -1194,279 +1198,279 @@ #endregion -//# region Play Media with Ssml Source +# region Play Media with Ssml Source -////app.MapPost("/playSsmlSourceToPstnTargetAsync", async (string pstnTarget, ILogger logger) => -////{ -//// CallMedia callMedia = GetCallMedia(); +//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!"); +// 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" -//// }; +// List playTo = new List { new PhoneNumberIdentifier(pstnTarget) }; +// PlayOptions playToOptions = new PlayOptions(ssmlSource, playTo) +// { +// OperationContext = "playToContext" +// }; -//// await callMedia.PlayAsync(playToOptions); +// await callMedia.PlayAsync(playToOptions); -//// return Results.Ok(); -////}).WithTags("Play SsmlSource Media APIs"); +// 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" -//// }; +//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); +// callMedia.Play(playToOptions); -//// return Results.Ok(); -////}).WithTags("Play SsmlSource Media APIs"); +// 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" -//// }; +//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); +// await callMedia.PlayAsync(playToOptions); -//// return Results.Ok(); -////}).WithTags("Play SsmlSource Media APIs"); +// 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!"); +//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" -//// }; +// List playTo = new List { new CommunicationUserIdentifier(acsTarget) }; +// PlayOptions playToOptions = new PlayOptions(ssmlSource, playTo) +// { +// OperationContext = "playToContext" +// }; -//// callMedia.Play(playToOptions); +// callMedia.Play(playToOptions); -//// return Results.Ok(); -////}).WithTags("Play SsmlSource Media APIs"); +// 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" -//// }; +//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); +// await callMedia.PlayAsync(playToOptions); -//// return Results.Ok(); -////}).WithTags("Play SsmlSource Media APIs"); +// 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" -//// }; +//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); +// callMedia.Play(playToOptions); -//// return Results.Ok(); -////}).WithTags("Play SsmlSource Media APIs"); +// 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); +//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"); +// 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!"); +//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); +// PlayToAllOptions playToAllOptions = new PlayToAllOptions(ssmlSource) +// { +// OperationContext = "playToAllContext" +// }; +// callMedia.PlayToAll(playToAllOptions); -//// return Results.Ok(); -////}).WithTags("Play SsmlSource Media APIs"); +// 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); +//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"); +// return Results.Ok(); +//}).WithTags("Play SsmlSource Media APIs"); -//#endregion +#endregion -//# region Play Media with File Source +# 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" -//// }; +//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); +// await callMedia.PlayAsync(playToOptions); -//// return Results.Ok(); -////}).WithTags("Play FileSource Media APIs"); +// 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" -//// }; +//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); +// callMedia.Play(playToOptions); -//// return Results.Ok(); -////}).WithTags("Play FileSource Media APIs"); +// 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" -//// }; +//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); +// await callMedia.PlayAsync(playToOptions); -//// return Results.Ok(); -////}).WithTags("Play FileSource Media APIs"); +// 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)); +//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" -//// }; +// List playTo = new List { new CommunicationUserIdentifier(acsTarget) }; +// PlayOptions playToOptions = new PlayOptions(fileSource, playTo) +// { +// OperationContext = "playToContext" +// }; -//// callMedia.Play(playToOptions); +// callMedia.Play(playToOptions); -//// return Results.Ok(); -////}).WithTags("Play FileSource Media APIs"); +// 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" -//// }; +//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); +// await callMedia.PlayAsync(playToOptions); -//// return Results.Ok(); -////}).WithTags("Play FileSource Media APIs"); +// 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" -//// }; +//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); +// callMedia.Play(playToOptions); -//// return Results.Ok(); -////}).WithTags("Play FileSource Media APIs"); +// 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); +//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"); +// return Results.Ok(); +//}).WithTags("Play FileSource Media APIs"); -////app.MapPost("/playFileSourceToAll", (ILogger logger) => -////{ -//// CallMedia callMedia = GetCallMedia(); -//// FileSource fileSource = new FileSource(new Uri(fileSourceUri)); +//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); +// PlayToAllOptions playToAllOptions = new PlayToAllOptions(fileSource) +// { +// OperationContext = "playToAllContext" +// }; +// callMedia.PlayToAll(playToAllOptions); -//// return Results.Ok(); -////}).WithTags("Play FileSource Media APIs"); +// 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); +//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"); +// return Results.Ok(); +//}).WithTags("Play FileSource Media APIs"); -//#endregion +#endregion //# region Play Media With Multiple Play Source @@ -1585,231 +1589,231 @@ //}).WithTags("Play Multiple Source Media APIs"); //#endregion -//#region Recognization +#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" -// }; +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 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 -// }; + 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); + await callMedia.StartRecognizingAsync(recognizeOptions); -// return Results.Ok(); -//}).WithTags("Start Recognization APIs"); + 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" -// }; +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 CommunicationUserIdentifier(pstnTarget); + var target = new CommunicationUserIdentifier(pstnTarget); -// var recognizeOptions = -// new CallMediaRecognizeDtmfOptions( -// targetParticipant: target, maxTonesToCollect: 4) -// { -// InterruptPrompt = false, -// InterToneTimeout = TimeSpan.FromSeconds(5), -// OperationContext = "DtmfContext", -// InitialSilenceTimeout = TimeSpan.FromSeconds(15), -// Prompt = textSource -// }; + 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); + callMedia.StartRecognizing(recognizeOptions); -// return Results.Ok(); -//}).WithTags("Start Recognization APIs"); + 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" -// }; +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 CommunicationUserIdentifier(pstnTarget); + var target = new CommunicationUserIdentifier(pstnTarget); -// var recognizeOptions = new CallMediaRecognizeSpeechOptions(targetParticipant: target) -// { -// InterruptPrompt = false, -// OperationContext = "SpeechContext", -// InitialSilenceTimeout = TimeSpan.FromSeconds(15), -// Prompt = textSource, -// EndSilenceTimeout = TimeSpan.FromSeconds(5), -// IsSentimentAnalysisEnabled = true, -// SpeechLanguages = new List { "en-US", "en-IN" }, -// OperationCallbackUri = eventCallbackUri -// }; + var recognizeOptions = new CallMediaRecognizeSpeechOptions(targetParticipant: target) + { + InterruptPrompt = false, + OperationContext = "SpeechContext", + InitialSilenceTimeout = TimeSpan.FromSeconds(15), + Prompt = textSource, + EndSilenceTimeout = TimeSpan.FromSeconds(5), + IsSentimentAnalysisEnabled = true, + SpeechLanguages = new List { "en-US", "en-IN" }, + OperationCallbackUri = eventCallbackUri + }; -// await callMedia.StartRecognizingAsync(recognizeOptions); + await callMedia.StartRecognizingAsync(recognizeOptions); -// return Results.Ok(); -//}).WithTags("Start Recognization APIs"); + 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" -// }; +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 CommunicationUserIdentifier(pstnTarget); + var target = new CommunicationUserIdentifier(pstnTarget); -// var recognizeOptions = new CallMediaRecognizeSpeechOptions(targetParticipant: target) -// { -// InterruptPrompt = false, -// OperationContext = "SpeechContext", -// InitialSilenceTimeout = TimeSpan.FromSeconds(15), -// Prompt = textSource, -// EndSilenceTimeout = TimeSpan.FromSeconds(5), -// IsSentimentAnalysisEnabled = true, -// SpeechLanguages = new List { "en-US", "en-IN" }, -// OperationCallbackUri = eventCallbackUri -// }; + var recognizeOptions = new CallMediaRecognizeSpeechOptions(targetParticipant: target) + { + InterruptPrompt = false, + OperationContext = "SpeechContext", + InitialSilenceTimeout = TimeSpan.FromSeconds(15), + Prompt = textSource, + EndSilenceTimeout = TimeSpan.FromSeconds(5), + IsSentimentAnalysisEnabled = true, + SpeechLanguages = new List { "en-US", "en-IN" }, + OperationCallbackUri = eventCallbackUri + }; -// callMedia.StartRecognizing(recognizeOptions); + callMedia.StartRecognizing(recognizeOptions); -// return Results.Ok(); -//}).WithTags("Start Recognization APIs"); + 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" -// }; +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 CommunicationUserIdentifier(pstnTarget); + var target = new CommunicationUserIdentifier(pstnTarget); -// var recognizeOptions = -// new CallMediaRecognizeSpeechOrDtmfOptions( -// targetParticipant: target, maxTonesToCollect: 4) -// { -// InterruptPrompt = false, -// OperationContext = "SpeechOrDTMFContext", -// InitialSilenceTimeout = TimeSpan.FromSeconds(15), -// Prompt = textSource, -// EndSilenceTimeout = TimeSpan.FromSeconds(5), -// IsSentimentAnalysisEnabled = true, -// SpeechLanguages = new List { "en-US", "en-IN" }, -// OperationCallbackUri = eventCallbackUri -// }; -// await callMedia.StartRecognizingAsync(recognizeOptions); + var recognizeOptions = + new CallMediaRecognizeSpeechOrDtmfOptions( + targetParticipant: target, maxTonesToCollect: 4) + { + InterruptPrompt = false, + OperationContext = "SpeechOrDTMFContext", + InitialSilenceTimeout = TimeSpan.FromSeconds(15), + Prompt = textSource, + EndSilenceTimeout = TimeSpan.FromSeconds(5), + IsSentimentAnalysisEnabled = true, + SpeechLanguages = new List { "en-US", "en-IN" }, + OperationCallbackUri = eventCallbackUri + }; + await callMedia.StartRecognizingAsync(recognizeOptions); -// return Results.Ok(); -//}).WithTags("Start Recognization APIs"); + 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" -// }; +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 CommunicationUserIdentifier(pstnTarget); + var target = new CommunicationUserIdentifier(pstnTarget); -// var recognizeOptions = -// new CallMediaRecognizeSpeechOrDtmfOptions( -// targetParticipant: target, maxTonesToCollect: 4) -// { -// InterruptPrompt = false, -// OperationContext = "SpeechOrDTMFContext", -// InitialSilenceTimeout = TimeSpan.FromSeconds(15), -// Prompt = textSource, -// EndSilenceTimeout = TimeSpan.FromSeconds(5), -// IsSentimentAnalysisEnabled = true, -// SpeechLanguages = new List { "en-US", "en-IN" }, -// OperationCallbackUri = eventCallbackUri -// }; -// callMedia.StartRecognizingAsync(recognizeOptions); + var recognizeOptions = + new CallMediaRecognizeSpeechOrDtmfOptions( + targetParticipant: target, maxTonesToCollect: 4) + { + InterruptPrompt = false, + OperationContext = "SpeechOrDTMFContext", + InitialSilenceTimeout = TimeSpan.FromSeconds(15), + Prompt = textSource, + EndSilenceTimeout = TimeSpan.FromSeconds(5), + IsSentimentAnalysisEnabled = true, + SpeechLanguages = new List { "en-US", "en-IN" }, + OperationCallbackUri = eventCallbackUri + }; + callMedia.StartRecognizingAsync(recognizeOptions); -// return Results.Ok(); -//}).WithTags("Start Recognization APIs"); + 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" -// }; +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 CommunicationUserIdentifier(pstnTarget); + var target = new CommunicationUserIdentifier(pstnTarget); -// var recognizeOptions = -// new CallMediaRecognizeChoiceOptions(targetParticipant: target, GetChoices()) -// { -// InterruptCallMediaOperation = false, -// InterruptPrompt = false, -// InitialSilenceTimeout = TimeSpan.FromSeconds(15), -// Prompt = textSource, -// OperationContext = "ChoiceContext", -// IsSentimentAnalysisEnabled = true, -// SpeechLanguages = new List { "en-US", "en-IN" }, -// OperationCallbackUri = eventCallbackUri -// }; + var recognizeOptions = + new CallMediaRecognizeChoiceOptions(targetParticipant: target, GetChoices()) + { + InterruptCallMediaOperation = false, + InterruptPrompt = false, + InitialSilenceTimeout = TimeSpan.FromSeconds(15), + Prompt = textSource, + OperationContext = "ChoiceContext", + IsSentimentAnalysisEnabled = true, + SpeechLanguages = new List { "en-US", "en-IN" }, + OperationCallbackUri = eventCallbackUri + }; -// await callMedia.StartRecognizingAsync(recognizeOptions); + await callMedia.StartRecognizingAsync(recognizeOptions); -// return Results.Ok(); -//}).WithTags("Start Recognization APIs"); + 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" -// }; +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 CommunicationUserIdentifier(pstnTarget); + var target = new CommunicationUserIdentifier(pstnTarget); -// var recognizeOptions = -// new CallMediaRecognizeChoiceOptions(targetParticipant: target, GetChoices()) -// { -// InterruptCallMediaOperation = false, -// InterruptPrompt = false, -// InitialSilenceTimeout = TimeSpan.FromSeconds(15), -// Prompt = textSource, -// OperationContext = "ChoiceContext", -// IsSentimentAnalysisEnabled = true, -// SpeechLanguages = new List { "en-US", "en-IN" }, -// OperationCallbackUri = eventCallbackUri -// }; + var recognizeOptions = + new CallMediaRecognizeChoiceOptions(targetParticipant: target, GetChoices()) + { + InterruptCallMediaOperation = false, + InterruptPrompt = false, + InitialSilenceTimeout = TimeSpan.FromSeconds(15), + Prompt = textSource, + OperationContext = "ChoiceContext", + IsSentimentAnalysisEnabled = true, + SpeechLanguages = new List { "en-US", "en-IN" }, + OperationCallbackUri = eventCallbackUri + }; -// callMedia.StartRecognizingAsync(recognizeOptions); + callMedia.StartRecognizingAsync(recognizeOptions); -// return Results.Ok(); -//}).WithTags("Start Recognization APIs"); + return Results.Ok(); +}).WithTags("Start Recognization APIs"); -//#endregion +#endregion //#region Recognization multiple play sources @@ -3474,6 +3478,7 @@ app.MapGet("/downloadRecording", async (ILogger logger) => { + recordingLocation = " https://us-storage.asm.skype.com/v1/objects/0-cus-d16-6803d3d1120ae9a5ce21a1c664841cd3/content/video"; if (!string.IsNullOrEmpty(recordingLocation)) { string downloadsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"); @@ -3481,12 +3486,12 @@ string fileName = $"Recording_{date}.{recordingFileFormat}"; logger.LogInformation($"Downloading recording location {recordingLocation}"); - string recordingLocationNew = recordingLocation.Replace("https://as-storage.asm.skype.com/", "https://prod.asyncgw.teams.microsoft.com/"); + string recordingLocationNew = recordingLocation.Replace("https://us-storage.asm.skype.com/", "https://prod.asyncgw.teams.microsoft.com/"); logger.LogInformation($"Downloading recording location new {recordingLocationNew}"); - var response = await client.GetCallRecording().DownloadStreamingAsync(new Uri(recordingLocationNew)); + //var response = await client.GetCallRecording().DownloadStreamingAsync(new Uri(recordingLocationNew)); - //var response2 = await client.GetCallRecording().DownloadToAsync(new Uri(recordingLocationNew), $"{downloadsPath}\\{fileName}"); + var response2 = await client.GetCallRecording().DownloadToAsync(new Uri(recordingLocationNew), $"{downloadsPath}\\{fileName}"); } else {