Convert LLM Output into Rich Telegram Messages — Auto-Media & Smart Chunking

Nodes

ccc8d19f-f0b3-4730-899f-8023aeb547e4083a55c9-df56-4154-959f-52737890cad02e3e39e3-0e17-4fae-9ac5-9ee31f9711edd2545cc0-4d6d-43fc-bbcc-62005c2452f0+1

Created by

DmDmitry Mikheev

Last edited 10 days ago

Telegram Rich Output Helper Workflow

Who is this for?
Builders of Telegram chat‑bots, AI assistants, or notification services who already run n8n and need to convert long, mixed‑media answers from an LLM (or any upstream source) into Telegram‑friendly messages.

Prerequisites

  1. A Telegram bot created with @BotFather.

  2. The bot’s HTTP API token saved as a Telegram API credential in n8n.

  3. n8n ≥ 1.0 with the built‑in Telegram node still installed.

  4. A parent workflow that calls this one via Execute Workflow and passes:

    • chatId — the destination chat ID (integer).
    • output — a string that can contain plain text and HTTP links to images, audio, or video.

What the workflow does

  1. Extract Links – A JavaScript Code node scans output, deduplicates URLs, and classifies each by file extension.
  2. Link Path
    • If no media links exist, the text path is used.
    • Otherwise, each link is routed through a Switch node that triggers the correct Telegram call (sendPhoto, sendAudio, sendVideo) so users get inline previews or players.
  3. Text Path
    • An IF node checks whether the remaining text exceeds Telegram’s 1 000‑character limit.
    • When it does, a Code node slices the text at line boundaries; SplitInBatches then sends the chunks sequentially so nothing is lost.
  4. All branches converge, keeping the whole exchange inside one execution.

Customisation tips

  • Adjust the character limit – edit the first expression in “If text too long”.
  • Filter/enrich links – extend the regex or add MIME checks before dispatch.
  • Captions & keyboards – populate additionalFields in the three “Send back” nodes.
  • Throughput vs. order – tweak the batch size in both SplitInBatches nodes.

With this template in place, your users receive the complete message, playable media, and zero manual formatting – all within Telegram’s API limits.

New to n8n?

Need help building new n8n workflows? Process automation for you or your company will save you time and money, and it's completely free!