Smart Telegram Bot Text/Image Router with Vision and Generation - n8n Workflow

Use this powerful n8n workflow to create a smart Telegram bot that routes messages: images for GPT-4o-Mini/NVIDIA Vila analysis, or text for Stable Diffusion 3 image generation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Developers looking to deploy multimodal AI services via a chat interface.
Content creators needing quick image generation or analysis from text prompts.
Researchers requiring automated, dual-path processing (Image-to-Text and Text-to-Image).
Users seeking powerful n8n templates for integrating OpenAI and NVIDIA APIs.

Overview

This robust n8n workflow acts as a sophisticated content router for a Telegram bot, demonstrating the power of integrating multiple AI services. It solves the challenge of handling complex, multimodal user inputs (images and text) seamlessly within a single automation pipeline. Utilizing a dynamic n8n node structure, this solution ensures users can interact naturally: sending images for detailed descriptions or text prompts for stunning visual creations using cutting-edge models like GPT-4o-Mini and Stable Diffusion 3. The entire process, from the initial n8n trigger to the final email report, is fully automated. This is a highly valuable addition to any collection of advanced n8n templates, showcasing how to efficiently manage complex branching logic.

How it Works

The automation begins with the Telegram n8n trigger, which listens for new messages.


  1. Trigger and Extraction: The 📱 Telegram Trigger n8n node captures the message. The subsequent Code n8n node, 📋 Extract Message Data, parses the input to determine the contentType (image or text) and extracts essential IDs (like photoFileId and chatId).

  2. Routing: The 🔀 Route by Content Type - Image or Text Switch n8n node directs the flow based on the content type.

  3. Image Analysis Path (Image Input): If an image is detected, the 📸 Get Image file from Telegram n8n node downloads the file. The image is then simultaneously analyzed by two separate vision APIs: Analyze image using GPT-4O-Mini and HTTP Nvidia Vila (using NVIDIA's VILA model). The results are combined using the 🔀 Merge AI Results n8n node.

  4. Text Generation Path (Text Input): If only text is detected, the n8n workflow sends a confirmation message back to Telegram (Get Text from Telegram). The text is then passed to the NVIDIA API NVIDIA Stable Diffusion 3 n8n node for image generation.

  5. Image Post-Processing: The resulting base64 image from Stable Diffusion 3 is converted into a storable binary file using the Convert to Binary File Code n8n node.

  6. Final Notification: Depending on the path taken, the result (either the AI description or the generated image) is formatted and delivered to the user via a Gmail n8n node, completing the execution of this complex n8n workflow.

Installation Guide

To set up this powerful n8n workflow, follow these steps:


  1. Import the n8n workflow: Copy the provided JSON code and paste it into your n8n instance via the 'Import from JSON' option.

  2. Telegram Bot Setup: Configure the 📱 Telegram Trigger n8n node using your Bot token. Ensure the webhook is active.

  3. Credential Setup:

OpenAI: Set up credentials for the Analyze image using GPT-4O-Mini n8n node (requires GPT-4o access).
NVIDIA: Set up HTTP Bearer Token credentials for both the HTTP Nvidia Vila and NVIDIA API NVIDIA Stable Diffusion 3 n8n node to access the NVIDIA AI APIs.
* Gmail: Configure OAuth2 credentials for the two Gmail n8n nodes, ensuring they have permission to send emails.

  1. Activation: Once all credentials and parameters (especially the recipient email addresses in the Gmail nodes) are set, activate the n8n workflow to start listening for Telegram messages.

Node Details

📱 Telegram Trigger: This n8n trigger is the starting point, configured to listen specifically for 'message' updates from the linked Telegram Bot.
📋 Extract Message Data (Code): A critical n8n node that uses custom JavaScript to normalize the incoming message, determine if it contains an 'image' or 'text', and extract necessary file and chat IDs.
🔀 Route by Content Type - Image or Text (Switch): This Switch n8n node is the core flow control, routing items based on the contentType extracted in the previous step, allowing for two distinct AI processes within one n8n workflow.
Analyze image using GPT-4O-Mini (OpenAI n8n node): Utilizes the LangChain compatible OpenAI n8n node to analyze the downloaded image file, providing a detailed description using GPT-4o-mini's vision capabilities.
HTTP Nvidia Vila: Custom HTTP Request n8n node configured to call the NVIDIA VILA model for an alternative or supplementary image analysis.
NVIDIA API NVIDIA Stable Diffusion 3 (HTTP Request): Configured as a POST request to generate an image based on the text prompt found in the Telegram message. It defines parameters like cfgscale and aspectratio.
Convert to Binary File (Code): This essential n8n node processes the base64 encoded image response from the Stable Diffusion 3 API, converting it into a binary file format that can be attached to the output email.
Send a message of image-to-text results / Send a message of text-to-image results (Gmail n8n nodes): These final n8n nodes deliver the processed results (AI descriptions or generated images) via email.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all
Created by
Cheng Siong Chin
Cheng Siong Chin

Prof. Cheng Siong CHIN serves as Chair Professor in Intelligent Systems Modelling and Simulation in Newcastle University, Singapore. His academic credentials include an M.Sc. in Advanced Control and Systems Engineering from The University of Manchester and a Ph.D. in Robotics from Nanyang Technological University.

Featured*