Skip to content

Commit

Permalink
Merge pull request #32 from team-telnyx/feature/add2fa
Browse files Browse the repository at this point in the history
Feature/add2fa
  • Loading branch information
d-telnyx authored Dec 16, 2020
2 parents 8888658 + d79b188 commit 0226b6d
Show file tree
Hide file tree
Showing 30 changed files with 787 additions and 421 deletions.
5 changes: 5 additions & 0 deletions src/Telnyx.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,13 @@ static async Task Main(string[] args)
telephonyCredentialExample.GetToken();
await telephonyCredentialExample.GetTokenAsync();

Console.WriteLine("2FA Verification Example...");
var verificationExample = new VerificationExample();
await verificationExample.RunVerification();

/*Only call with your credentials*/
//GetWebhook();

}

public async static Task<HttpStatusCode> ReceiveAndHandleWebhook()
Expand Down
47 changes: 47 additions & 0 deletions src/Telnyx.Example/VerificationExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Threading.Tasks;
using Telnyx.net.Services.VerifyAPI;

namespace Telnyx.Example
{
[ExcludeFromCodeCoverage]
public class VerificationExample
{
private VerificationService verifyService = new VerificationService();

public async Task RunVerification()
{
VerifyProfileOptions profileOptions = new VerifyProfileOptions
{
DefaultTimeoutSecs = 300,
MessagingEnabled = true,
MessagingTemplate = "Hello this is a test {code}",
Name = "Test Profile",
RcsEnabled = false
};
Console.WriteLine($"Creating profile: {profileOptions.Name}");
var profile = await verifyService.CreateVerificationProfileAsync(profileOptions);
Console.WriteLine($"Profile Created. Id: {profile.Id.Value}");
VerifyOptions verifyOptions = new VerifyOptions
{
TimeoutSecs = 300,
PhoneNumber = "+13100000010",
VerifyProfileId = profile.Id.Value,
Type = "sms",
};
Console.WriteLine($"Creating verification");
var verification = await verifyService.CreateVerificationAsync(verifyOptions);
Console.WriteLine($"Verification created successfully: {verification.Id} with status {verification.Status}");

Console.WriteLine($"Checking verification status current status: {verification.Status}");
var getStatus = await verifyService.GetVerificationAsync(verification.Id.ToString());
Console.WriteLine($"Verification retrieved previous status: {verification.Status}, current status: {getStatus.Status}");



}
}
}
6 changes: 6 additions & 0 deletions src/Telnyx.net/Entities/Enum/RecordType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ public enum RecordType

[EnumMember(Value = "billing_group")]
BillingGroup = 54,

[EnumMember(Value = "verify_profile")]
VerifyProfile = 55,

[EnumMember(Value = "verification")]
Verification = 56,
}

}
37 changes: 37 additions & 0 deletions src/Telnyx.net/Entities/Enum/VerifyStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Telnyx.net.Infrastructure.JsonConverters;

namespace Telnyx.net.Entities.Enum
{
[JsonConverter(typeof(SafeStringEnumConverter), Unknown)]
public enum VerifyStatus
{
Unknown = -1,
[EnumMember(Value = "pending")]
Pending = 0,
[EnumMember(Value = "sms_delivery_failed")]
SmsDeliveryFailed = 1,
[EnumMember(Value = "accepted")]
Accepted = 2,
[EnumMember(Value = "expired")]
Expired = 3,
[EnumMember(Value = "not_enough_credit")]
NotEnoughCredit = 4,
[EnumMember(Value = "network_error")]
NetworkError = 5,
[EnumMember(Value = "number_unreachable")]
NumberUnreachable = 6,
[EnumMember(Value = "internal_error")]
InternalError = 7,
[EnumMember(Value = "invalid_destination")]
InvalidDestination = 8,
[EnumMember(Value = "timed_out")]
TimedOut = 9
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ public enum LineTypeEnum
[JsonProperty("completed_at")]
public DateTime? CompletedAt { get; set; }

[JsonProperty("organization_id")]
public Guid? OrganizationId { get; set; }
/// <inheritdoc/>
string IHasId.Id
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,11 @@ public class NewMessagingSenderId : BaseOptions
/// <value>If the profile this number is associated with has webhooks, use them for delivery notifications. If webhooks are also specified on the message itself, they will be attempted first, then those on the profile.</value>
[JsonProperty("use_profile_webhooks")]
public bool? UseProfileWebhooks { get; set; }

/// <summary>
/// Automatically detect if an SMS message is unusually long and exceeds a recommended limit of message parts.
/// </summary>
[JsonProperty("auto_detect")]
public bool AutoDetect { get; set; }
}
}
52 changes: 52 additions & 0 deletions src/Telnyx.net/Entities/VerifyAPI/Verify.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telnyx.net.Entities.Enum;

