Multi-Step Telegram Bot with Dynamic Command Menus - n8n Workflow

Build an advanced, stateful Telegram bot using this n8n workflow template. Learn how to manage conversation state across multiple users and commands using n8n nodes and static data.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Developers and automators needing advanced, conversational Telegram bot functionality.

  • Users looking to implement state management within a single n8n workflow.

  • Businesses requiring structured data collection or support through a messaging platform.

  • Individuals seeking robust n8n templates for social media integration.

Overview

This expert-level n8n workflow provides the critical infrastructure for a sophisticated, conversational Telegram bot. Unlike simple request/response bots, this n8n automation template leverages static data storage via custom n8n node configuration to track the user's specific conversation state. This state management is essential for multi-step interactions, ensuring that when a user inputs follow-up data (after triggering a command like /start_survey), the n8n workflow knows exactly which process to route the data to. By maintaining state unique to each chat ID, this flow ensures scalability and reliable interaction, making it one of the most powerful n8n templates for building complex chat interfaces.

How it Works

The entire process is initiated by the Telegram Trigger n8n node, which listens for incoming messages.


  1. Initial Screening and Command Check: When a message arrives, the n8n workflow first executes a basic Send Typing action for a better user experience. The flow then passes the data to the Command Check n8n node (If node) to determine if the message is a new command (e.g., /command1).

  2. Command Routing and State Setting: If a command is detected, the Switch (Command Routing) n8n node directs the execution based on the specific command text. A subsequent Code n8n node (e.g., Set waitingForContent1) then sets a conversation state flag in the workflow's global static data, linked to the user’s Chat ID. A Telegram n8n node immediately follows, requesting the user's necessary content.

  3. Handling Follow-up Content: If the Command Check n8n node determines the input is not a command, the flow retrieves the existing state using the Prepare IF Value n8n node (which accesses the static data).

  4. State-Based Processing: The Check State n8n node routes the follow-up message to the appropriate processing branch (Command1 processing, Command2 processing, etc., which are currently placeholders but where custom logic would reside).

  5. Completion and Cleanup: After the data is processed, the Telegram n8n node sends the final result back to the user. Crucially, the final step involves the Clear State Code n8n node, which removes the state flag for that Chat ID, preparing the n8n workflow for the user's next command.

Installation Guide

To use this powerful n8n workflow template, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON code and paste it into your n8n instance using the 'New' -> 'Import from JSON' option.

  2. Telegram Credentials: Ensure you have configured a valid Telegram bot token credential. This is required for the Telegram Trigger n8n node and all subsequent Telegram nodes.

  3. Activate the Trigger: Open the Telegram Trigger n8n node and save the configuration. If running n8n self-hosted, ensure your webhook URL is accessible.

  4. Initialize Static Data: Before activating the main flow, manually execute the Temp to Initiate Static Data Code n8n node once. As the sticky note explains, this initializes the telegramStates object required for storing conversation state.

  5. Customize Logic: Replace the NoOp nodes (Command1 processing, etc.) with your specific business logic (e.g., Google Sheets ops, database lookups, or AI calls).

  6. Activate: Once configured, activate the entire n8n workflow to start handling live Telegram inputs.

Node Details

Telegram Trigger n8n node: The entry point for the n8n workflow. It listens for all incoming messages from your configured Telegram bot.
Command Check (If n8n node): Determines if the incoming message starts with a recognized command structure (e.g., /command). This is vital for differentiating initial requests from subsequent content inputs.
Switch (Command Routing) n8n node: Routes the flow based on the exact command received, initiating the correct state-setting sequence.
Set waitingForContentX (Code n8n node): These nodes are essential for state management. They use JavaScript to write the current waiting state (e.g., 'waitingForContent1') specific to the Chat ID into the global static data of the n8n workflow.
Prepare IF Value (Code n8n node): Reads the current state from the static data for a non-command message. This allows the subsequent logic to decide where the user is in the conversation flow.
Check State (Switch n8n node): This node uses the value retrieved by 'Prepare IF Value' to route the user's content to the relevant processing branch.


  • Clear State (Code n8n node): Resets the conversation state for the specific user after the full interaction is complete, ensuring the next message starts fresh. This clean-up is crucial for proper function of the n8n templates.

Related n8n Workflows

Paid

Nodes: 7 Nodes
Updated: December 26 2025
View all
Created by
Daniel Jimenez
Daniel Jimenez

I specialize in building custom integrations for businesses, focusing on appointment systems, CRM-integrated chatbots, and data collection workflows. I streamline processes by connecting tools like calendars, CRMs, and messaging platforms (including WhatsApp and Voiceflow) to automate data gathering and user triage.

Featured*