-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor(sms): inbounds as IInbound * refactor(verification): make specific request by type Update report response model with new data * refactor(verification): update models to split verification status and report responses * fix: rename flashCall to flashcall * chore: remove obsolete test * chore(sms): remove Type prop, add serde based on json value
- Loading branch information
Showing
24 changed files
with
602 additions
and
242 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Sinch.SMS.Inbounds | ||
{ | ||
public class BinaryInbound : IInbound | ||
{ | ||
/// <summary> | ||
/// The ID of this inbound message. | ||
/// </summary> | ||
#if NET7_0_OR_GREATER | ||
public required string Id { get; set; } | ||
|
||
#else | ||
public string Id { get; set; } = null!; | ||
|
||
#endif | ||
|
||
/// <summary> | ||
/// The phone number that sent the message. | ||
/// </summary> | ||
#if NET7_0_OR_GREATER | ||
public required string From { get; set; } | ||
#else | ||
public string From { get; set; } = null!; | ||
#endif | ||
|
||
|
||
/// <summary> | ||
/// The Sinch phone number or short code to which the message was sent. | ||
/// </summary> | ||
#if NET7_0_OR_GREATER | ||
public required string To { get; set; } | ||
#else | ||
public string To { get; set; } = null!; | ||
#endif | ||
|
||
/// <summary> | ||
/// The message content Base64 encoded. <br/><br/> | ||
/// Max 140 bytes together with udh. | ||
/// </summary> | ||
#if NET7_0_OR_GREATER | ||
public required string Body { get; set; } | ||
#else | ||
public string Body { get; set; } = null!; | ||
#endif | ||
|
||
|
||
/// <summary> | ||
/// If this inbound message is in response to a previously sent message that contained a client reference, | ||
/// then this field contains that client reference.<br /><br /> | ||
/// Utilizing this feature requires additional setup on your account. | ||
/// Contact your <see href="https://dashboard.sinch.com/settings/account-details">account manager</see> | ||
/// to enable this feature. | ||
/// </summary> | ||
public string? ClientReference { get; set; } | ||
|
||
/// <summary> | ||
/// The MCC/MNC of the sender's operator if known. | ||
/// </summary> | ||
public string? OperatorId { get; set; } | ||
|
||
/// <summary> | ||
/// When the message left the originating device. Only available if provided by operator. | ||
/// </summary> | ||
public DateTime? SendAt { get; set; } | ||
|
||
/// <summary> | ||
/// When the system received the message. | ||
/// </summary> | ||
#if NET7_0_OR_GREATER | ||
public required DateTime ReceivedAt { get; set; } | ||
#else | ||
public DateTime ReceivedAt { get; set; } | ||
#endif | ||
|
||
/// <summary> | ||
/// The UDH header of a binary message HEX encoded. Max 140 bytes together with body. | ||
/// </summary> | ||
|
||
#if NET7_0_OR_GREATER | ||
public required string Udh { get; set; } | ||
#else | ||
public string Udh { get; set; } = null!; | ||
#endif | ||
} | ||
} |
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,54 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using Sinch.Core; | ||
|
||
namespace Sinch.SMS.Inbounds | ||
{ | ||
/// <summary> | ||
/// Marker interface for Inbound types | ||
/// </summary> | ||
[JsonInterfaceConverter(typeof(InboundJsonConverter))] | ||
public interface IInbound | ||
{ | ||
} | ||
|
||
public class InboundJsonConverter : JsonConverter<IInbound> | ||
{ | ||
public override IInbound? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
var elem = JsonElement.ParseValue(ref reader); | ||
var descriptor = elem.EnumerateObject().FirstOrDefault(x => x.Name == "type"); | ||
var method = descriptor.Value.GetString(); | ||
|
||
if (SmsType.Text.Value == method) | ||
return elem.Deserialize<SmsInbound>(options); | ||
|
||
if (SmsType.Binary.Value == method) | ||
return elem.Deserialize<BinaryInbound>(options); | ||
|
||
throw new JsonException( | ||
$"Failed to match verification method object, got prop `{descriptor.Name}` with value `{method}`"); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, IInbound value, JsonSerializerOptions options) | ||
{ | ||
var type = value.GetType(); | ||
if (type == typeof(SmsInbound)) | ||
{ | ||
JsonSerializer.Serialize(writer, value as SmsInbound, options); | ||
} | ||
|
||
if (type == typeof(BinaryInbound)) | ||
{ | ||
JsonSerializer.Serialize(writer, value as BinaryInbound, options); | ||
} | ||
else | ||
{ | ||
throw new InvalidOperationException( | ||
$"Cannot serialize unknown type of {nameof(IInbound)}"); | ||
} | ||
} | ||
} | ||
} |
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
4 changes: 1 addition & 3 deletions
4
...Verification/Report/Response/PriceBase.cs → src/Sinch/Verification/Common/PriceBase.cs
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
11 changes: 5 additions & 6 deletions
11
src/Sinch/Verification/Report/Response/ReportCalloutVerificationResponse.cs
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 |
---|---|---|
@@ -1,15 +1,14 @@ | ||
using Sinch.Verification.Common; | ||
|
||
namespace Sinch.Verification.Report.Response | ||
{ | ||
public class ReportCalloutVerificationResponse : VerificationReportResponseBase, IVerificationReportResponse | ||
{ | ||
/// <summary> | ||
/// Shows whether the call is complete or not. | ||
/// </summary> | ||
public bool CallComplete { get; set; } | ||
public override VerificationMethod Method { get; protected set; } = VerificationMethod.Callout; | ||
|
||
/// <summary> | ||
/// Prices associated with this verification | ||
/// Shows whether the call is complete or not. | ||
/// </summary> | ||
public Price? Price { get; set; } | ||
public bool? CallComplete { get; set; } | ||
} | ||
} |
11 changes: 5 additions & 6 deletions
11
src/Sinch/Verification/Report/Response/ReportFlashCallVerificationResponse.cs
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 |
---|---|---|
@@ -1,17 +1,16 @@ | ||
using System.Text.Json.Serialization; | ||
using Sinch.Verification.Common; | ||
|
||
namespace Sinch.Verification.Report.Response | ||
{ | ||
public class ReportFlashCallVerificationResponse : VerificationReportResponseBase, IVerificationReportResponse | ||
{ | ||
/// <summary> | ||
/// Free text that the client is sending, used to show if the call/SMS was intercepted or not. | ||
/// </summary> | ||
public Source? Source { get; set; } | ||
[JsonInclude] | ||
public override VerificationMethod Method { get; protected set; } = VerificationMethod.FlashCall; | ||
|
||
/// <summary> | ||
/// Prices associated with this verification | ||
/// Shows whether the call is complete or not. | ||
/// </summary> | ||
public Price? Price { get; set; } | ||
public bool? CallComplete { 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
Oops, something went wrong.