What This Workflow Does
This workflow listens for Telegram messages that have text, voice notes, or images.
It checks if the message sender is allowed to talk to the bot.
Then, it sorts messages by type and uses AI to understand or analyze each one.
Finally, it sends replies based on the message content.
This helps save time by automating replies and understanding tasks without manual work.
Tools and Services Used
- Telegram Bot API: Receives user messages.
- OpenAI API: Transcribes voice messages and classifies text messages.
- n8n Workflows: Automates webhook listening, message routing, and sending replies.
- LangChain OpenAI: Classifies messages as tasks or others.
- Secure HTTPS Webhook URL: Ensures safe communication between Telegram and n8n.
Inputs, Processing Steps, and Outputs
Inputs
- Incoming Telegram messages including text, audio (voice notes), and images.
- Sender information to check authorization.
Processing Steps
- Webhook node listens for incoming Telegram messages.
- Validation node checks if the user sending the message is authorized.
- Message Router sends messages to different paths based on type: text, audio, or image.
- Audio messages are fetched, transcribed using OpenAI, and then classified.
- Text messages are extracted and classified using LangChain text classifier.
- Image messages are downloaded, converted to proper format, and sent to OpenAI’s GPT-4o Mini for analysis.
- Replies are formed and sent back to Telegram users based on classification results.
- Webhook setup nodes manage testing and production webhook URLs via Telegram API.
Outputs
- Appropriate Telegram replies based on message type and classification.
- Status messages for webhook setup confirmation.
Beginner Step-by-Step: How to Use This Workflow in n8n
Download and Import Workflow
- Download the workflow file using the Download button on this page.
- In n8n editor, click on “Import from File”.
- Select the downloaded file to import the workflow.
Configure Credentials and Settings
- Add your Telegram Bot API token in the Telegram Token & Webhooks node under the
tokenfield. - Enter your secure public HTTPS webhook URLs for both test and production environments.
- Add your OpenAI API Key in all nodes that require AI services.
- Update user IDs and names in the Validation node to include authorized Telegram users.
- Change any channel IDs, emails, or other identifiers if needed for your setup.
Test and Activate
- Send test messages (text, voice, image) to your Telegram bot. Confirm workflow processes messages and replies correctly.
- Adjust message texts or classification prompts if needed.
- When ready, activate the workflow by toggling the switch to “ACTIVE”.
- Set the webhook URL you want the bot to use by triggering the Set Webhook Production URL node for live usage.
You can also explore self-host n8n if you want more control over hosting the automation.
How the Workflow Works – Input → Process → Output
Input
Telegram messages arrive through the Webhook node.
Messages can be text, voice messages, or images.
Process
First, the Validation node checks if the sender is allowed.
Then, Message Router routes messages by type.
Audio files get downloaded, sent to OpenAI for transcription, then classified as task or other.
Text messages get extracted and classified in LangChain OpenAI nodes.
Images are downloaded, converted to base64 and back for AI readiness, then analyzed by GPT-4o Mini model.
Output
After classification and analysis, the workflow sends tailored replies via Telegram API nodes.
Webhook setup and status nodes manage Telegram bot webhook URLs for testing and production environments.
Customization Ideas
- Add more users in the Validation node to widen who can use the bot.
- Change classification labels from “task” and “other” to more detailed categories in text classifiers.
- Edit response messages to add personal style or brand voice in message nodes.
- Add new message type routes like video or documents in Message Router to support more media.
Common Problems and Fixes
- Error: “Unable to process your message.” reply.
Reason: User not authorized or message format unmatched.
Fix: Check the Validation node user data matches Telegram sender. Confirm message types handled by Message Router. - Error: No webhook updates.
Reason: Bad webhook URL or Bot token.
Fix: Verify HTTPS webhook URLs and tokens in Telegram Token & Webhooks. Use Get Telegram Webhook Info to confirm webhook is active. - Error: Transcription fails or texts unclear.
Reason: Poor audio quality or OpenAI key issues.
Fix: Test clear audio, check API key and limits.
Pre-Production Checklist
- Make sure Telegram Bot token is set correctly in Telegram Token & Webhooks.
- Try webhook URLs with test URL before switching to production URL.
- Verify the Validation node user info matches the Telegram users.
- Send test messages of all types and verify routing and replies.
- Check OpenAI API credentials for transcription and classification work.
- Backup workflow before big changes to save your work.
Deployment Guide
After testing, turn the workflow on by switching it to “ACTIVE”.
Use the status nodes to watch for webhook health and chat activity.
Set webhook URL in Set Webhook Production URL node and enable that webhook.
Disable test webhook to avoid message conflicts.
Check status replies regularly to see webhook connection updates.
Summary of Benefits and Results
✓ Saves time by automating Telegram message replies.
✓ Checks user authorization automatically to prevent errors.
✓ Classifies text and audio messages to spot tasks easily.
✓ Analyzes image content with AI for smart replies.
✓ Handles webhook setup and status for reliable bot operation.
✓ Easy to test before moving to live production.
