Telegram Bot Authorization and Admin Alert System (BotGuard) - n8n Workflow

Implement a secure authorization layer for your Telegram bot using this n8n workflow. Whitelist users via a custom n8n node and instantly alert multiple administrators on unauthorized access attempts. Protect your paid API credits and resources.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Developers hosting Telegram bots that use expensive external APIs (e.g., OpenAI).

  • Bot owners needing granular control over who can access specific bot functions.

  • Anyone looking for reusable n8n templates to secure their public-facing n8n workflow.

  • Automation specialists who need robust flow control using custom JavaScript logic within an n8n node.

Overview

Running a public bot without an authorization layer can be costly and risky, especially if the bot consumes paid resources like AI credits or heavy server processing time. This powerful n8n workflow, dubbed 'BotGuard,' solves this critical problem by implementing a simple yet effective whitelist security layer directly within your automation flow.

This specific n8n workflow starts with an n8n trigger (Telegram) and immediately processes the user's ID against defined whitelists using a custom Code n8n node. If unauthorized access occurs, the user receives a tailored denial message (complete with their user ID for easy whitelisting), and all configured administrators receive an instant, detailed alert about the breach attempt. This ensures you maintain control over resource consumption and security. It's an essential piece of core logic flow control for any serious Telegram automation using n8n.

How it Works

This authorization n8n workflow follows a strict security path:


  1. Incoming Message: The Telegram n8n trigger activates upon receiving a new user message.

  2. Authorization Check: The central 'BotGuard Authorization' Code n8n node executes custom JavaScript. Here, the workflow checks the incoming User ID against the AllowedUsers array and the Administrators array (both defined within the node). It calculates the authorization status and generates three possible messages: success, denied, and admin alert.

  3. Flow Decision: The 'Check Authorization' If n8n node inspects the allowEntry flag created in the previous step.

  4. Authorized Path: If allowEntry is true, the flow proceeds to 'Send Success', confirming authorization to the user. After this step, you would typically integrate your main processing logic (e.g., calling an OpenAI API).

  5. Denied Path: If allowEntry is false, the user receives the 'Send Denied' message, which includes the denied user's ID.

  6. Admin Alert: Following the denial, the 'Check Admin Notify' If n8n node verifies if an alert message was generated. If so, the workflow uses the 'Prepare Admin Notifications' Code n8n node to split the data, creating one item for every administrator listed in the configuration.

  7. Final Notification: The 'Notify Admin' Telegram n8n node then executes for each admin item, sending a detailed alert about the unauthorized access attempt, complete with the user's message and details.

Installation Guide

To deploy this specialized n8n workflow template, follow these steps:


  1. Import Workflow: Copy the provided JSON data. In your n8n instance, create a new workflow and select 'Import from File' (or paste the JSON directly).

  2. Configure Credentials: All Telegram n8n node instances use the same credentials. Click on any Telegram node (e.g., 'Telegram Trigger' or 'Send Success') and configure or select your existing Telegram Bot API credentials.

  3. Customize BotGuard: Open the 'BotGuard Authorization' Code n8n node. Locate the AllowedUsers and Administrators arrays at the top of the code block. Crucially, replace the placeholder IDs with the actual User IDs and corresponding usernames for your authorized users and administrators.

  4. Activate: Save the n8n workflow and toggle it to 'Active.' The Telegram n8n trigger will now be listening for messages, enforcing your authorization rules immediately.

Node Details

Telegram Trigger (n8n trigger): Initiates the entire n8n workflow whenever a message is received by your configured Telegram bot.
BotGuard Authorization (Code n8n node): The core logic. This custom n8n node defines whitelists (AllowedUsers and Administrators), extracts user details, checks the user ID against the whitelist, and generates dynamic response messages based on the outcome. It sets the botGuard.allowEntry flag.
Check Authorization (If n8n node): A key piece of core logic flow control. It evaluates the botGuard.allowEntry value to determine if the user's request should be processed or blocked.
Send Success / Send Denied (Telegram n8n node): Handles communication back to the user, sending either the welcome message or the denial message (which instructs the user on how to request access).
Check Admin Notify (If n8n node): Ensures that admin alerts are only processed if an actual unauthorized access attempt occurred (i.e., adminMessage is not empty).
Prepare Admin Notifications (Code n8n node): This advanced Code n8n node processes the list of administrators and clones the flow data for each admin. This ensures that a single notification attempt reaches multiple administrative chat IDs, leveraging the powerful item processing capabilities of n8n.

Related n8n Workflows

Free

Nodes: 5 Nodes
Updated: December 26 2025
View all
Created by
Ruslan Elishev
Ruslan Elishev

Professional Product Director that cought vibe of Automaion and Solo Programming and Context Aware AI Vibe coding.

Featured*