Sending messages using Azure communication service(.NET)
This blog is to share the exciting news for all the azure developers !!!!, Microsoft recently launched rich communication APIs. It is currently in public preview. Many companies like amazon connect, Twilio, Nexmo provides calling and messaging services. As a competitor Azure expanded its services into such a communication platform.
We all know that in this current COVID-19 situation, Microsoft Teams is the preferable app for most of the companies, colleges, schools. So no doubt that it’s a rich technology. You might be wondering what’s the connection between teams and azure communication service ..???
The ACS is built on top of the same reliable and scalable platform powered by Microsoft Teams. No need to have an another thought on security and privacy , the communications are encrypted and met the HIPAA and GDPR guidelines
Features of ACS
It allows developers to add the following features across applications, Sites, & mobile computing platforms. Those services are available for both mobile and web apps. We can make use of the below service with just a few lines of code.
Video calling app
Supported communication scenarios: one-to-one, one-to-many, many-to-many, Browser-to-browser, browser-to-app, and app-to-app communication and also the public switched telephony network.
Create a communication service
Go to Communication Services-> Select appropriate Subscription, Resource Group. Enter the Resource Name and create it
Deployment takes a few minutes to create your resource. Go to resource to acquire phone numbers and to get access keys to authorize API calls. It’s good to store the access key in the azure key vault.
Get Connection string
Navigate to Keys on the right to copy the Connection string.
Get Phone numbers
Note: Phone number is available only to the paid Azure subscriptions which have United States billing address.
Navigate to Phone Numbers on the right to get a number.
For now, it’s available only to the united states. Select the Use case based on your need. Here we will look into the way to send SMS from an application.
Geographic -10 digit telephone number with local area codes.
Toll-free — 10 digit telephone number with distinct area codes. We can call any number free of charge. It applies only to the application and not to the people.
One-way outbound SMS - send SMS messages to users. For example, notification and two-factor authentication scenarios.
Two-way inbound and outbound SMS - send and receive messages from users. For example, customer service scenarios.
One-way outbound telephone calling - make calls to users. For example, customer service and voice notification scenarios.
- Customize the number to send a message or call.
- Search and place an order. The costs depend on the number type and the destination number called.
This telephone numbers is used to initiate outbound calls and build SMS communications solution
Sample Use case
Create an HTTP triggered function to share the GitHub link as a shortened URL to the given mobile number.
Build .NET Core App
I prefer to go with a serverless application, but you can go ahead with any application on your own.
Visual Studio -> Azure Functions-> HTTP trigger. Set Authorization level to Anonymous. Add the Azure.Communication.Sms NuGet package
Add the following namespaces
Write a code to get the TO mobile number from the request and deserialize it. Create a shorten form URL using a tiny URL. Add it to the formatted message to send to the given number.
Create an SMS client object by passing the noted connection string. The connection string is needed to authenticate the client. Now it’s time to call Send functionality.
Download the source code.
Exciting news for all the azure developers !!!!, Microsoft recently launched rich communication APIs. It is currently…
All set!!! Run the app.
Happy coding :)