Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/otp code #69

Merged
merged 6 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false

# this. preferences
dotnet_style_qualification_for_field = true
dotnet_style_qualification_for_field = false:silent
dotnet_style_qualification_for_property = false:silent
dotnet_style_qualification_for_method = false:silent
dotnet_style_qualification_for_event = false:silent
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.8.0] - 2024-01-08
### Added
- Implementing OTP Request and verify

## [2.7.0] - 2023-06-26
### Added
- Whatsapp Multi-Product Template Messages
Expand Down
13 changes: 8 additions & 5 deletions CM.Text.Tests/CM.Text.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions CM.Text/BusinessMessaging/CarouselBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class CarouselBuilder
/// <param name="carouselCardWidth"></param>
public CarouselBuilder(CarouselCardWidth carouselCardWidth)
{
this._carouselCardWidth = carouselCardWidth;
_carouselCardWidth = carouselCardWidth;
}

/// <summary>
Expand All @@ -29,7 +29,7 @@ public CarouselBuilder(CarouselCardWidth carouselCardWidth)
/// <returns></returns>
public CarouselBuilder AddCard(RichCard card)
{
this._cards.Add(card);
_cards.Add(card);
return this;
}

Expand All @@ -41,7 +41,7 @@ public CarouselMessage Build()
{
return new CarouselMessage
{
Carousel = new Carousel {Cards = this._cards.ToArray(), CarouselCardWidth = this._carouselCardWidth}
Carousel = new Carousel {Cards = _cards.ToArray(), CarouselCardWidth = _carouselCardWidth}
};
}
}
Expand Down
44 changes: 22 additions & 22 deletions CM.Text/BusinessMessaging/MessageBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class MessageBuilder
/// <param name="to"></param>
public MessageBuilder(string messageText, string from, params string[] to)
{
this._message = new Message
_message = new Message
{
Body = new Body
{
Expand All @@ -44,8 +44,8 @@ public MessageBuilder(string messageText, string from, params string[] to)
/// <returns></returns>
public Message Build()
{
this._message.RichContent = this._richContent;
return this._message;
_message.RichContent = _richContent;
return _message;
}

/// <summary>
Expand All @@ -59,7 +59,7 @@ public Message Build()
/// </remarks>
public MessageBuilder WithAllowedChannels(params Channel[] channels)
{
this._message.AllowedChannels = channels;
_message.AllowedChannels = channels;
return this;
}

Expand All @@ -70,7 +70,7 @@ public MessageBuilder WithAllowedChannels(params Channel[] channels)
/// <returns></returns>
public MessageBuilder WithReference(string reference)
{
this._message.Reference = reference;
_message.Reference = reference;
return this;
}

Expand All @@ -97,7 +97,7 @@ public MessageBuilder WithReference(string reference)
/// <returns></returns>
public MessageBuilder WithValidityPeriod(string period)
{
this._message.Validity = period;
_message.Validity = period;
return this;
}

Expand All @@ -110,10 +110,10 @@ public MessageBuilder WithValidityPeriod(string period)
/// <returns></returns>
public MessageBuilder WithRichMessage(IRichMessage richMessage)
{
if (this._richContent == null)
this._richContent = new RichContent();
if (_richContent == null)
_richContent = new RichContent();

this._richContent.AddConversationPart(richMessage);
_richContent.AddConversationPart(richMessage);
return this;
}

Expand All @@ -125,10 +125,10 @@ public MessageBuilder WithRichMessage(IRichMessage richMessage)
/// <returns></returns>
public MessageBuilder WithSuggestions(params SuggestionBase[] suggestions)
{
if (this._richContent == null)
this._richContent = new RichContent();
if (_richContent == null)
_richContent = new RichContent();

this._richContent.Suggestions = suggestions;
_richContent.Suggestions = suggestions;
return this;
}

Expand All @@ -138,7 +138,7 @@ public MessageBuilder WithSuggestions(params SuggestionBase[] suggestions)
/// </summary>
public MessageBuilder WitHybridAppKey(Guid appKey)
{
this._message.HybridAppKey = appKey;
_message.HybridAppKey = appKey;
return this;
}

Expand All @@ -150,10 +150,10 @@ public MessageBuilder WitHybridAppKey(Guid appKey)
/// <returns></returns>
public MessageBuilder WithTemplate(TemplateMessage template)
{
if (this._richContent == null)
this._richContent = new RichContent();
if (_richContent == null)
_richContent = new RichContent();

this._richContent.AddConversationPart(template);
_richContent.AddConversationPart(template);
return this;
}

Expand All @@ -164,10 +164,10 @@ public MessageBuilder WithTemplate(TemplateMessage template)
/// <returns></returns>
public MessageBuilder WithInteractive(WhatsAppInteractiveMessage interactive)
{
if (this._richContent == null)
this._richContent = new RichContent();
if (_richContent == null)
_richContent = new RichContent();

this._richContent.AddConversationPart(interactive);
_richContent.AddConversationPart(interactive);
return this;
}

Expand All @@ -178,10 +178,10 @@ public MessageBuilder WithInteractive(WhatsAppInteractiveMessage interactive)
/// <returns></returns>
public MessageBuilder WithApplePay(ApplePayRequest applePayRequest)
{
if (this._richContent == null)
this._richContent = new RichContent();
if (_richContent == null)
_richContent = new RichContent();

this._richContent.AddConversationPart(applePayRequest);
_richContent.AddConversationPart(applePayRequest);
return this;
}
}
Expand Down
6 changes: 3 additions & 3 deletions CM.Text/BusinessMessaging/Model/MultiChannel/MediaContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public MediaContent()
/// <param name="mimeType"></param>
public MediaContent(string mediaName, string mediaUri, string mimeType)
{
this.MediaName = mediaName;
this.MediaUri = mediaUri;
this.MimeType = mimeType;
MediaName = mediaName;
MediaUri = mediaUri;
MimeType = mimeType;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MediaMessage()
/// <param name="mimeType"></param>
public MediaMessage(string mediaName, string mediaUri, string mimeType)
{
this.Media = new MediaContent(mediaName, mediaUri, mimeType);
Media = new MediaContent(mediaName, mediaUri, mimeType);
}

/// <summary>
Expand Down
24 changes: 12 additions & 12 deletions CM.Text/BusinessMessaging/Model/MultiChannel/RichContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class RichContent
/// </summary>
public RichContent()
{
this.Conversation = null;
this.Suggestions = null;
Conversation = null;
Suggestions = null;
}

/// <summary>
Expand All @@ -38,14 +38,14 @@ public RichContent()
/// <param name="part"></param>
public void AddConversationPart(IRichMessage part)
{
if (this.Conversation == null)
this.Conversation = new[] {part};
if (Conversation == null)
Conversation = new[] {part};
else
{
var newArr = this.Conversation;
Array.Resize(ref newArr, this.Conversation.Length + 1);
var newArr = Conversation;
Array.Resize(ref newArr, Conversation.Length + 1);
newArr[newArr.Length - 1] = part;
this.Conversation = newArr;
Conversation = newArr;
}
}

Expand All @@ -55,14 +55,14 @@ public void AddConversationPart(IRichMessage part)
/// <param name="suggestion"></param>
public void AddSuggestion(SuggestionBase suggestion)
{
if (this.Suggestions == null)
this.Suggestions = new[] {suggestion};
if (Suggestions == null)
Suggestions = new[] {suggestion};
else
{
var newArr = this.Suggestions;
Array.Resize(ref newArr, this.Suggestions.Length + 1);
var newArr = Suggestions;
Array.Resize(ref newArr, Suggestions.Length + 1);
newArr[newArr.Length - 1] = suggestion;
this.Suggestions = newArr;
Suggestions = newArr;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public TextMessage()
/// <param name="text"></param>
public TextMessage(string text)
{
this.Text = text;
Text = text;
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions CM.Text/CM.Text.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>icon.png</PackageIcon>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/../CHANGELOG.md"))</PackageReleaseNotes>
<Version>2.7.0</Version>
<Version>2.8.0</Version>
<PackageProjectUrl>https://github.com/cmdotcom/text-sdk-dotnet</PackageProjectUrl>
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyVersion>2.7.0</AssemblyVersion>
<FileVersion>2.7.0</FileVersion>
<AssemblyVersion>2.8.0</AssemblyVersion>
<FileVersion>2.8.0</FileVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>

Expand Down Expand Up @@ -63,7 +63,7 @@
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Text.Json" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions CM.Text/Common/Constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ internal static class Constant
internal static readonly string TextSdkReference = $"text-sdk-dotnet-{typeof(TextClient).Assembly.GetName().Version}";

internal const string BusinessMessagingGatewayJsonEndpoint = "https://gw.cmtelecom.com/v1.0/message";

internal const string OtpRequestEndpoint = "https://api.cm.com/otp/v2/otp";
internal const string OtpVerifyEndpointFormatter = "https://api.cm.com/otp/v2/otp/{0}/verify";

internal static readonly string BusinessMessagingGatewayMediaTypeJson = "application/json";
internal static readonly string BusinessMessagingBodyTypeAuto = "AUTO";
internal static readonly int BusinessMessagingMessagePartsMinDefault = 1;
Expand Down
83 changes: 83 additions & 0 deletions CM.Text/Identity/OtpRequest.cs
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; }
}
}
Loading