Setting the Scene:
The CEO of one of your top customers emails your team. They’re angry. ALL CAPS SHOUTING ANGRY!
But your team is busy, the email will be attended to in the order it was received. It languishes in the queue and then receives a paltry response, further enraging your customer.
This scenario happens more often than most Customer Service executives would prefer to admit.
Is there a better way?
Microsoft MVP Daniel Christian recently showed how to route text through Azure Sentiment Analysis via Power Automate. The Azure service analyses and scores submitted text, ultimately deciding if the written sentiment is positive or negative. Pretty cool.
What if we could pair Azure Sentiment Analysis with a customer service queue? What if emails with negative sentiment from our customers could automatically create a triage queue or be directed senior leadership team for immediate action?
‘The Innovators’ author Walter Isaacson mentions that when it comes to AI ‘the hard things are easy, and the easy things are hard.’ This was my experience over the past few weeks playing with Azure Sentiment Analysis and Power Automate.
To best simulate a production scenario, I tested from my work email. Nothing major, just some self-affirmations like ‘Nathan, your Power Platform demos are awesome’ (for testing purposes). But the AI consistently scored negative.
What’s going on here?
One of Power Automates best features is the ability to analyse the execution line by line, to see what’s happening. As I dug into the details of the Sentiment Analysis connector, I noticed that there was much more text analysed than I emailed.
Azure Sentiment Analysis breaks text blobs down per sentence and scores them individually before averaging them for an overall sentiment score. Intergen (like all companies) appends a lengthy email disclaimer to all outgoing emails. Nice, friendly, positive prose written by our lawyers warning anyone receiving email from us of the ramifications of doing so.
That’s why the sentiment scores were negative.
To A/B test I sent the same message as above from my personal (disclaimer free) email and got a positive score.
We need to remove the email signature, which is easy right?
Remember the Isaacson quote?
Case in point. The hard stuff (determining if text sentiment is positive or negative) was easy. The easy stuff (removing the email signature) proved difficult.
Any human eye balling an email message can instantly determine the tone of the body (the text we want to analyse) and the signature (what we want to remove). So how do we get a machine to do this programmatically?
There are no easy answers. Routing customers to a portal to submit queries via structured text is the preferred possibility, however email is hard to eradicate.
So how did I do it?
Most emails end with various signoffs. (The actual term is valediction). ‘Sincerely,’ ‘Best Regards,’ for example. If we can scan the text for these words, we could extract a substring (the email body) and send that to Azure for analysis.
Easy peasy lemon squeezy?
Not yet. After lots of trial and error I arrived at regex. These are clever tools that allow you to do many things. In this instance, I needed to pass an array of email valedictions through the email body to see if I got a hit.
Power Automate doesn’t natively support regular expression otherwise known as regex currently. There’s paid add-ons.
However, this blog from Paul Murana How to use Regex in Power Automate (tachytelic.net) shows how to add regex into your cloud flow via Office TypeScript in Excel.
So that’s how I programmatically removed the signature from an email prior to passing it to Azure cognitive services for sentiment analysis.
It’s not a fool proof solution, if someone skips the valediction or uses one, I’ve not accounted for, the regex won’t pick it up. But it’s a start.
Now that we have added a regex expression to our flow, we can remove the email disclaimers from the body and get a much more accurate read of the sender’s sentiment before deciding how to route the email.
Hope you found this helpful. If you have solved this issue using a different method, I would love to hear about it.