{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "fe8f2304-f2f6-45d5-8f26-3e07f59f2122",
      "name": "Sticky Note \u2014 Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1744,
        944
      ],
      "parameters": {
        "color": 5,
        "width": 560,
        "height": 496,
        "content": "# \ud83d\udcf8 Telegram \u2192 AIMLAPI Vision Bot\n\nThis workflow receives photos from users in Telegram, \nencodes them to base64, and sends them to **AIMLAPI** \n(GPT-4o Vision) for analysis.\n\n---\n## \ud83d\ude80 Features\n* Image content recognition\n* OCR (extract text from photos)\n* Concise description in the reply\n* Automatic response back to Telegram\n"
      },
      "typeVersion": 1
    },
    {
      "id": "fc3443dd-7c1d-478f-846b-e20b2d480898",
      "name": "Sticky Note \u2014 Setup Guide",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2320,
        944
      ],
      "parameters": {
        "color": 5,
        "width": 560,
        "height": 496,
        "content": "# \ud83d\udee0 Setup Guide\n\n### 1. \ud83d\udcf2 Create a Telegram Bot\n* In [@BotFather](https://t.me/BotFather) \u2192 /newbot\n* Save the API Token\n\n### 2. \ud83d\udd10 Connect Telegram API in n8n\n* Go to Credentials \u2192 Telegram API\n* Paste the token from BotFather\n\n### 3. \ud83d\udd0c Connect AIMLAPI\n* Go to Credentials \u2192 AI/ML API\n* Enter your API Key\n* Base URL: https://api.aimlapi.com/v1\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a00ee4eb-0c89-48a2-87c1-000197b71a55",
      "name": "Sticky Note \u2014 Receive Message",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        944,
        1552
      ],
      "parameters": {
        "color": 3,
        "width": 384,
        "height": 448,
        "content": "# \ud83d\udce5 Step 1 \u2014 Receive Telegram Message\n\nListens for new messages in Telegram.\nExtracts:\n* chat.id (where to reply)\n* photo.file_id (photo file ID)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "375019d6-a2c0-438c-950c-376603599dc5",
      "name": "Sticky Note \u2014 GPT\u20115 Processing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1744,
        1552
      ],
      "parameters": {
        "width": 384,
        "height": 448,
        "content": "# \ud83d\udcf7 Step 2 \u2014 Get Photo\n\nFetches the file by `file_id` from Telegram.\nResult: binary photo data (jpg/jpeg/png).\n"
      },
      "typeVersion": 1
    },
    {
      "id": "e58d2186-f12e-43a4-9b7c-a644d27e64fa",
      "name": "Sticky Note \u2014 Send Response",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2144,
        1552
      ],
      "parameters": {
        "color": 4,
        "width": 384,
        "height": 448,
        "content": "# \ud83e\udde9 Step 3 \u2014 Convert to base64\n\nConverts the binary file into a base64 string,\nwhich will be passed to AIMLAPI Vision.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "06a31bfb-15af-40fe-b468-057cf985180f",
      "name": "Sticky Note \u2014 Logging",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2944,
        1552
      ],
      "parameters": {
        "color": 5,
        "width": 384,
        "height": 448,
        "content": "# \ud83e\udde0 Step 4 \u2014 AIMLAPI Vision\n\nMakes a request to AIMLAPI GPT-4o with:\n1. Instruction: \"Describe this image. Extract visible text.\"\n2. The base64 image passed as `image_url`.\n\nResult: description + OCR text.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "7cc29371-2e04-440c-baea-4f7a716a5acf",
      "name": "Sticky Note \u2014 Receive Message1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1344,
        1552
      ],
      "parameters": {
        "color": 3,
        "width": 384,
        "height": 448,
        "content": "# \ud83d\udcac Step 1.5 \u2014 Simulate Typing\n\nSends a \"typing\u2026\" action to the user\nwhile the bot processes the photo.\n\nCreates a more natural user experience.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "3eb41a97-ae1e-45df-8699-99c7db819cf0",
      "name": "Sticky Note \u2014 Send Response1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2544,
        1552
      ],
      "parameters": {
        "color": 4,
        "width": 384,
        "height": 448,
        "content": "# \ud83e\uddd1\u200d\ud83d\udcbb Step 3.5 \u2014 Normalize MIME\n\nJS code builds a proper Data URI:\n`data:image/jpeg;base64,...`\n\nTelegram sometimes returns `image/jpg` \u2014 \nthis is replaced with the standard `image/jpeg`.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "d616db57-d547-42b7-8b75-d41d769ad814",
      "name": "Sticky Note \u2014 Logging1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3344,
        1552
      ],
      "parameters": {
        "color": 5,
        "width": 384,
        "height": 448,
        "content": "# \ud83d\udce4 Step 5 \u2014 Send Reply\n\nSends the model\u2019s response back to the user \nin Telegram as a text message/caption.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "d9b3cdf6-096d-426a-811b-9b35fa15f759",
      "name": "Step 1 \u00b7 \ud83d\udce9 Telegram Trigger (In)",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        1072,
        1824
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "969d9b61-fcab-4907-b670-ef12da530051",
      "name": "Step 1.5 \u00b7 \ud83d\udcac Typing\u2026",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1472,
        1824
      ],
      "parameters": {
        "chatId": "={{ $json.message.chat.id }}",
        "operation": "sendChatAction"
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e24fb8ae-5090-45b4-bc77-4d2ddb054245",
      "name": "Step 2 \u00b7 \ud83d\udcf7 Get Photo",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1888,
        1824
      ],
      "parameters": {
        "fileId": "={{ $('Step 1 \u00b7 \ud83d\udce9 Telegram Trigger (In)').item.json.message.photo[$('Step 1 \u00b7 \ud83d\udce9 Telegram Trigger (In)').item.json.message.photo.length - 1].file_id }}",
        "resource": "file",
        "additionalFields": {
          "mimeType": "image/jpeg"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "34e8b41b-ccd9-431c-92a0-0b1471295c55",
      "name": "Step 3 \u00b7 \ud83e\udde9 Extract \u2192 base64",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2288,
        1824
      ],
      "parameters": {
        "options": {},
        "operation": "binaryToPropery"
      },
      "typeVersion": 1
    },
    {
      "id": "3cc458c3-ff28-4d34-9e40-769fa229f8ff",
      "name": "Step 3.5 \u00b7 \ud83e\uddd1\u200d\ud83d\udcbb Build Data URI",
      "type": "n8n-nodes-base.code",
      "position": [
        2672,
        1824
      ],
      "parameters": {
        "jsCode": "// Build a proper Data URI for Vision API\n// Base64 from previous node\nconst base64Data = $input.first().json.data;;\n\n// Telegram may report image/jpg; normalize to image/jpeg\nlet fixedMime = 'image/jpeg';\n\nreturn [{\n  dataUri: `data:${fixedMime};base64,${base64Data}`\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "dbc396b9-d19a-4f7a-a26a-77b60d3cc9bc",
      "name": "Step 4 \u00b7 \ud83e\udde0 AIMLAPI Vision (HTTP)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3088,
        1824
      ],
      "parameters": {
        "url": "https://api.aimlapi.com/v1/chat/completions",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"model\": \"openai/gpt-4o\",\n  \"messages\": [\n    {\n      \"role\": \"user\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"Describe this image. Then extract any visible text (OCR). Keep it concise.\"\n        },\n        {\n          \"type\": \"image_url\",\n          \"image_url\": {\n            \"url\": \"{{ $json.dataUri }}\"\n          }\n        }\n      ]\n    }\n  ],\n  \"max_tokens\": 300\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "aimlApi"
      },
      "credentials": {
        "aimlApi": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.2
    },
    {
      "id": "ca71edf8-19e8-4f9f-acbb-506a1bcb0240",
      "name": "Step 5 \u00b7 \ud83d\udce4 Reply to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        3488,
        1824
      ],
      "parameters": {
        "text": "={{ $json?.choices?.[0]?.message?.content || \"Sorry, the model returned an empty response.\" }}",
        "chatId": "={{ $('Step 1 \u00b7 \ud83d\udce9 Telegram Trigger (In)').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false,
          "reply_to_message_id": "={{ $('Step 1 \u00b7 \ud83d\udce9 Telegram Trigger (In)').item.json.message.message_id }}",
          "disable_web_page_preview": true
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    }
  ],
  "connections": {
    "Step 2 \u00b7 \ud83d\udcf7 Get Photo": {
      "main": [
        [
          {
            "node": "Step 3 \u00b7 \ud83e\udde9 Extract \u2192 base64",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 1.5 \u00b7 \ud83d\udcac Typing\u2026": {
      "main": [
        [
          {
            "node": "Step 2 \u00b7 \ud83d\udcf7 Get Photo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 3 \u00b7 \ud83e\udde9 Extract \u2192 base64": {
      "main": [
        [
          {
            "node": "Step 3.5 \u00b7 \ud83e\uddd1\u200d\ud83d\udcbb Build Data URI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 1 \u00b7 \ud83d\udce9 Telegram Trigger (In)": {
      "main": [
        [
          {
            "node": "Step 1.5 \u00b7 \ud83d\udcac Typing\u2026",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 4 \u00b7 \ud83e\udde0 AIMLAPI Vision (HTTP)": {
      "main": [
        [
          {
            "node": "Step 5 \u00b7 \ud83d\udce4 Reply to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 3.5 \u00b7 \ud83e\uddd1\u200d\ud83d\udcbb Build Data URI": {
      "main": [
        [
          {
            "node": "Step 4 \u00b7 \ud83e\udde0 AIMLAPI Vision (HTTP)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}