Skip to content

Commit 7359782

Browse files
authored
Merge pull request #69 from cmdotcom/feature/otp_code
Feature/otp code
2 parents ead36bf + 087e30d commit 7359782

18 files changed

+390
-65
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dotnet_sort_system_directives_first = true
2424
dotnet_separate_import_directive_groups = false
2525

2626
# this. preferences
27-
dotnet_style_qualification_for_field = true
27+
dotnet_style_qualification_for_field = false:silent
2828
dotnet_style_qualification_for_property = false:silent
2929
dotnet_style_qualification_for_method = false:silent
3030
dotnet_style_qualification_for_event = false:silent

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [2.8.0] - 2024-01-08
8+
### Added
9+
- Implementing OTP Request and verify
10+
711
## [2.7.0] - 2023-06-26
812
### Added
913
- Whatsapp Multi-Product Template Messages

CM.Text.Tests/CM.Text.Tests.csproj

+8-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="FluentAssertions" Version="6.7.0" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
14-
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
15-
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
16-
<PackageReference Include="coverlet.collector" Version="3.1.2" />
12+
<PackageReference Include="FluentAssertions" Version="6.12.0" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
14+
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
15+
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
16+
<PackageReference Include="coverlet.collector" Version="6.0.0">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
1720
</ItemGroup>
1821

1922
<ItemGroup>

CM.Text/BusinessMessaging/CarouselBuilder.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class CarouselBuilder
1919
/// <param name="carouselCardWidth"></param>
2020
public CarouselBuilder(CarouselCardWidth carouselCardWidth)
2121
{
22-
this._carouselCardWidth = carouselCardWidth;
22+
_carouselCardWidth = carouselCardWidth;
2323
}
2424

2525
/// <summary>
@@ -29,7 +29,7 @@ public CarouselBuilder(CarouselCardWidth carouselCardWidth)
2929
/// <returns></returns>
3030
public CarouselBuilder AddCard(RichCard card)
3131
{
32-
this._cards.Add(card);
32+
_cards.Add(card);
3333
return this;
3434
}
3535

@@ -41,7 +41,7 @@ public CarouselMessage Build()
4141
{
4242
return new CarouselMessage
4343
{
44-
Carousel = new Carousel {Cards = this._cards.ToArray(), CarouselCardWidth = this._carouselCardWidth}
44+
Carousel = new Carousel {Cards = _cards.ToArray(), CarouselCardWidth = _carouselCardWidth}
4545
};
4646
}
4747
}

CM.Text/BusinessMessaging/MessageBuilder.cs

