{
  "name": "My workflow",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "id": "70dedd8a-0833-40aa-a150-a78093131dd0",
      "name": "Build Image URL",
      "type": "n8n-nodes-base.set",
      "position": [
        140,
        420
      ],
      "typeVersion": 3.4
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.image_url || $json.text || $json.message.text }}",
        "options": {
          "systemMessage": "You are a smart assistant who explains images or answers text and voice messages."
        }
      },
      "id": "8339bac5-3219-4bfe-bbea-4da5c259c9e2",
      "name": "AI Agent (LLaMA 3.3 Vision)",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        400,
        180
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').first().json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {}
      },
      "id": "2575bbe8-b782-4a97-a9bb-041210a47a55",
      "name": "Send Response",
      "type": "n8n-nodes-base.telegram",
      "position": [
        740,
        180
      ],
      "typeVersion": 1.2,
      "webhookId": "e90ac720-b598-44b5-8eff-dfc3a1288fe8",
      "credentials": {
        "telegramApi": {
          "id": "mFO8UO7A10zPeoGJ",
          "name": "Telegram account 2"
        }
      }
    },
    {
      "parameters": {
        "url": "=https://api.telegram.org/bot7827300351:AAFdxoEhHcJex7oxwCAlcQEQG-IlVulyjs8/getFile?file_id={{ $json[\"message\"][\"photo\"][\"1\"][\"file_id\"] }}",
        "options": {}
      },
      "id": "b5835a92-679c-437b-adc7-29b2477b91b8",
      "name": "Get Telegram File Path1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -160,
        440
      ],
      "typeVersion": 4.2
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "c10d5ac0-8847-4019-8a73-e2af2212e7bb",
                    "leftValue": "={{ $json.message.text }}",
                    "rightValue": "Text",
                    "operator": {
                      "type": "string",
                      "operation": "notEmpty",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Text"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "ae45a927-68bc-42df-96ee-4b278299d398",
                    "leftValue": "={{ $json.message.photo }}",
                    "rightValue": "Photo",
                    "operator": {
                      "type": "string",
                      "operation": "notEmpty",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Photo"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "104878ac-44c3-4f0f-8ec0-fa73bfb6b36b",
                    "leftValue": "={{ $json.message.voice }}",
                    "rightValue": "Voice",
                    "operator": {
                      "type": "string",
                      "operation": "notEmpty",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Voice"
            }
          ]
        },
        "looseTypeValidation": true,
        "options": {
          "allMatchingOutputs": true
        }
      },
      "id": "62a425bf-0339-4e02-975f-6710b9fa7ee6",
      "name": "Switch: Text, Voice, Image",
      "type": "n8n-nodes-base.switch",
      "position": [
        -380,
        140
      ],
      "typeVersion": 3.2,
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -680,
        200
      ],
      "id": "48ff7b9a-0e9a-4c0f-9991-9cd903603213",
      "name": "Telegram Trigger",
      "webhookId": "f99e853d-1dbc-4eaa-b0fa-3e106d936592",
      "credentials": {
        "telegramApi": {
          "id": "mFO8UO7A10zPeoGJ",
          "name": "Telegram account 2"
        }
      }
    },
    {
      "parameters": {
        "model": "shisa-ai/shisa-v2-llama3.3-70b:free",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "typeVersion": 1,
      "position": [
        420,
        380
      ],
      "id": "2ee8a827-e011-415b-b060-f954f320cc6a",
      "name": "OpenRouter Chat Model",
      "credentials": {
        "openRouterApi": {
          "id": "HD3iQVnKSBUan6ma",
          "name": "OpenRouter account 2"
        }
      }
    },
    {
      "parameters": {
        "url": "=https://api.telegram.org/bot7827300351:AAFdxoEhHcJex7oxwCAlcQEQG-IlVulyjs8/getFile",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "file_id",
              "value": "={{ $json.message.voice.file_id }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -200,
        40
      ],
      "id": "ec8907b4-2dc4-40d0-9b5d-b3e6e81ad407",
      "name": "Get file path",
      "retryOnFail": true,
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "url": "=https://api.telegram.org/file/bot7911937629:AAGgD2aUq_Cxu_s8ECOI8b9_MnPKzHSfh0w/{{ $node[\"Get file path\"].json[\"result\"][\"file_path\"] }}",
        "options": {
          "response": {
            "response": {
              "neverError": true,
              "responseFormat": "file"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        0,
        0
      ],
      "id": "8a63238d-19bb-4dec-9faa-c8b1b067f881",
      "name": "Download actual voice file",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.wit.ai/speech?v=20240304",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer 7KUM7SKQECLY7G5B5TOSMELZ65UITE26"
            },
            {
              "name": "Content-Type",
              "value": "audio/ogg"
            }
          ]
        },
        "sendBody": true,
        "contentType": "binaryData",
        "inputDataFieldName": "data",
        "options": {
          "response": {
            "response": {
              "responseFormat": "text"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        220,
        0
      ],
      "id": "441529d0-dbd2-4b29-8308-4f19b8040a08",
      "name": "Voice-to-text"
    },
    {
      "parameters": {
        "mode": "raw",
        "jsonOutput": "={\n  \"message\": {\n    \"text\": \"={{ $json.message.text }}\"\n  },\n  \"sessionId\": \"={{ $json.message.chat.id }}\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        20,
        240
      ],
      "id": "dc8977f7-04b3-4fa5-b637-9eecf0fe2acf",
      "name": "Edit Fields"
    }
  ],
  "pinData": {},
  "connections": {
    "Switch: Text, Voice, Image": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Telegram File Path1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get file path",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Switch: Text, Voice, Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent (LLaMA 3.3 Vision)",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get file path": {
      "main": [
        [
          {
            "node": "Download actual voice file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Telegram File Path1": {
      "main": [
        [
          {
            "node": "Build Image URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Image URL": {
      "main": [
        [
          {
            "node": "AI Agent (LLaMA 3.3 Vision)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download actual voice file": {
      "main": [
        [
          {
            "node": "Voice-to-text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Voice-to-text": {
      "main": [
        [
          {
            "node": "AI Agent (LLaMA 3.3 Vision)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent (LLaMA 3.3 Vision)": {
      "main": [
        [
          {
            "node": "Send Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent (LLaMA 3.3 Vision)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "4b0bb008-41a2-41d7-9872-eadc9b4a8a71",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "c62c3bf3e63dc537e21f997fc83e8ee2b3e0ac853f006e402926886a2eb4f670"
  },
  "id": "4h5QMqzEcLMsqRjp",
  "tags": []
}