{
  "name": "Football Trivia Generator",
  "nodes": [
    {
      "parameters": {
        "path": "trivia-football-generator",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-trigger",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [
        200,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.z.ai/v1/chat/completions",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer {{$credentials.apiKey}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"model\": \"zai-pro\",\n  \"messages\": [\n    {\n      \"role\": \"system\",\n      \"content\": \"You are an expert football trivia creator with deep knowledge of Premier League, La Liga, World Cup, European leagues, and football history. Generate engaging, accurate, and challenging football trivia questions.\"\n    },\n    {\n      \"role\": \"user\",\n      \"content\": \"Generate {{ $json.numQuestions }} football trivia questions about {{ $json.category || 'general football' }} at {{ $json.difficulty }} difficulty level.\\n\\nCategories available: Premier League, La Liga, World Cup, Bundesliga, Serie A, Ligue 1, European Competitions (Champions League, Europa League), International Football, Football History, Player Records, Manager Trivia, Stadium Facts.\\n\\nRequirements:\\n1. Include diverse question types: multiple-choice, true-false, text-input\\n2. Multiple-choice: 4 options (a, b, c, d)\\n3. Text-input: provide alternative acceptable answers\\n4. Include clear explanations with interesting facts\\n5. Questions should span different eras and aspects of football\\n6. Include player identification, club history, tournament facts, records\\n7. For player questions, include era/hint context\\n\\nReturn in this exact JSON format:\\n{\\n  \\\"topic\\\": \\\"Football - {{ $json.category || 'General' }}\\\",\\n  \\\"category\\\": \\\"{{ $json.category || 'General' }}\\\",\\n  \\\"difficulty\\\": \\\"{{ $json.difficulty }}\\\",\\n  \\\"questions\\\": [\\n    {\\n      \\\"id\\\": \\\"1\\\",\\n      \\\"type\\\": \\\"multiple-choice\\\",\\n      \\\"question\\\": \\\"Which club won the UEFA Champions League in 2020?\\\",\\n      \\\"correctAnswer\\\": \\\"a\\\",\\n      \\\"options\\\": [\\n        {\\\"id\\\": \\\"a\\\", \\\"text\\\": \\\"Bayern Munich\\\"},\\n        {\\\"id\\\": \\\"b\\\", \\\"text\\\": \\\"Paris Saint-Germain\\\"},\\n        {\\\"id\\\": \\\"c\\\", \\\"text\\\": \\\"Manchester City\\\"},\\n        {\\\"id\\\": \\\"d\\\", \\\"text\\\": \\\"Liverpool\\\"}\\n      ],\\n      \\\"explanation\\\": \\\"Bayern Munich won the 2020 Champions League, defeating Paris Saint-Germain 1-0 in the final held in Lisbon.\\\"\\n    }\\n  ],\\n  \\\"total_questions\\\": {{ $json.numQuestions }}\\n}\"\n    }\n  ],\n  \"temperature\": 0.7,\n  \"max_tokens\": 4000\n}"
      },
      "id": "z-ai-llm",
      "name": "Z.AI LLM - Football Questions",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const response = items[0].json;\nconst input = items[0].json;\n\n// Parse AI response\nlet parsedData;\ntry {\n  const content = response.choices[0].message.content;\n  const jsonMatch = content.match(/\\{[\\s\\S]*\\}/);\n  if (jsonMatch) {\n    parsedData = JSON.parse(jsonMatch[0]);\n  } else {\n    parsedData = JSON.parse(content);\n  }\n} catch (error) {\n  return [{\n    json: {\n      error: 'Failed to parse AI response',\n      details: error.message,\n      rawResponse: response\n    }\n  }];\n}\n\n// Football-specific categories\nconst category = input.category || 'General Football';\nconst categories = [\n  {\n    name: category,\n    description: `Trivia focused on ${category}`,\n    subcategories: ['Key Facts', 'Notable Moments', 'Records']\n  },\n  {\n    name: 'Football History',\n    description: 'Historical facts and milestones',\n    subcategories: ['World Cup', 'European Competitions', 'Club History']\n  },\n  {\n    name: 'Players & Managers',\n    description: 'Trivia about famous personalities',\n    subcategories: ['All-Time Greats', 'Current Stars', 'Legendary Managers']\n  }\n];\n\n// Format questions with football-specific enhancements\nconst formattedQuestions = parsedData.questions.map((q, index) => ({\n  id: q.id || (index + 1).toString(),\n  type: q.type,\n  question: q.question,\n  correctAnswer: q.correctAnswer,\n  explanation: q.explanation,\n  options: q.options,\n  acceptableAnswers: q.acceptableAnswers,\n  // Add football metadata\n  hint: q.hint || null,\n  era: q.era || 'Modern Football'\n}));\n\n// Calculate difficulty distribution\nconst difficulty = input.difficulty || 'medium';\nconst difficultyDistribution = {};\nformattedQuestions.forEach(q => {\n  const diff = q.difficulty || difficulty;\n  difficultyDistribution[diff] = (difficultyDistribution[diff] || 0) + 1;\n});\n\nreturn [{\n  json: {\n    topic: parsedData.topic || 'Football',\n    category: parsedData.category || 'General Football',\n    difficulty: difficulty,\n    categories: categories,\n    questions: formattedQuestions,\n    total_questions: formattedQuestions.length,\n    difficulty_distribution: difficultyDistribution,\n    // Football-specific metadata\n    game_type: 'football',\n    has_hints: true,\n    has_eras: true\n  }\n}];"
      },
      "id": "format-response",
      "name": "Format Football Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        800,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}"
      },
      "id": "respond-to-webhook",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1100,
        300
      ]
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Z.AI LLM - Football Questions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Z.AI LLM - Football Questions": {
      "main": [
        [
          {
            "node": "Format Football Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Football Response": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 1,
  "updatedAt": "2024-01-22T12:00:00.000Z",
  "versionId": "1"
}