Image-to-Text OCR & AI Refinement Bot - n8n Workflow

Automate Optical Character Recognition (OCR) and text cleanup using an n8n workflow triggered by Telegram images. This n8n template uses AI agents for polished, readable output.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

• Users who frequently need to digitize text from photos (OCR) and require high accuracy.
• Businesses needing automated, reliable data extraction from image receipts, documents, or labels.
• Developers looking for advanced n8n templates integrating Telegram, external APIs, and AI Agents.
• Anyone seeking a powerful, chat-based OCR solution built using an efficient n8n workflow.

Overview

This comprehensive n8n workflow provides a robust solution for digitizing text from images received via Telegram. Standard Optical Character Recognition (OCR) often produces messy, poorly formatted results. This n8n workflow goes beyond simple extraction. It starts with the Telegram n8n trigger, seamlessly handles image retrieval and encoding, uses a dedicated n8n node for OCR via an external API, and then leverages the power of an AI Agent (powered by Google Gemini) to perform extensive text cleanup and enhancement. This means the final output is not just raw text, but a human-readable, corrected, and logically structured document, demonstrating the full capability of what a complex n8n automation can achieve.

How it Works

The entire process is managed by a single automated n8n workflow, starting from a user action.


  1. Trigger Activation: The n8n trigger, a Telegram Trigger n8n node, activates when a user sends an image message to the linked bot.

  2. Input Cleanup: The Clean Input Data n8n node uses a Set operation to extract essential information: the user's chatID (for the reply) and the fileid of the highest resolution image.

  3. Image Retrieval: The get file Telegram n8n node downloads the actual image content using the extracted fileid.

  4. Base64 Conversion: The Convert to base64 n8n node prepares the binary file data for API transmission by transforming it into a base64 encoded string property.

  5. OCR Execution: An HTTP Request n8n node (labeled OCR) sends the base64 image payload to an external OCR service (requires custom configuration of the URL) to receive the initial raw text extraction.

  6. AI Refinement: The raw text is passed to the AI Agent n8n node. This agent is connected to the Google Gemini Chat Model and uses specific system instructions to fix recognition errors, improve formatting, and summarize complex text layouts into digestible bullet points.

  7. Final Response: The resulting cleaned text (output) is finally sent back to the user's chatID via the last Telegram n8n node, completing this powerful n8n workflow.

Installation Guide

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


  1. Import the n8n Workflow: Copy the provided JSON data and import it directly into your n8n instance using the 'Import Workflow' option.

  2. Telegram Credentials: You must provide credentials for two Telegram n8n nodes (Telegram Trigger and the final Telegram node). Ensure the Telegram Bot API key is configured and linked to the credentials named 'Ruri Image Reader' or update the credentials links within the imported n8n template.

  3. Gemini Credentials: Provide the API key for the Google Gemini Chat Model in the relevant n8n node, or link your existing Google PaLM/Gemini credentials.

  4. OCR Configuration: The OCR (HTTP Request) n8n node is currently configured with a placeholder URL ('#'). You must update the URL and payload structure to match your chosen external OCR API service (e.g., Azure Cognitive Services, Tesseract wrapper, or a custom microservice).

  5. Activation: Once credentials and the OCR endpoint are set, activate the Telegram Trigger n8n node and the overall n8n workflow to start listening for incoming image messages.

Node Details

This n8n workflow relies on several specialized n8n node types to manage file handling, external API interaction, and AI processing:

Telegram Trigger (n8n trigger): The starting point of the n8n workflow. It is configured to listen for new 'message' updates, specifically filtering for messages containing images.
Clean Input Data (Set n8n node): Essential for flow control. It uses expressions (={{ $json.message.chat.id }} and array indexing for photo) to extract the user ID and the largest image file ID, cleaning the data for subsequent n8n nodes.
get file (Telegram n8n node): Downloads the image content from Telegram's servers using the file ID extracted in the previous step.
Convert to base64 (Extract From File n8n node): Changes the binary image file into a base64 string, which is the standard input format for most external OCR APIs.
OCR (HTTP Request n8n node): Sends the base64 encoded image data to the third-party OCR service to perform the core text extraction. This specific n8n node requires careful setup based on the chosen OCR provider's API documentation.
Google Gemini Chat Model (Language Model n8n node): Defines the large language model used for text refinement. It provides the computational engine for the AI Agent n8n node.
AI Agent (Langchain Agent n8n node): Receives the raw OCR text. It executes a complex prompt designed to clean up formatting errors, fix recognition mistakes, and restructure the output (e.g., summarizing tabular data) before the final step of the n8n workflow.
Telegram (Message n8n node): The final action. It uses the stored chatID to send the highly refined, easy-to-read output text back to the original user.

Related n8n Workflows

Free

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

Featured*