The Complete Kairon AI Email Assistant with n8n Guide by John EchenduThe Complete Kairon AI Email Assistant with n8n Guide by John Echendu

The Complete Kairon AI Email Assistant with n8n Guide

John Echendu

John Echendu

Monitors your Gmail inbox for new emails
Analyzes emails using AI for tone, priority, and content
Drafts professional replies automatically
Notifies you via Telegram with interactive buttons
Manages the entire email lifecycle with simple taps
You are an executive assistant for a busy professional. Your primary role is to process emails efficiently.

When you receive an email, you must perform the following tasks and respond ONLY with a JSON object.

Your JSON object must have these exact keys:
- "summary": A concise, plain English summary of the email (max 100 words)
- "tone": Classify the tone as one of: Angry, Urgent, Neutral, Curious, Happy, Professional, Request
- "priority": Classify the priority as one of: High, Medium, Low
- "suggested_reply": A professional, concise, and appropriate reply based on the email content and inferred intent

Example of expected JSON output:
{
"summary": "Meeting cancellation due to unforeseen circumstances, proposing reschedule.",
"tone": "Neutral",
"priority": "Medium",
"suggested_reply": "Hi [Name], thanks for the update. Let me know when you're available to reschedule."
}

Ensure all output is valid JSON. Do not include any other text or formatting outside the JSON object.

Set the model to gpt-4o-mini for cost-effectiveness and speed.
Run the node to create the Assistant.
Note the Assistant ID returned in the response (asst_...) — you'll use this in your assistant threads.
Once you've stored the Assistant ID safely, delete this node from your workflow to keep things clean.
OpenAI_ThreadID - Type: Single Line Text Used to maintain the thread with OpenAI Assistant API.
Telegram_Prompt_MessageID - Type: Single Line Text - Used to track the Telegram message that prompted user feedback.
To help Kairon focus only on important emails and avoid unnecessary API usage (which can cost money), you can set up a Gmail label, though it's totally optional.
Go to Gmail and create a new label called Kairon-Process.
Then go to: Gmail Settings → Filters and Blocked Addresses → Create a new filter
Set up rules for the emails you want Kairon to process (e.g., emails from specific senders or with certain keywords).
In the filter actions, select: Apply the label → Kairon-Process
This way, Kairon will only monitor emails with that label—helping you stay within usage limits, especially if you're on a paid OpenAI plan.
If this is your dedicated business inbox or you're just starting out, you can skip the label and have Kairon watch all incoming emails. It’s the fastest way to get up and running—no filters needed.
Just keep in mind that without filters, it may process more messages than necessary, which could slightly increase token usage if you're on a paid plan.
Gmail Trigger → Clean Email → OpenAI Analysis → Parse Response → 
Branch (Success/Failure) → Save to Airtable → Telegram Notification

const output = [];

for (const item of $input.all()) {
// Extract sender information
const from = item.json.From;
const subject = item.json.Subject;

// Get email body - prioritize plain text
let body = item.json.snippet || item.json.Body || item.json.body || "(no body found)";

// Basic HTML cleaning if needed
if (typeof body === 'string') {
body = body.replace(/<[^>]*>?/gm, ''); // Remove HTML tags
body = body.trim();
// Remove common signatures
body = body.split(/-- \n|Sent from my iPhone/i)[0];
}

output.push({
json: {
sender: from,
topic: subject,
content: body,
gmailMessageId: item.json.id
}
});
}

return output;

try {
// Extract AI response
const aiResponseString = $input.item.json.output;

// Parse JSON
const parsedJson = JSON.parse(aiResponseString);

// Return success with thread ID
return {
json: {
isSuccess: true,
summary: parsedJson.summary,
tone: parsedJson.tone,
priority: parsedJson.priority,
suggested_reply: parsedJson.suggested_reply,
threadId: $input.item.json.threadId
}
};

} catch (error) {
// Handle parsing errors
return {
json: {
isSuccess: false,
error: error.message,
originalAiOutput: $input.item.json.output,
threadId: $input.item.json.threadId
}
};
}

const now = new Date(new Date().toLocaleString('en-US', { timeZone: 'Africa/Lagos' }));
const hour = now.getHours();
let greeting;

