🔓 Unlock all 10,000+ workflows & prompts free Join Newsletter →
✅ Full access unlocked — explore all 10,000 AI workflow and prompt templates Browse Templates →
Home n8n Workflow
January 22, 2026

Telegram + PostgreSQL: every chat logged and routed

Lisa Granqvist Partner Workflow Automation Expert

Support chats get messy fast. A customer sends a Telegram message, someone replies late (or not at all), and later you can’t reconstruct what happened because the context is scattered across devices and people.

This Telegram Postgres logging setup hits support leads first, honestly. But agency owners managing client inboxes and ops managers trying to standardize responses feel the same drag. You get cleaner history, fewer missed follow-ups, and replies that stay consistent even when your team is tired.

This workflow routes every incoming message through rules, optional voice output, and a database log in PostgreSQL. You’ll see what it automates, what it changes day to day, and what you need to run it reliably.

How This Automation Works

The full n8n workflow, from trigger to final output:

n8n Workflow Template: Telegram + PostgreSQL: every chat logged and routed

The Problem: Telegram support chats lack reliable context

Telegram is great for fast conversations, but it’s terrible as a system of record. Messages come in across time zones, multiple agents jump in, and suddenly the “source of truth” is whoever remembers what was promised. Then a customer asks, “Can you resend that detail?” and you’re scrolling through days of chat, trying to find one line. It’s not just slow. It creates inconsistent replies, missed handoffs, and awkward follow-ups that make you look disorganized.

It adds up fast. Here’s where it breaks down in real teams.

  • Important messages get buried, so replies happen late or not at all when the inbox gets busy.
  • Without a PostgreSQL log, you can’t easily audit who said what when a dispute pops up.
  • Voice replies are a nice touch, but generating and sending them manually is a hassle you stop doing after day two.
  • Provider rules (language, voice availability, routing) live in people’s heads instead of a database you can update once.

The Solution: Route replies and log every chat to PostgreSQL

This workflow acts like a message “output layer” for Telegram. It receives a message payload from another workflow (or a test trigger), looks up the right provider configuration from PostgreSQL (with Redis caching to keep it snappy), then decides how to respond. If voice output is enabled for that provider, it generates a TTS voice clip through the MiniMax API in the correct language, fetches the audio, and sends it to Telegram. It also sends the text reply (either as a normal message or a threaded reply) and writes both the input and output into PostgreSQL line by line so you can search, audit, or reuse the data later.

The workflow starts when a message is handed in through an execute-subworkflow trigger (or the built-in chat test trigger). It then validates the payload, loads provider rules from cache or Postgres, and routes to text-only or text-plus-voice. Finally, it dispatches to Telegram and inserts chat logs into Postgres.

What You Get: Automation vs. Results

Example: What This Looks Like

Say your Telegram support line gets 40 messages a day. Manually, logging the key details and sending a consistent reply might take about 3 minutes per message once you include context switching, copying text, and writing notes. That’s roughly 2 hours daily. With this workflow, the “work” is basically reviewing and improving your provider rules in Postgres, while n8n handles routing, optional voice creation, and inserts both input/output logs automatically. You still answer customers. You just stop doing the admin glue.

What You’ll Need

  • n8n instance (try n8n Cloud free)
  • Self-hosting option if you prefer (Hostinger works well)
  • Telegram for sending messages and replies
  • PostgreSQL to store provider rules and chat logs
  • Redis for caching provider lookups
  • MiniMax API key (get it from your MiniMax dashboard) for optional TTS voice
  • OpenAI API key (get it from the OpenAI platform) if you use the AI Agent/Chat Model nodes

Skill level: Advanced. You’ll connect multiple credentials, set up database tables, and be comfortable debugging payloads when a branch doesn’t match.

Don’t want to set this up yourself? Talk to an automation expert (free 15-minute consultation).

How It Works

A message comes in from a parent workflow. The “Workflow Launch Trigger” (execute sub-workflow trigger) waits for a payload, and the Input Mapper normalizes fields so downstream logic stays predictable.

