Announcing the new Azure Communication Services Libraries GA

Jorge Garcia Hirota

Jorge

Today, we’re excited to announce that the Azure Communication Services is generally available. Developers can now add chat, voice calling, video calling, traditional telephone calling, SMS messaging, and other forms of real-time communication to their applications using the same technology that powers Microsoft Teams. Interoperability with Microsoft Teams is also supported (public preview).

We recently showcased Azure Communication Services at Microsoft Ignite. To see how these services work together, you can watch our feature sessions here:

SDK Availability

The Azure Communication Services development experience is divided into several composable client libraries that support a wide array of platforms and languages:

AreaJavaScript.NETPythonJava SEiOS*Android*
CommonnpmnugetMavenGitHubMaven
Phone Numbers**npmnugetPyPiMaven
ChatnpmnugetPyPiMavenGitHubMaven
SMSnpmnugetPyPiMaven
CallingnpmGitHubMaven

**All mobile SDKs (Android and iOS) are under public preview mode.*

**Phone numbers SDKs (JavaScript/TypeScript, .NET, Python, & Java) are under public preview mode.

Identity

You can create identities with the Azure Communication Services Identity library. An identity serves as an identifier in conversations and is used to create access tokens. The same identity can participate in multiple simultaneous sessions across multiple devices. An identity can also have multiple active access tokens at the same time.

Key concepts

CommunicationIdentityClient is used to creating and revoke tokens. There are currently three ways to authenticate clients:

The identity client can be authenticated using a connection string acquired from an Azure Communication Resources in the Azure Portal.

// Get a connection string to our Azure Communication resource. 
var connectionString = ""; 
var client = new CommunicationIdentityClient(connectionString);

The endpoint and access key acquired from an Azure Communication Resources in the Azure Portal can be used:

var endpoint = new Uri("https://my-resource.communication.azure.com");
var accessKey = "<access_key>";
var client = new CommunicationIdentityClient(endpoint, new AzureKeyCredential(accessKey));

Clients can authenticate using a valid Active Directory token via Azure.Identity:

var endpoint = new Uri("https://my-resource.communication.azure.com"); 
TokenCredential tokenCredential = new DefaultAzureCredential(); 
var client = new CommunicationIdentityClient(endpoint, tokenCredential);

Visit the “Use Managed Identities” site to find more details.

SMS

Azure Communication Services enables you to send and receive SMS text messages using the Communication Services SMS client libraries. These client libraries can be used to support customer service scenarios, appointment reminders, two-factor authentication, and other real-time communication needs. Communication Services SMS allows you to reliably send messages while exposing deliverability and response rate insights surrounding your campaigns.

  • Simple setup experience for adding SMS capability to your applications.
  • High Velocity message support over toll free numbers for A2P (Application to Person) use cases in the United States.
  • Two-way conversations to support scenarios like customer support, alerts, and appointment reminders.
  • Reliable Delivery with real-time delivery reports for messages sent from your application.
  • Opt-Out handling support to automatically detect and respect opt-outs for toll-free numbers. Opt-outs for US toll-free numbers are mandated and enforced by US carriers.

Key concepts

SmsClient provides the functionality to send messages among phone numbers. SmsClient can be authenticated using the connection string and also be authenticated using a valid token credential; you can review the options that we listed before under Identity section.

string endpoint = "<endpoint_url>";
TokenCredential tokenCredential = new DefaultAzureCredential();
SmsClient smsClient = new SmsClient(new Uri(endpoint), tokenCredential);
    
SmsSendResult sendResult = smsClient.Send(
    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: "Hello World via SMS"
);

You should replace <from-phone-number> with an SMS-enabled phone number associated with your Communication Services resource and <to-phone-number> with the phone number you wish to send a message to.

Visit the SMS SDK site to find more details.

Phone numbers

Azure Communication Services allows you to use phone numbers to make voice calls and send SMS messages with the public-switched telephone network (PSTN). If your phone number will be used by an application (for example, to make calls or send messages on behalf of your organization), you can select a toll-free or local (geographic) number. If your phone number is being used by a person (for example, a user of your calling application), the local (geographic) phone number must be used. You can review more details in our “Phone Numbers” documentation site.

Key concepts

Phone numbers can be searched through the search creation API by providing an area code, application type, phone number type, and capabilities. The phone number(s) in the search result will be reserved for ten minutes during which you can purchase them; otherwise, they will be released automatically. If the search is not purchased, the phone numbers will become available to others after ten minutes. The phone numbers found through the search operation could be acquired for the Azure resource and used by other communication services.

The initial step is creating a PhoneNumbersClient to start interacting with the phone numbers. To create a new PhoneNumbersClient you need a connection string to the Azure Communication Services resource that you can get from the Azure Portal once you have created the resource.

Phone numbers need to be searched before they can be purchased. Search is a long running operation that can be started byStartSearchAvailablePhoneNumbers function that returns an SearchAvailablePhoneNumbersOperation object.SearchAvailablePhoneNumbersOperation can be used to update status of the operation and to check for completeness.

To create a client, you can use any of the suggested Identity options that we listed before; for this example, we use via a connection string. You can set a connection string based on an environment variable, a configuration setting, or any way that works for your application.

// Get a connection string to our Azure Communication resource.
var connectionString = "<connection_string>";
var client = new PhoneNumbersClient(connectionString);

