Create a Power Automate solution for Implementing Smart Email Management based on LUIS Predictions

This post is part 2 of a 2 part series on Creating a LUIS application for Smart Email Management.

In our previous article, we built and deployed a LUIS application, trained it by passing in example ‘Utterances‘ for created ‘Intents‘ and performed tests so as to check if the LUIS is able to provide correct ‘IntentScores‘ for the test ‘Utterances‘.

 

To reduce the complexity, we will divide this article in two parts:

  1. Design and train our LUIS application
  2. Power Automate solution for Implementing Smart Email Management based on LUIS Predictions.

 

In this article, we will create a Power Automate solution to grab the ‘Prediction‘ and in turn the ‘CorrectIntent‘ exposed by the ‘LUIS application‘, based on which we will Automate Decision Making.

Our Primary Goal behind this solution is to implement smart sorting of emails (by passing the email body to LUIS) that are received/dropped in a Shared Mailbox folder and thereby automate assignment of those emails to correct Microsoft Team channels based on ‘Intent‘ and ‘Prediction Score‘.

 

Prerequisites-

Before you begin, please make sure the following prerequisites are in place:

 

Let’s start configuring our Power Automate (Flow) solution then.

Step 1 – When a new email arrives

  • For the ‘Folder‘ as shown in the image below, select the appropriate folder of the mailbox using the ‘Folder menu‘ present in the right hand side.
  • The ‘Inbox‘ folder of the mailbox selected, as shown in the image below, is the same folder where all emails will be received/dropped before we go ahead and implement smart sorting using LUIS predictions.

Trigger

 

Step 2 – Get Prediction

  • For the ‘App Id‘ as shown in the image below, click on the drop down menu and from the list of LUIS applications, select the correct LUIS application present in your subscription.
  • For the ‘Utterance text‘, Navigate to the ‘Add dynamic content‘ line and choose ‘Subject‘ or ‘Body Preview‘ present inside ‘When a new email arrives‘ action.

GetPrediction

 

Step 3 – Initialize Variable

  • Next, Add an ‘Initialize Variable‘ action and for the ‘Name‘ as shown in the image below, enter ‘CorrectIntent‘.
  • For the ‘Type‘, select ‘String‘ from the drop down menu.

InitVar

 

Step 4 – Parse JSON

  • For the ‘Content‘ as shown in the image below, Navigate to the ‘Add dynamic content‘ line and choose LUIS Prediction available under the ‘Get Prediction‘ action.
  • For the ‘Schema‘, please enter the following schema-
{
    “type”: “object”,
    “properties”: {
        “query”: {
            “type”: “string”
        },
        “topScoringIntent”: {
            “type”: “object”,
            “properties”: {
                “intent”: {
                    “type”: “string”
                },
                “score”: {
                    “type”: “number”
                }
            }
        },
        “intents”: {
            “type”: “array”,
            “items”: {
                “type”: “object”,
                “properties”: {
                    “intent”: {
                        “type”: “string”
                    },
                    “score”: {
                        “type”: “number”
                    }
                },
                “required”: [
                    “intent”,
                    “score”
                ]
            }
        },
        “entities”: {
            “type”: “array”,
            “items”: {
                “type”: “object”,
                “properties”: {
                    “entity”: {
                        “type”: “string”
                    },
                    “type”: {
                        “type”: “string”
                    },
                    “startIndex”: {
                        “type”: “integer”
                    },
                    “endIndex”: {
                        “type”: “integer”
                    },
                    “score”: {
                        “type”: “number”
                    }
                },
                “required”: [
                    “entity”,
                    “type”,
                    “startIndex”,
                    “endIndex”,
                    “score”
                ]
            }
        }
    }
}

ParseJP

 

 

Step 5 – Compose

  • Next, Add a ‘Compose‘ action and for the ‘Inputs‘ as shown in the image below, Navigate to ‘Add dynamic content‘ line and choose ‘Intent‘ option available under ‘Parse JSON‘ action.

Compose

 

Step 6 – Set Variable

  • Now we will set the ‘CorrectIntent‘ variable created above.
  • For the ‘Name‘ as shown in the image below, select the variable ‘CorrectIntent‘ from the drop down menu.
  • For the ‘Value‘ as shown in the image below, Navigate to the ‘Add dynamic content line‘ and choose ‘Outputs‘ option available under the ‘Compose‘ action.

SetVar

 

Step 7 – Switch case

  • Next, add a ‘Switch‘ conditional action.
  • For the ‘On‘ field as shown in the image below, Navigate to the ‘Add dynamic content‘ line and select ‘CorrectIntent‘ available inside the ‘Variables‘ section.
  • Basically what we are doing here is matching the CorrectIntent i.e the Intent that has scored the highest among all the intents based on the pre-trained prediction model.
  • When the ‘CorrectIntent‘ matches the ‘Equals‘ parameter it will switch to that particular case.
  • If you closely observe the ‘Cases‘, the names for each Case is same as that of the Intents created in the LUIS application that we deployed earlier in part 1.
  • Since we want to assign email message to a particular Microsoft team channel based on the LUIS Predictions and CorrectIntent let’s go ahead and create some channels.
  • As shown in the image below, add ‘Post a message‘ action inside each of the Cases.
  • For the ‘Team‘, select the correct Team from the drop down menu. Similarly for the ‘Channel‘ select the appropriate team channel from the drop down menu.
  • In the ‘Message‘ field inside the ‘Post a message‘ action as shown in the image below, configure a message and navigate to the ‘Add dynamic content‘ line and choose ‘Utterance text‘ available inside the Get Prediction action so that the message present in the received email gets copied.

Post

 

Now that we have configured the Power Automate solution, let’s forward an email message to our Shared Mailbox folder and check if the LUIS application is indeed able to correctly predict the Intent and based on CorrectIntent if the message gets posted in the correct Microsoft Team channel.

Email sent to the Inbox folder of the Shared Mailbox-

Email

 

Scores for different Intents as predicted by LUIS and Top scoring Intent-

IntentScoring

TopScore

 

Email message smart sort and uploaded as a message in correct Microsoft Team channel-

FinalOutput

Advertisement

2 thoughts on “Create a Power Automate solution for Implementing Smart Email Management based on LUIS Predictions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s