Use Case - Analyzing Email Content With AI

This use case briefly shows how to set up email AI analysis via Power Automate.

Before you start

 

INC Icon Legend Accordion

Show Icon Legend

💡 = A hint to signal learnings, improvements or useful information in context. 🔍 = Info points out essential notes or related page in context.
☝ = Notifies you about fallacies and tricky parts that help avoid problems. 🤔 = Asks and answers common questions and troubleshooting points.
❌ = Warns you of actions with irreversible / data-destructive consequence. ✅ = Intructs you to perform a certain (prerequired) action to complete a related step.
 
 

Flow Overview

The flow starts with the “When a task changes state” Trigger Event from the Nimbus Power Automate Connector on the event when an agent accepts the email. We then set a system message and call the AI model via HTTP using a specific system message and the email content as inputs. We'll get a JSON response back where we need to find the answer for further processing. After that, we can update the task and post an adaptive card into the chat with the agent.

Show flow overview…

 
 

How-to Steps

Prepare the View in Nimbus

In Nimbus we want to get this view when a new email is accepted by an agent:

Nimbus showing “Summary" and "Sentiment” fields, generated dynamically from an Email at the point of an incoming task 

To achieve this, we need to create the parameters Summary, Sentiment and Reply in Nimbus. In the service settings of the service receiving the emails we need to add these parameters to the My Sessions View. Go to the admin portal Services > Edit Service > Extensions and add the parameters to the Session Parameter list:

Summary and Sentiment session parameter placement

Create and deploy an AI model

In Azure AI Studio, we deploy the chat completion model GPT-4o. ☝Note down the URL and the key for later use.

Go to the chat playground and experiment with the system message. The following message will be used in our Power Automate flow:

You will be given an Email. Given the email, you need to summarize it, then give a sentiment score and draft a possible short reply. Please return your answer as a machine readible JSON of the following format without using markdown:
{
	"Summary": "Martina Willig is extremely dissatisfied with her recent order, receiving a yellow painted cupboard instead of the ordered table",
	"Sentiment": "-2 (Negative)",
	"Reply": "Dear Martina Willig, 
	I sincerely apologize for the inconvenience. Thank you for your patience and understanding. 
	Best regards,
	[Your Name]
	Customer Service Team"
}

Create the Flow in Power Automate

Start with “When a task changes state” trigger and set the event to “Connected to User”, filter on Email modality and Inbound.
Add a variable to the flow and name it “SystemMessage”. Add the system message you explored in Azure AI Studio to it.

Add a HTTP element to the flow and enter the URL and api-key from your model to it. 

 

💡 We recommend using an Azure Key Vault for any api-keys. You can create an environment variable in Power Automate which will hold the value in a more secure way. Read more about it here Use environment variables for Azure Key Vault secrets - Power Apps | Microsoft Learn.

 

Add the following content to the body:

{
"messages": [
 {
  "role": "system",
  "content": [
   {
    "type": "text",
    "text": "@{outputs('SystemMessage')}"
   }
  ]
 },
 {
  "role": "user",
  "content": [
   {
    "type": "text",
    "text": "Subject: @{triggerOutputs()?['body/emailSubject']}, Email Body: @{triggerOutputs()?['body/emailBodyUniquePlainText']}"
   }
  ]
 }
],
"temperature": 0.7,
"top_p": 0.95,
"max_tokens": 800
}

 

Add a Parse JSON element to the flow.

Content=@{body('HTTP')}

Schema=

{
 "type": "object",
 "properties": {
   "choices": {
     "type": "array",
     "items": {
       "type": "object",
       "properties": {
         "finish_reason": {
           "type": "string"
         },
         "index": {
           "type": "integer"
         },
         "message": {
           "type": "object",
           "properties": {
             "content": {
               "type": "string"
             },
             "role": {
               "type": "string"
             }
           }
         }
       },
       "required": [
         "finish_reason",
         "index",
         "message"
       ]
     }
   },
   "created": {
     "type": "integer"
   },
   "id": {
     "type": "string"
   },
   "model": {
     "type": "string"
   },
   "object": {
     "type": "string"
   },
   "system_fingerprint": {
     "type": "string"
   },
   "usage": {
     "type": "object",
     "properties": {
       "completion_tokens": {
         "type": "integer"
       },
       "prompt_tokens": {
         "type": "integer"
       },
       "total_tokens": {
         "type": "integer"
       }
     }
   }
 }
}

 

Add a Compose element to the flow

Input=@{outputs('HTTP')?['body']['choices'][0]['message']['content']}

Add a Parse JSON element to the flow

Content=@{outputs('HTTP')?['body']['choices'][0]['message']['content']}

Schema=

{
 "type": "object",
 "properties": {
   "Summary": {
     "type": "string"
   },
   "Sentiment": {
     "type": "string"
   },
   "Reply": {
     "type": "string"
   }
 }
}

 

Now Update the Nimbus Task with the Values from the AI response mapped to the parameters.

Additionally, you can send an adaptive card with the analysis to a channel or a chat

Recipient=@{triggerOutputs()?['body/LastConnectedUserUPN']}

Card JSON=

{
 "type": "AdaptiveCard",
 "body": [
   {
     "type": "ColumnSet",
     "columns": [
       {
         "type": "Column",
         "items": [
           {
             "type": "Image",
             "style": "Person",
             "url": "https://luware.com/de/wp-content/uploads/2024/05/Luware-Nimbus_BoxLogo-860x860.png",
             "size": "Small"
           }
         ],
         "width": "auto"
       },
       {
         "type": "Column",
         "items": [
           {
             "type": "TextBlock",
             "weight": "Bolder",
             "text": "Luware Nimbus via Power Automate",
             "wrap": true
           },
           {
             "type": "TextBlock",
             "spacing": "None",
             "text": "@{triggerOutputs()?['body/ServiceName']}",
             "isSubtle": true,
             "maxLines": 1,
             "wrap": true
           }
         ],
         "width": "stretch"
       }
     ]
   },
   {
     "type": "TextBlock",
     "text": "Email Analysis",
     "wrap": true,
     "weight": "Bolder",
     "style": "heading",
     "spacing": "Large",
     "separator": true
   },
   {
     "type": "FactSet",
     "facts": [
       {
         "title": "Sender",
         "value": "@{triggerOutputs()?['body/customerIdentifier']}"
       },
       {
         "title": "Subject",
         "value": "@{triggerOutputs()?['body/emailSubject']}"
       },
       {
         "title": "Sentiment",
         "value": "@{body('ResponseJSON')?['Sentiment']}"
       },
       {
         "title": "Summary",
         "value": "@{body('ResponseJSON')?['Summary']}"
       }
     ]
   },
   {
     "type": "TextBlock",
     "text": "Suggested Reply",
     "wrap": true,
     "weight": "Bolder"
   },
   {
     "type": "TextBlock",
     "text": "@{body('ResponseJSON')?['Reply']}",
     "wrap": true,
     "maxLines": 20
   }
 ],
 "$schema": "https://adaptivecards.io/schemas/adaptive-card.json",
 "version": "1.4"
}

 

Test Your Flow

  1. Go to Microsoft Copilot and generate a fake Email. You can reuse these prompts:
  • please generate a sample email from an angry customer complaining about a wrong order
  • please generate a random sample email from an happy customer
  • please generate a random sample email from customer with neutral sentiment
  1. Send an email to your service to start the trigger.
  2. Accept the Email task in Nimbus.
  3. You should now see the analysis and the adaptive card.

Table of Contents