Provider settings are loaded and cached. The workflow checks if the provider exists, looks it up in Redis, and falls back to PostgreSQL if it’s not cached yet. Once found, it saves the provider record back into Redis so future runs don’t keep hitting the database.

The response path is chosen. Switch and If nodes route based on media type and whether voice output is enabled. If voice is needed, the Language Router selects the right template (English, Japanese, Chinese, Yue), then MiniMax TTS creates audio and the workflow fetches the result for delivery.

Telegram gets the final output, and Postgres gets the receipt. The workflow sends either a normal Telegram message or a reply in-thread, optionally sends a voice note, and inserts both the chat input and output rows into PostgreSQL so your history is searchable later.

You can easily modify the provider lookup logic to pull from a different table based on your needs. See the full implementation guide below for customization options.

Step-by-Step Implementation Guide

Step 1: Configure the Execute Workflow Trigger

Set up the workflow entry points so production executions and chat tests both normalize input data into a shared format.

  1. Add and position Workflow Launch Trigger as the primary trigger for external workflow calls.
  2. Add Chat Test Trigger for interactive testing and connect it to Test Field Mapper.
  3. Connect Test Field Mapper to Input Mapper so both triggers feed the same input schema.
  4. Connect Workflow Launch Trigger to Input Mapper to keep the production path aligned with test data.

Step 2: Connect Provider Cache and Database Services

Configure provider lookup and caching so the workflow can resolve provider details efficiently.

  1. From Input Mapper, connect to Provider Missing Check to determine whether provider data exists.
  2. Route the missing-provider path to Provider Cache Lookup and then to Provider Cache Check.
  3. Connect the cache-hit path from Provider Cache Check to Parse Cache Data, then to Provider Mapper.
  4. Connect the cache-miss path from Provider Cache Check to Load Provider Records, then to Cache Provider Save, and finally to Provider Mapper.
  5. Ensure Provider Mapper outputs to both Media Route and Input Presence Check in parallel.

Credential Required: Connect your Redis credentials for Provider Cache Lookup and Cache Provider Save, and connect your Postgres credentials for Load Provider Records.

Step 3: Set Up Media Routing and Language Selection

Route media handling and choose the correct language settings before requesting audio from Minimax.

  1. Connect Media Route to Provider Voice Check to determine whether to generate voice output.
  2. From Provider Voice Check, route voice-enabled requests to Language Router.
  3. Connect Language Router to Chinese Yue Set, Chinese Set, Japanese Set, and English Set as defined in the workflow.
  4. Connect each language set node (Chinese Yue Set, Chinese Set, Japanese Set, English Set) to Minimax TTS Request.
  5. Connect Minimax TTS Request to Fetch Minimax Audio to retrieve the audio file.
  6. Connect Fetch Minimax Audio to Telegram Voice Dispatch for voice delivery.

Credential Required: Connect the appropriate HTTP authentication or API credentials in Minimax TTS Request and Fetch Minimax Audio for your Minimax endpoint.

Step 4: Configure Reply Logic and Telegram Outputs

Control whether replies are required and dispatch either voice or text messages via Telegram.

  1. Connect Telegram Voice Dispatch to Reply Needed Check to determine whether to respond with a follow-up.
  2. Route the non-voice path from Provider Voice Check to Reply Needed Check as defined in the workflow.
  3. Connect Reply Needed Check to Telegram Reply Dispatch for direct replies, and to Telegram Message Dispatch for standard messages.
  4. Send both Telegram Reply Dispatch and Telegram Message Dispatch to Final Output Set to standardize the response.
  5. Ensure Alt Media Route connects to Reply Needed Check for alternate media routing.

Credential Required: Connect your Telegram credentials for Telegram Voice Dispatch, Telegram Reply Dispatch, and Telegram Message Dispatch.

Step 5: Add Input and Output Logging

Log incoming requests and resulting outputs to your database for observability and analytics.

  1. From the parallel branch, connect Provider Mapper to Input Presence Check.
  2. Connect Input Presence Check to Log Input Insert to store inbound payload details.
  3. Chain Log Input Insert to Log Output Insert to capture the workflow response metadata.

