-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add samples for opt-out management and update readme (#47534)
- Loading branch information
1 parent
6fe23e5
commit 01f732e
Showing
7 changed files
with
281 additions
and
3 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
51 changes: 51 additions & 0 deletions
51
sdk/communication/Azure.Communication.Sms/samples/Sample2_OptOutsApi.md
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,51 @@ | ||
# Opt Out Management | ||
This sample demonstrates how to check if customers phone numbers are in the Opt Out list, and add or remove entries to it. | ||
|
||
To get started you'll need a Communication Service Resource. See [README][README] for prerequisites and instructions. | ||
|
||
## Creating an `SmsClient` | ||
SMS clients can be authenticated using the connection string acquired from an Azure Communication Resource in the Azure Portal. Alternatively, SMS clients can also be authenticated using a valid token credential. | ||
|
||
```C# Snippet:Azure_Communication_Sms_Tests_Samples_CreateSmsClientWithToken | ||
string endpoint = "<endpoint_url>"; | ||
TokenCredential tokenCredential = new DefaultAzureCredential(); | ||
SmsClient client = new SmsClient(new Uri(endpoint), tokenCredential); | ||
``` | ||
|
||
## Check if a list of recipients is in the Opt Out list | ||
To check if the recipients are in the Opt Out list, call the function from the `SmsClient.OptOuts.Check` with a list of recipient phone numbers. | ||
```C# Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Check | ||
var optOutCheckResults = smsClient.OptOuts.Check( | ||
from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS | ||
to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers | ||
foreach (var result in optOutCheckResults.Value) | ||
{ | ||
Console.WriteLine($"{result.To}: {result.IsOptedOut}"); | ||
} | ||
``` | ||
## Add a list of recipients to Opt Out list | ||
To add the list of recipients to Opt Out list, call the function from the `SmsClient.OptOuts.Add` with a list of recipient phone numbers. | ||
```C# Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Add | ||
var optOutAddResults = smsClient.OptOuts.Add( | ||
from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS | ||
to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers | ||
foreach (var result in optOutAddResults.Value) | ||
{ | ||
Console.WriteLine($"{result.To}: {result.HttpStatusCode}"); | ||
} | ||
``` | ||
|
||
## Remove a list of recipients from Opt Out list | ||
To remove the list of recipients to Opt Out list, call the function from the `SmsClient.OptOuts.Remove` with a list of recipient phone numbers. | ||
```C# Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Remove | ||
var optOutRemoveResults = smsClient.OptOuts.Remove( | ||
from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS | ||
to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers | ||
foreach (var result in optOutRemoveResults.Value) | ||
{ | ||
Console.WriteLine($"{result.To}: {result.HttpStatusCode}"); | ||
} | ||
``` | ||
|
||
[README]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/communication/Azure.Communication.Sms/README.md#getting-started |
51 changes: 51 additions & 0 deletions
51
sdk/communication/Azure.Communication.Sms/samples/Sample2_OptOutsApiAsync.md
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,51 @@ | ||
# Opt Out Management | ||
This sample demonstrates how to check if customers phone numbers are in the Opt Out list, and add or remove entries to it. | ||
|
||
To get started you'll need a Communication Service Resource. See [README][README] for prerequisites and instructions. | ||
|
||
## Creating an `SmsClient` | ||
SMS clients can be authenticated using the connection string acquired from an Azure Communication Resource in the Azure Portal. Alternatively, SMS clients can also be authenticated using a valid token credential. | ||
|
||
```C# Snippet:Azure_Communication_Sms_Tests_Samples_CreateSmsClientWithToken | ||
string endpoint = "<endpoint_url>"; | ||
TokenCredential tokenCredential = new DefaultAzureCredential(); | ||
SmsClient client = new SmsClient(new Uri(endpoint), tokenCredential); | ||
``` | ||
|
||
## Check if a list of recipients is in the Opt Out list | ||
To check if the recipients are in the Opt Out list, call the function from the `SmsClient.OptOuts.CheckAsync` with a list of recipient phone numbers. | ||
```C# Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_CheckAsync | ||
var optOutCheckResults = await smsClient.OptOuts.CheckAsync( | ||
from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS | ||
to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers | ||
foreach (var result in optOutCheckResults.Value) | ||
{ | ||
Console.WriteLine($"{result.To}: {result.IsOptedOut}"); | ||
} | ||
``` | ||
## Add a list of recipients to Opt Out list | ||
To add the list of recipients to Opt Out list, call the function from the `SmsClient.OptOuts.AddAsync` with a list of recipient phone numbers. | ||
```C# Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_AddAsync | ||
var optOutAddResults = await smsClient.OptOuts.AddAsync( | ||
from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS | ||
to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers | ||
foreach (var result in optOutAddResults.Value) | ||
{ | ||
Console.WriteLine($"{result.To}: {result.HttpStatusCode}"); | ||
} | ||
``` | ||
|
||
## Remove a list of recipients from Opt Out list | ||
To remove the list of recipients to Opt Out list, call the function from the `SmsClient.OptOuts.RemoveAsync` with a list of recipient phone numbers. | ||
```C# Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_RemoveAsync | ||
var optOutRemoveResults = await smsClient.OptOuts.RemoveAsync( | ||
from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS | ||
to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers | ||
foreach (var result in optOutRemoveResults.Value) | ||
{ | ||
Console.WriteLine($"{result.To}: {result.HttpStatusCode}"); | ||
} | ||
``` | ||
|
||
[README]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/communication/Azure.Communication.Sms/README.md#getting-started |
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
130 changes: 130 additions & 0 deletions
130
sdk/communication/Azure.Communication.Sms/tests/samples/Sample2_OptOutsApi.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 |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
using Azure.Core.TestFramework; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.Communication.Sms.Tests.samples | ||
{ | ||
/// <summary> | ||
/// Samples that are used in the README.md file. | ||
/// </summary> | ||
public partial class Sample2_OptOutsApi : SmsClientLiveTestBase | ||
{ | ||
public Sample2_OptOutsApi(bool isAsync) : base(isAsync) | ||
{ | ||
} | ||
|
||
[Test] | ||
[AsyncOnly] | ||
public async Task CheckOptOutAsync() | ||
{ | ||
SmsClient smsClient = CreateSmsClient(); | ||
#region Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_CheckAsync | ||
var optOutCheckResults = await smsClient.OptOuts.CheckAsync( | ||
//@@ from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS | ||
//@@ to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers | ||
/*@@*/ from: TestEnvironment.FromPhoneNumber, | ||
/*@@*/ to: new string[] { TestEnvironment.ToPhoneNumber, TestEnvironment.ToPhoneNumber }); | ||
foreach (var result in optOutCheckResults.Value) | ||
{ | ||
Console.WriteLine($"{result.To}: {result.IsOptedOut}"); | ||
} | ||
#endregion Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_CheckAsync | ||
} | ||
|
||
[Test] | ||
[AsyncOnly] | ||
public async Task AddOptOutAsync() | ||
{ | ||
SmsClient smsClient = CreateSmsClient(); | ||
#region Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_AddAsync | ||
var optOutAddResults = await smsClient.OptOuts.AddAsync( | ||
//@@ from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS | ||
//@@ to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers | ||
/*@@*/ from: TestEnvironment.FromPhoneNumber, | ||
/*@@*/ to: new string[] { TestEnvironment.ToPhoneNumber, TestEnvironment.ToPhoneNumber }); | ||
foreach (var result in optOutAddResults.Value) | ||
{ | ||
Console.WriteLine($"{result.To}: {result.HttpStatusCode}"); | ||
} | ||
#endregion Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_AddAsync | ||
} | ||
|
||
[Test] | ||
[AsyncOnly] | ||
public async Task RemoveOptOutAsync() | ||
{ | ||
SmsClient smsClient = CreateSmsClient(); | ||
#region Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_RemoveAsync | ||
var optOutRemoveResults = await smsClient.OptOuts.RemoveAsync( | ||
//@@ from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS | ||
//@@ to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers | ||
/*@@*/ from: TestEnvironment.FromPhoneNumber, | ||
/*@@*/ to: new string[] { TestEnvironment.ToPhoneNumber, TestEnvironment.ToPhoneNumber }); | ||
|
||
foreach (var result in optOutRemoveResults.Value) | ||
{ | ||
Console.WriteLine($"{result.To}: {result.HttpStatusCode}"); | ||
} | ||
#endregion Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_RemoveAsync | ||
} | ||
|
||
[Test] | ||
[SyncOnly] | ||
public void CheckOptOut() | ||
{ | ||
SmsClient smsClient = CreateSmsClient(); | ||
#region Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Check | ||
var optOutCheckResults = smsClient.OptOuts.Check( | ||
//@@ from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS | ||
//@@ to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers | ||
/*@@*/ from: TestEnvironment.FromPhoneNumber, | ||
/*@@*/ to: new string[] { TestEnvironment.ToPhoneNumber, TestEnvironment.ToPhoneNumber }); | ||
foreach (var result in optOutCheckResults.Value) | ||
{ | ||
Console.WriteLine($"{result.To}: {result.IsOptedOut}"); | ||
} | ||
#endregion Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Check | ||
} | ||
|
||
[Test] | ||
[SyncOnly] | ||
public void AddOptOut() | ||
{ | ||
SmsClient smsClient = CreateSmsClient(); | ||
#region Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Add | ||
var optOutAddResults = smsClient.OptOuts.Add( | ||
//@@ from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS | ||
//@@ to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers | ||
/*@@*/ from: TestEnvironment.FromPhoneNumber, | ||
/*@@*/ to: new string[] { TestEnvironment.ToPhoneNumber, TestEnvironment.ToPhoneNumber }); | ||
foreach (var result in optOutAddResults.Value) | ||
{ | ||
Console.WriteLine($"{result.To}: {result.HttpStatusCode}"); | ||
} | ||
#endregion Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Add | ||
} | ||
|
||
[Test] | ||
[SyncOnly] | ||
public void RemoveOptOut() | ||
{ | ||
SmsClient smsClient = CreateSmsClient(); | ||
#region Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Remove | ||
var optOutRemoveResults = smsClient.OptOuts.Remove( | ||
//@@ from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS | ||
//@@ to: new string[] { "<to-phone-number-1>", "<to-phone-number-2>" }); // E.164 formatted recipient phone numbers | ||
/*@@*/ from: TestEnvironment.FromPhoneNumber, | ||
/*@@*/ to: new string[] { TestEnvironment.ToPhoneNumber, TestEnvironment.ToPhoneNumber }); | ||
|
||
foreach (var result in optOutRemoveResults.Value) | ||
{ | ||
Console.WriteLine($"{result.To}: {result.HttpStatusCode}"); | ||
} | ||
#endregion Snippet:Azure_Communication_Sms_OptOuts_Tests_Samples_Remove | ||
} | ||
} | ||
} |