Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample application CallAutomation_OPS_CallingScenarios #182

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35514.174
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CallAutomation_OPS_CallingScenarios", "CallAutomation_OPS_CallingScenarios\CallAutomation_OPS_CallingScenarios.csproj", "{2655133A-A01D-4C6D-8F18-38DA587C78E2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2655133A-A01D-4C6D-8F18-38DA587C78E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2655133A-A01D-4C6D-8F18-38DA587C78E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2655133A-A01D-4C6D-8F18-38DA587C78E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2655133A-A01D-4C6D-8F18-38DA587C78E2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Communication.CallAutomation" Version="1.4.0-alpha.20241217.1" />
<PackageReference Include="Azure.Messaging.EventGrid" Version="4.21.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using Azure.Communication.CallAutomation;
using System.Net.WebSockets;
using System.Text;

namespace CallAutomation_OPS_CallingScenarios
{
public class Helper
{
/// <summary>
/// Accept WebSocket Connection, and then Loop in receiving data transmitted from client.
/// </summary>
/// <param name="webSocket"></param>
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<byte>(buffer), cancellationToken);

while (!receiveResult.CloseStatus.HasValue)
{
string msg = Encoding.UTF8.GetString(buffer, 0, receiveResult.Count);

var response = StreamingDataParser.Parse(msg);

if (response != null)
{
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.Ticks);
Console.WriteLine("DURATION-->" + transcriptionData.Duration.Ticks);
Console.WriteLine("PARTICIPANT-->" + transcriptionData.Participant.RawId);
Console.WriteLine("CONFIDENCE-->" + transcriptionData.Confidence);
Console.WriteLine("RESULT STATUS-->" + transcriptionData.ResultState);
foreach (var word in transcriptionData.Words)
{
Console.WriteLine("WORDS TEXT-->" + word.Text);
Console.WriteLine("WORDS OFFSET-->" + word.Offset.Ticks);
Console.WriteLine("WORDS DURATION-->" + word.Duration.Ticks);
}
Console.WriteLine("***************************************************************************************");
}

}

await webSocket.SendAsync(
new ArraySegment<byte>(buffer, 0, receiveResult.Count),
receiveResult.MessageType,
receiveResult.EndOfMessage,
CancellationToken.None);

receiveResult = await webSocket.ReceiveAsync(
new ArraySegment<byte>(buffer), CancellationToken.None);
}

await webSocket.CloseAsync(receiveResult.CloseStatus.Value, receiveResult.CloseStatusDescription, CancellationToken.None);
}
catch (Exception ex)
{
Console.WriteLine($"Exception -> {ex}");
}
finally
{
}
}
}
}
Loading