feat: smart title & content parsing for telegram photo captions in n8n workflow

This commit is contained in:
mstfyldz
2026-08-16 18:35:58 +03:00
parent 42e675fec2
commit c63c03b42c
2 changed files with 6 additions and 6 deletions
@@ -233,7 +233,7 @@
},
{
"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\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 || `Voice_Note_${durSec}s.m4a`;\n \n // Telegram voice file_id ile Bunny CDN kalıcı linki 1:1 tam eşleşir!\n const voiceFileId = audioObj.file_id;\n audioUrl = `https://cdn.ayrislegal.com/journal/voice_${voiceFileId}.m4a`;\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: 'audio',\n date: dateStr,\n timestamp: timeStr,\n mood: aiParsed.mood || 'spark',\n moodLabel: aiParsed.moodLabel || 'Fikir Patlaması',\n title: aiParsed.title || 'Voice Note',\n content: $(\"Transcribe a recording\")?.first()?.json?.text || 'Sesli Not',\n marginNotes: aiParsed.marginNotes || ['← Voice note 🎙️'],\n tags: aiParsed.tags || ['telegram', 'voice'],\n likes: 1,\n stampedText: 'VOICE NOTE',\n audioDuration: audioDuration || '01:00',\n audioTitle: audioTitle || 'Voice_Note.m4a',\n audioUrl: audioUrl\n }\n};\n"
"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\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 || `Voice_Note_${durSec}s.m4a`;\n \n const voiceFileId = audioObj.file_id;\n audioUrl = `https://cdn.ayrislegal.com/journal/voice_${voiceFileId}.m4a`;\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: 'audio',\n date: dateStr,\n timestamp: timeStr,\n mood: aiParsed.mood || 'spark',\n moodLabel: aiParsed.moodLabel || 'Fikir Patlaması',\n title: aiParsed.title || 'Voice Note',\n content: $(\"Transcribe a recording\")?.first()?.json?.text || 'Sesli Not',\n marginNotes: aiParsed.marginNotes || ['← Voice note 🎙️'],\n tags: aiParsed.tags || ['telegram', 'voice'],\n likes: 1,\n stampedText: 'VOICE NOTE',\n audioDuration: audioDuration || '01:00',\n audioTitle: audioTitle || 'Voice_Note.m4a',\n audioUrl: audioUrl\n }\n};\n"
},
"id": "32fe7f7c-fbae-4f19-8944-b530d4bceb1c",
"name": "Format Journal Payload1",
@@ -363,7 +363,7 @@
"messages": {
"values": [
{
"content": "Sen Mustafa Yıldız'ın (mstfyldz) kişisel dijital günlüğünün yapay zeka yayın editörüsün.\nGörevin, Telegram'dan gönderilen fotoğraf yazısını analiz ederek biçimlendirmek.\n\nSADECE aşağıdaki JSON formatında yanıt ver:\n{\n \"type\": \"polaroid\",\n \"mood\": \"visual\",\n \"moodLabel\": \"Polaroid & Kırıntılar\",\n \"title\": \"Polaroid Anı\",\n \"imageCaption\": \"Fotoğraf açıklaması\",\n \"stampedText\": \"POLAROID\",\n \"marginNotes\": [\"← samimi el yazısı kenar notu\"],\n \"tags\": [\"fotoğraf\", \"polaroid\"]\n}\n",
"content": "Sen Mustafa Yıldız'ın (mstfyldz) kişisel dijital günlüğünün yapay zeka yayın editörüsün.\nGörevin, Telegram'dan gönderilen fotoğraf yazısını analiz ederek biçimlendirmek.\n\nEğer metinde ayrı bir başlık verilmemişse, fotoğrafa ve açıklamaya uygun kısa, yaratıcı 2-4 kelimelik şık bir başlık üret.\n\nSADECE aşağıdaki JSON formatında yanıt ver:\n{\n \"type\": \"polaroid\",\n \"mood\": \"visual\",\n \"moodLabel\": \"Polaroid & Kırıntılar\",\n \"title\": \"Fotoğrafa uygun yaratıcı kısa başlık\",\n \"stampedText\": \"POLAROID\",\n \"marginNotes\": [\"← samimi el yazısı kenar notu\"],\n \"tags\": [\"fotoğraf\", \"polaroid\"]\n}\n",
"role": "system"
},
{
@@ -392,7 +392,7 @@
},
{
"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\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\nconst photoObj = msg?.photo ? msg.photo[msg.photo.length - 1] : null;\nconst photoFileId = photoObj?.file_id;\nconst imageUrl = photoFileId \n ? `https://cdn.ayrislegal.com/journal/photo_${photoFileId}.jpg` \n : `https://cdn.ayrislegal.com/journal/photo_${Date.now()}.jpg`;\nconst imageCaption = msg.caption || aiParsed.imageCaption || 'Polaroid Anı';\n\nreturn {\n json: {\n id: `post-tg-${Date.now()}`,\n type: 'polaroid',\n date: dateStr,\n timestamp: timeStr,\n mood: 'visual',\n moodLabel: 'Polaroid & Kırıntılar',\n title: aiParsed.title || imageCaption,\n content: msg.caption || 'Telegram fotoğrafı',\n marginNotes: aiParsed.marginNotes || ['← Telegram fotoğrafı 📸'],\n tags: aiParsed.tags || ['telegram', 'polaroid'],\n likes: 1,\n stampedText: 'POLAROID',\n imageUrl: imageUrl,\n imageCaption: imageCaption\n }\n};\n"
"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\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\nconst photoObj = msg?.photo ? msg.photo[msg.photo.length - 1] : null;\nconst photoFileId = photoObj?.file_id;\nconst imageUrl = photoFileId \n ? `https://cdn.ayrislegal.com/journal/photo_${photoFileId}.jpg` \n : `https://cdn.ayrislegal.com/journal/photo_${Date.now()}.jpg`;\n\nconst rawCaption = (msg.caption || '').trim();\nlet title = undefined;\nlet content = rawCaption || 'Fotoğraf Anısı';\n\nif (rawCaption.includes('\\n')) {\n // Telegram'da ilk satır BAŞLIK, alt satırlar İÇERİK\n const lines = rawCaption.split('\\n');\n title = lines[0].trim();\n content = lines.slice(1).join('\\n').trim() || lines[0].trim();\n} else {\n // Tek satırsa başlığı Yapay Zeka üretsin, metin içerik kalsın\n title = aiParsed.title || rawCaption || 'Polaroid Anı';\n}\n\nreturn {\n json: {\n id: `post-tg-${Date.now()}`,\n type: 'polaroid',\n date: dateStr,\n timestamp: timeStr,\n mood: 'visual',\n moodLabel: 'Polaroid & Kırıntılar',\n title: title,\n content: content,\n marginNotes: aiParsed.marginNotes || ['← Telegram fotoğrafı 📸'],\n tags: aiParsed.tags || ['telegram', 'polaroid'],\n likes: 1,\n stampedText: 'POLAROID',\n imageUrl: imageUrl,\n imageCaption: rawCaption || title\n }\n};\n"
},
"id": "ea3e4585-66bf-4dbc-b140-5da6e0b15b2d",
"name": "Format Journal Payload2",
+3 -3
View File
@@ -233,7 +233,7 @@
},
{
"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\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 || `Voice_Note_${durSec}s.m4a`;\n \n // Telegram voice file_id ile Bunny CDN kalıcı linki 1:1 tam eşleşir!\n const voiceFileId = audioObj.file_id;\n audioUrl = `https://cdn.ayrislegal.com/journal/voice_${voiceFileId}.m4a`;\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: 'audio',\n date: dateStr,\n timestamp: timeStr,\n mood: aiParsed.mood || 'spark',\n moodLabel: aiParsed.moodLabel || 'Fikir Patlaması',\n title: aiParsed.title || 'Voice Note',\n content: $(\"Transcribe a recording\")?.first()?.json?.text || 'Sesli Not',\n marginNotes: aiParsed.marginNotes || ['← Voice note 🎙️'],\n tags: aiParsed.tags || ['telegram', 'voice'],\n likes: 1,\n stampedText: 'VOICE NOTE',\n audioDuration: audioDuration || '01:00',\n audioTitle: audioTitle || 'Voice_Note.m4a',\n audioUrl: audioUrl\n }\n};\n"
"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\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 || `Voice_Note_${durSec}s.m4a`;\n \n const voiceFileId = audioObj.file_id;\n audioUrl = `https://cdn.ayrislegal.com/journal/voice_${voiceFileId}.m4a`;\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: 'audio',\n date: dateStr,\n timestamp: timeStr,\n mood: aiParsed.mood || 'spark',\n moodLabel: aiParsed.moodLabel || 'Fikir Patlaması',\n title: aiParsed.title || 'Voice Note',\n content: $(\"Transcribe a recording\")?.first()?.json?.text || 'Sesli Not',\n marginNotes: aiParsed.marginNotes || ['← Voice note 🎙️'],\n tags: aiParsed.tags || ['telegram', 'voice'],\n likes: 1,\n stampedText: 'VOICE NOTE',\n audioDuration: audioDuration || '01:00',\n audioTitle: audioTitle || 'Voice_Note.m4a',\n audioUrl: audioUrl\n }\n};\n"
},
"id": "32fe7f7c-fbae-4f19-8944-b530d4bceb1c",
"name": "Format Journal Payload1",
@@ -363,7 +363,7 @@
"messages": {
"values": [
{
"content": "Sen Mustafa Yıldız'ın (mstfyldz) kişisel dijital günlüğünün yapay zeka yayın editörüsün.\nGörevin, Telegram'dan gönderilen fotoğraf yazısını analiz ederek biçimlendirmek.\n\nSADECE aşağıdaki JSON formatında yanıt ver:\n{\n \"type\": \"polaroid\",\n \"mood\": \"visual\",\n \"moodLabel\": \"Polaroid & Kırıntılar\",\n \"title\": \"Polaroid Anı\",\n \"imageCaption\": \"Fotoğraf açıklaması\",\n \"stampedText\": \"POLAROID\",\n \"marginNotes\": [\"← samimi el yazısı kenar notu\"],\n \"tags\": [\"fotoğraf\", \"polaroid\"]\n}\n",
"content": "Sen Mustafa Yıldız'ın (mstfyldz) kişisel dijital günlüğünün yapay zeka yayın editörüsün.\nGörevin, Telegram'dan gönderilen fotoğraf yazısını analiz ederek biçimlendirmek.\n\nEğer metinde ayrı bir başlık verilmemişse, fotoğrafa ve açıklamaya uygun kısa, yaratıcı 2-4 kelimelik şık bir başlık üret.\n\nSADECE aşağıdaki JSON formatında yanıt ver:\n{\n \"type\": \"polaroid\",\n \"mood\": \"visual\",\n \"moodLabel\": \"Polaroid & Kırıntılar\",\n \"title\": \"Fotoğrafa uygun yaratıcı kısa başlık\",\n \"stampedText\": \"POLAROID\",\n \"marginNotes\": [\"← samimi el yazısı kenar notu\"],\n \"tags\": [\"fotoğraf\", \"polaroid\"]\n}\n",
"role": "system"
},
{
@@ -392,7 +392,7 @@
},
{
"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\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\nconst photoObj = msg?.photo ? msg.photo[msg.photo.length - 1] : null;\nconst photoFileId = photoObj?.file_id;\nconst imageUrl = photoFileId \n ? `https://cdn.ayrislegal.com/journal/photo_${photoFileId}.jpg` \n : `https://cdn.ayrislegal.com/journal/photo_${Date.now()}.jpg`;\nconst imageCaption = msg.caption || aiParsed.imageCaption || 'Polaroid Anı';\n\nreturn {\n json: {\n id: `post-tg-${Date.now()}`,\n type: 'polaroid',\n date: dateStr,\n timestamp: timeStr,\n mood: 'visual',\n moodLabel: 'Polaroid & Kırıntılar',\n title: aiParsed.title || imageCaption,\n content: msg.caption || 'Telegram fotoğrafı',\n marginNotes: aiParsed.marginNotes || ['← Telegram fotoğrafı 📸'],\n tags: aiParsed.tags || ['telegram', 'polaroid'],\n likes: 1,\n stampedText: 'POLAROID',\n imageUrl: imageUrl,\n imageCaption: imageCaption\n }\n};\n"
"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\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\nconst photoObj = msg?.photo ? msg.photo[msg.photo.length - 1] : null;\nconst photoFileId = photoObj?.file_id;\nconst imageUrl = photoFileId \n ? `https://cdn.ayrislegal.com/journal/photo_${photoFileId}.jpg` \n : `https://cdn.ayrislegal.com/journal/photo_${Date.now()}.jpg`;\n\nconst rawCaption = (msg.caption || '').trim();\nlet title = undefined;\nlet content = rawCaption || 'Fotoğraf Anısı';\n\nif (rawCaption.includes('\\n')) {\n // Telegram'da ilk satır BAŞLIK, alt satırlar İÇERİK\n const lines = rawCaption.split('\\n');\n title = lines[0].trim();\n content = lines.slice(1).join('\\n').trim() || lines[0].trim();\n} else {\n // Tek satırsa başlığı Yapay Zeka üretsin, metin içerik kalsın\n title = aiParsed.title || rawCaption || 'Polaroid Anı';\n}\n\nreturn {\n json: {\n id: `post-tg-${Date.now()}`,\n type: 'polaroid',\n date: dateStr,\n timestamp: timeStr,\n mood: 'visual',\n moodLabel: 'Polaroid & Kırıntılar',\n title: title,\n content: content,\n marginNotes: aiParsed.marginNotes || ['← Telegram fotoğrafı 📸'],\n tags: aiParsed.tags || ['telegram', 'polaroid'],\n likes: 1,\n stampedText: 'POLAROID',\n imageUrl: imageUrl,\n imageCaption: rawCaption || title\n }\n};\n"
},
"id": "ea3e4585-66bf-4dbc-b140-5da6e0b15b2d",
"name": "Format Journal Payload2",