// N8N WORKFLOW
AI STREAM INTELLIGENCE SYSTEM
Full Douyin livestream analysis pipeline. Receives audio chunks via webhook, transcribes with Google STT Chirp 2 (Mandarin/Cantonese/English), analyzes sentiment/topics/keywords via Gemini, writes structured rows to Google Sheets, and sends highlights to Telegram.
TRIGGER
Webhook (POST /your-webhook-path)
NODES
JSON EXPORT
{
"name": "AI Stream Intelligence System",
"active": true,
"nodes": [
{
"id": "node-001",
"name": "🌐 Webhook Ingest",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [-560, 128],
"parameters": {
"httpMethod": "POST",
"path": "/your-webhook-path",
"options": {}
}
},
{
"id": "node-002",
"name": "⚙️ Config & Router",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [-304, 128],
"parameters": {
"jsCode": "const CONFIG = {\n GCP_PROJECT_ID: 'YOUR_GCP_PROJECT',\n GCS_BUCKET: 'YOUR_BUCKET_NAME',\n GEMINI_API_KEY: 'YOUR_KEY_HERE',\n GEMINI_MODEL: 'gemini-2.5-flash-lite',\n SHEET_ID: 'YOUR_SHEET_ID',\n SHEET_TAB: 'Stream_Analytics',\n TELEGRAM_BOT_TOKEN: 'YOUR_KEY_HERE',\n TELEGRAM_CHAT_ID: 'YOUR_CHAT_ID',\n CHUNK_SECONDS: 30,\n MAX_RETRIES: 3,\n};\nconst input = $input.first().json.body || $input.first().json;\nconst job = {\n config: CONFIG,\n job_id: input.job_id || `job_${Date.now()}`,\n source_type: input.source_type || 'unknown',\n gcs_uri: input.gcs_uri || input.audio_gcs_uri || '',\n language_hint: input.language_hint || 'cmn-Hans-CN',\n chunk_index: input.chunk_index ?? 0,\n streamer: input.streamer || '',\n session_date: input.session_date || new Date().toISOString().slice(0,10),\n sheet_tab_name: input.sheet_tab_name || input.session_date || new Date().toISOString().slice(0,10),\n};\nreturn [{ json: job }];"
}
},
{
"id": "node-003",
"name": "🔊 Google STT v2 (Chirp 2)",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [0, 0],
"parameters": {
"method": "POST",
"url": "=https://europe-west4-speech.googleapis.com/v2/projects/YOUR_GCP_PROJECT/locations/europe-west4/recognizers/_:recognize",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "googleApi",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"config\": {\n \"autoDecodingConfig\": {},\n \"languageCodes\": [\"cmn-Hans-CN\", \"yue-Hant-HK\", \"en-US\"],\n \"model\": \"chirp_2\"\n },\n \"uri\": \"{{ $json.gcs_uri }}\"\n}",
"options": { "timeout": 120000 }
},
"credentials": {
"googleApi": { "id": "YOUR_CRED_ID", "name": "Google Cloud SA" }
}
},
{
"id": "node-004",
"name": "📝 STT Normalizer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [-16, 464],
"parameters": {
"jsCode": "const item = $input.first().json;\nlet raw_transcript = '';\nif (item.results && Array.isArray(item.results)) {\n for (const r of item.results) {\n raw_transcript += (r.alternatives?.[0]?.transcript || '') + ' ';\n }\n}\nreturn [{ json: { ...item, raw_transcript: raw_transcript.trim() || '[NO TRANSCRIPT]' } }];"
}
},
{
"id": "node-005",
"name": "🤖 Gemini Analysis",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [240, 304],
"parameters": {
"method": "POST",
"url": "=https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent?key=YOUR_KEY_HERE",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={"contents": [{"parts": [{"text": "Analyze this Douyin livestream transcript. Return ONLY valid JSON with keys: language_detected, translation_en, translation_de, keywords (array), topics (array), sentiment, sentiment_score (-1 to 1), flags (array), music_detected (bool), summary_en, summary_de. Transcript: {{ $json.raw_transcript }}"}]}], "generationConfig": {"maxOutputTokens": 4096, "thinkingConfig": {"thinkingBudget": 0}}}"
}
},
{
"id": "node-006",
"name": "📊 Row Builder",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [480, 304],
"parameters": {
"jsCode": "const gemResp = $input.first().json;\nconst stt = $('📝 STT Normalizer').first().json;\nconst meta = $('⚙️ Config & Router').first().json;\nlet g = {};\ntry {\n const raw = gemResp?.candidates?.[0]?.content?.parts?.[0]?.text || '{}';\n g = JSON.parse(raw.replace(/```json|```/g,'').trim());\n} catch(e) {\n g = { flags: ['PARSE_ERROR'], sentiment: 'neutral', sentiment_score: 0 };\n}\nreturn [{ json: {\n Timestamp: new Date().toISOString(),\n Streamer: meta.streamer,\n Transcript_Original: stt.raw_transcript,\n Translation_EN: g.translation_en || '',\n Translation_DE: g.translation_de || '',\n Keywords: (g.keywords||[]).join('; '),\n Topics: (g.topics||[]).join('; '),\n Sentiment: g.sentiment || '',\n Sentiment_Score: g.sentiment_score ?? 0,\n Flags: (g.flags||[]).join('; '),\n Music_Detected: !!g.music_detected,\n Summary_EN: g.summary_en || '',\n Summary_DE: g.summary_de || '',\n Language_Detected: g.language_detected || '',\n Chunk_Index: meta.chunk_index,\n Audio_GCS_URI: meta.gcs_uri,\n} }];"
}
},
{
"id": "node-007",
"name": "📋 Google Sheets Write",
"type": "n8n-nodes-base.googleSheets",
"typeVersion": 4.5,
"position": [720, 304],
"parameters": {
"authentication": "serviceAccount",
"operation": "append",
"documentId": { "__rl": true, "value": "YOUR_SHEET_ID", "mode": "id" },
"sheetName": { "__rl": true, "value": "={{ $('⚙️ Config & Router').first().json.sheet_tab_name }}", "mode": "name" },
"columns": { "mappingMode": "autoMapInputData" }
},
"credentials": {
"googleApi": { "id": "YOUR_CRED_ID", "name": "Google Cloud SA" }
}
},
{
"id": "node-008",
"name": "📤 Telegram Notify",
"type": "n8n-nodes-base.telegram",
"typeVersion": 1.2,
"position": [960, 304],
"parameters": {
"chatId": "YOUR_CHAT_ID",
"text": "={{ '🎙 *' + $json.Streamer + '*\n' + $json.Translation_EN }}",
"additionalFields": { "parse_mode": "Markdown", "message_thread_id": 5 }
},
"credentials": {
"telegramApi": { "id": "YOUR_CRED_ID", "name": "CloudBro-Telegram" }
}
}
],
"connections": {
"🌐 Webhook Ingest": { "main": [[{ "node": "⚙️ Config & Router", "type": "main", "index": 0 }]] },
"⚙️ Config & Router": { "main": [[{ "node": "🔊 Google STT v2 (Chirp 2)", "type": "main", "index": 0 }]] },
"🔊 Google STT v2 (Chirp 2)": { "main": [[{ "node": "📝 STT Normalizer", "type": "main", "index": 0 }]] },
"📝 STT Normalizer": { "main": [[{ "node": "🤖 Gemini Analysis", "type": "main", "index": 0 }]] },
"🤖 Gemini Analysis": { "main": [[{ "node": "📊 Row Builder", "type": "main", "index": 0 }]] },
"📊 Row Builder": { "main": [[{ "node": "📋 Google Sheets Write", "type": "main", "index": 0 }]] },
"📋 Google Sheets Write": { "main": [[{ "node": "📤 Telegram Notify", "type": "main", "index": 0 }]] }
},
"settings": { "executionOrder": "v1" }
}