-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bas Gijzen
committed
Jan 8, 2024
1 parent
3501d8d
commit 09bec63
Showing
7 changed files
with
309 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.Text.Json.Serialization; | ||
using JetBrains.Annotations; | ||
|
||
namespace CM.Text.Identity | ||
{ | ||
/// <summary> | ||
/// A request to send an OTP towards an end-user. | ||
/// </summary> | ||
[PublicAPI] | ||
public class OtpRequest | ||
{ | ||
/// <summary> | ||
/// Required: This is the sender name. | ||
/// The maximum length is 11 alphanumerical characters or 16 digits. Example: 'MyCompany' | ||
/// </summary> | ||
[JsonPropertyName("from")] | ||
public string From { get; set; } | ||
|
||
/// <summary> | ||
/// Required: The destination mobile numbers. | ||
/// This value should be in international format. | ||
/// A single mobile number per request. Example: '00447911123456' | ||
/// </summary> | ||
[JsonPropertyName("to")] | ||
public string To { get; set; } | ||
|
||
/// <summary> | ||
/// The length of the code (min 4, max 10). default: 5. | ||
/// </summary> | ||
[JsonPropertyName("digits")] | ||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
public int? Digits { get; set; } | ||
|
||
/// <summary> | ||
/// The expiry in seconds (min 10, max 3600). default: 60 seconds. | ||
/// </summary> | ||
[JsonPropertyName("expiry")] | ||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
public int? Expiry { get; set; } | ||
|
||
/// <summary> | ||
/// The channel to send the code. | ||
/// Supported values: auto, sms, push, whatsapp, voice, email. | ||
/// Channel auto is only available with a SOLiD subscription. | ||
/// </summary> | ||
[JsonPropertyName("channel")] | ||
public string Channel { get; set; } = "sms"; | ||
|
||
/// <summary> | ||
/// The locale, for WhatsApp supported values: en, nl, fr, de, it, es. | ||
/// Default: en | ||
/// | ||
/// For Voice: the spoken language in the voice call, | ||
/// supported values: de-DE, en-AU, en-GB, en-IN, en-US, es-ES, fr-CA, fr-FR, it-IT, ja-JP, nl-NL | ||
/// Default: en-GB. | ||
/// | ||
/// For Email: The locale for the email template. | ||
/// </summary> | ||
[JsonPropertyName("locale")] | ||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
[CanBeNull] | ||
public string Locale { get; set; } | ||
|
||
/// <summary> | ||
/// The app key, when <see cref="Channel"/> is 'push' | ||
/// </summary> | ||
[JsonPropertyName("pushAppKey")] | ||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
[CanBeNull] | ||
public string PushAppKey { get; set; } | ||
|
||
/// <summary> | ||
/// For WhatsApp, set a custom message. You can use the placeholder {code}, this will be replaced by the actual code. | ||
/// Example: Your code is: {code}. This is only used as a fallback in case the message could not be delivered via WhatsApp. | ||
/// | ||
/// For email, Set a custom message to be used in the email message. Do not include the {code} placeholder. | ||
/// </summary> | ||
[JsonPropertyName("message")] | ||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] | ||
[CanBeNull] | ||
public string Message { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
| ||
using JetBrains.Annotations; | ||
|
||
namespace CM.Text.Identity | ||
{ | ||
/// <summary> | ||
/// Builder class to construct messages | ||
/// </summary> | ||
[PublicAPI] | ||
public class OtpRequestBuilder | ||
{ | ||
private readonly OtpRequest _otpRequest; | ||
|
||
/// <summary> | ||
/// Creates a new OtpRequestBuilder | ||
/// </summary> | ||
/// <param name="from"></param> | ||
/// <param name="to"></param> | ||
public OtpRequestBuilder(string from, string to) | ||
{ | ||
_otpRequest = new OtpRequest { From = from, To = to }; | ||
} | ||
|
||
/// <summary> | ||
/// Constructs the request. | ||
/// </summary> | ||
/// <returns></returns> | ||
public OtpRequest Build() | ||
{ | ||
return _otpRequest; | ||
} | ||
|
||
/// <summary> | ||
/// Set the channel | ||
/// </summary> | ||
public OtpRequestBuilder WithChannel(string channel) | ||
{ | ||
_otpRequest.Channel = channel; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// Sets The length of the code (min 4, max 10). default: 5. | ||
/// </summary> | ||
/// <param name="digits"></param> | ||
/// <returns></returns> | ||
public OtpRequestBuilder WithDigits(int digits) | ||
{ | ||
_otpRequest.Digits = digits; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// The expiry in seconds (min 10, max 3600). default: 60 seconds. | ||
/// </summary> | ||
public OtpRequestBuilder WithExpiry(int expiryInSeconds) | ||
{ | ||
_otpRequest.Expiry = expiryInSeconds; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// The locale, for WhatsApp supported values: en, nl, fr, de, it, es. | ||
/// Default: en | ||
/// | ||
/// For Voice: the spoken language in the voice call, | ||
/// supported values: de-DE, en-AU, en-GB, en-IN, en-US, es-ES, fr-CA, fr-FR, it-IT, ja-JP, nl-NL | ||
/// Default: en-GB. | ||
/// | ||
/// For Email: The locale for the email template. | ||
/// </summary> | ||
/// <param name="locale"></param> | ||
/// <returns></returns> | ||
public OtpRequestBuilder WithLocale(string locale) | ||
{ | ||
_otpRequest.Locale = locale; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// The app key, when the channel is 'push' | ||
/// </summary> | ||
/// <param name="pushAppKey"></param> | ||
/// <returns></returns> | ||
public OtpRequestBuilder WithPushAppKey(string pushAppKey) | ||
{ | ||
_otpRequest.PushAppKey = pushAppKey; | ||
return this; | ||
} | ||
|
||
/// <summary> | ||
/// For WhatsApp, set a custom message. You can use the placeholder {code}, this will be replaced by the actual code. | ||
/// Example: Your code is: {code}. This is only used as a fallback in case the message could not be delivered via WhatsApp. | ||
/// | ||
/// For email, Set a custom message to be used in the email message. Do not include the {code} placeholder. | ||
/// </summary> | ||
/// <param name="message"></param> | ||
/// <returns></returns> | ||
public OtpRequestBuilder WithMessage(string message) | ||
{ | ||
_otpRequest.Message = message; | ||
return this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace CM.Text.Identity | ||
{ | ||
/// <summary> | ||
/// The result of an OTP request. | ||
/// </summary> | ||
public class OtpResult | ||
{ | ||
/// <summary> | ||
/// The identifier of the OTP. | ||
/// </summary> | ||
[JsonPropertyName("id")] | ||
public string Id { get; set; } | ||
/// <summary> | ||
/// The channel used to send the code. | ||
/// </summary> | ||
[JsonPropertyName("channel")] | ||
public string Channel { get; set; } | ||
/// <summary> | ||
/// Indicates if the code was valid. | ||
/// </summary> | ||
[JsonPropertyName("verified")] | ||
public bool Verified { get; set; } | ||
/// <summary> | ||
/// The date the OTP was created. | ||
/// </summary> | ||
[JsonPropertyName("createdAt")] | ||
public DateTime CreatedAt { get; set; } | ||
/// <summary> | ||
/// The date the OTP will expire. | ||
/// </summary> | ||
[JsonPropertyName("expiresAt")] | ||
public DateTime ExpiresAt { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters