{
  "id": "WkWebhookViral91",
  "name": "Webhook \u2192 \u7206\u6b3e\u8cbc\u6587 API (Agent \u53ef\u547c\u53eb \u00b7 \u672c\u6a5f Ollama)",
  "nodes": [
    {
      "parameters": {
        "content": "\ud83c\udf09 \u6a4b\u63a5\u7bc4\u672c \u00b7 Agent Farm \u2194 n8n\n\n\u9019\u689d\u662f\u300c\u6a4b 1\u300d\uff1a\u4efb\u4f55\u7a0b\u5f0f\uff08\u542b Claude agent\uff09\u7528 curl \u6253\u5b83\uff0c\u5c31\u89f8\u767c n8n \u751f\u6210\u3001\u518d\u628a\u7d50\u679c\u56de\u50b3\u3002\n\n\u7528\u6cd5\uff1a\n1. \u5148\u6309\u53f3\u4e0a Publish \u555f\u7528\n2. curl POST \u2192 http://localhost:5678/webhook/viral-post\n   body \u5e36 { \"topic\": \"\u4f60\u7684\u4e3b\u984c\" }\n3. \u56de\u61c9\u5c31\u662f\u751f\u6210\u597d\u7684\u7206\u6b3e\u8cbc\u6587\n\n\u8a73\u7d30\u6307\u4ee4\u898b docs/91\u3002",
        "height": 320,
        "width": 400,
        "color": 6
      },
      "id": "node-note",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        180,
        110
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "viral-post",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "node-webhook",
      "name": "Webhook (POST)",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        470
      ]
    },
    {
      "parameters": {
        "jsCode": "let b = $json.body;\nif (typeof b === 'string') { try { b = JSON.parse(b); } catch (e) { b = {}; } }\nb = b || {};\nconst topic = (b.topic || $json.topic || ($json.query && $json.query.topic) || '\u96a8\u610f\u5beb\u4e00\u5247\u7bc4\u4f8b\u8cbc\u6587').toString();\nconst prompt = '\u4f60\u662f\u793e\u7fa4\u5167\u5bb9\u5beb\u624b\uff0c\u64c5\u9577\u53cd\u4e3b\u6d41\u6846\u67b6\u7684\u7206\u6b3e\u8cbc\u6587\u3002\u6839\u64da\u4e3b\u984c\uff0c\u70ba FB / IG / Threads \u5404\u5beb\u4e00\u5247\u8349\u7a3f\uff1a\u53cd\u76f4\u89ba\u9264\u5b50\u958b\u982d\u3001\u7b2c\u4e00\u4eba\u7a31\u771f\u5be6\u53e3\u8a9e\u3001\u7d50\u5c3e\u4e0d\u91e3\u4e92\u52d5\u3001\u7e41\u9ad4\u4e2d\u6587\u5168\u5f62\u6a19\u9ede\u3002\\n\\n\u4e3b\u984c\uff1a\\n' + topic;\nreturn [{ json: { topic, prompt } }];"
      },
      "id": "node-prompt",
      "name": "Build Prompt",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        470
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://host.docker.internal:11434/api/chat",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ model: 'qwen2.5:latest', messages: [ { role: 'system', content: '\u4f60\u662f\u53f0\u7063\u4eba\uff0c\u4e00\u5f8b\u4f7f\u7528\u53f0\u7063\u7e41\u9ad4\u4e2d\u6587\u8207\u53f0\u7063\u6163\u7528\u8a9e\u56de\u8986\uff0c\u7d55\u5c0d\u4e0d\u8981\u51fa\u73fe\u4efb\u4f55\u7c21\u9ad4\u5b57\u6216\u4e2d\u570b\u7528\u8a9e\u3002' }, { role: 'user', content: $json.prompt } ], stream: false }) }}",
        "options": {
          "timeout": 180000
        }
      },
      "id": "node-ollama",
      "name": "Generate with Ollama",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        680,
        470
      ]
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\nlet result = '';\ntry { result = (data.message && data.message.content) || (data.content && data.content[0] && data.content[0].text) || data.response || ''; } catch (e) {}\nif (!result) result = JSON.stringify(data);\nreturn [{ json: { result } }];"
      },
      "id": "node-extract",
      "name": "Extract Result",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        900,
        470
      ]
    },
    {
      "parameters": {
        "respondWith": "text",
        "responseBody": "={{ $json.result }}",
        "options": {}
      },
      "id": "node-respond",
      "name": "Respond to Agent",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1120,
        470
      ]
    }
  ],
  "connections": {
    "Webhook (POST)": {
      "main": [
        [
          {
            "node": "Build Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Prompt": {
      "main": [
        [
          {
            "node": "Generate with Ollama",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate with Ollama": {
      "main": [
        [
          {
            "node": "Extract Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Result": {
      "main": [
        [
          {
            "node": "Respond to Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}