if (hour >= 5 && hour < 12) {
greeting = "Good morning! ☀️";
} else if (hour >= 12 && hour < 17) {
greeting = "Good afternoon! 🌤️";
} else {
greeting = "Good evening! 🌙";
}

return [{
json: {
...$input.item.json,
greeting: greeting
}
}];

<b>{{ $json.greeting }}</b>

Hope you're having a good day!

<b>{{ $json.safeSender }}</b> just sent you an email with the subject <i>{{ $('Code').item.json.topic }}</i>

{{ $('Parse & Validate AI Response').item.json.summary }}

Tone seems <b>{{ $('Parse & Validate AI Response').item.json.tone }}</b>, <b>{{ $('Parse & Validate AI Response').item.json.priority }}</b> priority.

<b>Here's my draft response:</b>
<i>{{ $('Parse & Validate AI Response').item.json.suggested_reply }}</i>

Should I send it, or would you like to adjust anything?

🚨 Kairon AI Agent Error!
An email could not be processed because the AI's response was not valid JSON.

Error Message: {{ $json.error }}

Original AI Output:
{{ $json.originalAiOutput }}

Telegram Trigger → Parse Command → Branch (Revision/Command) →
Route Actions → Execute Action → Update Database → Send Confirmation

const message = $input.item.json.message;
const chatId = message.chat.id;
const messageText = message.text;

// Check if this is a reply to a revision prompt
if (message.reply_to_message && message.reply_to_message.from.is_bot) {
return {
json: {
isRevision: true,
revisionInstructions: messageText,
chatId: chatId,
repliedToMessageId: message.reply_to_message.message_id.toString()
}
};
}

// Parse standard commands like "/approve recordId"
const commandText = messageText.split(' ').slice(1).join(' ');
const parts = commandText.split(' ');

if (parts.length === 2 && parts[0].startsWith('/')) {
const action = parts[0].substring(1);
const recordId = parts[1];

return {
json: {
isRevision: false,
isValidCommand: true,
action: action,
recordId: recordId,
chatId: chatId
}
};
}

// Invalid command
return {
json: {
isValidCommand: false
}
};

try {
const aiResponseString = $input.item.json.output;
const parsedJson = JSON.parse(aiResponseString);

return {
json: {
isSuccess: true,
summary: parsedJson.summary,
tone: parsedJson.tone,
priority: parsedJson.priority,
suggested_reply: parsedJson.suggested_reply,
threadId: $input.item.json.threadId
}
};

} catch (error) {
return {
json: {
isSuccess: false,
error: error.message,
originalAiOutput: $input.item.json.output,
threadId: $input.item.json.threadId
}
};
}

Perfect! I've updated the draft with your changes. ✨

Here's the revised version:

<i>{{ $('Parse & Validate Revised Reply').item.json.suggested_reply }}</i>

How does this look? Ready to send or need more adjustments?

Congratulations! 🎉 You've just built your own AI-powered email assistant that can handle your inbox like a personal chief of staff.
✅ Monitor your Gmail 24/7
✅ Analyze every email with AI intelligence
✅ Draft professional responses automatically
✅ Notify you instantly via Telegram
✅ Execute your decisions with one tap
✅ Learn from your revisions for better responses
Test with a friend - Have them send you different types of emails
Customize the greeting - Make it sound more like you
Adjust the AI instructions - Fine-tune for your communication style
Set up VIP filters - Create special labels for important contacts
Building Kairon is just the beginning of your AI automation journey. If you run into any issues, have questions, or want to share your experience:
New features you'd like to see added
Integrations with other tools (Slack, Discord, WhatsApp?)
AI improvements for better email understanding
Workflow optimizations you've discovered
Industry-specific customizations you've built
If something's not working quite right, paste your error message or describe the issue in the comments. The community (and I) are here to help you get Kairon running smoothly.
Remember: You're not just following a tutorial - you're building a tool that will genuinely transform how you handle email. Every business professional needs this kind of AI assistance, and you just built it from scratch!
Let's build the future of email management together. Drop your experiences, questions, and ideas in the comments below! 👇
Like this project

Posted Aug 2, 2025

AI email agent built with n8n, OpenAI, Airtable & Telegram. Analyzes emails, drafts replies, and waits for one-tap approval. Solves inbox overload.