Azure.Communication.Sms 1.1.0-beta.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
This is a prerelease version of Azure.Communication.Sms.
dotnet add package Azure.Communication.Sms --version 1.1.0-beta.1
NuGet\Install-Package Azure.Communication.Sms -Version 1.1.0-beta.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Azure.Communication.Sms" Version="1.1.0-beta.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Azure.Communication.Sms --version 1.1.0-beta.1
#r "nuget: Azure.Communication.Sms, 1.1.0-beta.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Azure.Communication.Sms as a Cake Addin
#addin nuget:?package=Azure.Communication.Sms&version=1.1.0-beta.1&prerelease

// Install Azure.Communication.Sms as a Cake Tool
#tool nuget:?package=Azure.Communication.Sms&version=1.1.0-beta.1&prerelease

Azure Communication SMS client library for .NET

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

Source code | Package (NuGet) | Product documentation

Getting started

Install the package

Install the Azure Communication SMS client library for .NET with NuGet:

dotnet add package Azure.Communication.Sms

Prerequisites

You need an Azure subscription and a Communication Service Resource to use this package.

To create a new Communication Service, you can use the Azure Portal, the Azure PowerShell, or the .NET management client library.

Key concepts

SmsClient provides the functionality to send messages between phone numbers.

Using statements

using System;
using Azure.Communication.Sms;

Authenticate the client

SMS clients can be authenticated using the connection string acquired from an Azure Communication Resource in the Azure Portal.

var connectionString = "<connection_string>"; // Find your Communication Services resource in the Azure portal
SmsClient client = new SmsClient(connectionString);

Alternatively, SMS clients can also be authenticated using a valid token credential. With this option, AZURE_CLIENT_SECRET, AZURE_CLIENT_ID and AZURE_TENANT_ID environment variables need to be set up for authentication.

string endpoint = "<endpoint_url>";
TokenCredential tokenCredential = new DefaultAzureCredential();
SmsClient client = new SmsClient(new Uri(endpoint), tokenCredential);

Examples

Send a 1:1 SMS Message

To send a SMS message, call the Send or SendAsync function from the SmsClient.

SmsSendResult sendResult = await smsClient.SendAsync(
    from: "<from-phone-number>", // Your E.164 formatted from phone number used to send SMS
    to: "<to-phone-number>", // E.164 formatted recipient phone number
    message: "Hi");
Console.WriteLine($"Sms id: {sendResult.MessageId}");

Send a 1:N SMS Message

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. You may also add pass in an options object to specify whether the delivery report should be enabled and set custom tags.

var response = await smsClient.SendAsync(
    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
    message: "Weekly Promotion!",
    options: new SmsSendOptions(enableDeliveryReport: true) // OPTIONAL
    {
        Tag = "marketing", // custom tags
        DeliveryReportTimeoutInSeconds = 90
    });
foreach (SmsSendResult result in response.Value)
{
    Console.WriteLine($"Sms id: {result.MessageId}");
    Console.WriteLine($"Send Result Successful: {result.Successful}");
}

Troubleshooting

SMS operations will throw an exception if the request to the server fails. Exceptions will not be thrown if the error is caused by an individual message, only if something fails with the overall request. Please use the Successful flag to validate each individual result to verify if the message was sent.

try
{
    var response = await smsClient.SendAsync(
        from: "<from-phone-number>" // Your E.164 formatted phone number used to send SMS
        to: new string [] {"<to-phone-number-1>", "<to-phone-number-2>"}, // E.164 formatted recipient phone number
        message: "Weekly Promotion!",
        options: new SmsSendOptions(enableDeliveryReport: true) // OPTIONAL
        {
            Tag = "marketing", // custom tags
        });
    foreach (SmsSendResult result in response.Value)
    {
        if (result.Successful)
        {
            Console.WriteLine($"Successfully sent this message: {result.MessageId} to {result.To}.");
        }
        else
        {
            Console.WriteLine($"Something went wrong when trying to send this message {result.MessageId} to {result.To}.");
            Console.WriteLine($"Status code {result.HttpStatusCode} and error message {result.ErrorMessage}.");
        }
    }
}
catch (RequestFailedException ex)
{
    Console.WriteLine(ex.Message);
}

Next steps

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (11)

Showing the top 5 NuGet packages that depend on Azure.Communication.Sms:

Package Downloads
Soenneker.Communication.Sms.Client The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

An async thread-safe singleton for the Azure Communication Services SMS client

Bot.Builder.Community.Adapters.ACS.SMS

Adapter for v4 of the Bot Builder .NET SDK to allow for a bot to be used with SMS via Azure Communication Services.

Bot.Builder.Community.Adapters.ACS.SMS.Core

Core package containing request / response mapper, and helper methods for when using Bot Builder .NET ACS Adapter.

RenetConsulting.Sdk.Communication.Azure

Package Description

T.vuue.I.vsob.A.alert

Package Description

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Azure.Communication.Sms:

Repository Stars
phongnguyend/Practical.CleanArchitecture
Full-stack .Net 8 Clean Architecture (Microservices, Modular Monolith, Monolith), Blazor, Angular 17, React 18, Vue 3, BFF with YARP, Domain-Driven Design, CQRS, SOLID, Asp.Net Core Identity Custom Storage, OpenID Connect, Entity Framework Core, Selenium, SignalR, Hosted Services, Health Checks, Rate Limiting, Cloud Services (Azure, AWS, Google)...
BotBuilderCommunity/botbuilder-community-dotnet
Part of the Bot Builder Community Project. Repository for extensions for the Bot Builder .NET SDK, including middleware, dialogs, recognizers and more.
Version Downloads Last updated
1.1.0-beta.1 324 4/24/2024
1.0.1 732,333 5/25/2021
1.0.0 40,663 3/29/2021
1.0.0-beta.4 2,396 3/10/2021
1.0.0-beta.3 35,423 11/16/2020
1.0.0-beta.2 118,016 10/6/2020
1.0.0-beta.1 9,987 9/22/2020