elsa-core/src/modules/Elsa.Telnyx/Activities/LookupNumber.cs
Sipke Schoorstra fad27d0fb0
Refactor composite activity input and scoped memory (#3815)
* Incremental work

* Enable control over when to include full compositie root

* Cleanup

* Update WorkflowDefinitionActivity

* Implement input as variables

* Delete unused class

* Remove less common types

* Rename ExpandoObject to JSON

* Implement variable scoping

* Remove parent/child relationship from MemoryRegister

* Add support for sending input to "trigger event" endpoint

* Add support for configuring input storage driver

* Remove unused namespace imports

* Auto-register activity types when running a workflow

* Fix missing variables from containers
2023-03-20 19:55:11 +01:00

49 lines
1.8 KiB
C#

using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;
using Elsa.Extensions;
using Elsa.Telnyx.Client.Models;
using Elsa.Telnyx.Client.Services;
using Elsa.Workflows.Core;
using Elsa.Workflows.Core.Attributes;
using Elsa.Workflows.Core.Models;
namespace Elsa.Telnyx.Activities;
/// <summary>
/// Returns information about the provided phone number.
/// </summary>
[Activity(Constants.Namespace, "Returns information about the provided phone number.", Kind = ActivityKind.Task)]
public class LookupNumber : CodeActivity<NumberLookupResponse>
{
/// <inheritdoc />
[JsonConstructor]
public LookupNumber([CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : base(source, line)
{
}
/// <summary>
/// The phone number to be looked up.
/// </summary>
[Input(Description = "The phone number to be looked up.")]
public Input<string> PhoneNumber { get; set; } = default!;
/// <summary>
/// The types of number lookups to be performed.
/// </summary>
[Input(
Description = "The types of number lookups to be performed.",
UIHint = InputUIHints.CheckList,
Options = new[] { "carrier", "caller-name" }
)]
public Input<ICollection<string>> Types { get; set; } = new(new List<string>());
/// <inheritdoc />
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
{
var telnyxClient = context.GetRequiredService<ITelnyxClient>();
var phoneNumber = PhoneNumber.Get(context) ?? throw new Exception("PhoneNumber is required.");
var types = Types.Get(context);
var response = await telnyxClient.NumberLookup.NumberLookupAsync(phoneNumber, types, context.CancellationToken);
context.Set(Result, response.Data);
}
}