Telegram + Google Sheets: block spam bots fast
Your Telegram group gets hit by a spam wave, and suddenly you’re playing whack-a-mole. You ban one bot, two more show up, and legit members get caught in the mess.
This is exactly what Telegram spam blocking automation is for. Community managers feel the pain first, but ops leads running customer groups and agency owners managing client communities run into it constantly too. The goal is simple: block bots fast, keep real people, and stop burning your day on manual bans.
This workflow uses a tiny math challenge (no AI costs) plus Google Sheets logging, so you get a cleaner chat and a quick audit trail. You’ll see what it does, how it flows, and what to watch for before you turn it on.
How This Automation Works
See how this solves the problem:
n8n Workflow Template: Telegram + Google Sheets: block spam bots fast
flowchart LR
subgraph sg0["📱 Telegram Flow"]
direction LR
n0["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/telegram.svg' width='40' height='40' /></div><br/>📱 Telegram Trigger"]
n1@{ icon: "mdi:swap-horizontal", form: "rounded", label: "🔍 Check New Member", pos: "b", h: 48 }
n2["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/code.svg' width='40' height='40' /></div><br/>🎲 Generate CAPTCHA Question"]
n3@{ icon: "mdi:database", form: "rounded", label: "💾 Store User Answer", pos: "b", h: 48 }
n4["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/telegram.svg' width='40' height='40' /></div><br/>❓ Send CAPTCHA Question"]
n5["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/httprequest.dark.svg' width='40' height='40' /></div><br/>🚫 Ban User (Failed CAPTCHA)"]
n6@{ icon: "mdi:swap-horizontal", form: "rounded", label: "✅ Verify Answer", pos: "b", h: 48 }
n7["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/telegram.svg' width='40' height='40' /></div><br/>🎉 Welcome New Member"]
n8@{ icon: "mdi:database", form: "rounded", label: "🗑️ Clean User Data (Success)", pos: "b", h: 48 }
n9["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/telegram.svg' width='40' height='40' /></div><br/>🗑️ Delete Join Message"]
n10["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/telegram.svg' width='40' height='40' /></div><br/>🗑️ Delete CAPTCHA Question (.."]
n11@{ icon: "mdi:database", form: "rounded", label: "📋 Find Pending CAPTCHA", pos: "b", h: 48 }
n12["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/telegram.svg' width='40' height='40' /></div><br/>🗑️ Delete User Message"]
n13@{ icon: "mdi:swap-vertical", form: "rounded", label: "⚙️ Bot Configuration", pos: "b", h: 48 }
n14@{ icon: "mdi:swap-vertical", form: "rounded", label: "Create URL for banrequest", pos: "b", h: 48 }
n6 --> n7
n6 --> n14
n0 --> n13
n1 --> n2
n1 --> n11
n7 --> n12
n13 --> n1
n14 --> n5
n4 --> n9
n11 --> n10
n9 --> n3
n12 --> n8
n2 --> n4
n5 --> n12
n10 --> n6
end
%% Styling
classDef trigger fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
classDef ai fill:#e3f2fd,stroke:#1976d2,stroke-width:2px
classDef aiModel fill:#e8eaf6,stroke:#3f51b5,stroke-width:2px
classDef decision fill:#fff8e1,stroke:#f9a825,stroke-width:2px
classDef database fill:#fce4ec,stroke:#c2185b,stroke-width:2px
classDef api fill:#fff3e0,stroke:#e65100,stroke-width:2px
classDef code fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
classDef disabled stroke-dasharray: 5 5,opacity: 0.5
class n0 trigger
class n1,n6 decision
class n3,n8,n11 database
class n5 api
class n2 code
classDef customIcon fill:none,stroke:none
class n0,n2,n4,n5,n7,n9,n10,n12 customIcon
The Challenge: Stopping Spam Without Punishing Real Members
Spam bots don’t just post junk. They change how your group feels. New members join, see a wall of scams, and leave. Regulars stop engaging because the chat is noisy, and you end up moderating instead of building a community. The worst part is the timing: spam floods tend to hit when you’re busy, so a “quick ban” turns into an hour of cleanup, plus follow-up messages from confused real users who got blocked by mistake.
It adds up fast. Here’s where it breaks down in day-to-day moderation.
- You have to react manually, which means bots get a window to post links before you notice.
- Human verification in chat gets messy, so your welcome messages and CAPTCHA prompts clutter everything.
- It’s hard to prove what happened later because there’s no clean record of who failed verification and why.
- Overcorrecting causes collateral damage, and honest members get banned during a spam surge.
The Fix: Math CAPTCHA + Auto-Cleanup + Sheets Logging
This n8n workflow turns spam control into an automatic gate at the moment someone joins (or the moment they try to talk). A new user triggers the process, the bot generates a simple math question (think “4 + 7 = ?”), and it sends that challenge directly in the group while tagging the user so it’s obvious who needs to respond. Their reply is recorded in Google Sheets, then the workflow looks up the pending challenge and checks the answer. If it’s correct, the bot welcomes them and cleans up the verification messages so your chat doesn’t turn into a support thread. If it’s wrong (or bot-like), the workflow prepares the ban request and blocks the user through a Telegram API call.
The workflow starts with a Telegram trigger and a quick “is this a new member event or a reply?” check. From there it either builds and delivers a math prompt, or it verifies the user’s message against what’s stored in Google Sheets. Finally, it routes to “welcome + cleanup” or “ban + cleanup,” so the end result is always a tidy room.
What Changes: Before vs. After
| What This Eliminates | Impact You’ll See |
|---|---|
|
|
Real-World Impact
Say your public group gets about 30 new joins a day during a promotion. Manually, even a “fast” flow takes maybe 2 minutes per person to greet, vet, ban obvious bots, and clean up messages. That’s about an hour daily, and it gets worse during raids. With this workflow, setup is once, then each join is handled automatically; you might spend 5 minutes a day checking the Google Sheet for anything suspicious. That’s real time back, not “nice to have” time.
Requirements
- n8n instance (try n8n Cloud free)
- Self-hosting option if you prefer (Hostinger works well)
- Telegram to run the bot in your group
- Google Sheets to log challenges and responses
- Telegram Bot Token (get it from @BotFather)
Skill level: Beginner. You’ll paste credentials, set a Sheet ID, and give the bot the right admin permissions.
Need help implementing this? Talk to an automation expert (free 15-minute consultation).
The Workflow Flow
A member joins or sends a message. The Telegram trigger catches the event instantly, then your bot settings are applied (token, group context, and message templates).
The workflow decides what kind of event it is. If it’s a new member, it generates a random math question and posts it tagging that user. If it’s a reply, it searches Google Sheets for the pending CAPTCHA record tied to that user.
Verification happens against a stored answer. The user’s reply is checked with simple logic (no AI), which keeps it fast and consistent. A correct answer routes to a welcome message; a wrong answer routes to a ban request.
Cleanup keeps the chat readable. Join notices, CAPTCHA prompts, and the user’s verification message get deleted, and the related row in Google Sheets is removed once the flow is complete.
You can easily modify the math difficulty to match your community, or change the welcome text and links based on your needs. See the full implementation guide below for customization options.
Step-by-Step Implementation Guide
Step 1: Configure the Telegram Trigger
Set up the workflow to listen for Telegram updates so new members and messages can be processed.
- Add the 📱 Telegram Intake Trigger node as your trigger.
- Credential Required: Connect your Telegram credentials (this is required for 📱 Telegram Intake Trigger and all Telegram action nodes).
- Verify the trigger is listening to your target group or bot updates.
⚠️ Common Pitfall: If the Telegram bot isn’t an admin in the group, delete actions in later steps will fail.
Step 2: Connect Google Sheets
Google Sheets is used to track pending CAPTCHA prompts and user replies.
- Open 💾 Record User Reply, 📋 Locate Pending CAPTCHA, and 🗑️ Purge User Records.
- Credential Required: Connect your Google Sheets credentials in each of these nodes.
- Map your spreadsheet and worksheet fields to match the data you want to store (user ID, CAPTCHA value, timestamps, etc.).
Keep the same spreadsheet structure across these Google Sheets nodes so lookups and cleanup actions stay in sync.
Step 3: Set Up Processing Logic
Configure the logic that validates new members and builds the CAPTCHA challenge.
- In ⚙️ Bot Settings, set any constants or flags your workflow depends on (e.g., group ID, ban thresholds).
- Configure 🔎 Validate New Member to route new joins to 🎲 Build CAPTCHA Prompt and existing replies to 📋 Locate Pending CAPTCHA.
- In 🎲 Build CAPTCHA Prompt, generate the CAPTCHA challenge and store the correct answer in the item data.
⚠️ Common Pitfall: If 🔎 Validate New Member isn’t filtering correctly, existing users may get new CAPTCHAs or replies may not be validated.
Step 4: Configure Output/Action Nodes
Set up the Telegram actions that deliver, remove, and confirm CAPTCHA interactions.
- Configure the Telegram action nodes as a group: ❓ Deliver CAPTCHA Prompt, 🗑️ Remove Join Notice, 🗑️ Clear CAPTCHA Prompt, 🎉 Greet New Member, and 🗑️ Remove User Message.
- Credential Required: Connect your Telegram credentials to each Telegram action node.
- Confirm message text and target chat/message IDs are pulled from previous nodes (especially after 🎲 Build CAPTCHA Prompt and ✅ Confirm Answer).
Use consistent message formatting in ❓ Deliver CAPTCHA Prompt so users understand how to reply.
Step 5: Configure Validation, Ban Flow, and Cleanup
This step connects CAPTCHA validation to greetings, cleanup, and automated bans.
- In ✅ Confirm Answer, set the condition to compare the user reply from 📋 Locate Pending CAPTCHA to the expected answer.
- Confirm the success path: ✅ Confirm Answer → 🎉 Greet New Member → 🗑️ Remove User Message → 🗑️ Purge User Records.
- Confirm the failure path: ✅ Confirm Answer → Prepare Ban Request URL → 🚫 Block User After Failure → 🗑️ Remove User Message.
- In Prepare Ban Request URL, set the request URL or parameters needed by 🚫 Block User After Failure.
⚠️ Common Pitfall: If the ban request URL is malformed, 🚫 Block User After Failure will fail silently and users won’t be blocked.
Step 6: Test and Activate Your Workflow
Run a full test to confirm CAPTCHA delivery, validation, and cleanup works end-to-end.
- Manually execute the workflow with a test user joining the Telegram group.
- Verify ❓ Deliver CAPTCHA Prompt sends a prompt and 🗑️ Remove Join Notice removes the join message.
- Submit a correct answer and confirm the flow reaches 🎉 Greet New Member and then 🗑️ Purge User Records.
- Submit an incorrect answer and confirm the flow reaches 🚫 Block User After Failure and then 🗑️ Remove User Message.
- Toggle the workflow to Active for production use.
Watch Out For
- Telegram admin permissions matter. If the bot can’t delete messages or ban users, check the group’s Administrator settings and confirm it has “Ban users” and “Delete messages” enabled.
- If you’re using Wait nodes or external rendering, processing times vary. Bump up the wait duration if downstream nodes fail on empty responses.
- Default prompts in AI nodes are generic. Add your brand voice early or you’ll be editing outputs forever.
Common Questions
About 5 minutes once your bot and Sheet are ready.
Yes. No coding required, but you do need to paste a bot token and connect Google Sheets credentials in n8n.
Yes. n8n has a free self-hosted option and a free trial on n8n Cloud. Cloud plans start at $20/month for higher volume. You’ll also need to factor in Google Sheets usage, which is typically covered under free tiers for normal community volumes.
Two options: n8n Cloud (managed, easiest setup) or self-hosting on a VPS. For self-hosting, Hostinger VPS is affordable and handles n8n well. Self-hosting gives you unlimited executions but requires basic server management.
You can. Most customizations are in the bot settings and the math challenge generation: change the welcome text in “⚙️ Bot Settings,” adjust the math difficulty in “🎲 Build CAPTCHA Prompt,” and swap the logging format in the Google Sheets steps. Some groups also shorten the time window for replies, or only challenge users who joined via invite links.
Usually it’s the bot token or missing admin rights in the group. Regenerate the token in @BotFather if needed, then confirm the bot is promoted to admin and allowed to delete messages and ban users. If it still fails, check the chat ID the workflow is targeting and make sure the bot is actually in that chat.
On self-hosted n8n, capacity mainly depends on your server and Telegram rate limits, not executions.
For Telegram moderation, n8n is usually the more practical fit because you can run branching logic, store and look up pending challenges, and call the Telegram API directly without fighting platform limits. It also gives you a self-hosting route, which matters if your group gets raided and you suddenly have a burst of events. Zapier and Make can work for simpler “send a message when X happens” automations, but chat moderation flows tend to get fiddly fast. Frankly, the moment you need cleanup, conditional bans, and logging, you’ll appreciate n8n’s flexibility. Talk to an automation expert if you want someone to sanity-check your exact setup.
Once it’s running, spam control stops being a daily fire drill and turns into background hygiene. You get a cleaner chat, fewer headaches, and a Google Sheet that tells you what happened when someone complains.
Need Help Setting This Up?
Our automation experts can build and customize this workflow for your specific needs. Free 15-minute consultation—no commitment required.