Skip to content

Commit 5372991

Browse files
minnieliuMinnie Liu
andauthored
[Communication] - SMS - API Design and Implementation 03-07 (Azure#19073)
* Initial commit of new SMS API * Fix build * Resolve PR comments and implement SmsModelFactory * Fix build * Regenerate export api * Address review comments Co-authored-by: Minnie Liu <peiliu@microsoft.com>
1 parent 22cb7ad commit 5372991

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1190
-443
lines changed

sdk/communication/Azure.Communication.Sms/CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44

55
### Added
66
- Added support to create SmsClient with AzureKeyCredential.
7-
- Support for creating SmsClient with TokenCredential
8-
7+
- Support for creating SmsClient with TokenCredential.
8+
- Added support for 1:N SMS messaging.
9+
- Added support for tagging SMS messages.
10+
- Send method series in SmsClient are idempotent under retry policy.
11+
12+
### Breaking
13+
- Updated `Task<Response<SendSmsResponse>> SendAsync(PhoneNumberIdentifier from, PhoneNumberIdentifier to, string message, SendSmsOptions sendSmsOptions = null, CancellationToken cancellationToken = default)`
14+
to `Task<Response<SmsSendResult>> SendAsync(string from, string to, string message, Models.SmsSendOptions options = default)`
15+
- Replaced `SendSmsResponse` with `SmsSendResult`
916

1017
## 1.0.0-beta.3 (2020-11-16)
1118

sdk/communication/Azure.Communication.Sms/README.md

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Azure Communication SMS client library for .NET
22
> Server Version:
3-
Chat client: 2020-07-20-preview1
3+
Sms client: 2021-03-07
44

55
This package contains a C# SDK for Azure Communication Services for SMS and Telephony.
66

@@ -11,7 +11,7 @@ This package contains a C# SDK for Azure Communication Services for SMS and Tele
1111
Install the Azure Communication SMS client library for .NET with [NuGet][nuget]:
1212

1313
```PowerShell
14-
dotnet add package Azure.Communication.Sms --version 1.0.0-beta.3
14+
dotnet add package Azure.Communication.Sms --version 1.0.0-beta.4
1515
```
1616

1717
### Prerequisites
@@ -25,6 +25,7 @@ To create a new Communication Service, you can use the [Azure Portal][communicat
2525
### Using statements
2626
```C# Snippet:Azure_Communication_Sms_Tests_UsingStatements
2727
using System;
28+
using System.Collections.Generic;
2829
using Azure.Communication.Sms;
2930
```
3031

@@ -45,40 +46,43 @@ TokenCredential tokenCredential = new DefaultAzureCredential();
4546
SmsClient client = new SmsClient(new Uri(endpoint), tokenCredential);
4647
```
4748

48-
### Thread safety
49-
We guarantee that all client instance methods are thread-safe and independent of each other ([guideline](https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-service-methods-thread-safety)). This ensures that the recommendation of reusing client instances is always safe, even across threads.
50-
51-
### Additional concepts
52-
<!-- CLIENT COMMON BAR -->
53-
[Client options](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#configuring-service-clients-using-clientoptions) |
54-
[Accessing the response](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#accessing-http-response-details-using-responset) |
55-
[Long-running operations](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#consuming-long-running-operations-using-operationt) |
56-
[Handling failures](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#reporting-errors-requestfailedexception) |
57-
[Diagnostics](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagnostics.md) |
58-
[Mocking](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#mocking) |
59-
[Client lifetime](https://devblogs.microsoft.com/azure-sdk/lifetime-management-and-thread-safety-guarantees-of-azure-sdk-net-clients/)
60-
<!-- CLIENT COMMON BAR -->
61-
6249
## Examples
6350
### Send a SMS Message
6451
To send a SMS message, call the `Send` or `SendAsync` function from the `SmsClient`.
6552
```C# Snippet:Azure_Communication_Sms_Tests_SendAsync
66-
SendSmsResponse result = await client.SendAsync(
67-
from: new PhoneNumber("+18001230000"), // Phone number acquired on your Azure Communication resource
68-
to: new PhoneNumber("+18005670000"),
53+
SmsSendResult result = await client.SendAsync(
54+
from: "+18001230000" // Phone number acquired on your Azure Communication resource
55+
to: "+18005670000",
6956
message: "Hi");
7057
Console.WriteLine($"Sms id: {result.MessageId}");
7158
```
72-
59+
### Send a Group SMS Message
60+
To send a SMS message to a list of recipients, call the `Send` or `SendAsync` function from the `SmsClient` with a list of recipient's phone numbers.
61+
You may also add pass in an options object to specify whether the delivery report should be enabled and set custom tags.
62+
```C# Snippet:Azure_Communication_SmsClient_Send_GroupSmsWithOptions
63+
Response<IEnumerable<SmsSendResult>> response = await client.SendAsync(
64+
from: "+18001230000" // Phone number acquired on your Azure Communication resource
65+
to: new string[] {"+18005670000", "+18008900000}",
66+
message: "Hi",
67+
options: new SmsSendOptions(enableDeliveryReport: true) // OPTIONAL
68+
{
69+
Tag = "marketing", // custom tags
70+
});
71+
IEnumerable<SmsSendResult> results = response.Value;
72+
foreach (SmsSendResult result in results)
73+
{
74+
Console.WriteLine($"Sms id: {result.MessageId}");
75+
}
76+
```
7377
## Troubleshooting
7478
All SMS operations will throw a RequestFailedException on failure.
7579

7680
```C# Snippet:Azure_Communication_Sms_Tests_Troubleshooting
7781
try
7882
{
79-
SendSmsResponse result = await client.SendAsync(
80-
from: new PhoneNumber("+18001230000"), // Phone number acquired on your Azure Communication resource
81-
to: new PhoneNumber("+18005670000"),
83+
SmsSendResult result = await client.SendAsync(
84+
from: "+18001230000" // Phone number acquired on your Azure Communication resource
85+
to: "+18005670000",
8286
message: "Hi");
8387
Console.WriteLine($"Sms id: {result.MessageId}");
8488
}
@@ -112,4 +116,3 @@ This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For m
112116
[nextsteps]:https://docs.microsoft.com/azure/communication-services/quickstarts/telephony-sms/send?pivots=programming-language-csharp
113117
[nuget]: https://www.nuget.org/
114118
[source]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/communication/Azure.Communication.Sms/src
115-
Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
11
namespace Azure.Communication.Sms
22
{
3-
public partial class SendSmsOptions
4-
{
5-
public SendSmsOptions() { }
6-
public bool? EnableDeliveryReport { get { throw null; } set { } }
7-
}
8-
public partial class SendSmsResponse
9-
{
10-
internal SendSmsResponse() { }
11-
public string MessageId { get { throw null; } }
12-
}
133
public partial class SmsClient
144
{
155
protected SmsClient() { }
166
public SmsClient(string connectionString) { }
177
public SmsClient(string connectionString, Azure.Communication.Sms.SmsClientOptions options) { }
188
public SmsClient(System.Uri endpoint, Azure.AzureKeyCredential keyCredential, Azure.Communication.Sms.SmsClientOptions options = null) { }
199
public SmsClient(System.Uri endpoint, Azure.Core.TokenCredential tokenCredential, Azure.Communication.Sms.SmsClientOptions options = null) { }
20-
public virtual Azure.Response<Azure.Communication.Sms.SendSmsResponse> Send(Azure.Communication.PhoneNumberIdentifier from, Azure.Communication.PhoneNumberIdentifier to, string message, Azure.Communication.Sms.SendSmsOptions sendSmsOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
21-
public virtual Azure.Response<Azure.Communication.Sms.SendSmsResponse> Send(Azure.Communication.PhoneNumberIdentifier from, System.Collections.Generic.IEnumerable<Azure.Communication.PhoneNumberIdentifier> to, string message, Azure.Communication.Sms.SendSmsOptions sendSmsOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
22-
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.Sms.SendSmsResponse>> SendAsync(Azure.Communication.PhoneNumberIdentifier from, Azure.Communication.PhoneNumberIdentifier to, string message, Azure.Communication.Sms.SendSmsOptions sendSmsOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
23-
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.Sms.SendSmsResponse>> SendAsync(Azure.Communication.PhoneNumberIdentifier from, System.Collections.Generic.IEnumerable<Azure.Communication.PhoneNumberIdentifier> to, string message, Azure.Communication.Sms.SendSmsOptions sendSmsOptions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
10+
public virtual Azure.Response<System.Collections.Generic.IEnumerable<Azure.Communication.Sms.SmsSendResult>> Send(string from, System.Collections.Generic.IEnumerable<string> to, string message, Azure.Communication.Sms.SmsSendOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
11+
public virtual Azure.Response<Azure.Communication.Sms.SmsSendResult> Send(string from, string to, string message, Azure.Communication.Sms.SmsSendOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
12+
public virtual System.Threading.Tasks.Task<Azure.Response<System.Collections.Generic.IEnumerable<Azure.Communication.Sms.SmsSendResult>>> SendAsync(string from, System.Collections.Generic.IEnumerable<string> to, string message, Azure.Communication.Sms.SmsSendOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
13+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Communication.Sms.SmsSendResult>> SendAsync(string from, string to, string message, Azure.Communication.Sms.SmsSendOptions options = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
2414
}
2515
public partial class SmsClientOptions : Azure.Core.ClientOptions
2616
{
27-
public const Azure.Communication.Sms.SmsClientOptions.ServiceVersion LatestVersion = Azure.Communication.Sms.SmsClientOptions.ServiceVersion.V1;
28-
public SmsClientOptions(Azure.Communication.Sms.SmsClientOptions.ServiceVersion version = Azure.Communication.Sms.SmsClientOptions.ServiceVersion.V1, Azure.Core.RetryOptions retryOptions = null, Azure.Core.Pipeline.HttpPipelineTransport transport = null) { }
17+
public SmsClientOptions(Azure.Communication.Sms.SmsClientOptions.ServiceVersion version = Azure.Communication.Sms.SmsClientOptions.ServiceVersion.V2021_03_07) { }
2918
public enum ServiceVersion
3019
{
31-
V1 = 1,
20+
V2021_03_07 = 1,
3221
}
3322
}
23+
public partial class SmsSendOptions
24+
{
25+
public SmsSendOptions(bool enableDeliveryReport) { }
26+
public bool EnableDeliveryReport { get { throw null; } }
27+
public string Tag { get { throw null; } set { } }
28+
}
29+
public partial class SmsSendResult
30+
{
31+
internal SmsSendResult() { }
32+
public string ErrorMessage { get { throw null; } }
33+
public int HttpStatusCode { get { throw null; } }
34+
public string MessageId { get { throw null; } }
35+
public bool Successful { get { throw null; } }
36+
public string To { get { throw null; } }
37+
}
3438
}
3539
namespace Azure.Communication.Sms.Models
3640
{
3741
public static partial class SmsModelFactory
3842
{
39-
public static Azure.Communication.Sms.SendSmsResponse SendSmsResponse(string messageId) { throw null; }
43+
public static Azure.Communication.Sms.SmsSendResult SmsSendResult(string to, int httpStatusCode, bool successful) { throw null; }
4044
}
4145
}

sdk/communication/Azure.Communication.Sms/src/Generated/Models/SendMessageRequest.Serialization.cs

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.Sms/src/Generated/Models/SendMessageRequest.cs

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/communication/Azure.Communication.Sms/src/Generated/Models/SendSmsOptions.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

sdk/communication/Azure.Communication.Sms/src/Generated/Models/SendSmsResponse.Serialization.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

sdk/communication/Azure.Communication.Sms/src/Generated/Models/SendSmsResponse.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

sdk/communication/Azure.Communication.Sms/src/Generated/Models/SmsRecipient.Serialization.cs

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)