Skip to main content

Sample Flow: Email Routing Workflow

Automatically processes incoming emails, classifies them using AI, and routes them to the appropriate department mailbox.


Overview

What it does:

  1. Receives an incoming email (forwarded or API-triggered)
  2. Uses AI to classify the email intent and extract key information
  3. Determines urgency and routing target
  4. Forwards the email to the correct team with an enriched summary
  5. Sends an auto-acknowledgment to the sender

Best for: Customer service departments, shared inboxes, operations teams handling high email volume.


Prerequisites

RequirementType
AI Provider (OpenAI / Anthropic)AI Provider Integration
Email ProviderEmail Integration
OPENAI_API_KEYSecret

Input Variables

{
"processId": "proc_email_routing",
"data": {
"senderName": "John Doe",
"senderEmail": "john@customer.com",
"emailSubject": "Urgent: Cannot access my account",
"emailBody": "Hi, I've been trying to log in for 2 hours and keep getting an error. I have a demo with a client at 3pm today and really need access. Please help urgently.",
"receivedAt": "2026-02-20T10:00:00Z"
}
}

Workflow Steps

[Start]

[AI Task: Analyze Email]
→ department: billing / technical / account / general / sales / hr
→ urgency: low / medium / high / critical
→ intent: one sentence summary
→ suggestedResponse: auto-response draft
→ needsHuman: true/false

[Script Task: Build Routing Config]
→ Sets teamEmail based on department
→ Sets escalationRequired flag

[Split: parallel]
↓ ↓
[Email: Team Alert] [Email: Auto-Ack to Sender]
↓ ↓
[Join: parallel]

[If/Else: Critical?]
↓ trueFlow (critical/high)
[SMS: Alert On-Call Team]
↓ falseFlow
(skip)

[End]

Node Configurations

AI Task: Analyze Email

systemPrompt: You are an email routing AI for a SaaS company. Analyze incoming emails and extract structured routing information. Respond with valid JSON only.

prompt: Analyze this email:

Subject: {emailSubject}
From: {senderName} <{senderEmail}>
Body: {emailBody}

Respond with:
{
"department": "billing|technical|account|general|sales|hr",
"urgency": "low|medium|high|critical",
"intent": "<one sentence summary of what the person wants>",
"keywords": ["<key topic 1>", "<key topic 2>"],
"suggestedResponse": "<professional auto-acknowledgment email body>",
"needsHuman": true|false,
"estimatedReplyTimeHours": <number>
}

Script Task: Build Routing Config

const routingMap = {
billing: { email: 'billing@yourcompany.com', name: 'Billing Team', sla: 4 },
technical: { email: 'tech@yourcompany.com', name: 'Technical Support', sla: 2 },
account: { email: 'accounts@yourcompany.com', name: 'Account Management', sla: 8 },
sales: { email: 'sales@yourcompany.com', name: 'Sales Team', sla: 1 },
hr: { email: 'hr@yourcompany.com', name: 'HR Team', sla: 24 },
general: { email: 'support@yourcompany.com', name: 'Support Team', sla: 8 }
};

const route = routingMap[department] || routingMap.general;

return {
teamEmail: route.email,
teamName: route.name,
slaHours: route.sla,
escalationRequired: urgency === 'critical' || urgency === 'high',
onCallPhone: '+15551234567'
};

Email: Team Alert (routing target)

recipientAddress: {teamEmail}
subject: [ROUTING] {urgency.toUpperCase()} - {emailSubject}
contentType: text/html
body:
<h3>Incoming Email Routed to {teamName}</h3>
<table>
<tr><td><b>From:</b></td><td>{senderName} ({senderEmail})</td></tr>
<tr><td><b>Urgency:</b></td><td>{urgency}</td></tr>
<tr><td><b>Intent:</b></td><td>{intent}</td></tr>
<tr><td><b>SLA:</b></td><td>Respond within {slaHours} hours</td></tr>
</table>
<h4>Original Email:</h4>
<p><b>Subject:</b> {emailSubject}</p>
<p>{emailBody}</p>
<h4>Suggested Response:</h4>
<p><i>{suggestedResponse}</i></p>

Email: Auto-Acknowledgment to Sender

recipientAddress: {senderEmail}
subject: RE: {emailSubject}
contentType: text/html
body:
<p>Dear {senderName},</p>
<p>Thank you for reaching out. We've received your email and our {teamName} team will get back to you within {slaHours} hours.</p>
<p>{suggestedResponse}</p>
<p>Best regards,<br>Support Team</p>

SMS: Alert On-Call Team (conditional)

Only executed when urgency is critical or high:

smsConnectionId: int_sms_placeholder
toNumber: {onCallPhone}
message: URGENT EMAIL: {urgency} priority from {senderName}. Subject: {emailSubject}. Check {teamEmail} immediately.

Output

{
"senderName": "John Doe",
"senderEmail": "john@customer.com",
"emailSubject": "Urgent: Cannot access my account",
"department": "technical",
"urgency": "critical",
"intent": "User cannot log into their account and has an urgent demo",
"teamEmail": "tech@yourcompany.com",
"teamName": "Technical Support",
"slaHours": 2,
"escalationRequired": true,
"suggestedResponse": "We understand the urgency and are looking into your account access issue immediately..."
}

Build This Yourself

  1. Navigate to /flows → click New Flow → name it "Email Routing" → Create
  2. From the Action Browser, drag onto canvas:
    • Start Event
    • AI Task (name: "Analyze Email")
    • Script Task (name: "Build Routing Config")
    • Service Task – Email (name: "Alert Team") — runs in parallel
    • Service Task – Email (name: "Auto-Acknowledgment to Sender") — runs in parallel
    • If/Else (name: "Is Critical?")
    • Service Task – SMS (name: "Alert On-Call Team") — on trueFlow only
    • End Event
  3. Connect: Start → AI Task → Script Task → both Email nodes (parallel paths) → If/Else → SMS (trueFlow) / skip (falseFlow) → End
  4. Configure the AI Task: paste the system prompt and prompt from the Node Configurations section
  5. Configure If/Else condition: ${urgency == 'critical' || urgency == 'high'}
  6. Configure each Email and SMS node with the templates above
  7. Click SavePublish
  8. Test via Run with sample input: senderName, senderEmail, emailSubject, emailBody