{"active":false,"connections":{"Alert Telegram":{"main":[[{"index":0,"node":"Log to Sheet","type":"main"}]]},"Classify Review (LLM)":{"main":[[{"index":0,"node":"Parse Classification","type":"main"}]]},"Draft Reply":{"main":[[{"index":0,"node":"Alert Telegram","type":"main"}]]},"Get New Review":{"main":[[{"index":0,"node":"Read Reviews Sheet","type":"main"}]]},"Is Negative?":{"main":[[{"index":0,"node":"Draft Reply","type":"main"}],[{"index":0,"node":"Log to Sheet","type":"main"}]]},"Parse Classification":{"main":[[{"index":0,"node":"Is Negative?","type":"main"}]]},"Parse First Review":{"main":[[{"index":0,"node":"Classify Review (LLM)","type":"main"}]]},"Read Reviews Sheet":{"main":[[{"index":0,"node":"Parse First Review","type":"main"}]]}},"id":"wf-02-review-sentiment","meta":{"instanceId":"n8n-template-factory","templateCredsSetupCompleted":false},"name":"Ecommerce Review Sentiment Router","nodes":[{"id":"node-trigger","name":"Get New Review","parameters":{},"position":[0,0],"type":"n8n-nodes-base.manualTrigger","typeVersion":1},{"id":"node-read-sheet","name":"Read Reviews Sheet","parameters":{"method":"GET","url":"={{ ($env.MOCK_API_URL || 'https://sheets.googleapis.com') + '/v4/spreadsheets/' + 'YOUR_SPREADSHEET_ID' + '/values/Reviews!A1:D20' }}"},"position":[240,0],"type":"n8n-nodes-base.httpRequest","typeVersion":4.2},{"id":"node-parse-review","name":"Parse First Review","parameters":{"jsCode":"const data = $input.first().json;\nconst rows = (data.values || []).slice(1);\nif (rows.length === 0) throw new Error('No reviews found in sheet');\nconst row = rows[0];\nconst rating = parseInt(row[3], 10);\nreturn [{ json: { reviewId: String(row[0] || ''), customer: String(row[1] || ''), text: String(row[2] || row[0] || ''), rating: Number.isFinite(rating) ? rating : 0 } }];","mode":"runOnceForAllItems"},"position":[480,0],"type":"n8n-nodes-base.code","typeVersion":2},{"id":"node-classify","name":"Classify Review (LLM)","parameters":{"headerParameters":{"parameters":[{"name":"Authorization","value":"Bearer YOUR_OPENAI_API_KEY"}]},"jsonBody":"={{ JSON.stringify({ model: 'gpt-4o-mini', response_format: { type: 'json_object' }, messages: [{ role: 'user', content: 'Classify this customer review. Return JSON with sentiment (positive/negative/neutral), category (slow_delivery/product_defect/wrong_size/praise/other), reply (a short draft response). Review: ' + $json.text + ' Rating: ' + $json.rating }] }) }}","method":"POST","sendBody":true,"sendHeaders":true,"specifyBody":"json","url":"={{ ($env.MOCK_API_URL || 'https://api.openai.com') + '/v1/chat/completions' }}"},"position":[720,0],"type":"n8n-nodes-base.httpRequest","typeVersion":4.2},{"id":"node-parse-class","name":"Parse Classification","parameters":{"jsCode":"const data = $input.first().json;\nconst content = data.choices && data.choices[0] ? data.choices[0].message.content : '{}';\nlet parsed = {};\ntry { parsed = JSON.parse(content); } catch (e) { parsed = {}; }\nconst review = $('Parse First Review').first().json;\nreturn [{ json: { ...review, sentiment: parsed.sentiment || 'neutral', category: parsed.category || 'other', draftReply: parsed.reply || 'Thank you for your feedback!' } }];","mode":"runOnceForAllItems"},"position":[960,0],"type":"n8n-nodes-base.code","typeVersion":2},{"id":"node-if","name":"Is Negative?","parameters":{"conditions":{"combinator":"or","conditions":[{"id":"cond-low-rating","leftValue":"={{ $json.rating }}","operator":{"name":"filter.operator.number.lt","operation":"lt","type":"number"},"rightValue":3},{"id":"cond-neg-sentiment","leftValue":"={{ $json.sentiment }}","operator":{"name":"filter.operator.string.equals","operation":"equals","type":"string"},"rightValue":"negative"}],"options":{"caseSensitive":true,"leftValue":"","typeValidation":"loose"}},"looseTypeValidation":true,"options":{}},"position":[1200,0],"type":"n8n-nodes-base.if","typeVersion":2.2},{"id":"node-draft","name":"Draft Reply","parameters":{"jsCode":"const item = $input.first().json;\nreturn [{ json: { ...item, replyText: item.draftReply, alertSent: false } }];","mode":"runOnceForAllItems"},"position":[1440,0],"type":"n8n-nodes-base.code","typeVersion":2},{"id":"node-telegram","name":"Alert Telegram","parameters":{"jsonBody":"={{ JSON.stringify({ chat_id: 'YOUR_TELEGRAM_CHAT_ID', text: 'Negative review (' + $json.category + ') from ' + $json.customer + ': ' + $json.text + ' Draft reply: ' + $json.replyText }) }}","method":"POST","sendBody":true,"specifyBody":"json","url":"={{ ($env.MOCK_API_URL || 'https://api.telegram.org') + '/bot' + 'YOUR_TELEGRAM_BOT_TOKEN' + '/sendMessage' }}"},"position":[1680,0],"type":"n8n-nodes-base.httpRequest","typeVersion":4.2},{"id":"node-log","name":"Log to Sheet","parameters":{"jsonBody":"={{ JSON.stringify({ range: 'Log!A1', values: [[$json.reviewId, $json.sentiment, $json.category, new Date().toISOString()]] }) }}","method":"POST","sendBody":true,"specifyBody":"json","url":"={{ ($env.MOCK_API_URL || 'https://sheets.googleapis.com') + '/v4/spreadsheets/' + 'YOUR_SPREADSHEET_ID' + '/values/Log!A1:append' }}"},"position":[1920,0],"type":"n8n-nodes-base.httpRequest","typeVersion":4.2}],"pinData":{},"settings":{"executionOrder":"v1"},"staticData":null}