One of Microsoft's frequent sayings is Azure is the world’s computer. Azure Communication Services allows for Azure to natively make phone calls and send text messages – reaching in a new way the mobile phones most of us carry.
In this post, without writing code (mostly), we’re going to build an Azure Logic App that receives SMS messages, analyzes the message’s sentiment, and acts upon that sentiment by responding with an SMS message. The Logic App is the focus of this post, but we’ll link to all the resources you need to get into the details and follow along. And while we’re going to use SMS in this example, the same exact Logic App flow can be used for incoming Chat messages over the Internet!
What’s the scenario?
Imagine that you’re a business that engages with customers in person or online. You might be delivering healthcare, helping users purchase or install a product, or get a mortgage. At the end of a customer engagement, you receive consent to follow up by SMS and ask them to send feedback:
|
Consumer Sends |
Employee Sends |
1 |
|
Thank you for visiting our store. Please text this number back with any feedback you might have. |
2 |
I had a really great time! Alice was very helpful. |
|
3 |
|
If Positive Thank you for visiting and sending us feedback!
If Negative We strive to give you a great experience. A senior associate will follow up with you to discuss your feedback and how we can do better. |
Your immediate response to feedback in most situations might be thank you for visiting Contoso and sending us feedback! But if a customer is upset and shares negative sentiment, you might take more immediate action and strike a more conciliatory tone. We’re going to build the following Logic App to prototype this intelligent response:
Get a phone number
Our first task is to create an Azure Communication Services resource and acquire a phone number. This is straightforward with Azure Portal experiences letting you get local and toll-free numbers across United States localities.
Receive SMS in a Logic App
Our Logic App is going to be triggered by incoming SMS messages. Those SMS messages are received by Azure Communication Services which fires events in EventGrid. You can build all kinds of connections with EventGrid, most commonly firing a WebHook to an external service.
But we’re making a Logic App. Start with a blank Logic App in the United States and the Event trigger:
And specifically, we’re going to monitor SMS received events. We can use filters on the EventGrid trigger to only fire for certain numbers associated with the Azure Communication Services resource. As noted earlier, you can see Chat events which can follow the same pattern as SMS.
Sentiment analysis
Here is where we use Azure Logic Apps with Azure Communication and Cognitive Services to do something cool. We’re going to pipe the message data from the received SMS into the Sentiment connector. Conveniently we’ll use the message id generated by Azure Communication Services as the transaction id for the Sentiment analysis.
Now I’ll admit, I was a little intimidated by those document fields. Luckily Azure Cognitive Services has a great API explorer to help me understand the inputs and outputs of the sentiment API. The output of this API will be documents that we iterate through, so we add a for each control and if/conditional control. The if/conditional control looks for negative sentiment:
Respond depending on sentiment
The Logic App responds to feedback using the Azure Communication Services SMS connector. We tried to make the connector super simple, with auto-population of your Azure provisioned phone numbers right in the experience:
The recipient of our SMS message is the from property and phone number from the original triggering SMS.
Connections for the future
I hope this was an interesting introduction into how Azure Communication Services integration with EventGrid and Logic Apps enables fast prototyping and delivery of complex communication scenarios. When thinking about these kind of SMS communications at production scale, consider:
- Automation of the control plane. If you’re building a solution for multiple businesses, it might pay off to use APIs to manage Azure Communication Service resources and phone numbers.
- Monitoring. You can monitor SMS interactions with Azure Monitor logs, and configure alerts, for example calling you if the service starts emitting HTTP 500 errors.
- Storage of SMS messages. EventGrid can pump received SMS messages to a plethora of sinks, and common SMS applications will have a database that retains content. Be mindful of your local regulatory requirements for storage and handling of data.
- Messaging Policy. Depending on local laws and etiquette, you need to consider user consent when sending SMS and opt-out flows because you are responsible for your application. We have introductory material online, as well as service safeguards which detect ‘STOP’ messages.
- Global numbers. Right now we’re only allocating US phone numbers. This obviously doesn’t work for global business, and we’re geographically expanding our phone number business as fast as possible.
In later posts, we’ll talk about more sophisticated communication, like bots powering interactive voice response systems. Building your own Logic App or got questions? Hit us up in the comments!
Posted at https://sl.advdat.com/2XhwDAN