AI-Powered Gmail Labeling, Knowledge Graph Building & Telegram Alerts - n8n Workflow

Use this powerful n8n workflow template to automate Gmail labeling using Gemini AI. Integrate with InfraNodus for knowledge graph creation and send real-time alerts via Telegram. This n8n automation streamlines email management and generates insights.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Individuals or teams receiving high volumes of email who need AI-driven organization.
Users who utilize n8n templates for advanced productivity and custom integrations.
Knowledge workers and researchers looking to automatically transform email content into a structured knowledge base (InfraNodus).
Anyone needing immediate Telegram notifications based on specific email categories defined within this n8n node structure.

Overview

This comprehensive n8n workflow solves the problem of manual email triage by implementing sophisticated AI classification and automated labeling. By leveraging the Google Gemini Chat Model within an n8n node, incoming emails are instantly categorized (e.g., Business, Urgent, Personal).

The value proposition is twofold: organization and insight. First, the automated labeling ensures your Gmail inbox remains tidy. Second, for key categories (like 'Business'), the workflow automatically cleans the email body and saves it as structured data in an InfraNodus knowledge graph. This process transforms unstructured email text into actionable insights, culminating in a synthesized "insight question" delivered directly to your Telegram chat. This entire n8n automation eliminates administrative overhead, ensuring crucial information is filed correctly and generating strategic ideas automatically.

How it Works

This n8n workflow begins execution whenever the Gmail Trigger detects a new email that was not sent by the user (-from:me).


  1. Trigger & Classification: The n8n trigger passes the email data to the Text Classifier n8n node, which utilizes the Google Gemini Chat Model to determine the appropriate labels (Business, Personal, Urgent, etc.) based on the custom descriptions provided in the n8n template configuration.

  2. Automated Labeling: Multiple Gmail n8n node steps run in parallel to apply the corresponding labels to the email message ID derived from the initial n8n trigger.

  3. Knowledge Graph Integration (Business Path): If the email is labeled 'Business', the flow branches. A Code n8n node cleans the HTML content and formats the email text, sender, and date into structured statements.

  4. InfraNodus Saving: The formatted statement is sent via an HTTP Request n8n node to the InfraNodus API, building or updating the specified knowledge graph. This powerful step demonstrates the utility of this n8n template.

  5. Insight Generation: A subsequent HTTP Request n8n node queries the newly updated InfraNodus graph to generate a strategic "insight question" or "idea" based on content gaps.

  6. Telegram Insight Alert: This generated insight question is immediately sent to a designated Telegram chat using the Telegram n8n node.

  7. Real-Time Category Alerts (Urgent Path): For other specified labels (Personal, Appointments, Urgent, Invoices), the flow aggregates the label IDs. It uses Gmail n8n nodes to fetch the human-readable label name and the email snippet.

  8. Telegram Notification: Finally, the email details (label name, subject snippet, and direct link to the message) are sent as a separate notification via a Telegram n8n node.

Installation Guide

To leverage this powerful n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON data and import it directly into your n8n instance via the Workflows tab.

  2. Gmail Setup: Configure the initial Gmail Trigger n8n node with OAuth2 credentials for the account you wish to monitor. Crucially, before running, ensure you create the corresponding labels (e.g., Business, Urgent, Appointments) in your Gmail account, as the Gmail Label n8n nodes require these IDs to function correctly.

  3. AI Classification Configuration:

Set up credentials for the Google Gemini Chat Model (using the Google Gemini/PaLM API).
Review the Text Classifier n8n node and ensure the custom categories and descriptions accurately reflect your needs. This is the core of the AI functionality in this n8n template.

  1. InfraNodus Integration (Steps 4 & 5):

Obtain an API key from InfraNodus.
Configure the HTTP Bearer Authentication credentials used by the InfraNodus Save to Graph and InfraNodus Question Generator n8n nodes.
Verify the name parameter in both nodes matches the desired graph name (e.g., gmail_business).

  1. Telegram Notification Setup (Steps 6 & 8):

Set up a Telegram bot via BotFather to get an API key.
Configure the Telegram API credentials used by the Send Insight to Telegram and Send Notification via Telegram n8n nodes.
Input the correct Chat ID for the destination chat in both Telegram n8n node configurations.

Node Details

This robust n8n workflow template uses several specialized n8n nodes:

Gmail Trigger: The initiating n8n trigger. It monitors the inbox for new messages and excludes emails sent by the user (-from:me).
Google Gemini Chat Model: Provides the generative AI capability for classification, linked directly to the Text Classifier. Requires a Google Gemini/PaLM API credential.
Text Classifier (Langchain n8n node): Takes the email subject and body as input and uses the Gemini model to categorize the content against predefined labels (Business, Personal, Urgent, etc.). Crucial for AI-driven automation within this n8n workflow.
Gmail (Add Labels Operation): Multiple instances (e.g., Label as Business, Label as Urgent). These n8n nodes apply the specified Gmail labels based on the classification results, using the message ID captured by the initial n8n trigger.
Code n8n node (Clean html and organize into statements): Custom JavaScript function that cleans HTML/CSS from the email body and structures the remaining text into a specific format, ready for the InfraNodus API. This customized n8n node is essential for data preparation.
HTTP Request (InfraNodus Save to Graph): Sends the cleaned, formatted email text to the InfraNodus platform to build the associated knowledge graph. This step showcases advanced n8n automation via API interaction.
HTTP Request (InfraNodus Question Generator): Queries the InfraNodus API to generate an analytical "insight question" based on the graph's content gaps, demonstrating the power of the n8n template for research.
Aggregate n8n node: Used to collect the output items from multiple parallel Labeling branches (e.g., Personal, Urgent) before proceeding to the notification phase.


  • Telegram n8n node: Two instances responsible for sending notifications: one for the generated InfraNodus insight and one for immediate alerts regarding urgent or personal emails.

Related n8n Workflows

Free

Nodes: 11 Nodes
Updated: December 26 2025
View all
Created by

I'm Dmitry, the founder of InfraNodus — an AI text network analysis tool. I'm passionate about networks and data visualization and its ability to reveal what everyone else is missing and to highlight different perspectives. I'm sharing the n8n templates that make use of this unique capability of InfraNodus for multiple scenarios.

Featured*