Contents

Detect the sentiment of your received emails

Contents

The last days I was doing a lot of researches on AI and Cogntive Services as this topic is a major topic for the future in the daily use. So I read a couple of blog posts about this and got an idea on how to use it. And today I want to show you a small prototype application which I created in order to combine the Azure Cognitive Service API with my most used tool for work, which is Outlook and packed it into an Azure Logic App as I am not a developer (as you might know by now) in order to save development effort. The basic idea was to create a solution which checks my received mails and detects the sentiment of the mail body in order to see if the sentiment score is high or low of the received mail. Therefore I created a logic app which is consisting of the following actions:

/static/img/capture20170629105229587.png

The Azure Logic App triggers each time a new mail arrives in my inbox, sends the body to the Text Analytics Service of the Cognitive Service API and the result which is basically the sentiment score of the mail will be inserted into a Power BI dataset in order to build a nice dashboard. But let’s start from the beginning and create the Logic App. So head over to your Azure portal and create a new Logic App:

/static/img/capture20170629110231049.png

When the app is deployed you can head over to the Logic App Designer and start to insert the first action which is the Outlook action “When a new email arrives”. So if you open up the Designer you will be presented with a couple of templates. But we will go with the blank one:

/static/img/capture20170629112000242.png

Next we will search for our trigger in the Office 365 Outlook service and click on “When a new email arrives”:

/static/img/capture20170629112100431.png

Now the Designer is prompting us to sign into your Office 365 mailbox so we will do that:

/static/img/capture20170629112215482.png

If you have SSO enabled, you won’t need to enter your credentials here. When you signed in you can choose your mailbox folder which should be checked. I will go for the Inbox in my case but you can choose whatever folder you want. You can also adapt the frequency the trigger should be fired. My settings are look like this:

/static/img/capture20170629112356964.png

Now we will add a new step which is the detection of the sentiment of the mail body. But before we can do this we need to create the Text Analytics service first. So save your app and click on the “+” symbol in your navigation pane of the Azure portal and search for “Cognitive Services” then click create. Now choose the following settings and change the Name, subscription and pricing tier to fit your needs (I have chosen the S1 priecing tier but you are good to go with the free one which is F0 as well!):

/static/img/capture20170629113033705.png

Now that this is created you can go to that service and get the necessary key:

/static/img/capture20170629113152165-1.png

Now we can go back to our Logic App and go to the designer to add a new action. To do this click “+ Next step” - “Add an action”:

/static/img/capture20170629112459089.png

Now we want to search for the connector “Text analytics” and choose the action of “Detect sentiment”. Now it asks us for a name and a key:

/static/img/capture20170629112621764.png

So we enter the name of the Text Analytics service we created earlier and the key. Now we need to enter the text which should be analysed, so we choose the Body of the email which we will receive:

/static/img/capture20170629113502759.png

So now we need to configure Power BI in order to receive the necessary information for our dashboard. So go to https://app.powerbi.com and create a new streaming data set in your workspace as follows:

/static/img/capture20170629121922437.png

Choose API as the source of your data:

/static/img/capture20170629121934795.png

Give it a name and insert values for the incoming data:

/static/img/capture20170629122046052.png

As we want to show the sender’s email address and the sentimentscore on our dashboard we need these two values. Additionally we will add the subject as a value. It is very important to enable “Historic data analysis” in order to show the values in the dashboard. When you’re ready click create. Now we can go back to our Logic App Designer and add another action. This time we will add the “Power BI - Add rows to a dataset” action.  Now we need to sign into our Power BI profile:

/static/img/capture20170629122943457.png

After we have signed in we need to provide the Workspace, Dataset (which we have just created) and the table information. If you have entered the data correctly you will be asked for our data values, which we defined in Power BI - subject, sentiment score and the sender:

/static/img/capture20170629123214407.png

After entering the data we just need to save the app and we are good to go to test it. The full design of the app should look like this:

/static/img/capture20170629124044478.png

So click on the run button in the Designer and send an email to your email address with a nice text. After a couple of seconds you should see that your app was triggered:

/static/img/capture20170629123536315.png

This means, that you can go on building your dashboard in Power BI and add the necessary data to a report which you can then link to a dashboard. Mine looks like this (very clear and not with much fancyness): /static/img/capture20170629123812730.png

So now you know how to implement a sentiment detection on received emails and insert the gathered data into a Power BI dashboard for analytics of the senders who like you and the ones who don’’t ;) Stay tuned as I will further develop this solution and add more functionality into it. Cheers!