fix: use telegram file_id for exact matching Bunny Storage paths and CDN links

This commit is contained in:
mstfyldz
2026-08-16 18:27:25 +03:00
parent 578961121b
commit 48132c192b
2 changed files with 190 additions and 166 deletions
+94 -83
View File
@@ -8,13 +8,13 @@
],
"additionalFields": {}
},
"id": "13ae8c1e-3cd2-4365-a6b2-8f3301a7f9db",
"id": "ace3e74e-3a67-4918-b080-046b980679fc",
"name": "Telegram Trigger",
"type": "n8n-nodes-base.telegramTrigger",
"typeVersion": 1.1,
"position": [
-304,
320
-464,
384
],
"webhookId": "ede016a9-34a3-4fc8-8725-291bd02403a2",
"credentials": {
@@ -38,7 +38,7 @@
},
"conditions": [
{
"leftValue": "={{ $json.message.voice }}",
"leftValue": "={{ $json.message.voice.file_id }}",
"rightValue": "",
"operator": {
"type": "string",
@@ -104,10 +104,10 @@
"type": "n8n-nodes-base.switch",
"typeVersion": 3.4,
"position": [
-96,
320
-256,
384
],
"id": "baebb5f0-df5f-4b90-98cb-eaf7fc3f3405",
"id": "1f700585-3a40-4bce-b35b-316881232adf",
"name": "Switch"
},
{
@@ -119,10 +119,10 @@
"type": "n8n-nodes-base.telegram",
"typeVersion": 1.2,
"position": [
160,
288
0,
352
],
"id": "b9f0a086-36db-462b-ae75-460b6ae6bf9a",
"id": "f897adad-d5be-4269-a8d3-ff6750c5f207",
"name": "Get a file",
"webhookId": "376048bf-8f95-4841-b048-46bdf3b82dfd",
"credentials": {
@@ -135,14 +135,12 @@
{
"parameters": {
"method": "PUT",
"url": "=https://storage.bunnycdn.net/apexlegal/journal/voice_{{ Date.now() }}.m4a",
"url": "=https://storage.bunnycdn.com/apexlegal/journal/voice_{{ $('Telegram Trigger').item.json.message.voice.file_id }}.m4a",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "AccessKey",
"value": "1cc9536e-7e5c-480d-8c93ac12ec46-357a-4d81"
},
{
"name": "Content-Type",
"value": "application/octet-stream"
@@ -150,17 +148,28 @@
]
},
"sendBody": true,
"specifyBody": "key",
"bodyKey": "data"
"contentType": "binaryData",
"inputDataFieldName": "data",
"options": {}
},
"id": "bunny-upload-voice",
"id": "05766cac-456d-4811-aad7-906efd6c910a",
"name": "Upload Voice to Bunny CDN",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [
380,
288
]
224,
240
],
"credentials": {
"httpBasicAuth": {
"id": "3bekMF2M9Kc5EE8i",
"name": "Unnamed credential"
},
"httpHeaderAuth": {
"id": "otPWoy574X5Ur4Q7",
"name": "bunnycdn"
}
}
},
{
"parameters": {
@@ -172,10 +181,10 @@
"type": "@n8n/n8n-nodes-langchain.openAi",
"typeVersion": 2.1,
"position": [
600,
288
256,
432
],
"id": "5942e900-db59-4a94-a68b-99f1f0480fce",
"id": "12eda10c-6cd0-4be4-93da-7fa51299a091",
"name": "Transcribe a recording",
"credentials": {
"openAiApi": {
@@ -207,13 +216,13 @@
"temperature": 0.7
}
},
"id": "fbecf695-5165-477f-9a1b-2f116572edf5",
"id": "fbfb3922-4588-4d8b-b2cf-a9317ed663e4",
"name": "OpenAI Mood & Curator1",
"type": "@n8n/n8n-nodes-langchain.openAi",
"typeVersion": 1,
"position": [
820,
288
512,
368
],
"credentials": {
"openAiApi": {
@@ -224,15 +233,15 @@
},
{
"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 || `Telegram_Voice_Note_${durSec}s.m4a`;\n \n const nowTs = Date.now();\n audioUrl = `https://cdn.ayrislegal.com/journal/voice_${nowTs}.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 || 'Telegram Ses Kaydı',\n content: $(\"Transcribe a recording\")?.first()?.json?.text || 'Sesli Not',\n marginNotes: aiParsed.marginNotes || ['← Telegram ses kaydı 🎙️'],\n tags: aiParsed.tags || ['telegram', 'voice'],\n likes: 1,\n stampedText: 'VOICE NOTE',\n audioDuration: audioDuration || '01:00',\n audioTitle: audioTitle || 'Telegram_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 || `Telegram_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 || 'Telegram Ses Kaydı',\n content: $(\"Transcribe a recording\")?.first()?.json?.text || 'Sesli Not',\n marginNotes: aiParsed.marginNotes || ['← Telegram ses kaydı 🎙️'],\n tags: aiParsed.tags || ['telegram', 'voice'],\n likes: 1,\n stampedText: 'VOICE NOTE',\n audioDuration: audioDuration || '01:00',\n audioTitle: audioTitle || 'Telegram_Voice_Note.m4a',\n audioUrl: audioUrl\n }\n};\n"
},
"id": "e149107d-0521-4ded-875e-53125a5d406b",
"id": "32fe7f7c-fbae-4f19-8944-b530d4bceb1c",
"name": "Format Journal Payload1",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1040,
288
880,
352
]
},
{
@@ -253,13 +262,13 @@
"jsonBody": "={{ JSON.stringify($json) }}",
"options": {}
},
"id": "34b351a4-ca88-4f0e-978a-69fa42b09856",
"id": "40dbc197-77c5-4233-ab4a-057d0aa7da77",
"name": "HTTP POST to Journal API1",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [
1260,
288
1104,
352
]
},
{
@@ -270,13 +279,13 @@
"parse_mode": "Markdown"
}
},
"id": "feac8b5a-3187-4fe7-a7c4-048490674594",
"id": "f71c2c26-d64f-4140-af95-4db7875d6290",
"name": "Telegram Send Confirmation1",
"type": "n8n-nodes-base.telegram",
"typeVersion": 1.2,
"position": [
1480,
288
1328,
352
],
"webhookId": "656440d2-a136-4926-a700-67a780664c91",
"credentials": {
@@ -295,10 +304,10 @@
"type": "n8n-nodes-base.telegram",
"typeVersion": 1.2,
"position": [
160,
608
0,
672
],
"id": "df183b43-0faf-4682-8071-37ac46b0fe01",
"id": "caf93a90-1b0e-4b2e-9e61-67684133e4d2",
"name": "Get a file1",
"webhookId": "376048bf-8f95-4841-b048-46bdf3b82dfd",
"credentials": {
@@ -311,14 +320,12 @@
{
"parameters": {
"method": "PUT",
"url": "=https://storage.bunnycdn.net/apexlegal/journal/photo_{{ Date.now() }}.jpg",
"url": "=https://storage.bunnycdn.com/apexlegal/journal/photo_{{ $('Telegram Trigger').item.json.message.photo[$('Telegram Trigger').item.json.message.photo.length - 1].file_id }}.jpg",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "AccessKey",
"value": "1cc9536e-7e5c-480d-8c93ac12ec46-357a-4d81"
},
{
"name": "Content-Type",
"value": "application/octet-stream"
@@ -326,17 +333,24 @@
]
},
"sendBody": true,
"specifyBody": "key",
"bodyKey": "data"
"contentType": "binaryData",
"inputDataFieldName": "data",
"options": {}
},
"id": "bunny-upload-photo",
"id": "2bc19925-c13c-4df7-a7d5-756070d8be75",
"name": "Upload Photo to Bunny CDN",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [
380,
608
]
224,
672
],
"credentials": {
"httpHeaderAuth": {
"id": "otPWoy574X5Ur4Q7",
"name": "bunnycdn"
}
}
},
{
"parameters": {
@@ -361,13 +375,13 @@
"temperature": 0.7
}
},
"id": "250514cb-c0f7-47ac-b20e-fd2176e209db",
"id": "7a143f2c-dba3-4267-ad45-b922a0244771",
"name": "OpenAI Mood & Curator2",
"type": "@n8n/n8n-nodes-langchain.openAi",
"typeVersion": 1,
"position": [
600,
608
448,
672
],
"credentials": {
"openAiApi": {
@@ -378,15 +392,15 @@
},
{
"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 nowTs = Date.now();\nconst imageUrl = `https://cdn.ayrislegal.com/journal/photo_${nowTs}.jpg`;\nconst imageCaption = msg.caption || aiParsed.imageCaption || 'Polaroid Anı';\n\nreturn {\n json: {\n id: `post-tg-${nowTs}`,\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`;\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"
},
"id": "4ef91a2e-304b-4454-a195-0025daae383a",
"id": "ea3e4585-66bf-4dbc-b140-5da6e0b15b2d",
"name": "Format Journal Payload2",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
820,
608
672,
672
]
},
{
@@ -407,13 +421,13 @@
"jsonBody": "={{ JSON.stringify($json) }}",
"options": {}
},
"id": "c249c1af-c3ca-4a4f-9540-231e1be109e4",
"id": "8c3341a3-fddd-422d-b3fe-443a95feed00",
"name": "HTTP POST to Journal API2",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [
1040,
608
880,
672
]
},
{
@@ -424,13 +438,13 @@
"parse_mode": "Markdown"
}
},
"id": "8433104f-9bb2-4afd-88e8-cdd9db756d99",
"id": "133f5737-42fb-4c39-b96d-ac599c8046e7",
"name": "Telegram Send Confirmation2",
"type": "n8n-nodes-base.telegram",
"typeVersion": 1.2,
"position": [
1260,
608
1104,
672
],
"webhookId": "656440d2-a136-4926-a700-67a780664c91",
"credentials": {
@@ -463,13 +477,13 @@
"temperature": 0.7
}
},
"id": "bd9bc72e-1873-4b89-b5ea-23b7d4cf6720",
"id": "8373912b-c5e3-403c-ba50-8fde9a181cc4",
"name": "OpenAI Mood & Curator",
"type": "@n8n/n8n-nodes-langchain.openAi",
"typeVersion": 1,
"position": [
160,
-60
0,
0
],
"credentials": {
"openAiApi": {
@@ -482,13 +496,13 @@
"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\nreturn {\n json: {\n id: `post-tg-${Date.now()}`,\n type: aiParsed.type || 'sticky',\n date: dateStr,\n timestamp: timeStr,\n mood: aiParsed.mood || 'spark',\n moodLabel: aiParsed.moodLabel || 'Fikir Patlaması',\n title: aiParsed.title || undefined,\n content: msg.text || '',\n marginNotes: aiParsed.marginNotes || ['← Telegram ile atıldı 📱'],\n tags: aiParsed.tags || ['telegram'],\n likes: 1,\n stampedText: aiParsed.stampedText || 'TELEGRAM'\n }\n};\n"
},
"id": "4dddf013-f5e6-4009-b202-d6b17aac525e",
"id": "3a5d2072-3a5b-4614-9204-380d543889bb",
"name": "Format Journal Payload",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
380,
-60
224,
0
]
},
{
@@ -509,13 +523,13 @@
"jsonBody": "={{ JSON.stringify($json) }}",
"options": {}
},
"id": "265e43cc-8c16-451d-8d79-5bfbf27d8687",
"id": "eab0b4d1-06a0-46b8-a31d-d674c7d001ee",
"name": "HTTP POST to Journal API",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [
600,
-60
448,
0
]
},
{
@@ -526,13 +540,13 @@
"parse_mode": "Markdown"
}
},
"id": "c4afd057-d48f-421d-abd2-ab3a0e56bb02",
"id": "8f693424-c151-40c2-9c38-b327c0ecb5e1",
"name": "Telegram Send Confirmation",
"type": "n8n-nodes-base.telegram",
"typeVersion": 1.2,
"position": [
820,
-60
672,
0
],
"webhookId": "656440d2-a136-4926-a700-67a780664c91",
"credentials": {
@@ -588,13 +602,7 @@
"node": "Upload Voice to Bunny CDN",
"type": "main",
"index": 0
}
]
]
},
"Upload Voice to Bunny CDN": {
"main": [
[
},
{
"node": "Transcribe a recording",
"type": "main",
@@ -603,6 +611,9 @@
]
]
},
"Upload Voice to Bunny CDN": {
"main": []
},
"Transcribe a recording": {
"main": [
[