Image Text Extraction via Telegram Bot and Gemini OCR - n8n Workflow

Use this powerful n8n workflow to create a Telegram bot that performs Optical Character Recognition (OCR) on uploaded images using the Gemini 2.0 Flash API. A perfect n8n templates for AI integration.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Users needing a fast, serverless OCR solution accessible via mobile messaging.

  • Automation specialists looking for practical n8n templates integrating messaging platforms with cutting-edge AI.

  • Developers wanting to deploy simple, secure AI services without complex web infrastructure.

  • Anyone needing to process visual data quickly using an n8n node configuration.

Overview

Leveraging the simplicity of Telegram and the power of the Gemini 2.0 Flash model, this n8n workflow provides an elegant solution for high-speed Optical Character Recognition (OCR). The challenge of integrating binary files (images) uploaded via a chat application into a secure REST API is solved entirely within this n8n automation. When a user uploads an image, the system automatically fetches the file, converts it into the necessary Base64 format, sends it to the Gemini API for text extraction, and returns the result instantly. This comprehensive n8n node sequence ensures reliable and efficient data processing, making it one of the most useful n8n templates for AI adoption.

How it Works

The execution of this n8n workflow follows a six-step process, initiated by an external event:


  1. Trigger Reception: The process begins with the Telegram Trigger n8n trigger, which activates immediately when an image message is received in the linked chat bot.

  2. Data Preparation: The 'Clean Input Data' Set n8n node extracts critical information: the chatID (for sending the response) and the fileid of the highest resolution image uploaded.

  3. File Retrieval: A subsequent Telegram n8n node uses the extracted fileid to download the actual image file from Telegram's servers.

  4. Binary Handling: The 'Extract from File' n8n node takes the binary image data and converts it into a Base64 encoded string, placing it in the data property—a format required by the Gemini API for inline data transfer.

  5. AI Processing (OCR): The 'Gemini OCR' n8n node (an HTTP Request) sends the Base64 image data to the gemini-2.0-flash:generateContent endpoint with the prompt “Extract text”. The authentication is handled using a Query Auth credential.

  6. Result Delivery: Finally, a dedicated Telegram n8n node uses the stored chatID to send the extracted text content back to the user who originally submitted the image, completing the entire n8n workflow loop.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON and import it directly into your n8n instance as a new n8n workflow.

  2. Telegram Bot Setup: Create a new Telegram Bot via BotFather and obtain the Bot Token. Configure a Telegram API credential in n8n using this token.

  3. Gemini API Setup: Obtain a Google AI Studio API key (e.g., AIzaSy...). Create a new HTTP Query Auth credential in n8n, setting the parameter name to key and the value to your Gemini API key. This credential is used by the 'Gemini OCR' n8n node.

  4. Credential Assignment: Ensure both Telegram n8n node instances and the Telegram Trigger n8n node are using the correct Telegram credential, and the 'Gemini OCR' n8n node is assigned the Gemini HTTP Query Auth credential.

  5. Activate: Save and activate the n8n workflow. The Telegram Trigger will automatically register its webhook, allowing the bot to receive images.

Node Details

This n8n workflow relies on a precise configuration of standard and specialized n8n node types:

Telegram Trigger (n8n trigger):
Function: Starts the n8n workflow upon receiving an image message.
Key Configuration: Configured to monitor 'message' updates and enable Download to ensure file metadata is available.

Clean Input Data (Set n8n node):
Function: Extracts the user's chatID and the fileid of the highest resolution image to be processed.
Key Configuration: Uses N8N expressions to dynamically select the largest file in the photo array: ={{ $json["message"]["photo"][$json["message"]["photo"].length - 1]["file
id"] }}.

get file (Telegram n8n node):
Function: Retrieves the binary content of the image file using the previously extracted fileId.
Key Configuration: Resource set to 'file'.

Extract from File (n8n node):
Function: Prepares the binary file for API transmission by encoding it to Base64 and mapping it to a JSON property, making it consumable by the HTTP Request body.
Key Configuration: Operation set to 'binaryToPropery'.

Gemini OCR (HTTP Request n8n node):
Function: Sends the Base64-encoded image and the extraction prompt to the Gemini 2.0 Flash API.
Key Configuration: URL points to the gemini-2.0-flash:generateContent endpoint. Uses JSON body structure containing inlineData for the image and Query Auth for API key inclusion.

Telegram (n8n node):
Function: Sends the final extracted text result back to the initiating user.
Key Configuration: Uses the stored chatID and the output from the Gemini request (={{ $json.output }}) as the message text.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by
Rudi Afandi
Rudi Afandi

Featured*