{
  "name": "Nodbot - Perplexity research with citations validation",
  "nodes": [
    {
      "parameters": {
        "path": "integration-perplexity-research-n8n",
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "id": "11f54993-fcde-4206-93c8-ccbfb49b342c",
      "name": "Webhook research request",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const src = $json.body ?? $json;\nconst topic = String(src.topic ?? '').replace(/\\s+/g, ' ').trim();\nif (topic.length < 20) throw new Error('Research topic is too vague');\nconst recencyDays = Number(src.recency_days ?? 30);\nconst domains = Array.isArray(src.must_include_domains) ? src.must_include_domains : [];\nconst today = new Date().toISOString().slice(0, 10);\nconst system = 'Return only JSON with keys: answer, key_findings[], citations[], open_questions[]. Every citation must have title, url, publisher, published_at if available.';\nconst user = `Today is ${today}. Research topic: ${topic}. Locale: ${src.locale ?? 'ru-RU'}. Prefer sources newer than ${recencyDays} days. Must check domains: ${domains.join(', ') || 'no required domains'}.`;\nreturn [{ json: {\n  perplexity: {\n    model: $env.PERPLEXITY_MODEL ?? 'sonar',\n    messages: [{ role: 'system', content: system }, { role: 'user', content: user }],\n    temperature: 0.2,\n    max_tokens: Number($env.PERPLEXITY_MAX_TOKENS ?? 1200)\n  },\n  validation: { min_citations: Number(src.min_citations ?? 3), recency_days: recencyDays, required_domains: domains }\n}}];"
      },
      "id": "9657aaf7-d33e-49f8-a19c-d2a373b1d455",
      "name": "Prepare Sonar prompt",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {},
      "id": "7bf533dc-9b13-4dae-a4df-9fe597a3b9cb",
      "name": "Call Perplexity API",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const src = $json.body ?? $json;\nconst topic = String(src.topic ?? '').replace(/\\s+/g, ' ').trim();\nif (topic.length < 20) throw new Error('Research topic is too vague');\nconst recencyDays = Number(src.recency_days ?? 30);\nconst domains = Array.isArray(src.must_include_domains) ? src.must_include_domains : [];\nconst today = new Date().toISOString().slice(0, 10);\nconst system = 'Return only JSON with keys: answer, key_findings[], citations[], open_questions[]. Every citation must have title, url, publisher, published_at if available.';\nconst user = `Today is ${today}. Research topic: ${topic}. Locale: ${src.locale ?? 'ru-RU'}. Prefer sources newer than ${recencyDays} days. Must check domains: ${domains.join(', ') || 'no required domains'}.`;\nreturn [{ json: {\n  perplexity: {\n    model: $env.PERPLEXITY_MODEL ?? 'sonar',\n    messages: [{ role: 'system', content: system }, { role: 'user', content: user }],\n    temperature: 0.2,\n    max_tokens: Number($env.PERPLEXITY_MAX_TOKENS ?? 1200)\n  },\n  validation: { min_citations: Number(src.min_citations ?? 3), recency_days: recencyDays, required_domains: domains }\n}}];"
      },
      "id": "ed1e068e-4466-4514-8afc-1e0196fba733",
      "name": "Validate citations",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {},
      "id": "045dea38-2fb1-49e1-8094-48a4a03273eb",
      "name": "Save research card",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    },
    {
      "parameters": {},
      "id": "e025442e-2424-49e6-9118-e779f63f9503",
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 2,
      "position": [
        1400,
        260
      ]
    }
  ],
  "connections": {
    "Webhook research request": {
      "main": [
        [
          {
            "node": "Prepare Sonar prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Sonar prompt": {
      "main": [
        [
          {
            "node": "Call Perplexity API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call Perplexity API": {
      "main": [
        [
          {
            "node": "Validate citations",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate citations": {
      "main": [
        [
          {
            "node": "Save research card",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save research card": {
      "main": [
        [
          {
            "node": "Respond",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "nodbot",
    "integration",
    "production"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "4ec83fb4-6c34-4359-8302-216a7d8091a7",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}