{
  "name": "mstfyldz Journal - Full Telegram & AI Automation",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ]
      },
      "id": "node-telegram-trigger",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.1,
      "position": [
        100,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.message.from.id }}",
              "operation": "equal",
              "value2": 123456789
            }
          ]
        }
      },
      "id": "node-auth-check",
      "name": "Security Check (Chat ID)",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        320,
        300
      ]
    },
    {
      "parameters": {
        "model": "gpt-4o-mini",
        "options": {
          "temperature": 0.7
        },
        "prompt": "=Sen Mustafa Yıldız'ın (mstfyldz) kişisel dijital günlüğünün AI yayın editörüsün. Telegram'dan gelen bu içeriği analiz et ve SADECE geçerli bir JSON nesnesi döndür.\n\nGelen Metin: \"{{ $json.message.text || $json.message.caption || '' }}\"\n\nKurallar:\n- mood: 'spark' | 'focus' | 'night' | 'calm' | 'visual'\n- moodLabel: 'Fikir Patlaması' | 'Aşırı Odak & Kaos' | 'Gece Melankolisi' | 'Sakin & Karalama' | 'Polaroid & Kırıntılar'\n- type: 'sticky' | 'notebook' | 'code' | 'polaroid' | 'audio'\n- stampedText: 'ONAYLANDI' | 'COMPILED' | 'DOĞRU TESPİT' | 'SUÇLU' | 'KARALAMA'\n- marginNotes: [ \"← samimi el yazısı kenar notu\" ]\n- tags: [ \"etiket1\", \"etiket2\" ]\n- title: \"Kısa ilgi çekici başlık (varsa metin yoksa null)\"\n\nBeklenen Çıktı Örneği:\n{\n  \"type\": \"sticky\",\n  \"mood\": \"spark\",\n  \"moodLabel\": \"Fikir Patlaması\",\n  \"title\": \"Sadelik Üzerine\",\n  \"stampedText\": \"ONAYLANDI\",\n  \"marginNotes\": [\"← tam olarak bu!\"],\n  \"tags\": [\"felsefe\", \"yazılım\"]\n}"
      },
      "id": "node-openai-curator",
      "name": "OpenAI Mood & Curator",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1,
      "position": [
        560,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const msg = $(\"Telegram Trigger\").first().json.message;\nlet aiParsed = {};\ntry {\n  const rawText = $input.first().json.message?.content || $input.first().json.text || '{}';\n  aiParsed = JSON.parse(rawText.replace(/```json|```/g, '').trim());\n} catch (e) {\n  aiParsed = {};\n}\n\n// Ses Kaydı (Voice / Audio) Tespiti ve Süre Hesabı\nconst audioObj = msg?.voice || msg?.audio;\nlet audioDuration = undefined;\nlet audioTitle = undefined;\nlet audioUrl = undefined;\n\nif (audioObj) {\n  const durSec = audioObj.duration || 0;\n  const mins = Math.floor(durSec / 60).toString().padStart(2, '0');\n  const secs = (durSec % 60).toString().padStart(2, '0');\n  audioDuration = `${mins}:${secs}`;\n  audioTitle = msg.audio?.file_name || `Telegram_Voice_Note_${durSec}s.m4a`;\n  \n  // Telegram Get File düğümünden gelen dosya yolu (Varsa)\n  const filePath = $(\"Telegram Get File\")?.first()?.json?.result?.file_path;\n  if (filePath) {\n    audioUrl = `https://api.telegram.org/file/bot[YOUR_BOT_TOKEN]/${filePath}`;\n  }\n}\n\nconst now = new Date();\nconst dateStr = now.toLocaleDateString('tr-TR', { day: '2-digit', month: 'short', year: 'numeric' }).toUpperCase();\nconst timeStr = now.toLocaleTimeString('tr-TR', { hour: '2-digit', minute: '2-digit' });\n\nreturn {\n  json: {\n    id: `post-tg-${Date.now()}`,\n    type: audioObj ? 'audio' : (aiParsed.type || 'sticky'),\n    date: dateStr,\n    timestamp: timeStr,\n    mood: aiParsed.mood || 'spark',\n    moodLabel: aiParsed.moodLabel || 'Fikir Patlaması',\n    title: aiParsed.title || (audioObj ? 'Telegram Ses Kaydı' : undefined),\n    content: $(\"OpenAI Whisper\")?.first()?.json?.text || msg.text || msg.caption || 'Sesli Not',\n    marginNotes: aiParsed.marginNotes || ['← Telegram ses kaydı 🎙️'],\n    tags: aiParsed.tags || ['telegram', 'voice'],\n    likes: 1,\n    stampedText: aiParsed.stampedText || 'VOICE NOTE',\n    audioDuration: audioDuration || aiParsed.audioDuration,\n    audioTitle: audioTitle || aiParsed.audioTitle,\n    audioUrl: audioUrl || aiParsed.audioUrl\n  }\n};\n"
      },
      "id": "node-code-formatter",
      "name": "Format Journal Payload",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        780,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://mstfyldz.com/api/posts",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}"
      },
      "id": "node-http-post",
      "name": "HTTP POST to Journal API",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        1000,
        300
      ]
    },
    {
      "parameters": {
        "chatId": "={{ $(\"Telegram Trigger\").first().json.message.chat.id }}",
        "text": "=✅ *Not Deftere Karalandı!*\n\n📖 *Format:* {{ $(\"Format Journal Payload\").first().json.type }}\n💡 *Mood:* {{ $(\"Format Journal Payload\").first().json.moodLabel }}\n📌 *Başlık:* {{ $(\"Format Journal Payload\").first().json.title || 'Başlıksız Not' }}\n🏷️ *Etiketler:* #{{ $(\"Format Journal Payload\").first().json.tags.join(' #') }}\n\n✍️ _\"{{ $(\"Format Journal Payload\").first().json.marginNotes[0] || '' }}\"_",
        "additionalFields": {
          "parse_mode": "Markdown"
        }
      },
      "id": "node-telegram-reply",
      "name": "Telegram Send Confirmation",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1220,
        300
      ]
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Security Check (Chat ID)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Security Check (Chat ID)": {
      "main": [
        [
          {
            "node": "OpenAI Mood & Curator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Mood & Curator": {
      "main": [
        [
          {
            "node": "Format Journal Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Journal Payload": {
      "main": [
        [
          {
            "node": "HTTP POST to Journal API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP POST to Journal API": {
      "main": [
        [
          {
            "node": "Telegram Send Confirmation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
