{
  "name": "SinoDossier — Cross-Border Ops, Review Triage & FX Margin Agent",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "crossborder-ops-triage",
        "options": {}
      },
      "id": "ops-node-trigger",
      "name": "1. Receive Review URL or Payout Event",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [180, 300],
      "webhookId": "crossborder-ops-triage-trigger"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.firecrawl.dev/v1/scrape",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_FIRECRAWL_API_KEY"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"url\": \"{{ $json.body.target_url }}\",\n  \"formats\": [\"markdown\"],\n  \"onlyMainContent\": true\n}",
        "options": {
          "timeout": 45000
        }
      },
      "id": "ops-node-firecrawl",
      "name": "2. Firecrawl Clean Markdown Scrape",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [440, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.openai.com/v1/chat/completions",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_OPENAI_API_KEY"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"gpt-4o-mini\",\n  \"response_format\": { \"type\": \"json_object\" },\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are the SinoDossier crossborder-ops-finance-agent Skill. Classify incoming negative reviews, support messages, or payout FX spreads into priority (P0 | P1 | P2) and root_cause (SHIPPING_DELAY | PACKAGING_DAMAGE | PRODUCT_DEFECT | WRONG_ITEM | FX_FEE_ALERT | PRE_SALE_QA). Draft a concise empathetic native reply under 90 words. Return strict JSON with keys: priority, root_cause, language, task_title, assigned_team, customer_reply_draft, supplier_action_note, fx_alert (boolean).\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Scraped content & event context:\\n{{ ($json.data?.markdown || JSON.stringify($('1. Receive Review URL or Payout Event').first().json.body)).slice(0, 10000) }}\"\n    }\n  ]\n}",
        "options": {}
      },
      "id": "ops-node-llm",
      "name": "3. AI Ops & FX Triage Skill",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [700, 300]
    },
    {
      "parameters": {
        "jsCode": "const raw = $input.first().json.choices?.[0]?.message?.content || '{}';\nconst parsed = JSON.parse(raw);\nconst priorityMap = { P0: 1, P1: 2, P2: 3 };\n\nreturn [\n  {\n    json: {\n      priority: parsed.priority || 'P1',\n      clickup_priority: priorityMap[parsed.priority] || 2,\n      root_cause: parsed.root_cause || 'PRE_SALE_QA',\n      language: parsed.language || 'en',\n      task_title: parsed.task_title || '[Ops Alert] New Store Ticket',\n      assigned_team: parsed.assigned_team || 'CS Lead',\n      customer_reply_draft: parsed.customer_reply_draft || '',\n      supplier_action_note: parsed.supplier_action_note || '',\n      fx_alert: Boolean(parsed.fx_alert)\n    }\n  }\n];"
      },
      "id": "ops-node-parse",
      "name": "4. Parse Triage & ClickUp Priority",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [960, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.clickup.com/api/v2/list/YOUR_CLICKUP_LIST_ID/task",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "YOUR_CLICKUP_API_TOKEN"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"name\": {{ JSON.stringify($json.task_title) }},\n  \"description\": {{ JSON.stringify('Root Cause: ' + $json.root_cause + '\\nAssigned Team: ' + $json.assigned_team + '\\n\\n--- AI Draft Reply (' + $json.language + ') ---\\n' + $json.customer_reply_draft + '\\n\\n--- Supplier / Finance Note ---\\n' + $json.supplier_action_note) }},\n  \"priority\": {{ $json.clickup_priority }},\n  \"tags\": [\"{{ $json.priority }}\", \"{{ $json.root_cause }}\"]\n}",
        "options": {}
      },
      "id": "ops-node-clickup",
      "name": "5. Create ClickUp Priority Task",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1220, 300]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "ops-p0-gate",
              "leftValue": "={{ $('4. Parse Triage & ClickUp Priority').first().json.priority }}",
              "rightValue": "P0",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "ops-node-if-p0",
      "name": "6. Is P0 Urgent or FX Leak?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [1480, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"text\": \"🚨 *P0 Cross-Border Alert* — {{ $('4. Parse Triage & ClickUp Priority').first().json.task_title }}\\n• Root Cause: {{ $('4. Parse Triage & ClickUp Priority').first().json.root_cause }}\\n• Draft Ready in ClickUp for 5-sec approval.\"\n}",
        "options": {}
      },
      "id": "ops-node-slack",
      "name": "7. Send Instant P0 Slack Alert",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1740, 220]
    }
  ],
  "connections": {
    "1. Receive Review URL or Payout Event": {
      "main": [
        [
          {
            "node": "2. Firecrawl Clean Markdown Scrape",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2. Firecrawl Clean Markdown Scrape": {
      "main": [
        [
          {
            "node": "3. AI Ops & FX Triage Skill",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3. AI Ops & FX Triage Skill": {
      "main": [
        [
          {
            "node": "4. Parse Triage & ClickUp Priority",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4. Parse Triage & ClickUp Priority": {
      "main": [
        [
          {
            "node": "5. Create ClickUp Priority Task",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5. Create ClickUp Priority Task": {
      "main": [
        [
          {
            "node": "6. Is P0 Urgent or FX Leak?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "6. Is P0 Urgent or FX Leak?": {
      "main": [
        [
          {
            "node": "7. Send Instant P0 Slack Alert",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "tags": [
    {
      "name": "SinoDossier"
    },
    {
      "name": "Ops-Finance"
    }
  ]
}
