{
  "name": "Sentiment Router",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "sentiment",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "sr0001-0001-4000-8000-000000000001",
      "name": "Receive Feedback Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300]
    },
    {
      "parameters": {
        "resource": "text",
        "operation": "message",
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "messages": {
          "values": [
            {
              "content": "Classify the sentiment of the following text. Respond with ONLY one word: POSITIVE, NEGATIVE, or NEUTRAL.\n\nText: {{ $json.body.text }}"
            }
          ]
        },
        "options": {
          "temperature": 0
        }
      },
      "id": "sr0001-0002-4000-8000-000000000002",
      "name": "Classify Sentiment",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1,
      "position": [460, 300]
    },
    {
      "parameters": {
        "rules": {
          "rules": [
            {
              "outputKey": "positive",
              "conditions": {
                "options": { "caseSensitive": false },
                "conditions": [
                  {
                    "leftValue": "={{ $json.message.content.trim() }}",
                    "rightValue": "POSITIVE",
                    "operator": { "type": "string", "operation": "equals" }
                  }
                ]
              }
            },
            {
              "outputKey": "negative",
              "conditions": {
                "options": { "caseSensitive": false },
                "conditions": [
                  {
                    "leftValue": "={{ $json.message.content.trim() }}",
                    "rightValue": "NEGATIVE",
                    "operator": { "type": "string", "operation": "equals" }
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "id": "sr0001-0003-4000-8000-000000000003",
      "name": "Route by Sentiment",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [680, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "name": "action",
              "value": "escalate_to_support",
              "type": "string"
            },
            {
              "name": "sentiment",
              "value": "NEGATIVE",
              "type": "string"
            },
            {
              "name": "originalText",
              "value": "={{ $('Receive Feedback Webhook').item.json.body.text }}",
              "type": "string"
            }
          ]
        }
      },
      "id": "sr0001-0004-4000-8000-000000000004",
      "name": "Flag for Support",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [900, 420]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "name": "action",
              "value": "log_positive_feedback",
              "type": "string"
            },
            {
              "name": "sentiment",
              "value": "POSITIVE",
              "type": "string"
            },
            {
              "name": "originalText",
              "value": "={{ $('Receive Feedback Webhook').item.json.body.text }}",
              "type": "string"
            }
          ]
        }
      },
      "id": "sr0001-0005-4000-8000-000000000005",
      "name": "Log Positive Feedback",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [900, 180]
    }
  ],
  "connections": {
    "Receive Feedback Webhook": {
      "main": [[{ "node": "Classify Sentiment", "type": "main", "index": 0 }]]
    },
    "Classify Sentiment": {
      "main": [[{ "node": "Route by Sentiment", "type": "main", "index": 0 }]]
    },
    "Route by Sentiment": {
      "main": [
        [{ "node": "Log Positive Feedback", "type": "main", "index": 0 }],
        [{ "node": "Flag for Support", "type": "main", "index": 0 }]
      ]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "meta": {},
  "pinData": {}
}
