AIFlowPost

How to Build a Telegram Bot With n8n

Updated 2026-10-06 · 1001 words

How to Build a Telegram Bot With n8n — AIFlowPost cover

This page may contain affiliate links. If you buy through them we may earn a commission at no extra cost to you.

Direct answer: building a Telegram bot in n8n takes four pieces: a bot token from Telegram's BotFather, an n8n Telegram credential using that token, a Telegram Trigger node to receive messages, and a Telegram node to send replies. With an HTTPS-reachable n8n instance, you can have a working echo bot live in under fifteen minutes, and a bot that calls an AI model for its replies in under thirty. The step almost everyone trips on is Telegram's webhook requirement: it will not deliver messages to an instance that isn't on HTTPS with a valid certificate.

Step 1: Create the bot and get a token from BotFather

Open a chat with @BotFather on Telegram and send /newbot. Follow the prompts to name your bot and choose a username ending in "bot." BotFather hands back an API token immediately, a string that looks like 123456789:ABCdefGhIJKlmNoPQRstuVwxyZ. Copy it somewhere safe; this token is the only credential n8n needs to act as your bot, and anyone who has it can control the bot, so treat it like a password.

While you're in BotFather, send /setprivacy and disable group privacy mode if you plan to add the bot to group chats and want it to see every message rather than only ones that mention it directly. Skip this if the bot will only run in private one-to-one chats.

Step 2: Add the Telegram credential in n8n

In n8n, open Credentials and create a new Telegram credential, pasting in the bot token from Step 1. n8n validates the token against Telegram's API immediately, so you'll know right away if you copied it wrong. This one credential covers both the trigger and the send nodes you'll add next; you don't need a separate token for each.

Step 3: Add the Telegram Trigger node

Start a new workflow and add a Telegram Trigger node. Select your credential, and under "Updates" pick message to catch every incoming chat message. Save the workflow and switch it to Active, this is the step people forget, and an inactive workflow never receives a single event even though it looks correctly configured in the editor.

If your n8n instance is self-hosted, this is where the HTTPS requirement bites. Telegram registers a webhook URL pointing at your n8n instance, and it will only deliver events to an address with a valid TLS certificate; our guide to using webhooks in n8n covers this requirement, plus securing and testing a webhook endpoint, in more depth than fits here. If you haven't set this up yet, our guide to self-hosting n8n covers the reverse-proxy and HTTPS steps in full; n8n Cloud users can skip this entirely since it's handled for you.

Step 4: Decide the bot's logic

This is where your bot stops being a Telegram connection and becomes an actual bot. The simplest version is an echo bot: connect the trigger directly to a Telegram node (Send Message), set the chat ID to {{ $json.message.chat.id }} and the text to whatever fixed or templated reply you want. This is enough to confirm your whole pipeline works end to end before adding real logic.

For anything more useful, insert a step between the trigger and the reply. A Set or IF node works for simple keyword-based routing, "if the message contains 'price', send the pricing reply." For a bot that should actually understand and respond to open-ended questions, replace that step with an AI Agent node instead; we walk through the agent-building side of this in detail in our guide to building an AI agent in n8n, and the short version is: connect an LLM credential, give the agent a system prompt describing its role, and pass the incoming message text as its input.

Step 5: Test without breaking a real chat

Open a direct message with your bot in Telegram (search its username) and send a test message. Watch the n8n execution log in real time; a failed or skipped node shows up immediately, which is far faster feedback than guessing from Telegram's side. Resist the urge to test in a group chat you actually use: a misconfigured trigger that fires on every message, including the bot's own replies, can spam a group with a reply loop while you're mid-debug.

Once the private-chat test behaves the way you want, add the bot to a group if that's where it will actually run, and re-check the privacy-mode setting from Step 1 if it isn't responding to messages that don't directly mention it.

Common pitfalls

The HTTPS webhook requirement from Step 3 is the single most common failure we see, and it's worth re-checking first if nothing happens when you message the bot. The second is forgetting to toggle the workflow Active after making a change; n8n doesn't auto-activate a saved workflow. Third, if you're parsing user input for commands, remember Telegram's Bot API sends the literal text including the leading slash (/start, /help), so a simple "equals" check will miss /start@yourbotname, the format Telegram uses in group chats; a "starts with" check is safer.

Symptom Fix
No messages received at all Instance isn't on valid HTTPS; fix TLS or use n8n Cloud
Bot ignores group messages Disable group privacy mode via /setprivacy
/start@yourbot not matching Use a "starts with" check, not "equals"

If you want the bot to initiate conversations rather than only reply, that requires a different trigger, typically a Schedule Trigger that sends a message via the Telegram node on a timer, since Telegram's Bot API doesn't let a bot message a user who hasn't messaged it first. For broader messaging automation beyond Telegram, our guide to automating WhatsApp with AI covers the equivalent setup on that platform, and our social media posting automation guide is a useful next step if the bot's job eventually grows into cross-platform content. If your team lives in Slack instead, our guide to building a Slack bot with n8n walks through the same trigger-and-reply pattern with Slack's own app and OAuth setup.

Frequently asked questions

Do I need to self-host n8n to build a Telegram bot?

No, n8n's cloud plan works fine and skips the HTTPS setup step entirely since it's handled for you. Self-hosting is worth it if you're already running n8n for other workflows or want full control over data, but it adds the requirement of your own domain and TLS certificate before Telegram webhooks will work.

Is it free to run a Telegram bot through n8n?

Telegram's Bot API itself is completely free with no usage limits for normal bot traffic. Your cost is n8n: free if you self-host on your own server (just the server cost), or n8n Cloud's paid tiers if you don't want to manage hosting. Any AI model you add on top, like OpenAI or Anthropic, bills separately per API call.

Can the bot respond with AI instead of fixed replies?

Yes. Drop an AI Agent node between the Telegram Trigger and the Send Message node, connect an LLM credential (OpenAI, Anthropic, or others), and give it a system prompt describing how it should respond. We cover the agent-building side in more depth in our guide to building an AI agent in n8n.

Why isn't my Telegram bot receiving messages in n8n?

The most common cause is a webhook that isn't reachable over HTTPS with a valid certificate; Telegram silently refuses to deliver to anything else. The second most common cause is leaving the workflow in a saved-but-inactive state. In n8n, the trigger only starts listening once the workflow's Active toggle is switched on, not just saved.

↑ Back to top