namespace Telnyx.net.Entities.VerifyAPI
{
public class Verify : VerifyBase
{
[JsonProperty("created_at")]
public DateTimeOffset? CreatedAt { get; set; }

[JsonProperty("id")]
public Guid Id { get; set; }

[JsonProperty("organization_id")]
public string OrganizationId { get; set; }

/// <summary>
/// Identifies the type of the resource.
/// </summary>
[JsonProperty("record_type")]
public RecordType? RecordType { get; set; }
/// <summary>
/// The possible statuses of the verify verification request.
/// </summary>
[JsonProperty("status")]
public VerifyStatus Status { get; set; }
/// <summary>
/// This is the number of seconds before the code of the request is expired. Once this request has expired, the code will no longer verify the user.
/// <para>Note: this will override the `default_timeout_secs` on the verify profile</para>
/// </summary>
[JsonProperty("timeout_secs")]
public long TimeoutSecs { get; set; }
/// <summary>
/// The identifier of the associated verify profile.
/// </summary>
[JsonProperty("verify_profile_id")]
public Guid VerifyProfileId { get; set; }
/// <summary>
/// The verification request type
/// </summary>
[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("updated_at")]
public DateTimeOffset? UpdatedAt { get; set; }
}
}
18 changes: 18 additions & 0 deletions src/Telnyx.net/Entities/VerifyAPI/VerifyBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Telnyx.net.Entities.VerifyAPI
{
public class VerifyBase : TelnyxEntity
{
/// <summary>
/// +E164 formatted phone number.
/// </summary>
[JsonProperty("phone_number")]
public string PhoneNumber { get; set; }
}
}
20 changes: 20 additions & 0 deletions src/Telnyx.net/Entities/VerifyAPI/VerifyCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telnyx.net.Entities.Enum;

namespace Telnyx.net.Entities.VerifyAPI
{
public class VerifyCode : VerifyBase
{
/// <summary>
/// Identifies if the verification code has been accepted or rejected.
/// <para>Options: ["accepted","rejected"]</para>
/// </summary>
[JsonProperty("response_code")]
public string ResponseCode { get; set; }
}
}
53 changes: 53 additions & 0 deletions src/Telnyx.net/Entities/VerifyAPI/VerifyProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telnyx.net.Entities.Enum;

namespace Telnyx.net.Entities.VerifyAPI
{
public class VerifyProfile : TelnyxEntity
{
[JsonProperty("created_at")]
public DateTimeOffset? CreatedAt { get; set; }
/// <summary>
/// For every request that is initiated via this verify Profile, this sets the number of seconds before a verification request code expires. Once the verification request expires, the user cannot use the code to verify their identity.
/// </summary>
[JsonProperty("default_timeout_secs")]
public long DefaultTimeoutSecs { get; set; }

[JsonProperty("id")]
public Guid? Id { get; set; }
/// <summary>
/// Enables SMS text messaging for the verify profile.
/// </summary>
[JsonProperty("messaging_enabled")]
public bool MessagingEnabled { get; set; }
/// <summary>
/// Optionally sets a messaging text template when sending the verification code. Uses `{code}` to template in the actual verification code.
/// </summary>
[JsonProperty("messaging_template")]
public string MessagingTemplate { get; set; }
/// <summary>
/// The name of the verify profile.
/// </summary>
[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("organization_id")]
public string OrganizationId { get; set; }
/// <summary>
/// Enables RCS messaging for the verify profile.
/// </summary>
[JsonProperty("rcs_enabled")]
public bool RcsEnabled { get; set; }

[JsonProperty("record_type")]
public RecordType? RecordType { get; set; }

[JsonProperty("updated_at")]
public DateTimeOffset? UpdatedAt { get; set; }
}
}
57 changes: 0 additions & 57 deletions src/Telnyx.net/Examples/MessagesExample.cs

This file was deleted.

Loading

0 comments on commit 0226b6d

Please sign in to comment.