{
  "name": "flag92 — Chatwoot Ticket Routing",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "chatwoot-webhook",
        "responseMode": "responseNode"
      },
      "name": "Webhook (Chatwoot)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [240, 320],
      "id": "node-1"
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            { "value1": "={{$json.event}}", "value2": "conversation_created" }
          ]
        }
      },
      "name": "Only on Created",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [480, 320],
      "id": "node-2"
    },
    {
      "parameters": {
        "operation": "completion",
        "model": "qwen2.5-72b-instruct",
        "prompt": "Classify the user intent. Return JSON {\"intent\": \"pre_sale\"|\"post_sale\"|\"complaint\"|\"general\"}.\n\nUser message: {{$json.content}}"
      },
      "name": "LLM: Classify Intent",
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 1.5,
      "position": [720, 240],
      "id": "node-3"
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            { "value1": "={{$json.intent}}", "value2": "complaint" }
          ]
        }
      },
      "name": "Is Complaint?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [960, 320],
      "id": "node-4"
    },
    {
      "parameters": {
        "url": "https://support.example.com/api/v1/accounts/1/conversations/{{$json.conversation_id}}/assignments",
        "authentication": "headerAuth",
        "method": "POST",
        "jsonParameters": true,
        "options": {},
        "bodyParametersJson": "{\n  \"team_id\": 2\n}"
      },
      "name": "Assign to Senior Team",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [1200, 240],
      "id": "node-5"
    },
    {
      "parameters": {
        "channel": "support-alerts",
        "text": "🚨 投诉工单：{{$json.subject}}\nID: {{$json.conversation_id}}"
      },
      "name": "Notify Lark/Slack",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.1,
      "position": [1200, 400],
      "id": "node-6"
    }
  ],
  "connections": {
    "Webhook (Chatwoot)": { "main": [[{ "node": "Only on Created", "type": "main", "index": 0 }]] },
    "Only on Created": { "main": [[{ "node": "LLM: Classify Intent", "type": "main", "index": 0 }]] },
    "LLM: Classify Intent": { "main": [[{ "node": "Is Complaint?", "type": "main", "index": 0 }]] },
    "Is Complaint?": { "main": [[{ "node": "Assign to Senior Team", "type": "main", "index": 0 }, { "node": "Notify Lark/Slack", "type": "main", "index": 0 }]] }
  },
  "settings": { "executionOrder": "v1" }
}