+22-22
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class MessageBuilder
2424
/// <param name="to"></param>
2525
public MessageBuilder(string messageText, string from, params string[] to)
2626
{
27-
this._message = new Message
27+
_message = new Message
2828
{
2929
Body = new Body
3030
{
@@ -44,8 +44,8 @@ public MessageBuilder(string messageText, string from, params string[] to)
4444
/// <returns></returns>
4545
public Message Build()
4646
{
47-
this._message.RichContent = this._richContent;
48-
return this._message;
47+
_message.RichContent = _richContent;
48+
return _message;
4949
}
5050

5151
/// <summary>
@@ -59,7 +59,7 @@ public Message Build()
5959
/// </remarks>
6060
public MessageBuilder WithAllowedChannels(params Channel[] channels)
6161
{
62-
this._message.AllowedChannels = channels;
62+
_message.AllowedChannels = channels;
6363
return this;
6464
}
6565

@@ -70,7 +70,7 @@ public MessageBuilder WithAllowedChannels(params Channel[] channels)
7070
/// <returns></returns>
7171
public MessageBuilder WithReference(string reference)
7272
{
73-
this._message.Reference = reference;
73+
_message.Reference = reference;
7474
return this;
7575
}
7676

@@ -97,7 +97,7 @@ public MessageBuilder WithReference(string reference)
9797
/// <returns></returns>
9898
public MessageBuilder WithValidityPeriod(string period)
9999
{
100-
this._message.Validity = period;
100+
_message.Validity = period;
101101
return this;
102102
}
103103

@@ -110,10 +110,10 @@ public MessageBuilder WithValidityPeriod(string period)
110110
/// <returns></returns>
111111
public MessageBuilder WithRichMessage(IRichMessage richMessage)
112112
{
113-
if (this._richContent == null)
114-
this._richContent = new RichContent();
113+
if (_richContent == null)
114+
_richContent = new RichContent();
115115

116-
this._richContent.AddConversationPart(richMessage);
116+
_richContent.AddConversationPart(richMessage);
117117
return this;
118118
}
119119

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

131-
this._richContent.Suggestions = suggestions;
131+
_richContent.Suggestions = suggestions;
132132
return this;
133133
}
134134

@@ -138,7 +138,7 @@ public MessageBuilder WithSuggestions(params SuggestionBase[] suggestions)
138138
/// </summary>
139139
public MessageBuilder WitHybridAppKey(Guid appKey)
140140
{
141-
this._message.HybridAppKey = appKey;
141+
_message.HybridAppKey = appKey;
142142
return this;
143143
}
144144

@@ -150,10 +150,10 @@ public MessageBuilder WitHybridAppKey(Guid appKey)
150150
/// <returns></returns>
151151
public MessageBuilder WithTemplate(TemplateMessage template)
152152
{
153-
if (this._richContent == null)
154-
this._richContent = new RichContent();
153+
if (_richContent == null)
154+
_richContent = new RichContent();
155155

156-
this._richContent.AddConversationPart(template);
156+
_richContent.AddConversationPart(template);
157157
return this;
158158
}
159159

@@ -164,10 +164,10 @@ public MessageBuilder WithTemplate(TemplateMessage template)
164164
/// <returns></returns>
165165
public MessageBuilder WithInteractive(WhatsAppInteractiveMessage interactive)
166166
{
167-
if (this._richContent == null)
168-
this._richContent = new RichContent();
167+
if (_richContent == null)
168+
_richContent = new RichContent();
169169

170-
this._richContent.AddConversationPart(interactive);
170+
_richContent.AddConversationPart(interactive);
171171
return this;
172172
}
173173

@@ -178,10 +178,10 @@ public MessageBuilder WithInteractive(WhatsAppInteractiveMessage interactive)
178178
/// <returns></returns>
179179
public MessageBuilder WithApplePay(ApplePayRequest applePayRequest)
180180
{
181-
if (this._richContent == null)
182-
this._richContent = new RichContent();
181+
if (_richContent == null)
182+
_richContent = new RichContent();
183183

184-
this._richContent.AddConversationPart(applePayRequest);
184+
_richContent.AddConversationPart(applePayRequest);
185185
return this;
186186
}
187187
}

CM.Text/BusinessMessaging/Model/MultiChannel/MediaContent.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public MediaContent()
2424
/// <param name="mimeType"></param>
2525
public MediaContent(string mediaName, string mediaUri, string mimeType)
2626
{
27-
this.MediaName = mediaName;
28-
this.MediaUri = mediaUri;
29-
this.MimeType = mimeType;
27+
MediaName = mediaName;
28+
MediaUri = mediaUri;
29+
MimeType = mimeType;
3030
}
3131

3232
/// <summary>

CM.Text/BusinessMessaging/Model/MultiChannel/MediaMessage.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public MediaMessage()
2525
/// <param name="mimeType"></param>
2626
public MediaMessage(string mediaName, string mediaUri, string mimeType)
2727
{
28-
this.Media = new MediaContent(mediaName, mediaUri, mimeType);
28+
Media = new MediaContent(mediaName, mediaUri, mimeType);
2929
}
3030

3131
/// <summary>

CM.Text/BusinessMessaging/Model/MultiChannel/RichContent.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public class RichContent
1616
/// </summary>
1717
public RichContent()
1818
{
19-
this.Conversation = null;
20-
this.Suggestions = null;
19+
Conversation = null;
20+
Suggestions = null;
2121
}
2222

2323
/// <summary>
@@ -38,14 +38,14 @@ public RichContent()
3838
/// <param name="part"></param>
3939
public void AddConversationPart(IRichMessage part)
4040
{
41-
if (this.Conversation == null)
42-
this.Conversation = new[] {part};
41+
if (Conversation == null)
42+
Conversation = new[] {part};
4343
else
4444
{
45-
var newArr = this.Conversation;
46-
Array.Resize(ref newArr, this.Conversation.Length + 1);
45+
var newArr = Conversation;
46+
Array.Resize(ref newArr, Conversation.Length + 1);
4747
newArr[newArr.Length - 1] = part;
48-
this.Conversation = newArr;
48+
Conversation = newArr;
4949
}
5050
}
5151

@@ -55,14 +55,14 @@ public void AddConversationPart(IRichMessage part)
5555
/// <param name="suggestion"></param>
5656
public void AddSuggestion(SuggestionBase suggestion)
5757
{
58-
if (this.Suggestions == null)
59-
this.Suggestions = new[] {suggestion};
58+
if (Suggestions == null)
59+
Suggestions = new[] {suggestion};
6060
else
6161
{
62-
var newArr = this.Suggestions;
63-
Array.Resize(ref newArr, this.Suggestions.Length + 1);
62+
var newArr = Suggestions;
63+
Array.Resize(ref newArr, Suggestions.Length + 1);
6464
newArr[newArr.Length - 1] = suggestion;
65-
this.Suggestions = newArr;
65+
Suggestions = newArr;
6666
}
6767
}
6868
}

CM.Text/BusinessMessaging/Model/MultiChannel/TextMessage.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public TextMessage()
2323
/// <param name="text"></param>
2424
public TextMessage(string text)
2525
{
26-
this.Text = text;
26+
Text = text;
2727
}
2828

2929
/// <summary>

