Azure Communication Services – Building an experimental messaging solution

Azure Communication Services (ACS) provides a managed platform and communication APIs to build real-time voice, video, SMS, and Chat functionality to your solution at scale. We can make our custom enterprise solution across any device or any platform. Azure Communication Services uses underlying reliable and secure infrastructure that powers by Microsoft Teams. So we don’t need to worry about the platform’s reliability and scalability while considering building a solution using ACS. When it comes to security and compliance, all the communications between ACS Platform and solutions are encrypted to meet privacy and compliance guidelines such as HIPAA and GDPR. Azure Communication Services also provides comprehensive supports of Developer’s SDKs and APIs for common platforms and languages, including Web, .NET, JavaScript, pythons, and devices like iOS and Android.  

The following solutions would be the widespread use cases for Azure Communication Services.

  • Phone and SMS Text – Phone Call, SMS Text Messaging and Verification System
  • Voice and video calling – One on One Call, Group Voice, and Video Call
  • Chat – One on One Chat, Group Chat Application, Live Chat Support

Moreover, integrating Azure Communication Services with other Azure PaaS services will give us a completely different perspective on building highly scalable and robust solutions with various use cases. For instance, by integrating Azure Cognitive Services with Azure Communication Services, we can bring real-time translation, sentiment analysis also can bring many capabilities of computer vision API’s

Architectural representation of Azure Communication Services, with Integration of Azure Cognitive Services, Azure Function and other Services.

While we will deep dive on some of these concepts in another post, In this post, let us look at how we can leverage the Azure Portal to provision ACS and explore some of the features by building one simple messaging application. Following is the reference diagram of what we are going to achieve by end of this post.

In case you are facing some challenges while building the samples, please check out the Troubleshooting Section to know about some items I faced and how I overcome them.

Provisioning The Azure Communication Services (ACS)

To start provisioning the Azure Communication Service, Log in to the Azure Portal, and Search for the “Azure Communication Services

Creating the ACS is similar to how we provision any other Azure Services, Choose your Azure Subscription, Resource Group, and Provide the Azure Communication Service Name. Once all the information is provided, go ahead, and create the service.

Acquiring Phone Numbers and Get Access Keys

Once the service is created, the very first thing we need to perform is getting the phone number. Navigate to the resource overview board. Here we need to focus on two items to start with.

  • Phone Numbers
  • Keys

To acquire the phone numbers, select the “# Phone Numbers” option from the overview board. In the Phone Numbers blade, Click on the + Get phone number button.

With the preview version of ACS, you can choose only the United States as a Phone Number selection country. Choose “An application will be making calls for sending SMS messages” as a Use case. Choose number type and chose SMS as “Inbound and outbound SMS.” As we focus only on the SMS part in this call, we can skip the calling option. However, you can update the calling and SMS options post you get the numbers as well

Once you choose the numbers features, it’s time to select how many numbers you required. Provide the quantity and click on search.

I have taken two numbers, as I will be using one as From and another To test the communication.

Finally, once you place the order, it will show the Order in Progress status and the Order Complete. From my experiences, this hardly takes 10-15 seconds to get the number.

Tip: Update and Release Phone Number Features

You can select any specific number, update the “Calling” and “SMS” features from the Phone Numbers window. If you want to release the number, you can remove it by clicking on the “Release” button. 

 Get the Access Keys

Access Keys authorize the APIs while communicating with Azure Communication Services. Take a note of the Connection String from the Primary Keys, which we will be using in our application.

 Building a client application

Create a new project in Visual Studio and add the following package reference. I created on WPF application client, you can choose anything else including a simple console application as well.

In the application XAML, a place once button control, attach the following code in the button_clickd event handler.  Update the connectionString, from and to the phone number.  Send() method Sends an SMS from a phone number that is acquired by the authenticated account, which is here getting validated by the connection string. SendSmsResponse  returns the responses back from Send() or SendAsync() method. 

 string connectionString =
  "endpoint=https://acsworkdemo.communication.azure.com/;accesskey=iaguTNg97Tn1xxxxxxxxxxx0tRuee1exxxxxxlv5ShimoA==";
            SmsClient acsSmsClient = new SmsClient(connectionString);
            SendSmsResponse acsSmsResult = acsSmsClient.Send(
                            from: new PhoneNumber("+1xxxxxxx9185"),
                            to: new PhoneNumber("+1xxxxxxx9190"),
                            message: "Hello SMS!! Powered By Azure Communication Services"
                          );

            MessageBox.Show($"Message Sent Successfully. Message ID{acsSmsResult.MessageId}");

You can download the source code from JanaAbhijit/Azure-Communication-Service-Sample: Azure Communication Service Sample (github.com)

That’s it. Run the application, click on the Send SMS button. Once the message sending is successful you will see the message ID with type as Outgoing as showing the following image.

 That’s it. It’s a very simple implementation. If you are holding a US number, update To phone number and test the SMS directly on your phone. If not, let us validate the messaging using Event Subscription.

Azure Communication Services – Event Subscription

Using the event subscription, we will be able to capture all the message ingestion to the platform and then validate or process the data as needed in the subsequent workflow. To create an “Event Subscription” navigate to the “Events” blade and then choose “+ Event Subscription

 

In the “Create Event Subscription” screen, provide the following details

  • Event Subscription Name
  • Topic Name
  • Event Type – Choose SMS Received and SMS Delivery Report Received
  • End Point Details – Azure Queue

In this implemented I have used Azure Storage Queue as endpoint for the incoming messages. However, you can utilize other endpoint including Azure Function, Azure Logic App, and Webhooks as well.

Once subscription is created, you can clearly review the complete flow that shows Azure Communication Service as Data Ingestion source and Storage Queue as End Point.

Run the Client Application for a couple of times, and come back and check the Azure Storage Queue. Here you can view and validate the message coming to the platform.

Troubleshooting

Take a look at this Issues incase your are facing similar problem.

Event Subscription does not work with Azure Communication Services · Issue #63934 · MicrosoftDocs/azure-docs (github.com)

Summary

Azure Communication Services (ACS) provides a managed platform and communication APIs to build real-time voice, video, SMS, and Chat functionality to your solution at scale. In this post, we have learned how to provision Azure Communication Services and build a simple SMS messaging application. We have also known how we can use event ingestion using Event Grid for Azure Communication Services. Combing Azure Communication Services with other Azure Platform Services will open up many possibilities for building solutions at scale. Do let me know what type of solution you plan to develop using Azure Communication Service in the comment box.

As of writing this article, Azure Communication Services is a preview service.

Azure ,

2 comments

Leave a comment