Skip to main content

Classify Gmail emails with OpenAI and Telegram feedback

Workflow preview

Workflow preview
100%
Classify Gmail emails with OpenAI and Telegram feedback preview
Open on n8n.io

1. Workflow Overview

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: Gm...

Best for

  • Ticket Management automation workflows
  • AI Summarization automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.outputparserstructured, @n8n/n8n-nodes-langchain.lmchatopenai, n8n-nodes-base.executeworkflowtrigger, n8n-nodes-base.telegram, n8n-nodes-base.datatabletool, n8n-nodes-base.manualtrigger, n8n-nodes-base.splitinbatches

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Michael Montaque.

Original n8n.io source

1.1 Workflow description

Title
Classify Gmail emails with OpenAI and Telegram feedback
Workflow name
Classify Gmail emails with OpenAI and Telegram feedback

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:

  • Gmail
  • OpenAI
  • Telegram
  • n8n Data Tables

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.

IMPORTANT Gmail Setup

Create a parent Gmail label named:

AI

Then create sub-labels underneath it.

Becuase the system dynamically fetches your labels:

  • you can customize your own labels
  • the AI only uses valid existing labels
  • labels stay synchronized with Gmail automatically

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;
Threshold Result
0.95 Very conservative
0.90 Recommended
0.80 More automation
0.70 Aggressive 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:

  • choose which label should apply
  • reject the classification
  • add additional instructions for more nuanced behavior

Historical Learning

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

If previous reviewed decisions exist:

  • confidence may increase
  • historical labels may be reused
  • automation becomes more accurate over time

Pending/unreviewed decisions are treated as weak references only.

Data Table Setup

Create an n8n Data Table named: Email Rules

Recommended columns:

Column Type
emailId string
threadId string
fromEmail string
fromName string
subject string
snippet string
confidence number
labelsApplied string
reason string
userQuestion string
ruleSuggestion string
isPending boolean
recommendedAction string

Suggested Improvements

Ideas for future upgrades:

  • broad email provider support
  • Notion-based rule management
  • AI-generated email drafts
  • Daily review digests
  • Multi-user support
  • Chat-based rule revision
  • Web dashboard
  • Safe-deletion

Requirements

  • Gmail (with sub-labels under AI)
  • OpenAI API Key
  • Telegram Chatbot

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - AI Check Email

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.8

Block 2 - Unwanted Email Output Parser

Type / Role
@n8n/n8n-nodes-langchain.outputParserStructured - outputParserStructured
Config choices
Version 1.2

Block 3 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.3

Block 4 - OpenAI Chat Model1

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.3

Block 5 - When Executed by Another Workflow

Type / Role
n8n-nodes-base.executeWorkflowTrigger - executeWorkflowTrigger
Config choices
Version 1.1

Block 6 - Telegram: Error

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 7 - Previous Rules and actions tool

Type / Role
n8n-nodes-base.dataTableTool - dataTableTool
Config choices
Version 1.1

Block 8 - When clicking ‘Execute workflow’

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

Block 9 - Loop Over Items

Type / Role
n8n-nodes-base.splitInBatches - splitInBatches
Config choices
Version 3

Block 10 - Telegram: Train

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 11 - filter for AI labels

Type / Role
n8n-nodes-base.filter - filter
Config choices
Version 2.3

Block 12 - Get all labels

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 13 - Get labels

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 14 - get AI labels

Type / Role
n8n-nodes-base.filter - filter
Config choices
Version 2.3

Block 15 - Update rule

Type / Role
n8n-nodes-base.dataTable - dataTable
Config choices
Version 1.1

Block 16 - Remove label: AI, Needs Review

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 17 - Gmail Trigger

Type / Role
n8n-nodes-base.gmailTrigger - gmailTrigger
Config choices
Version 1.3

Block 18 - Add rule for review

Type / Role
n8n-nodes-base.dataTable - dataTable
Config choices
Version 1.1

Block 19 - add label & email metadata to ai output

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 20 - Get all pending rules

Type / Role
n8n-nodes-base.dataTable - dataTable
Config choices
Version 1.1

Block 21 - Delete rule

Type / Role
n8n-nodes-base.dataTable - dataTable
Config choices
Version 1.1

Block 22 - Message: Deleted rule

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 23 - Message: Added rule

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 24 - Add AI recommended labels

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Showing the first 24 of 40 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow Classify Gmail emails with OpenAI and Telegram feedback
Complexity advanced
Nodes 40
Categories Ticket Management, AI Summarization
Author Michael Montaque
Published 19 May 2026

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/15805/15805.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Classify Gmail emails with OpenAI and Telegram feedback do?

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: Gm...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Ticket Management, AI Summarization use case.