Interactive Telegram Multi-Select Checkbox Bot with Postgres - n8n Workflow

A robust n8n workflow utilizing a Telegram trigger to implement an interactive multi-select checkbox module, saving choices and status updates directly to a Postgres database. Download these advanced n8n templates.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Developers needing advanced, interactive interfaces within a Telegram bot environment.

  • Businesses requiring structured data input from mobile users via Telegram.

  • n8n users looking for technical examples of managing persistent state across multiple Telegram interactions.

  • Automation specialists seeking complex n8n templates for database integration and dynamic UI generation.

Overview

Managing persistent state and interactive elements like multi-select checkboxes in chat applications can be challenging. This specific n8n workflow solves this by tightly integrating a Telegram bot with a Postgres database, allowing users to interactively select items from a list, much like a shopping cart or a survey form, and instantly updating the choices visible via an inline keyboard. Every selection is recorded immediately in Postgres, ensuring data integrity and enabling dynamic feedback. This advanced n8n workflow demonstrates powerful use of the n8n node ecosystem, particularly utilizing the n8n trigger for immediate response and custom code for UI rendering. This solution is ideal for building custom ordering systems or sophisticated data capture tools within Telegram.

How it Works

The entire process begins when a user interacts with the bot, activating the Telegram Trigger n8n trigger.


  1. Initialization and Variables: The flow starts with Variables TG and Initialization set n8n nodes, defining necessary variables for user and chat IDs.

  2. Start Command Handling: The Start? if n8n node checks if the user initiated the flow. If true, a Welcome Message is sent, and the user's bot status is recorded in Postgres using the Upsert bot status on START n8n node.

  3. Interaction Routing: If it's not a start command, the Define Type switch n8n node routes the input. If it’s a new order (New?), the process creates a new order record in Postgres (Add Order), fetches the available Shop List items, and adds the initial choices (Add Shop List Choice).

  4. UI Generation and Initial Send: The Convert statuses code n8n node takes the database data, formats it into a list with checkbox statuses, and sends the interactive message via the Send Telegram n8n node, logging the message ID for later edits.

  5. Handling Callbacks (Edits): When a user clicks an inline button (a selection), the flow runs through a Switch and subsequent Postgres lookups (Get Order, Get messageid). The core selection logic happens when the flow uses the message ID to Update Shop List Choice in Postgres. It then fetches the new choices (Get Shop List Choice).

  6. Dynamic UI Update: The Convert statuses and antistatuses code n8n node processes the updated selection list, generating a new inline keyboard layout. The Edit Telegram n8n node then replaces the previous message content and keyboard, giving the user instant feedback without flooding the chat with new messages. This message ID is updated in Postgres (Update messageid ).

  7. Final Submission: When the user confirms the selection (routed via the Answers switch n8n node), the final chosen items are fetched from Postgres, summarized (Union List), and the previous messages are deleted (Delete Prev SMS). A final Results message is sent confirming the order, completing this comprehensive n8n workflow.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON and paste it directly into your n8n instance to import the n8n templates.

  2. Credentials Setup:

Telegram: You must configure a Telegram API credential for all Telegram n8n node instances (Telegram Trigger, Send, Edit, etc.). Ensure your bot is created via BotFather.
Postgres: Configure your Postgres database credentials. All Postgres n8n node steps rely on this connection.

  1. Database Schema: This n8n workflow assumes the existence of specific tables to store user status, order details, shop list items, and selected choices. You must ensure your database schema matches the SQL queries used within the Postgres n8n node configurations (e.g., storing messageid, chatid, and item status).

  2. Webhook Activation: Ensure the Telegram Trigger n8n trigger is active. It will listen for incoming messages and callbacks from your configured Telegram bot.

  3. Code Node Customization: Review the Code n8n nodes (Convert statuses) to ensure the logic aligns with how your specific item data is structured and how you wish the inline keyboard buttons to be generated.

Node Details

Telegram Trigger (n8n trigger): The entry point of the n8n workflow, activated by incoming messages or callback queries from the Telegram bot.
Postgres Node (Multiple Instances): Essential for state management. Nodes like Add Order, Get Shop List, Update Shop List Choice, and Update message_id handle the persistence of user choices, order status, and message IDs for dynamic message editing.
Set Node (Variables TG, Initialization): Used to define and map crucial data elements like chat IDs and user information at the start of the n8n workflow execution.
If Node (Start?, New?, Active?): Manages flow control, determining if a command is a fresh start, a new order, or a status update.
Switch Node (Define Type, Switch, Answers): Critical control flow n8n node for routing callback queries based on the data sent via the inline keyboard buttons, ensuring the correct logic path is executed (e.g., selection vs. final submission).
Code Node (Convert statuses): A custom n8n node used to dynamically generate the complex structure required for the Telegram inline keyboard. It reads the current selections from Postgres and formats the buttons (e.g., [x] Item A, [ ] Item B) based on the database status.

Related n8n Workflows

Paid

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

Analyst-Developer

Featured*