LLM Integrator for Telegram

    This is a workflow designed to integrate famous LLMs into a telegram bot.

    Shared 11/29/2025

    7 views

    Visual Workflow

    JSON Code

    {
      "meta": {
        "templateCredsSetupCompleted": true
      },
      "nodes": [
        {
          "id": "219f1194-50e9-44a6-9c20-ee5dcb178742",
          "name": "Process Base64",
          "type": "n8n-nodes-base.code",
          "position": [
            528,
            -1552
          ],
          "parameters": {
            "jsCode": "// Extract and clean the base64 data\nconst response = $input.first().json;\nlet base64Data = '';\n\n// Check different possible response structures\nif (response.choices && response.choices[0] && response.choices[0].message) {\n  const message = response.choices[0].message;\n  \n  // Check for images array\n  if (message.images && message.images[0] && message.images[0].image_url) {\n    base64Data = message.images[0].image_url.url;\n  }\n  // Check for content with base64\n  else if (message.content && message.content.includes('base64')) {\n    base64Data = message.content;\n  }\n  // Check for direct base64 in content\n  else if (message.content) {\n    base64Data = message.content;\n  }\n}\n\n// Clean the base64 data - remove data URL prefix if present\nif (base64Data.startsWith('data:image/')) {\n  base64Data = base64Data.split(',')[1];\n}\n\n// Remove any whitespace or newlines\nbase64Data = base64Data.replace(/\\s/g, '');\n\nreturn {\n  base64: base64Data,\n  originalResponse: response\n};"
          },
          "typeVersion": 2
        },
        {
          "id": "886131c7-7ff9-4a2a-b954-4a4e83cbd85d",
          "name": "Convert to File",
          "type": "n8n-nodes-base.convertToFile",
          "position": [
            704,
            -1552
          ],
          "parameters": {
            "options": {
              "fileName": "generated_image.png",
              "mimeType": "image/png"
            },
            "operation": "toBinary",
            "sourceProperty": "base64"
          },
          "typeVersion": 1.1
        },
        {
          "id": "06f52270-114e-4b8f-ac17-152735a41366",
          "name": "Send Photo to Telegram",
          "type": "n8n-nodes-base.telegram",
          "position": [
            880,
            -1552
          ],
          "parameters": {
            "chatId": "YOUR_CHAT_ID",
            "operation": "sendPhoto",
            "binaryData": true,
            "additionalFields": {
              "caption": "Here's your generated image about the meaning of life! 🎨"
            }
          },
          "credentials": {
            "telegramApi": {
              "id": "",
              "name": "Jup"
            }
          },
          "typeVersion": 1.2
        },
        {
          "id": "746259f4-d48a-49b2-b0d9-abc17ff81f81",
          "name": "Telegram Trigger1",
          "type": "n8n-nodes-base.telegramTrigger",
          "position": [
            -1152,
            -1184
          ],
          "parameters": {
            "updates": [
              "message"
            ],
            "additionalFields": {}
          },
          "credentials": {
            "telegramApi": {
              "id": "",
              "name": "Telegram account"
            }
          },
          "typeVersion": 1.2
        },
        {
          "id": "992feb0e-d505-4a16-8062-936272900aed",
          "name": "AI Agent1",
          "type": "@n8n/n8n-nodes-langchain.agent",
          "position": [
            -240,
            -1184
          ],
          "parameters": {
            "text": "=You are a tool selector and executor.\nYou have access to these tools: grok, chatgpt, claude, gemini, free, perplexity, image-generator.\n\nRules:\n1. If the user explicitly mentions a tool name, call that tool.\n2. If it's code, tech or automation related, call claude.\n3. If it's about generating, creating, or making images, call image-generator.\n4. If it's about finance, biology, medical, sports or learning call chatgpt.\n5. If it's about general science, call grok.\n6. If it's a research, call perplexity\n7. Otherwise, call free.\n\nWhen you decide, do not return the tool name as plain text.\nInstead, call the tool with the user's full message which is: {{ $json.message.text }}.\n\nOutput:\nafter the tool responds back to the reqest, simply send it to the next node which is telegram.\n",
            "options": {},
            "promptType": "define"
          },
          "retryOnFail": true,
          "typeVersion": 2.2
        },
        {
          "id": "2b783eb1-8530-4552-9bfb-afaaad7f4c80",
          "name": "Simple Memory7",
          "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
          "position": [
            -832,
            -944
          ],
          "parameters": {
            "sessionKey": "={{ $('Telegram Trigger1').item.json.message.text }}",
            "sessionIdType": "customKey",
            "contextWindowLength": 10
          },
          "typeVersion": 1.3
        },
        {
          "id": "90afd44a-4d8c-4a48-9744-8c7030915890",
          "name": "ChatGPT1",
          "type": "@n8n/n8n-nodes-langchain.agentTool",
          "position": [
            -704,
            -944
          ],
          "parameters": {
            "text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Prompt__User_Message_', ``, 'string') }}",
            "options": {}
          },
          "typeVersion": 2.2
        },
        {
          "id": "8f0bdb26-2952-432e-be8c-4b4dfb0402ec",
          "name": "Gemini1",
          "type": "@n8n/n8n-nodes-langchain.agentTool",
          "position": [
            -400,
            -944
          ],
          "parameters": {
            "text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Prompt__User_Message_', ``, 'string') }}",
            "options": {}
          },
          "typeVersion": 2.2
        },
        {
          "id": "71581200-67a8-4fcd-8d97-b655262e7e0c",
          "name": "Grok1",
          "type": "@n8n/n8n-nodes-langchain.agentTool",
          "position": [
            -112,
            -944
          ],
          "parameters": {
            "text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Prompt__User_Message_', ``, 'string') }}",
            "options": {}
          },
          "typeVersion": 2.2
        },
        {
          "id": "d82c026c-f27a-4450-8182-cc595a221480",
          "name": "claude model1",
          "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
          "position": [
            176,
            -736
          ],
          "parameters": {
            "model": "anthropic/claude-sonnet-4",
            "options": {}
          },
          "credentials": {
            "openRouterApi": {
              "id": "",
              "name": "OpenRouter account"
            }
          },
          "typeVersion": 1
        },
        {
          "id": "9dfb9dd9-4432-4ce8-bca0-2730b48d8cd9",
          "name": "gpt model1",
          "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
          "position": [
            -704,
            -736
          ],
          "parameters": {
            "model": "openai/gpt-4o-mini",
            "options": {}
          },
          "credentials": {
            "openRouterApi": {
              "id": "",
              "name": "OpenRouter account"
            }
          },
          "typeVersion": 1
        },
        {
          "id": "ca5e69d2-5a03-4b77-9297-fc8a764c548f",
          "name": "gemini model1",
          "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
          "position": [
            -400,
            -736
          ],
          "parameters": {
            "model": "google/gemini-2.5-flash-image-preview",
            "options": {}
          },
          "credentials": {
            "openRouterApi": {
              "id": "",
              "name": "OpenRouter account"
            }
          },
          "typeVersion": 1
        },
        {
          "id": "dba29107-ecc4-4631-984d-54d22654b38d",
          "name": "OpenRouter Model1",
          "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
          "position": [
            -960,
            -944
          ],
          "parameters": {
            "model": "x-ai/grok-4-fast:free",
            "options": {}
          },
          "credentials": {
            "openRouterApi": {
              "id": "",
              "name": "OpenRouter account"
            }
          },
          "typeVersion": 1
        },
        {
          "id": "146212b5-d8c6-4464-9bf5-fa9047b30bd9",
          "name": "Claude1",
          "type": "@n8n/n8n-nodes-langchain.agentTool",
          "position": [
            176,
            -944
          ],
          "parameters": {
            "text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Prompt__User_Message_', ``, 'string') }}",
            "options": {}
          },
          "typeVersion": 2.2
        },
        {
          "id": "ea05aabf-8563-4b06-b554-162b1ac6a00f",
          "name": "grok free1",
          "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
          "position": [
            752,
            -736
          ],
          "parameters": {
            "model": "x-ai/grok-4",
            "options": {}
          },
          "credentials": {
            "openRouterApi": {
              "id": "",
              "name": "OpenRouter account"
            }
          },
          "typeVersion": 1
        },
        {
          "id": "f606d351-4b66-4e57-b8fa-351adf72972a",
          "name": "Sticky Note3",
          "type": "n8n-nodes-base.stickyNote",
          "position": [
            -1008,
            -1280
          ],
          "parameters": {
            "color": 3,
            "width": 2016,
            "height": 288,
            "content": "Messaging"
          },
          "typeVersion": 1
        },
        {
          "id": "b34c3bf4-11b8-4d6b-883d-5dc268d969d7",
          "name": "grok fast model1",
          "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
          "position": [
            -112,
            -736
          ],
          "parameters": {
            "model": "x-ai/grok-4-fast",
            "options": {}
          },
          "credentials": {
            "openRouterApi": {
              "id": "",
              "name": "OpenRouter account"
            }
          },
          "typeVersion": 1
        },
        {
          "id": "4f9904ee-3f63-4139-a28e-933bbf80a55c",
          "name": "Perplexity1",
          "type": "@n8n/n8n-nodes-langchain.agentTool",
          "position": [
            464,
            -944
          ],
          "parameters": {
            "text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Prompt__User_Message_', ``, 'string') }}",
            "options": {}
          },
          "typeVersion": 2.2
        },
        {
          "id": "f90235e1-8f66-444f-b622-71d53ef91db3",
          "name": "Sonar1",
          "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
          "position": [
            464,
            -736
          ],
          "parameters": {
            "model": "perplexity/sonar",
            "options": {}
          },
          "credentials": {
            "openRouterApi": {
              "id": "",
              "name": "OpenRouter account"
            }
          },
          "typeVersion": 1
        },
        {
          "id": "e7a6a3e7-e0f4-41d3-ad45-3ad3f3923280",
          "name": "Free1",
          "type": "@n8n/n8n-nodes-langchain.agentTool",
          "position": [
            752,
            -944
          ],
          "parameters": {
            "text": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Prompt__User_Message_', ``, 'string') }}",
            "options": {}
          },
          "typeVersion": 2.2
        },
        {
          "id": "0cef96b6-11e9-4285-90d2-1c361f828678",
          "name": "Simple Memory8",
          "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
          "position": [
            336,
            -736
          ],
          "parameters": {
            "sessionKey": "={{ $('Telegram Trigger1').item.json.message.text }}",
            "sessionIdType": "customKey"
          },
          "typeVersion": 1.3
        },
        {
          "id": "2f685fd4-ed0f-4fe8-8235-c21a90f917e0",
          "name": "Simple Memory9",
          "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
          "position": [
            48,
            -736
          ],
          "parameters": {
            "sessionKey": "={{ $('Telegram Trigger1').item.json.message.text }}",
            "sessionIdType": "customKey"
          },
          "typeVersion": 1.3
        },
        {
          "id": "bd08708a-e9d4-4e8d-9b2b-e0a6c1d40f73",
          "name": "Simple Memory10",
          "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
          "position": [
            -272,
            -736
          ],
          "parameters": {
            "sessionKey": "={{ $('Telegram Trigger1').item.json.message.text }}",
            "sessionIdType": "customKey"
          },
          "typeVersion": 1.3
        },
        {
          "id": "afc2b3f9-1e22-4a0b-9e14-3d643cfd6a27",
          "name": "Simple Memory11",
          "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
          "position": [
            -560,
            -736
          ],
          "parameters": {
            "sessionKey": "={{ $('Telegram Trigger1').item.json.message.text }}",
            "sessionIdType": "customKey"
          },
          "typeVersion": 1.3
        },
        {
          "id": "24aed012-5c18-4fc3-a642-7d3f1e679e14",
          "name": "Simple Memory12",
          "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
          "position": [
            896,
            -736
          ],
          "parameters": {
            "sessionKey": "={{ $('Telegram Trigger1').item.json.message.text }}",
            "sessionIdType": "customKey"
          },
          "typeVersion": 1.3
        },
        {
          "id": "541f753f-1086-48d2-9792-673d1b934042",
          "name": "Simple Memory13",
          "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
          "position": [
            624,
            -736
          ],
          "parameters": {
            "sessionKey": "={{ $('Telegram Trigger1').item.json.message.text }}",
            "sessionIdType": "customKey"
          },
          "typeVersion": 1.3
        }
      ],
      "pinData": {},
      "connections": {
        "Free1": {
          "ai_tool": [
            [
              {
                "node": "AI Agent1",
                "type": "ai_tool",
                "index": 0
              }
            ]
          ]
        },
        "Grok1": {
          "ai_tool": [
            [
              {
                "node": "AI Agent1",
                "type": "ai_tool",
                "index": 0
              }
            ]
          ]
        },
        "Sonar1": {
          "ai_languageModel": [
            [
              {
                "node": "Perplexity1",
                "type": "ai_languageModel",
                "index": 0
              }
            ]
          ]
        },
        "Claude1": {
          "ai_tool": [
            [
              {
                "node": "AI Agent1",
                "type": "ai_tool",
                "index": 0
              }
            ]
          ]
        },
        "Gemini1": {
          "ai_tool": [
            [
              {
                "node": "AI Agent1",
                "type": "ai_tool",
                "index": 0
              }
            ]
          ]
        },
        "ChatGPT1": {
          "ai_tool": [
            [
              {
                "node": "AI Agent1",
                "type": "ai_tool",
                "index": 0
              }
            ]
          ]
        },
        "AI Agent1": {
          "main": [
            [
              {
                "node": "Process Base64",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "gpt model1": {
          "ai_languageModel": [
            [
              {
                "node": "ChatGPT1",
                "type": "ai_languageModel",
                "index": 0
              }
            ]
          ]
        },
        "grok free1": {
          "ai_languageModel": [
            [
              {
                "node": "Free1",
                "type": "ai_languageModel",
                "index": 0
              }
            ]
          ]
        },
        "Perplexity1": {
          "ai_tool": [
            [
              {
                "node": "AI Agent1",
                "type": "ai_tool",
                "index": 0
              }
            ]
          ]
        },
        "claude model1": {
          "ai_languageModel": [
            [
              {
                "node": "Claude1",
                "type": "ai_languageModel",
                "index": 0
              }
            ]
          ]
        },
        "gemini model1": {
          "ai_languageModel": [
            [
              {
                "node": "Gemini1",
                "type": "ai_languageModel",
                "index": 0
              }
            ]
          ]
        },
        "Process Base64": {
          "main": [
            [
              {
                "node": "Convert to File",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Simple Memory7": {
          "ai_memory": [
            [
              {
                "node": "AI Agent1",
                "type": "ai_memory",
                "index": 0
              }
            ]
          ]
        },
        "Simple Memory8": {
          "ai_memory": [
            [
              {
                "node": "Claude1",
                "type": "ai_memory",
                "index": 0
              }
            ]
          ]
        },
        "Simple Memory9": {
          "ai_memory": [
            [
              {
                "node": "Grok1",
                "type": "ai_memory",
                "index": 0
              }
            ]
          ]
        },
        "Convert to File": {
          "main": [
            [
              {
                "node": "Send Photo to Telegram",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Simple Memory10": {
          "ai_memory": [
            [
              {
                "node": "Gemini1",
                "type": "ai_memory",
                "index": 0
              }
            ]
          ]
        },
        "Simple Memory11": {
          "ai_memory": [
            [
              {
                "node": "ChatGPT1",
                "type": "ai_memory",
                "index": 0
              }
            ]
          ]
        },
        "Simple Memory12": {
          "ai_memory": [
            [
              {
                "node": "Free1",
                "type": "ai_memory",
                "index": 0
              }
            ]
          ]
        },
        "Simple Memory13": {
          "ai_memory": [
            [
              {
                "node": "Perplexity1",
                "type": "ai_memory",
                "index": 0
              }
            ]
          ]
        },
        "grok fast model1": {
          "ai_languageModel": [
            [
              {
                "node": "Grok1",
                "type": "ai_languageModel",
                "index": 0
              }
            ]
          ]
        },
        "OpenRouter Model1": {
          "ai_languageModel": [
            [
              {
                "node": "AI Agent1",
                "type": "ai_languageModel",
                "index": 0
              }
            ]
          ]
        },
        "Telegram Trigger1": {
          "main": [
            [
              {
                "node": "AI Agent1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        }
      }
    }