{
  "name": "Vorlux AI | VTuber Expression Controller",
  "active": false,
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "vtuber-expression",
        "options": { "responseMode": "lastNode" }
      },
      "id": "webhook-trigger",
      "name": "Expression Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [220, 300]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const data = $input.first().json.body || $input.first().json;\nconst message = data.message || data.text || '';\nconst sentiment = data.sentiment || null;\n\n// Simple sentiment analysis if not provided\nlet emotion = sentiment;\nif (!emotion) {\n  const lower = message.toLowerCase();\n  if (/haha|lol|lmao|😂|funny|joke/i.test(lower)) emotion = 'happy';\n  else if (/sad|cry|😢|sorry|miss/i.test(lower)) emotion = 'sad';\n  else if (/angry|mad|hate|😡|wtf/i.test(lower)) emotion = 'angry';\n  else if (/wow|omg|amazing|🤯|insane/i.test(lower)) emotion = 'surprised';\n  else if (/love|❤️|heart|adore|best/i.test(lower)) emotion = 'love';\n  else if (/think|hmm|🤔|wonder/i.test(lower)) emotion = 'thinking';\n  else emotion = 'neutral';\n}\n\nconst expressionMap = {\n  happy: { mouth: 'smile', eyes: 'happy', brows: 'raised', intensity: 0.8 },\n  sad: { mouth: 'frown', eyes: 'sad', brows: 'worried', intensity: 0.6 },\n  angry: { mouth: 'angry', eyes: 'angry', brows: 'furrowed', intensity: 0.9 },\n  surprised: { mouth: 'open', eyes: 'wide', brows: 'raised', intensity: 1.0 },\n  love: { mouth: 'smile', eyes: 'heart', brows: 'raised', intensity: 0.9 },\n  thinking: { mouth: 'neutral', eyes: 'look_away', brows: 'one_raised', intensity: 0.5 },\n  neutral: { mouth: 'neutral', eyes: 'normal', brows: 'normal', intensity: 0.3 }\n};\n\nconst expression = expressionMap[emotion] || expressionMap.neutral;\nreturn [{ json: { emotion, expression, character: data.character || 'myla', message, timestamp: new Date().toISOString() } }];"
      },
      "id": "analyze-sentiment",
      "name": "Analyze Sentiment",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/vtuber/emotion",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ character: $json.character, emotion: $json.emotion, expression: $json.expression }) }}",
        "options": { "timeout": 5000 }
      },
      "id": "set-expression",
      "name": "Set VTuber Expression",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [700, 300]
    },
    {
      "parameters": {
        "url": "http://host.docker.internal:3010/api/animations/trigger",
        "method": "POST",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ character: $json.character, animation: $json.emotion, intensity: $json.expression.intensity }) }}",
        "options": { "timeout": 5000 }
      },
      "id": "trigger-animation",
      "name": "Trigger Animation",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [940, 300]
    },
    {
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "return [{ json: { success: true, emotion: $('Analyze Sentiment').first().json.emotion, character: $('Analyze Sentiment').first().json.character } }];"
      },
      "id": "response",
      "name": "Build Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [1180, 300]
    }
  ],
  "connections": {
    "Expression Webhook": { "main": [[{ "node": "Analyze Sentiment", "type": "main", "index": 0 }]] },
    "Analyze Sentiment": { "main": [[{ "node": "Set VTuber Expression", "type": "main", "index": 0 }]] },
    "Set VTuber Expression": { "main": [[{ "node": "Trigger Animation", "type": "main", "index": 0 }]] },
    "Trigger Animation": { "main": [[{ "node": "Build Response", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
