🎫 Classify Gmail emails with OpenAI and Telegram feedback

⚑ 25 views · 🎫 Ticket Management & Triage

Description

An AI-powered Gmail assistant built with n8n that automatically labels emails, learns from your decisions, and safely improves over time using human-in-the-loop training.

This workflow combines:

to create a trainable AI inbox workflow that behaves more like an executive assistant than a traditional spam filter.

Features

βœ… AI-powered Gmail classification βœ… Dynamic Gmail label discovery βœ… Human-in-the-loop review system βœ… Trainable via Telegram βœ… Historical learning from previous decisions βœ… Gmail-safe architecture (labels first, no auto-delete) βœ… Backfill support for older emails βœ… Configurable confidence thresholds

How It Works

The system uses a simple but powerful workflow:

New Email ↓ AI analyzes email ↓ Apply labels if confident ↓ If uncertain β†’ send for review ↓ User teaches AI through Telegram ↓ Future emails become easier to classify

The workflow dynamically loads all your labels but it filters for sub-labels under the parent label AI.

Screenshot 20260518 at 7.22.12β€―PM.png

IMPORTANT Gmail Setup

Create a parent Gmail label named:

AI

Then create sub-labels underneath it.

Becuase the system dynamically fetches your labels:

What’s happening underneath the hood?

Every processed email receives the AI parent label so emails are not repeatedly reprocessed.

The workflow uses a configurable confidence threshold.

// Example
item
.json.confidenceThreshold = .9;
ThresholdResult
0.95Very conservative
0.90Recommended
0.80More automation
0.70Aggressive automation

If confidence is:

ABOVE threshold β†’ labels are applied automatically BELOW threshold β†’ email enters review queue

Human-in-the-Loop Training

When the AI is uncertain the email is tagged and a rule is added to the data table for review. Once you trigger the training flow, Telegram asks the user how future emails should be handled.

For each email rule, the user can:

Historical Learning

Before asking the user for help, the AI searches previous decisions from the same sender.

If previous reviewed decisions exist:

Pending/unreviewed decisions are treated as weak references only.

Data Table Setup

Create an n8n Data Table named: Email Rules

Recommended columns:

ColumnType
emailIdstring
threadIdstring
fromEmailstring
fromNamestring
subjectstring
snippetstring
confidencenumber
labelsAppliedstring
reasonstring
userQuestionstring
ruleSuggestionstring
isPendingboolean
recommendedActionstring

Suggested Improvements

Ideas for future upgrades:

Requirements

πŸ”— Nodes Used

Telegram, Gmail, Gmail Trigger, Execute Workflow Trigger, Filter, AI Agent

πŸ“₯ Import

Download workflow.json and import into n8n: Workflow menu β†’ Import from File

πŸ“– Importing guide Β· πŸ”‘ Credential setup