Credential Required: Connect your Postgres credentials for Log Input Insert and Log Output Insert.

Step 6: Add Error Handling

This workflow does not include a dedicated error-handling branch, so monitoring should be handled externally or by enabling node-level error outputs.

  1. Review nodes with error output settings like Fetch Minimax Audio and Minimax TTS Request to decide if you want to add custom error routing.
  2. Consider adding a separate error workflow in n8n settings if you need centralized failure alerts.

Step 7: Test and Activate Your Workflow

Validate both the chat test path and the production trigger before enabling the workflow.

  1. Run a manual test using Chat Test Trigger and verify Final Output Set receives the expected response.
  2. Trigger Workflow Launch Trigger from a calling workflow and confirm provider data flows through Provider Mapper and out to Telegram nodes.
  3. A successful execution should show the audio dispatch path reaching Telegram Voice Dispatch or the text reply path reaching Telegram Reply Dispatch/Telegram Message Dispatch.
  4. When satisfied, toggle the workflow to Active in n8n for production use.
🔒

Unlock Full Step-by-Step Guide

Get the complete implementation guide + downloadable template

Common Gotchas

  • Telegram credentials can expire or need specific permissions. If things break, check your n8n credential settings and the bot’s access to the target chat first.
  • 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.

Frequently Asked Questions

How long does it take to set up this Telegram Postgres logging automation?

Plan on about 1–2 hours once your database and credentials are ready.

Do I need coding skills to automate Telegram Postgres logging?

No, but you will need to be comfortable wiring credentials and verifying database fields. A little SQL confidence helps when you import the required tables.

Is n8n free to use for this Telegram Postgres logging workflow?

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 MiniMax TTS API usage (it varies by audio length) and any OpenAI usage if you keep the AI nodes enabled.

Where can I host n8n to run this automation?

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.

Can I customize this Telegram Postgres logging workflow for WhatsApp instead of Telegram?

Yes, but you’ll swap the Telegram dispatch nodes (Telegram Message Dispatch, Telegram Reply Dispatch, Telegram Voice Dispatch) for your WhatsApp provider’s send-message actions. Most teams also adjust the media routing switches (Media Route and Alt Media Route) so the “reply vs message” behavior matches the new channel. The PostgreSQL logging pieces can stay the same, which is the nice part.

Why is my Telegram connection failing in this workflow?

Usually it’s the bot token or chat permissions. Regenerate or reselect the Telegram credentials in n8n, then confirm the bot is actually allowed to post in the target chat or channel. If replies fail but messages succeed, double-check that the reply metadata (message IDs) is being passed through your Input Mapper. Rate limiting can also show up if you blast out messages during tests.

How many messages can this Telegram Postgres logging automation handle?

A lot—practically, it’s limited by your n8n execution capacity and how fast Postgres and the TTS API respond.

Is this Telegram Postgres logging automation better than using Zapier or Make?

For this workflow, n8n is a better fit because it handles branching logic (media routing, “reply needed” checks, language switches) without turning into a spaghetti bill. It also supports a real database-first design, which matters when you want PostgreSQL to be the system of record instead of a hidden step. Redis caching is another big win if you’re looking up provider settings frequently. Zapier or Make can still work for lightweight chat notifications, but voice generation plus logging plus routing gets expensive and awkward fast. If you’re on the fence, Talk to an automation expert and we’ll map the simplest stack for your volume.

Once this is running, Telegram becomes a proper support channel with memory, routing, and receipts in PostgreSQL. Set it up once, then spend your time on real conversations instead of chasing missing context.

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.

Lisa Granqvist

Workflow Automation Expert

Expert in workflow automation and no-code tools.

×

Use template

Get instant access to this n8n workflow Json file

💬
Get a free quote today!
Get a free quote today!

Tell us what you need and we'll get back to you within one working day.

Get a free quote today!
Get a free quote today!

Tell us what you need and we'll get back to you within one working day.

Launch login modal Launch register modal