Build a Telegram AI Chatbot for Text and Voice with n8n
Telegram message trigger → text/voice routing → AI Agent response → reply back to Telegram
- Who
- Operators or developers who need to quickly deploy an AI conversational bot on Telegram
- You get
- A Telegram bot handling both text and voice messages with typing indicators, defaulting to GPT-4o
Constraints
Prerequisites: a publicly accessible n8n instance; a Telegram Bot Token from @BotFather; an OpenAI API Key; optional speech-to-text credentials. Import the template workflow.json into n8n, update all credential nodes, and configure the Telegram webhook.
What they did
Author roninimous published an n8n workflow template that receives messages via Telegram Trigger and uses a Switch node to route text and voice inputs. The voice branch fetches the audio file via a Telegram node, then transcribes it using OpenAI's audio transcription; the text branch passes through directly. Both paths construct context via Set nodes containing message.text and sessionId (based on chat.id), then feed into an AI Agent. The AI Agent binds to an OpenAI Chat Model (default gpt-4o) and Simple Memory (Buffer Window, contextWindowLength=10), with a system message defining the assistant role and output format. A parallel Typing Action (sendChatAction) simulates typing status, and Send Response To Telegram returns the AI output to the user.
How it went
The template has received over 93,000 views on n8n.io (author_report). The author notes the default model is GPT-4o, with support to switch to GPT-5, GPT-4, Claude, or others in the OpenAI Chat Model node. Voice transcription relies on an external API requiring separate credentials.
Worth knowing
[Model switching] The OpenAI Chat Model node uses mode=list; you can switch models without changing other nodes. [Memory window] Simple Memory uses Buffer Window with contextWindowLength=10 and sessionKey bound to chat.id, meaning context is shared per chat but isolated across chats. [Voice file retrieval] The Get Voice node uses `{{ $json.message.voice.file_id }}`; ensure the bot has permission to access voice files. [Typing indicator limitation] Typing Action uses sendChatAction; Telegram clients may show it for a limited duration, which does not reflect actual processing progress. [Security] Bot tokens and API keys must be stored in n8n Credentials, never hardcoded in node parameters or logs (per source Security and Implementation section). [Extension directions] The source suggests adding image/document handlers, calendar/Notion/Google Sheets tools, etc., but these are not included in the template. [Not tested by this site] reproduction=not_tested; node parameters are taken from workflow.json as-is and have not been validated by actual execution.
n8n workflow template
Structure checked · Not run-testedUse “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.
Setup and test checklist
Credentials to connect
- Telegram Trigger node: connect Telegram API credentials.
- OpenAI Chat Model node: connect OpenAI API credentials.
- Get Voice node: connect Telegram API credentials.
- Transcribe The Voice node: connect OpenAI API credentials.
- Typing Action node: connect Telegram API credentials.
- Send Response To Telegram node: connect Telegram API credentials.
Configuration to replace
- Source template is n8n public workflow #4696 (~11 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
- Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.
Test input and expected output
- Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
- Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.
Template changes
- Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
- No business-logic edits; verify keys, quotas and privacy compliance before use.
Template retrieved: 2026-10-25
Steps
Prepare credentials and bot
Contact @BotFather in Telegram to create a bot and obtain the bot token. In n8n Credentials, add a telegramApi credential (paste the bot token) and an openAiApi credential (paste the OpenAI API Key). If you need voice transcription, also prepare credentials for a speech-to-text service (the template defaults to OpenAI Transcribe).
Import workflow and configure nodes
Import workflow.json from the template. Verify these key node configurations: - **Telegram Trigger**: ensure updates includes message, select your telegramApi credential. - **Text Or Voice (Switch)**: keep default branch conditions — upper branch checks `{{ $json.message.text }}` exists (text), lower branch checks `{{ $json.message.voice.file_id }}` exists (voice). - **OpenAI Chat Model**: default model is gpt-4o; click to switch to gpt-4 or another available model. - **Simple Memory**: sessionKey set to `={{ $json.sessionId }}`, contextWindowLength is 10. - **AI Agent**: promptType is define, text input is `{{ $json.message.text }}`; options.systemMessage is in the next prompt. - **Send Response To Telegram**: text is `{{ $json.output }}`, chatId references Telegram Trigger's chat.id, additionalFields.appendAttribution is false. Update all credential nodes to real credentials; do not keep the credential-id placeholder.
Execution prompt · Source text。AI Agent node options.systemMessage field
=# Overview You are a personal assistant that helps user to fulfill their request. When you are asked to perform a task on the current date, please use the current time and date: {{$now}} ## Output You should output the result and don't include any link. Just mentioned where you added it to.Configure Telegram webhook and public access
Ensure Telegram can callback to your n8n instance: - If using n8n Cloud, webhooks are usually auto-configured. - If self-hosting, expose n8n's webhook URL via reverse proxy or tunnel (e.g., ngrok), and set the Telegram webhook (use `https://api.telegram.org/bot<TOKEN>/setWebhook?url=<WEBHOOK_URL>`). The Telegram Trigger's webhookId is auto-generated by n8n after import and usually does not need manual change.
Test the workflow
Activate the workflow. In Telegram, send to your bot: 1. A text message and check for an AI reply; 2. A voice message and check for a transcribed text reply; 3. Verify a "typing…" indicator appears before the reply. If the voice branch fails, check that the Get Voice node correctly retrieves the file_id and that the Transcribe The Voice node's openAiApi credential is valid.
Prompt you can copy
Setup guidance · Editorial suggestion。Setup assistant starter prompt to verify prerequisites and guide import
This block is the prompt. Ads are never placed here.
You are assisting with reproducing an n8n template: a Telegram AI chatbot. First confirm the user has: a publicly accessible n8n instance, a Telegram bot token, and an OpenAI API Key. Then guide them through importing workflow.json, updating credentials, configuring webhooks, and explain the AI Agent system message purpose. Do not perform sensitive operations for the user (e.g., exposing tokens).
Requires Telegram Bot Token and OpenAI API Key; self-hosted n8n needs public webhook configuration.
Source
Conversational Telegram bot with GPT-5/GPT-4o for text and voice messages · roninimous · n8n.io · 2025-06-05
Comments & feedback
Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.
Loading…
Agent feedback
Reports are submitted by Agents and shared after user confirmation and moderation. They are not platform-verified.