{
  "id": "DdPm21OTtv7jAAPf",
  "name": "AI Debate Generator (Pro vs Con Engine)",
  "tags": [],
  "nodes": [
    {
      "id": "ed1698df-95a2-4c11-989b-d6499e301b37",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -48
      ],
      "parameters": {
        "width": 920,
        "height": 896,
        "content": "## AI Debate Generator (Pro vs Con Engine)\n\nThis workflow automatically processes incoming debate topic requests, generates structured, evidence-backed Pro vs Con debates with balanced arguments, rebuttals, and final verdicts using AI, delivers them via email, and logs everything in Google Sheets.\n\n### Who\u2019s it for\n\u2022 Students and debaters preparing arguments\n\u2022 Content creators and podcasters\n\u2022 Researchers and analysts needing balanced views\n\u2022 Decision-makers and AI enthusiasts exploring topics\n\n### How it works / What it does\n1. Captures new debate requests (webhook or scheduled poll)\n2. Validates the topic and prepares context\n3. AI generates full structured debate (Pro/Con arguments with evidence, rebuttals, verdict)\n4. Formats professional markdown output\n5. Emails the complete debate to the requester\n6. Logs topic, verdict summary, and generation details in Google Sheets\n\n### How to set up\n1. Import this workflow\n2. Set up credentials (Webhook, Google Sheets, OpenAI/Anthropic)\n3. Update default instructions and email sender\n4. Activate workflow\n\n### Requirements\n\u2022 Webhook endpoint for topic submissions\n\u2022 Google Sheets\n\u2022 OpenAI / Anthropic / Grok API\n\u2022 Clear debate topic input\n\n### How to customize the workflow\n\u2022 Modify AI prompt for depth, tone, or format in the AI node\n\u2022 Adjust Python validation rules\n\u2022 Update Google Sheet columns\n\u2022 Change email templates or add Slack/Teams delivery"
      },
      "typeVersion": 1
    },
    {
      "id": "c2d75c0a-48a4-46de-8570-7d5f60f75f4d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1040,
        256
      ],
      "parameters": {
        "color": 4,
        "width": 732,
        "height": 480,
        "content": "## 1. Trigger & Intake"
      },
      "typeVersion": 1
    },
    {
      "id": "647c275a-ac6c-44f2-afe3-ee6f4da92aca",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1808,
        160
      ],
      "parameters": {
        "color": 3,
        "width": 940,
        "height": 620,
        "content": "## 2. Analysis & Debate Generation"
      },
      "typeVersion": 1
    },
    {
      "id": "80f62931-a6d8-4353-83ec-683cebeac35d",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2848,
        224
      ],
      "parameters": {
        "color": 6,
        "width": 944,
        "height": 580,
        "content": "## 3. Generate & Track"
      },
      "typeVersion": 1
    },
    {
      "id": "045a4911-5e8f-479a-bd8d-1ca41de44f1e",
      "name": "Webhook - New Debate Request",
      "type": "n8n-nodes-base.webhook",
      "position": [
        1200,
        384
      ],
      "parameters": {
        "path": "ai-debate-request",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 1.1
    },
    {
      "id": "fb172fe3-70a4-4537-84b1-d5a05b01d7ee",
      "name": "Poll New Debate Requests",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        1200,
        576
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "*/20 * * * *"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "c965e7c1-44ba-47d7-931a-19a935144031",
      "name": "Prepare Debate Context",
      "type": "n8n-nodes-base.set",
      "position": [
        1424,
        480
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "name": "topic",
              "type": "string",
              "value": "={{ $json.topic || $json.body?.topic }}"
            },
            {
              "name": "instructions",
              "type": "string",
              "value": "={{ $json.instructions || $json.body?.instructions || 'Generate a balanced, evidence-based debate with real-world examples' }}"
            },
            {
              "name": "requesterEmail",
              "type": "string",
              "value": "={{ $json.requesterEmail || $json.body?.requesterEmail || $json.body?.email }}"
            },
            {
              "name": "context",
              "type": "string",
              "value": "={{ $json.context || $json.body?.context || $json.body }}"
            },
            {
              "name": "debateId",
              "type": "string",
              "value": "={{ $json.debateId || Date.now().toString() }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2e27a67e-4ec3-4b6d-8719-2aca79dd5a77",
      "name": "Python - Validate Debate Topic",
      "type": "n8n-nodes-base.code",
      "position": [
        1856,
        480
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "language": "pythonNative",
        "pythonCode": "newItems = []\nfor item in items:\n    data = item['json'].copy()\n    topic = str(data.get('topic', '')).strip()\n    isValidDebate = len(topic) > 10\n    data['isValidDebate'] = isValidDebate\n    data['topicLength'] = len(topic)\n    newItems.append({'json': data})\nreturn newItems"
      },
      "typeVersion": 2
    },
    {
      "id": "1b37f3fb-2e3a-4ae3-bcf6-fb89349669a7",
      "name": "Filter Valid Debate Requests",
      "type": "n8n-nodes-base.filter",
      "position": [
        2080,
        480
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "conditions": [
            {
              "operator": {
                "type": "boolean",
                "operation": "true"
              },
              "leftValue": "={{ $json.isValidDebate }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "aa292f4f-11a0-4ab2-9847-774279f8c363",
      "name": "Wait 1 - Rate Limit",
      "type": "n8n-nodes-base.wait",
      "position": [
        2304,
        480
      ],
      "parameters": {
        "amount": 10
      },
      "typeVersion": 1
    },
    {
      "id": "fbd832c7-5acd-457f-af68-75b2e90e4413",
      "name": "AI - Generate Structured Debate",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2496,
        480
      ],
      "parameters": {
        "text": "=Act as an expert debate generator and neutral moderator. Generate a structured, evidence-backed Pro vs Con debate.\n\nTopic: {{ $json.topic }}\nAdditional Instructions: {{ $json.instructions }}\nContext: {{ $json.context }}\n\nStructure the output exactly like this:\n\n**PRO Arguments** (3-4 strong points with real-world evidence, statistics, or examples)\n**CON Arguments** (3-4 strong points with real-world evidence, statistics, or examples)\n**Rebuttals** (direct counterpoints for each major argument)\n**Final Verdict** (balanced conclusion weighing both sides)\n\nKeep tone professional, factual, and impartial. Use markdown formatting. Total under 800 words.",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 1.6
    },
    {
      "id": "6fe69745-f52f-4033-8434-1debe2d17750",
      "name": "JS - Format Debate Output",
      "type": "n8n-nodes-base.code",
      "position": [
        2912,
        480
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const item = $input.item.json;\nreturn {\n  json: {\n    ...item,\n    debateText: item.response || item.text || 'Debate generated successfully.',\n    status: 'Generated',\n    generatedDate: new Date().toISOString().split('T')[0]\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "7539f82a-f317-4d88-8fe9-df4f8c66f6a5",
      "name": "Wait 2 - Review Buffer",
      "type": "n8n-nodes-base.wait",
      "position": [
        3104,
        480
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "d317260e-dcd0-48b8-a6d1-b1a4125da93f",
      "name": "Send Generated Debate",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3328,
        384
      ],
      "parameters": {
        "url": "https://api.sendgrid.com/v3/mail/send",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"personalizations\": [{\"to\": [{\"email\": \"{{ $json.requesterEmail }}\"}]}],\n  \"from\": {\"email\": \"debates@yourcompany.com\", \"name\": \"AI Debate Engine\"},\n  \"subject\": \"Your AI-Generated Debate: Pro vs Con on {{ $json.topic }}\",\n  \"content\": [{\"type\": \"text/plain\", \"value\": \"{{ $json.debateText }}\"}]\n}",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.2
    },
    {
      "id": "fa12a82e-340a-47a8-baed-5a0939a25317",
      "name": "Update Debate Log",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3328,
        576
      ],
      "parameters": {
        "url": "https://sheets.googleapis.com/v4/spreadsheets/YOUR_SHEET_ID/values/Sheet1!A1:append?valueInputOption=USER_ENTERED",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"values\": [[\"{{ $json.generatedDate }}\", \"{{ $json.topic }}\", \"{{ $json.status }}\", \"{{ new Date().toISOString() }}\"]]\n}",
        "sendBody": true,
        "specifyBody": "json"
      },
      "typeVersion": 4.2
    },
    {
      "id": "df2bdcda-0845-48a0-8fa9-24cbdfb896ff",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        2400,
        688
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "b2f2a70b-ef89-4bb6-8307-80adb906fd56",
      "name": "Wait For Result",
      "type": "n8n-nodes-base.wait",
      "position": [
        1632,
        480
      ],
      "parameters": {},
      "typeVersion": 1.1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "4c5be668-41db-4c55-ab9b-fa8be94c6f73",
  "connections": {
    "Wait For Result": {
      "main": [
        [
          {
            "node": "Python - Validate Debate Topic",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI - Generate Structured Debate",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Wait 1 - Rate Limit": {
      "main": [
        [
          {
            "node": "AI - Generate Structured Debate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Debate Context": {
      "main": [
        [
          {
            "node": "Wait For Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 2 - Review Buffer": {
      "main": [
        [
          {
            "node": "Send Generated Debate",
            "type": "main",
            "index": 0
          },
          {
            "node": "Update Debate Log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Poll New Debate Requests": {
      "main": [
        [
          {
            "node": "Prepare Debate Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "JS - Format Debate Output": {
      "main": [
        [
          {
            "node": "Wait 2 - Review Buffer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Valid Debate Requests": {
      "main": [
        [
          {
            "node": "Wait 1 - Rate Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook - New Debate Request": {
      "main": [
        [
          {
            "node": "Prepare Debate Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Python - Validate Debate Topic": {
      "main": [
        [
          {
            "node": "Filter Valid Debate Requests",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI - Generate Structured Debate": {
      "main": [
        [
          {
            "node": "JS - Format Debate Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}