Telegram Subscription Access Control with PostgreSQL Backend - n8n Workflow

Verify user subscriptions to Telegram channels automatically using this robust n8n workflow integrated with PostgreSQL for persistent access control and user status tracking. Find more n8n templates here.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Community managers needing automated access control for premium Telegram groups.

  • Developers looking for advanced n8n templates for Telegram bots.

  • Businesses requiring reliable database integration (PostgreSQL) with their social media automation.

  • Users who want a complex n8n node configuration example for conditional access logic.

Overview

This sophisticated n8n workflow addresses the challenge of securely managing access to private Telegram channels. It functions as a robust gatekeeper, ensuring that only users who meet specific subscription criteria, potentially including referral tracking, are granted access or information. By utilizing PostgreSQL, the n8n workflow maintains persistent state information about users and the channels they must join. This system goes beyond simple checks, allowing for administrative commands to dynamically add or delete channels, making this n8n template highly flexible. The core value is providing automated, reliable membership verification without manual intervention, powered entirely by a specialized n8n node structure. This intricate n8n design allows for comprehensive control over user interactions.

How it Works


  1. The n8n workflow starts with the Telegram Trigger node, initiating upon any incoming message or command from a user. This n8n trigger captures essential user data.

  2. Initial setup nodes (Set) establish crucial variables. An Is Admin? conditional check splits the flow for administrative versus general user operations.

  3. The flow uses PostgreSQL nodes (Get Bot Status) to retrieve the user's current interaction state, routing the flow through a series of Switch and If nodes (Define Type, Define flow).

  4. Admin Path: If an admin command (e.g., adding a channel, listing channels) is detected, the flow updates the bot status in the PostgreSQL database and uses Telegram nodes to communicate success or request further information (e.g., Add Channel, Delete Channel via Postgres).

  5. Subscription Check Path (User): The flow first checks for referral parameters (Referal?) and updates user status using the Update bot status and referal PostgreSQL n8n node.

  6. It retrieves the required channel list from the database using the Get Channels Postgres n8n node.

  7. The Get Subscription statuses Telegram n8n node queries the Telegram API to verify the user's membership status for each required channel.

  8. The Union statuses n8n node aggregates the results. The Check (If) n8n node then determines if the user is fully compliant.

  9. If successful, the user receives a confirmation via a Telegram n8n node (Check success). If unsuccessful, the user receives an alert via the Check failed Telegram n8n node, prompting them to complete the subscription requirements. This comprehensive n8n workflow provides fine-grained access control.

Installation Guide

This advanced n8n template requires three primary credentials and involves numerous webhooks setup.


  1. Import the n8n workflow: Copy the provided JSON and import it into your n8n instance.

  2. Telegram Bot Setup: Configure a Telegram Bot credential. Ensure this bot is an administrator in all channels it needs to verify access for. You must register the webhook URL for the main Telegram Trigger node and all subsequent Telegram action nodes.

  3. PostgreSQL Credential: Set up the connection details for your PostgreSQL database. This database must contain tables structured to store user bot status, channel lists, and potentially referral data. The n8n node operations rely heavily on these connections.

  4. Google Drive Credential (Optional): If you intend to deliver files upon successful subscription, you must enable and configure the Google Drive credentials for the disabled Get File and Download File n8n nodes.

  5. Activate: Save the n8n workflow and activate the Telegram Trigger to begin processing commands.

Node Details

Telegram Trigger: The starting n8n trigger point. This n8n node listens for user commands and messages, feeding the data into the n8n workflow execution.
Postgres (Multiple Instances): Used extensively for database operations related to user state and channel management.
Get Bot Status: Retrieves a user's current interaction context.
Add Channel/Delete Channel: Manages the required channel list in the database.
Upsert bot status on START: Initializes or updates a user's record.
Telegram (Multiple Instances): Handles all communications and API checks.
Get Subscription statuses: Crucial n8n node that uses the Telegram API to verify user membership against the channel list fetched from Postgres.
Check success/Check failed: Sends conditional responses to the user.
If / Switch (Multiple Instances): Core logic control n8n nodes (Is Admin?, Define Type, Check). Directs the n8n workflow flow based on user roles and subscription verification results.
Aggregate (Union statuses): This n8n node is used to combine results from multiple subscription checks (one for each required channel) before the final decision is made by the Check n8n node.

Related n8n Workflows

Paid

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by
Andrew
Andrew

Analyst-Developer

Featured*