In the vibrant world of automation and artificial intelligence, tools like Microsoft's Power Automate are transforming the way we interact with information and manage our workflows. Today, let's dive into the interesting process of creating a Power Automate flow, specifically designed to send notifications based on the sentiment of an email received from a manager, utilizing AI Builder's capabilities.
Understanding Power Automate and AI Builder
Before we proceed, let's understand what Power Automate and AI Builder are. Power Automate is a service provided by Microsoft that helps you create automated workflows between your favorite apps and services to synchronize files, get notifications, collect data, and more.
AI Builder, on the other hand, is a feature of Power Automate that brings the power of artificial intelligence through a point-and-click experience. You can add intelligence to your workflows and analyze content in a way that is accessible to every user.
Crafting the Flow: "Send a Notification with the Sentiment of Manager's Email"
Now, let's explore the steps you'd take to build a flow that sends a notification with the sentiment of your manager's email.
Step 1. Trigger - "On New Email"
Our automation journey begins when a new email arrives. The Power Automate flow gets triggered automatically, ensuring that no new message goes unnoticed.
Create a trigger "When a new email arrives (V2)" and create a flow.
Step 2. Actions - "Get My Profile" and "Get Manager"
Once the flow is triggered, the next step is to gather the necessary information. The flow retrieves your profile details and then fetches information about your manager. This is crucial for the flow to understand the context of the incoming emails.
Add an action - "Get my profile" from Outlook connector.
{
"type": "OpenApiConnection",
"inputs": {
"host": {
"apiId": "/providers/Microsoft.PowerApps/apis/shared_office365users",
"connection": "shared_office365users",
"operationId": "MyProfile_V2"
}
},
"runAfter": {}
}
Step 3. Condition - "Check if it is My Manager"
The heart of the flow is the decision-making condition. Here, the system checks if the email received is indeed from your manager. This step is pivotal as it ensures that the subsequent actions are performed only on emails that are from your manager, hence maintaining the relevance of the notification.
Add the action "Get User Profile" from Outlook connection and using dynamics content select "User Principal Name".
Code View
{
"type": "OpenApiConnection",
"inputs": {
"parameters": {
"id": "@outputs('Get_my_profile')?['body/userPrincipalName']"
},
"host": {
"apiId": "/providers/Microsoft.PowerApps/apis/shared_office365users",
"connection": "shared_office365users",
"operationId": "Manager_V2"
}
},
"runAfter": {
"Get_my_profile": [
"Succeeded"
]
}
}
Step 4. Sentiment Analysis - "Html to Text" and "Analyze Sentiment"
If the email is from your manager, the flow converts the HTML email content to plain text, making it ready for analysis. Following this, the AI Builder steps in to perform sentiment analysis on the text. It's like a mini-emotion detector, gauging whether the content is positive or negative.
Add condition to check from email using condition control.
Code view
{
"type": "If",
"expression": {
"equals": [
"@triggerOutputs()?['body/From']",
"@outputs('Get_manager')?['body/mail']"
]
},
"actions": {
"Html_to_text": {
"type": "OpenApiConnection",
"inputs": {
"parameters": {
"Content": "<p>@{triggerOutputs()?['body/body']}</p>"
},
"host": {
"apiId": "/providers/Microsoft.PowerApps/apis/shared_conversionservice",
"connection": "shared_conversionservice",
"operationId": "HtmlToText"
}
}
},
"Analyze_positive_or_negative_sentiment_in_text": {
"type": "OpenApiConnection",
"inputs": {
"parameters": {
"item/requestv2/language": "EN",
"item/requestv2/text": "@outputs('Html_to_text')?['body']",
"recordId": "f1c549c2-a97e-47a5-b612-c5c2bab0f163"
},
"host": {
"apiId": "/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps",
"connection": "shared_commondataserviceforapps",
"operationId": "aibuilderpredict_sentimentanalysis"
}
},
"runAfter": {
"Html_to_text": [
"Succeeded"
]
},
"metadata": {
"flowSystemMetadata": {
"portalOperationId": "aibuilderpredict_sentimentanalysis",
"portalOperationGroup": "aibuilder",
"portalOperationApiDisplayNameOverride": "AI Builder",
"portalOperationIconOverride": "https://content.powerapps.com/resource/makerx/static/pauto/images/designeroperations/aiBuilderNew.51dbdb6b.png",
"portalOperationBrandColorOverride": "#0A76C4",
"portalOperationApiTierOverride": "Standard"
}
}
},
"Send_an_email_(V2)": {
"type": "OpenApiConnection",
"inputs": {
"parameters": {
"emailMessage/To": "@outputs('Get_manager')?['body/mail']",
"emailMessage/Subject": "Feedback sentiment analysis:@{triggerOutputs()?['body/subject']}",
"emailMessage/Body": "<p><span style=\"white-space: pre-wrap;\">Hi </span>@{outputs('Get_manager')?['body/givenName']}<span style=\"white-space: pre-wrap;\">,</span></p><br><p><span style=\"white-space: pre-wrap;\">We got feedback and it's overall</span><span style=\"white-space: pre-wrap;\"> </span>@{outputs('Analyze_positive_or_negative_sentiment_in_text')?['body/responsev2/predictionOutput/result/sentiment']}</p>",
"emailMessage/Importance": "Normal"
},
"host": {
"apiId": "/providers/Microsoft.PowerApps/apis/shared_office365",
"connection": "shared_office365",
"operationId": "SendEmailV2"
}
},
"runAfter": {
"Analyze_positive_or_negative_sentiment_in_text": [
"Succeeded"
]
}
}
},
"else": {
"actions": {}
},
"runAfter": {
"Get_manager": [
"Succeeded",
"Failed",
"Skipped"
]
}
}
and then convert Email HTML to Text. Using Action "HTML To Text".
Code View
{
"type": "OpenApiConnection",
"inputs": {
"parameters": {
"Content": "<p>@{triggerOutputs()?['body/body']}</p>"
},
"host": {
"apiId": "/providers/Microsoft.PowerApps/apis/shared_conversionservice",
"connection": "shared_conversionservice",
"operationId": "HtmlToText"
}
}
}
Now add the AI action "Analyze Positive and Negative sentiment in text."
Code View
{
"type": "OpenApiConnection",
"inputs": {
"parameters": {
"item/requestv2/language": "EN",
"item/requestv2/text": "@outputs('Html_to_text')?['body']",
"recordId": "f1c549c2-a97e-47a5-b612-c5c2bab0f163"
},
"host": {
"apiId": "/providers/Microsoft.PowerApps/apis/shared_commondataserviceforapps",
"connection": "shared_commondataserviceforapps",
"operationId": "aibuilderpredict_sentimentanalysis"
}
},
"runAfter": {
"Html_to_text": [
"Succeeded"
]
},
"metadata": {
"flowSystemMetadata": {
"portalOperationId": "aibuilderpredict_sentimentanalysis",
"portalOperationGroup": "aibuilder",
"portalOperationApiDisplayNameOverride": "AI Builder",
"portalOperationIconOverride": "https://content.powerapps.com/resource/makerx/static/pauto/images/designeroperations/aiBuilderNew.51dbdb6b.png",
"portalOperationBrandColorOverride": "#0A76C4",
"portalOperationApiTierOverride": "Standard"
}
}
}
And pass plain text as input from previous action.
Step 5. Notification - "Send an Email (V2)"
Based on the sentiment analysis, the flow then crafts a notification email. If the sentiment is positive, you could receive a cheerful notification. If it's negative, the notification could prompt you to address any concerns.
Use action "Send an Email (V2)" from put to send email back to manager with result.
{
"type": "OpenApiConnection",
"inputs": {
"parameters": {
"emailMessage/To": "@outputs('Get_manager')?['body/mail']",
"emailMessage/Subject": "Feedback sentiment analysis:@{triggerOutputs()?['body/subject']}",
"emailMessage/Body": "<p><span style=\"white-space: pre-wrap;\">Hi </span>@{outputs('Get_manager')?['body/givenName']}<span style=\"white-space: pre-wrap;\">,</span></p><br><p><span style=\"white-space: pre-wrap;\">We got feedback and it's overall</span><span style=\"white-space: pre-wrap;\"> </span>@{outputs('Analyze_positive_or_negative_sentiment_in_text')?['body/responsev2/predictionOutput/result/sentiment']}</p>",
"emailMessage/Importance": "Normal"
},
"host": {
"apiId": "/providers/Microsoft.PowerApps/apis/shared_office365",
"connection": "shared_office365",
"operationId": "SendEmailV2"
}
},
"runAfter": {
"Analyze_positive_or_negative_sentiment_in_text": [
"Succeeded"
]
}
}
The Indian Context
In India, with its vast diversity and different levels of technological adoption, simplifying tech solutions is critical. The flow we discussed does exactly that. It automates a complex process, making it accessible to anyone with basic knowledge of email and workflows. This not only saves time but also introduces the power of AI to the everyday user.
Conclusion
Incorporating AI into daily work processes can seem daunting, but with tools like Power Automate and AI Builder, it becomes a walk in the park. Indian businesses and individuals can leverage these technologies to enhance productivity and make informed decisions based on the insights derived from AI.
Through this blog, we have seen how a simple email can be turned into actionable insights using the blend of automation and AI, catering to the Indian audience's need for simplicity and efficiency. Automation is not just for the tech-savvy; it is for everyone who aspires to work smarter, not harder.