Email Thread Summarizer & Reply Drafter
On a flagged Outlook email, walks the entire thread, generates a concise summary plus a draft reply, and posts to a Teams channel for team visibility.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
This flow triggers when the connection owner flags an email in Outlook, sends the message body to Azure OpenAI for summarization plus a structured reply suggestion, and posts the result as a formatted HTML message to a configured Microsoft Teams channel. It's an "AI triage" pattern — flag a thread you want summarized, get the digest in your team channel a few seconds later.
Use Case
Long email threads chew up time when teams need to share status with a wider audience. People often summarize threads manually before forwarding to leadership or a Teams channel — slow, error-prone, and the reply suggestion is rarely worded the same way twice. This flow lets anyone flag a thread to trigger an AOAI summary that lands in a Teams channel, complete with a suggested reply the owner can review and adapt before sending.
The flow is ideal for teams that:
- Trigger is just 'flag an email' — no new workflow for end users to learn.
- Azure OpenAI handles both the summary and the reply draft in a single call.
- Output goes to Teams (not Drafts) so the whole team sees it without inbox forwarding.
- Teams channel + group IDs in env vars — repoint to a different team without flow edits.
Flow Architecture
When An Email Is Flagged
Outlook OnFlaggedEmailFires when the connection owner flags a mail item.
Init 7 variables
InitializeVariablevarAOAIEndpoint, varAOAIDeployment, varAOAIApiVersion, varAOAIApiKey, varTeamsGroupId, varTeamsChannelId from env vars; varSystemPrompt held inline.
Compose AOAI Request Body
ComposeBuilds the chat-completions JSON body — system message from varSystemPrompt, user message from triggerOutputs()?['body/body/content'].
Call Azure OpenAI
HTTPPOSTs to {endpoint}/openai/deployments/{deployment}/chat/completions?api-version={version} with api-key header.
Parse AOAI Completion / Parse Structured Reply
ParseJsonExtracts choices[0].message.content and parses the LLM's JSON output into summary, actionItems, draftReply.
Compose Teams Message HTML
ComposeBuilds the HTML body with headings for Summary, Action Items, Draft Reply.
Post Summary To Teams
Teams PostMessageToChannelPosts the composed HTML to channel varTeamsChannelId inside team varTeamsGroupId.
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_AOAIEndpoint | String | — | Azure OpenAI resource endpoint URL. |
| flowlibs_AOAIDeployment | String | — | Chat-completion deployment name. |
| flowlibs_AOAIApiVersion | String | 2024-02-15-preview | API version string. |
| flowlibs_AOAIApiKey | String | — | Azure OpenAI API key — stored as Secret env var. |
| flowlibs_TeamsGroupId | String | — | GUID of the target Microsoft 365 Group / Team. |
| flowlibs_TeamsChannelId | String | — | Channel identifier within the team where the summary is posted. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| Office 365 Outlook | shared_office365 | OnFlaggedEmail (trigger) |
| Teams | shared_teams | PostMessageToChannel |
| HTTP | shared_http | POST (Azure OpenAI chat-completions endpoint) |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Save draft to Outlook Drafts
- Add an Outlook Reply to email (V3) action with Save Draft set to true after the parse step, before the Teams post.
- Adaptive card instead of HTML
- Replace Compose Teams Message HTML and Post Summary To Teams with Post adaptive card in a chat or channel.
- Walk the entire thread
- Add an Outlook List emails (V3) filtered by conversationId before the AOAI call to pass the whole thread.
- Promote the system prompt to an env var
- Replace Init varSystemPrompt with parameters('flowlibs_SummarizerPrompt').
- Switch to a shared mailbox trigger
- Replace the trigger with the shared-mailbox flagged variant or a scheduled scan over the messages endpoint with a flagStatus filter.
- Add @mention to the Teams post
- Use Post adaptive card and wait for response so the channel post tags a reviewer.
- Log every summary to Dataverse/SharePoint
- Add a Create item/AddRecord parallel branch after Parse Structured Reply so summaries are searchable later.
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01Email body content (passed to AOAI)
Pulls the HTML body of the flagged message.
EXPR.02Build AOAI URL
Concatenates endpoint + deployment + version into the chat-completions URL.
EXPR.03Pull AOAI message content
Reads choices[0].message.content from the response.
EXPR.04Parse the structured reply JSON
Converts the message content string back to a typed object.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.