Sweep unread Gmail junk to spam with GPT-5, Telegram, and Google Sheets

Go to Workflow
0 views
Built by Friedrich Bremer Friedrich Bremer
Created on October 07, 2026

Description

Quick overview
This workflow sweeps unread Gmail inbox messages on a schedule or via Telegram, uses OpenAI GPT-5 to identify high-confidence junk from unknown senders, moves selected emails to Gmail Spam, logs each run to Google Sheets, and sends a Telegram report with a one-tap undo.

How it works
Runs daily on a cron schedule or starts from a Telegram message/callback button.
Fetches unread messages from Gmail Inbox and pulls recent Gmail Sent mail to build a list of known contacts and domains.
Filters out emails from people you have written to, then sends only remaining candidates to OpenAI GPT-5 for junk classification with a confidence rating.
Keeps borderline/low-confidence items in the inbox and prepares an undo batch for the high-confidence junk selected for moving.
Stores the undo batch in workflow static data, then moves each selected Gmail message to Spam (and removes Inbox/Unread labels).
Sends a Telegram report listing what moved and why with an inline “Undo” button, and appends a run log entry to Google Sheets.
If the undo button is tapped later, restores the batch from Spam back to the Inbox and confirms the result in Telegram (or reports that the undo batch expired).

Setup
Add a Gmail OAuth2 credential with permission to read messages and modify labels.
Add an OpenAI credential and ensure the model selection is available for the OpenAI node (set to gpt-5).
Create a Telegram bot with @BotFather, add a Telegram credential, and set the admin_chat_id value in the Config step for scheduled notifications.
Add a Google Sheets credential, then select the target spreadsheet and sheet/tab in both Google Sheets logging steps.
Review and adjust the Config values (Gmail search query, inbox limit, sent lookback, max moves per run, and undo window) before enabling the daily schedule.

Nodes Used (6)

Code
n8n-nodes-base.code
Gmail
n8n-nodes-base.gmail
Google Sheets
n8n-nodes-base.googleSheets
HTTP Request
n8n-nodes-base.httpRequest
OpenAI
@n8n/n8n-nodes-langchain.openAi
Telegram
n8n-nodes-base.telegram