CM.Text/CM.Text.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1414
<PackageIcon>icon.png</PackageIcon>
1515
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/../CHANGELOG.md"))</PackageReleaseNotes>
16-
<Version>2.7.0</Version>
16+
<Version>2.8.0</Version>
1717
<PackageProjectUrl>https://github.com/cmdotcom/text-sdk-dotnet</PackageProjectUrl>
1818
<NeutralLanguage>en</NeutralLanguage>
1919
<GenerateDocumentationFile>true</GenerateDocumentationFile>
20-
<AssemblyVersion>2.7.0</AssemblyVersion>
21-
<FileVersion>2.7.0</FileVersion>
20+
<AssemblyVersion>2.8.0</AssemblyVersion>
21+
<FileVersion>2.8.0</FileVersion>
2222
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
2323
</PropertyGroup>
2424

@@ -63,7 +63,7 @@
6363
</ItemGroup>
6464

6565
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
66-
<PackageReference Include="System.Text.Json" Version="7.0.0" />
66+
<PackageReference Include="System.Text.Json" Version="8.0.0" />
6767
</ItemGroup>
6868

6969
<ItemGroup>

CM.Text/Common/Constant.cs

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ internal static class Constant
55
internal static readonly string TextSdkReference = $"text-sdk-dotnet-{typeof(TextClient).Assembly.GetName().Version}";
66

77
internal const string BusinessMessagingGatewayJsonEndpoint = "https://gw.cmtelecom.com/v1.0/message";
8+
9+
internal const string OtpRequestEndpoint = "https://api.cm.com/otp/v2/otp";
10+
internal const string OtpVerifyEndpointFormatter = "https://api.cm.com/otp/v2/otp/{0}/verify";
11+
812
internal static readonly string BusinessMessagingGatewayMediaTypeJson = "application/json";
913
internal static readonly string BusinessMessagingBodyTypeAuto = "AUTO";
1014
internal static readonly int BusinessMessagingMessagePartsMinDefault = 1;

CM.Text/Identity/OtpRequest.cs

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System.Text.Json.Serialization;
2+
using JetBrains.Annotations;
3+
4+
namespace CM.Text.Identity
5+
{
6+
/// <summary>
7+
/// A request to send an OTP towards an end-user.
8+
/// </summary>
9+
[PublicAPI]
10+
public class OtpRequest
11+
{
12+
/// <summary>
13+
/// Required: This is the sender name.
14+
/// The maximum length is 11 alphanumerical characters or 16 digits. Example: 'MyCompany'
15+
/// </summary>
16+
[JsonPropertyName("from")]
17+
public string From { get; set; }
18+
19+
/// <summary>
20+
/// Required: The destination mobile numbers.
21+
/// This value should be in international format.
22+
/// A single mobile number per request. Example: '00447911123456'
23+
/// </summary>
24+
[JsonPropertyName("to")]
25+
public string To { get; set; }
26+
27+
/// <summary>
28+
/// The length of the code (min 4, max 10). default: 5.
29+
/// </summary>
30+
[JsonPropertyName("digits")]
31+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
32+
public int? Digits { get; set; }
33+
34+
/// <summary>
35+
/// The expiry in seconds (min 10, max 3600). default: 60 seconds.
36+
/// </summary>
37+
[JsonPropertyName("expiry")]
38+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
39+
public int? Expiry { get; set; }
40+
41+
/// <summary>
42+
/// The channel to send the code.
43+
/// Supported values: auto, sms, push, whatsapp, voice, email.
44+
/// Channel auto is only available with a SOLiD subscription.
45+
/// </summary>
46+
[JsonPropertyName("channel")]
47+
public string Channel { get; set; } = "sms";
48+
49+
/// <summary>
50+
/// The locale, for WhatsApp supported values: en, nl, fr, de, it, es.
51+
/// Default: en
52+
///
53+
/// For Voice: the spoken language in the voice call,
54+
/// supported values: de-DE, en-AU, en-GB, en-IN, en-US, es-ES, fr-CA, fr-FR, it-IT, ja-JP, nl-NL
55+
/// Default: en-GB.
56+
///
57+
/// For Email: The locale for the email template.
58+
/// </summary>
59+
[JsonPropertyName("locale")]
60+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
61+
[CanBeNull]
62+
public string Locale { get; set; }
63+
64+
/// <summary>
65+
/// The app key, when <see cref="Channel"/> is 'push'
66+
/// </summary>
67+
[JsonPropertyName("pushAppKey")]
68+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
69+
[CanBeNull]
70+
public string PushAppKey { get; set; }
71+
72+
/// <summary>
73+
/// For WhatsApp, set a custom message. You can use the placeholder {code}, this will be replaced by the actual code.
74+
/// Example: Your code is: {code}. This is only used as a fallback in case the message could not be delivered via WhatsApp.
75+
///
76+
/// For email, Set a custom message to be used in the email message. Do not include the {code} placeholder.
77+
/// </summary>
78+
[JsonPropertyName("message")]
79+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
80+
[CanBeNull]
81+
public string Message { get; set; }
82+
}
83+
}

0 commit comments

Comments
 (0)