var capabilities = new PhoneNumberCapabilities(calling:PhoneNumberCapabilityType.None, sms:PhoneNumberCapabilityType.Outbound);

var searchOperation = await client.StartSearchAvailablePhoneNumbersAsync(countryCode, PhoneNumberType.TollFree, PhoneNumberAssignmentType.Application, capabilities);
await searchOperation.WaitForCompletionAsync();

var purchaseOperation = await client.StartPurchasePhoneNumbersAsync(searchOperation.Value.SearchId);
await purchaseOperation.WaitForCompletionResponseAsync();

Visit the “Telephony Concepts” site to find more details.

Calling

You can use Azure Communication Services Calling client library to make and receive one-to-one or group voice and video calls. Your calls can be made to other Internet-connected devices and to plain-old telephones. You can use the Communication Services JavaScript, Android, or iOS client libraries to build applications that allow your users to speak to one another in private conversations or in group discussions. Azure Communication Services supports calls to and from services or Bots.

There are two separate families of Calling client libraries, for clients and services. Currently available client libraries are intended for end-user experiences: websites and native apps.

Calling client library capabilities

The calling client libraries support the following capabilities:

Group of featuresCapabilityJSJava (Android)Objective-C (iOS)
Core CapabilitiesPlace a one-to-one call between two users✔️✔️✔️
Place a group call with more than two users (up to 350 users)✔️✔️✔️
Invite another VoIP participant to join an ongoing group call✔️✔️✔️
Mid call controlTurn your video on/off✔️✔️✔️
Mute/Unmute mic✔️✔️✔️
Select audio and video input/output devices✔️✔️✔️
Screen sharingShare the entire screen or a select application✔️
RosterList and remove participants✔️✔️✔️
PSTNPlace a one-to-one call with a PSTN participant✔️✔️✔️
Place a group call with PSTN participants✔️✔️✔️
Promote a one-to-one call with a PSTN participant into a group call✔️✔️✔️
Echo BotTest your mic, speaker, and camera with an audio testing service (available by calling 8:echo123)✔️✔️✔️

JavaScript calling client library support by OS and browser

Azure Communication Services client libraries support the following browsers:

Chrome Safari Edge (Chromium)
Android ✔️
iOS ✔️
macOS ✔️ ✔️
Windows ✔️ ✔️
Ubuntu/Linux ✔️

Visit the Calling SDK site to get more details.

Chat

Azure Communication Services Chat client library can be used to add real-time text chat to your applications.

Key concepts

A chat conversation is represented by a chat thread. Each user in the chat thread is called a thread participant and is backed by a communication user created through the Azure Communication Identity package. Thread participants can chat with one another privately in a 1:1 chat or huddle up in a 1:N group chat. Users also get near-real time updates for when others are typing and when they have read the messages.

Create a ChatClient

This will allow you to create, get, or delete chat threads.

To authenticated in the ChatClient, you will need to authenticate by the user that is intended to send and receive messages. The user and its token can be created using the Azure Communication Identity package (you can review the options that we listed before Identity section).

ChatClient chatClient = new ChatClient(
    endpoint,
    new CommunicationTokenCredential(userToken));

Once you initialize a ChatClient class, you can perform chat operations:

Create a chat thread

var chatParticipant = new ChatParticipant(identifier: new CommunicationUserIdentifier(id: "<user_id>"))
{
    DisplayName = "UserDisplayName"
};
CreateChatThreadResult createChatThreadResult = await chatClient.CreateChatThreadAsync(topic: "Hello world!", participants: new[] { chatParticipant });
ChatThreadClient chatThreadClient = chatClient.GetChatThreadClient(threadId: createChatThreadResult.ChatThread.Id);
string threadId = chatThreadClient.Id;

Once you initialized a ChatThreadClient class, you can do the following chat operations:

Send a message

SendChatMessageResult sendChatMessageResult = await chatThreadClient.SendMessageAsync(content:"hello world", type: ChatMessageType.Text);
string messageId = sendChatMessageResult.Id;

Receive chat messages from a chat thread

AsyncPageable<chatmessage> allMessages = chatThreadClient.GetMessagesAsync();
await foreach (ChatMessage message in allMessages)
{
    Console.WriteLine($"{message.Id}:{message.Content.Message}");
}

Add participants

var user1 = new CommunicationUserIdentifier(id: "<user_id_for_josh>");
var gloria = new CommunicationUserIdentifier(id: "<user_id_for_gloria>");
var amy = new CommunicationUserIdentifier(id: "<user_id_for_amy>");

var participants = new[]
{
    new ChatParticipant(josh) { DisplayName = "Josh" },
    new ChatParticipant(gloria) { DisplayName = "Gloria" },
    new ChatParticipant(amy) { DisplayName = "Amy" }
};

await chatThreadClient.AddParticipantsAsync(participants: participants);

Visit the Chat SDK site to find more details.

Conclusion

We hope this was a valuable technical introduction to Azure Communication Services and what you can use today to build and ship rich communication experiences.

If you want to learn more and get started, here are some quick links to our official documentation:

References

Azure SDK Blog Contributions

Thank you for reading this Azure SDK blog post! We hope that you learned something new and welcome you to share this post. We are open to Azure SDK blog contributions. Please contact us at azsdkblog@microsoft.com with your topic and we’ll get you set up as a guest blogger.

0 comments

Leave a comment