{
  "name": "OmniBrain-n8n (Full Architecture)",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "id": "telegram-trigger-node-id",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1,
      "position": [
        100,
        300
      ],
      "credentials": {
        "telegramBotApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "expression",
        "numberOutputs": 5,
        "output": "={{ $json.message && $json.message.voice ? 0 : ($json.message && $json.message.photo ? 1 : ($json.message && $json.message.document ? 2 : ($json.message && $json.message.text ? 3 : 4))) }}"
      },
      "id": "switch-type-node-id",
      "name": "Switch Type",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        300,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "file_id",
              "value": "={{ $json.message.voice.file_id }}"
            },
            {
              "name": "file_type",
              "value": "voice"
            }
          ]
        }
      },
      "id": "set-voice-info-node-id",
      "name": "Set Voice File Info",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        550,
        80
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "file_id",
              "value": "={{ $json.message.photo[$json.message.photo.length - 1].file_id }}"
            },
            {
              "name": "file_type",
              "value": "photo"
            }
          ]
        }
      },
      "id": "set-photo-info-node-id",
      "name": "Set Photo File Info",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        550,
        190
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "file_id",
              "value": "={{ $json.message.document.file_id }}"
            },
            {
              "name": "file_type",
              "value": "document"
            }
          ]
        }
      },
      "id": "set-doc-info-node-id",
      "name": "Set Doc File Info",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        550,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://api.telegram.org/bot8603419021:AAG9Ju1AoCtBCkKBnKopOYVWLBbqzuJxReU/getFile",
        "sendQuery": true,
        "queryParametersUi": {
          "parameter": [
            {
              "name": "file_id",
              "value": "={{ $json.file_id }}"
            }
          ]
        },
        "options": {}
      },
      "id": "telegram-getfile-node-id",
      "name": "Telegram getFile",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        750,
        190
      ]
    },
    {
      "parameters": {
        "url": "=https://api.telegram.org/file/bot8603419021:AAG9Ju1AoCtBCkKBnKopOYVWLBbqzuJxReU/{{ $json.result.file_path }}",
        "responseFormat": "file",
        "options": {}
      },
      "id": "download-file-node-id",
      "name": "Download File",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        920,
        190
      ]
    },
    {
      "parameters": {
        "rules": {
          "rules": [
            {
              "value1": "={{ $node[\"Telegram getFile\"].input.json.file_type }}",
              "value2": "voice",
              "operation": "equal"
            },
            {
              "value1": "={{ $node[\"Telegram getFile\"].input.json.file_type }}",
              "value2": "photo",
              "operation": "equal"
            },
            {
              "value1": "={{ $node[\"Telegram getFile\"].input.json.file_type }}",
              "value2": "document",
              "operation": "equal"
            }
          ]
        }
      },
      "id": "switch-file-type-node-id",
      "name": "Switch File Type",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        1090,
        190
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.groq.com/openai/v1/audio/transcriptions",
        "sendHeaders": true,
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            }
          ]
        },
        "sendBody": true,
        "bodyContentType": "multipart-form-data",
        "specifyBody": "multipart",
        "multipartBodyFormParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "whisper-large-v3"
            },
            {
              "parameterType": "formBinaryParameter",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {}
      },
      "id": "groq-whisper-node-id",
      "name": "Groq Whisper",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1270,
        80
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=AQ.Ab8RN6KwUYVjmGg0pg_k3kJs8TVaPvfDkXNpe4B9ZHBHrr2UKg",
        "sendBody": true,
        "specifyBody": "json",
        "requestBody": "{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Bu g\u00f6rseli analiz et. \u0130\u00e7inde devre \u015femas\u0131, kod ekran\u0131 veya dok\u00fcman varsa oku, a\u00e7\u0131kla ve teknik detaylar\u0131n\u0131 \u00e7\u0131kar. E\u011fer normal bir g\u00f6rselse ne oldu\u011funu a\u00e7\u0131kla.\"\n        },\n        {\n          \"inlineData\": {\n            \"mimeType\": \"image/jpeg\",\n            \"data\": \"{{ $binary.data.toBase64() }}\"\n          }\n        }\n      ]\n    }\n  ]\n}",
        "options": {}
      },
      "id": "gemini-vision-node-id",
      "name": "Gemini Vision",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1270,
        190
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=AQ.Ab8RN6KwUYVjmGg0pg_k3kJs8TVaPvfDkXNpe4B9ZHBHrr2UKg",
        "sendBody": true,
        "specifyBody": "json",
        "requestBody": "{\n  \"contents\": [\n    {\n      \"parts\": [\n        {\n          \"text\": \"Bu dok\u00fcman\u0131 analiz et, i\u00e7indeki \u00f6nemli bilgileri \u00f6zetle ve teknik detaylar\u0131 \u00e7\u0131kar.\"\n        },\n        {\n          \"inlineData\": {\n            \"mimeType\": \"{{ $binary.data.mimeType }}\",\n            \"data\": \"{{ $binary.data.toBase64() }}\"\n          }\n        }\n      ]\n    }\n  ]\n}",
        "options": {}
      },
      "id": "gemini-doc-parser-node-id",
      "name": "Gemini Doc Parser",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1270,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "query",
              "value": "={{ $json.message.text }}"
            },
            {
              "name": "context",
              "value": ""
            },
            {
              "name": "source",
              "value": "text"
            }
          ]
        }
      },
      "id": "format-text-input-node-id",
      "name": "Format Text Input",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        550,
        410
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "query",
              "value": "={{ $json.text }}"
            },
            {
              "name": "context",
              "value": "Ses Kayd\u0131 Transkripti"
            },
            {
              "name": "source",
              "value": "voice"
            }
          ]
        }
      },
      "id": "format-voice-input-node-id",
      "name": "Format Voice Input",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1470,
        80
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "query",
              "value": "G\u00f6rsel Analiz Raporu"
            },
            {
              "name": "context",
              "value": "={{ $json.candidates[0].content.parts[0].text }}"
            },
            {
              "name": "source",
              "value": "photo"
            }
          ]
        }
      },
      "id": "format-photo-input-node-id",
      "name": "Format Photo Input",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1470,
        190
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "query",
              "value": "Dok\u00fcman Analiz Raporu"
            },
            {
              "name": "context",
              "value": "={{ $json.candidates[0].content.parts[0].text }}"
            },
            {
              "name": "source",
              "value": "document"
            }
          ]
        }
      },
      "id": "format-doc-input-node-id",
      "name": "Format Doc Input",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1470,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.groq.com/openai/v1/chat/completions",
        "sendHeaders": true,
        "headerParametersUi": {
          "parameter": [
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "requestBody": "{\n  \"model\": \"llama-3.3-70b-versatile\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"Sen OmniBrain sisteminin ana beyin LLM modelisin. G\u00f6revin, Telegram'dan gelen ve \u00f6n-i\u015flemeden ge\u00e7mi\u015f girdileri analiz etmektir. Yan\u0131t\u0131n\u0131 mutlaka \u015fu JSON format\u0131nda d\u00f6nmelisin: { \\\"response\\\": \\\"Kullan\u0131c\u0131ya Telegram \u00fczerinden g\u00f6nderilecek T\u00fcrk\u00e7e, anla\u015f\u0131l\u0131r, teknik olarak zengin ve nazik yan\u0131t. Markdown format\u0131nda yaz\u0131labilir.\\\", \\\"save_to_db\\\": true veya false (E\u011fer girdi bir not, yap\u0131lacak i\u015f/task, kod par\u00e7as\u0131, devre \u015femas\u0131, \u00f6nemli fikir veya hat\u0131rlatma i\u00e7eriyorsa true, aksi takdirde false yap), \\\"db_data\\\": { \\\"title\\\": \\\"Notun k\u0131sa ba\u015fl\u0131\u011f\u0131 (max 5-6 kelime)\\\", \\\"content\\\": \\\"Notun veya g\u00f6revin detayl\u0131 a\u00e7\u0131klamas\u0131\\\", \\\"category\\\": \\\"Task (G\u00f6rev) veya Idea (Fikir) veya Technical (Teknik) veya General (Genel)\\\" } }. Ba\u015fka hi\u00e7bir \u015fey yazma, sadece bu JSON nesnesini d\u00f6n.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Girdi Kayna\u011f\u0131: {{ $json.source }}\\nBa\u011flam: {{ $json.context }}\\nSorgu/\u0130\u00e7erik: {{ $json.query }}\"\n    }\n  ],\n  \"response_format\": {\n    \"type\": \"json_object\"\n  }\n}",
        "options": {}
      },
      "id": "groq-llama-node-id",
      "name": "Groq Llama 3.3",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        1690,
        240
      ]
    },
    {
      "parameters": {
        "mode": "runOnce",
        "jsCode": "const input = items[0].json;\nlet parsedContent = {};\ntry {\n  parsedContent = JSON.parse(input.choices[0].message.content);\n} catch (e) {\n  parsedContent = {\n    response: \"AI yan\u0131t\u0131 i\u015flenirken hata olu\u015ftu. Ham yan\u0131t: \" + input.choices[0].message.content,\n    save_to_db: false,\n    db_data: { title: \"Hata\", content: input.choices[0].message.content, category: \"General\" }\n  };\n}\n\nconst telegramMessage = $node[\"Telegram Trigger\"].json.message;\nconst chatId = telegramMessage.chat.id;\nconst messageId = telegramMessage.message_id;\n\nreturn [{ \n  json: {\n    chat_id: chatId,\n    message_id: messageId,\n    response: parsedContent.response,\n    save_to_db: parsedContent.save_to_db,\n    db_data: parsedContent.db_data,\n    raw_ai: parsedContent\n  }\n}];"
      },
      "id": "parse-ai-response-node-id",
      "name": "Parse AI Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1870,
        240
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.save_to_db }}",
              "value2": true
            }
          ]
        }
      },
      "id": "should-save-db-node-id",
      "name": "Should Save to DB?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        2050,
        240
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "value": "YOUR_NOTION_DATABASE_ID",
          "mode": "id"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Title",
              "title": "={{ $json.db_data.title }}"
            },
            {
              "key": "Content",
              "richText": [
                {
                  "text": {
                    "content": "={{ $json.db_data.content }}"
                  }
                }
              ]
            },
            {
              "key": "Category",
              "select": "={{ $json.db_data.category }}"
            }
          ]
        }
      },
      "id": "save-to-notion-node-id",
      "name": "Save to Notion",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2,
      "position": [
        2250,
        140
      ],
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "response",
              "value": "={{ $node[\"Parse AI Response\"].json.response }}\\n\\n\u2705 *Notion'a Kaydedildi!*\\n\ud83d\udccc *Ba\u015fl\u0131k:* {{ $node[\"Parse AI Response\"].json.db_data.title }}\\n\ud83d\uddc2\ufe0f *Kategori:* {{ $node[\"Parse AI Response\"].json.db_data.category }}"
            },
            {
              "name": "chat_id",
              "value": "={{ $node[\"Parse AI Response\"].json.chat_id }}"
            },
            {
              "name": "message_id",
              "value": "={{ $node[\"Parse AI Response\"].json.message_id }}"
            }
          ]
        }
      },
      "id": "append-success-msg-node-id",
      "name": "Append Success Message",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        2430,
        140
      ]
    },
    {
      "parameters": {
        "chatId": "={{ $json.chat_id }}",
        "text": "={{ $json.response }}",
        "additionalFields": {
          "replyToMessageId": "={{ $json.message_id }}",
          "parse_mode": "Markdown"
        }
      },
      "id": "telegram-send-node-id",
      "name": "Telegram Send Message",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        2650,
        240
      ],
      "credentials": {
        "telegramBotApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "chat_id",
              "value": "={{ $node[\"Telegram Trigger\"].json.message.chat.id }}"
            },
            {
              "name": "message_id",
              "value": "={{ $node[\"Telegram Trigger\"].json.message.message_id }}"
            },
            {
              "name": "response",
              "value": "\u26a0\ufe0f Desteklenmeyen bir mesaj t\u00fcr\u00fc g\u00f6nderdiniz. OmniBrain asistan\u0131 \u015fu an i\u00e7in sadece ses kayd\u0131, foto\u011fraf, dok\u00fcman ve d\u00fcz metin girdilerini desteklemektedir."
            }
          ]
        }
      },
      "id": "fallback-handler-node-id",
      "name": "Fallback Handler",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        550,
        520
      ]
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Switch Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch Type": {
      "main": [
        [
          {
            "node": "Set Voice File Info",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Photo File Info",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set Doc File Info",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Format Text Input",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fallback Handler",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Voice File Info": {
      "main": [
        [
          {
            "node": "Telegram getFile",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Photo File Info": {
      "main": [
        [
          {
            "node": "Telegram getFile",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Doc File Info": {
      "main": [
        [
          {
            "node": "Telegram getFile",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram getFile": {
      "main": [
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File": {
      "main": [
        [
          {
            "node": "Switch File Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch File Type": {
      "main": [
        [
          {
            "node": "Groq Whisper",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Gemini Vision",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Gemini Doc Parser",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Whisper": {
      "main": [
        [
          {
            "node": "Format Voice Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Vision": {
      "main": [
        [
          {
            "node": "Format Photo Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Doc Parser": {
      "main": [
        [
          {
            "node": "Format Doc Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Text Input": {
      "main": [
        [
          {
            "node": "Groq Llama 3.3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Voice Input": {
      "main": [
        [
          {
            "node": "Groq Llama 3.3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Photo Input": {
      "main": [
        [
          {
            "node": "Groq Llama 3.3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Doc Input": {
      "main": [
        [
          {
            "node": "Groq Llama 3.3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Llama 3.3": {
      "main": [
        [
          {
            "node": "Parse AI Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI Response": {
      "main": [
        [
          {
            "node": "Should Save to DB?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Should Save to DB?": {
      "main": [
        [
          {
            "node": "Save to Notion",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Telegram Send Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Notion": {
      "main": [
        [
          {
            "node": "Append Success Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append Success Message": {
      "main": [
        [
          {
            "node": "Telegram Send Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fallback Handler": {
      "main": [
        [
          {
            "node": "Telegram Send Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {},
  "staticData": null,
  "meta": {
    "templateCredsSetupCompleted": true
  }
}