From 832cff8a660d503b9869be39cb358a1ee52bb510 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Tue, 28 Feb 2023 15:37:32 +0100 Subject: [PATCH] Add GetCallStatus activity --- .../Elsa.Telnyx/Activities/GetCallStatus.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/modules/Elsa.Telnyx/Activities/GetCallStatus.cs diff --git a/src/modules/Elsa.Telnyx/Activities/GetCallStatus.cs b/src/modules/Elsa.Telnyx/Activities/GetCallStatus.cs new file mode 100644 index 000000000..942a044c7 --- /dev/null +++ b/src/modules/Elsa.Telnyx/Activities/GetCallStatus.cs @@ -0,0 +1,45 @@ +using System.Runtime.CompilerServices; +using System.Text.Json.Serialization; +using Elsa.Extensions; +using Elsa.Telnyx.Client.Services; +using Elsa.Workflows.Core.Activities.Flowchart.Attributes; +using Elsa.Workflows.Core.Attributes; +using Elsa.Workflows.Core.Models; + +namespace Elsa.Telnyx.Activities; + +/// +[FlowNode("Alive", "Dead", "Done")] +[Activity(Constants.Namespace, "Get the status of a call.", Kind = ActivityKind.Task)] +public class GetCallStatus : CodeActivity +{ + /// + [JsonConstructor] + public GetCallStatus([CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : base(source, line) + { + } + + /// + /// Unique identifier and token for controlling the call. + /// + [Input( + DisplayName = "Call Control ID", + Description = "Unique identifier and token for controlling the call.", + Category = "Advanced" + )] + public Input CallControlId { get; set; } = default!; + + /// + protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) + { + var client = context.GetRequiredService(); + var callControlId = CallControlId.Get(context); + var response = await client.Calls.GetStatusAsync(callControlId, context.CancellationToken); + var isAlive = response.Data.IsAlive; + var outcome = isAlive ? "Alive" : "Dead"; + + Result.Set(context, isAlive); + + await context.CompleteActivityWithOutcomesAsync(outcome, "Done"); + } +} \ No newline at end of file