{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "7e0aa177-12cf-4a1c-a035-2a5aaf460bff",
      "name": "Form Submission Trigger",
      "type": "n8n-nodes-base.jotFormTrigger",
      "position": [
        7936,
        5072
      ],
      "parameters": {
        "form": "YOUR_JOTFORM_FORM_ID"
      },
      "typeVersion": 1
    },
    {
      "id": "ea0090ca-7a4d-481c-b3ad-469d70fa292e",
      "name": "Collect Individual Response",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        8144,
        5072
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "9bd60900-84a2-400d-8fb7-09b7ce7600bf",
      "name": "Generate Personal Report",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        8352,
        5072
      ],
      "parameters": {
        "text": "=Analyze this survey response and generate a concise personalized report.\n\ntodays date :- {{ $now }}\n\nRESPONDENT DATA:\n{{ $json.data.toJsonString() }}\n\nINSTRUCTIONS:\n1. Extract: Age, Gender, Employment, Email\n2. Analyze responses and identify 3-4 key insights\n3. Generate 3-4 specific recommendations\n4. Create compact HTML report with:\n   - Professional header with gradient background\n   - Recipient info section\n   - Key Insights section with styled bullets\n   - Recommendations section with styled bullets\n   - Modern, clean design with good spacing\n   - Professional color scheme\n   - Footer with thank you message\n\nSTYLING REQUIREMENTS:\n- Use modern, professional colors (blues, grays)\n- Clear typography with good hierarchy\n- Proper spacing and padding\n- Rounded corners on sections\n- Subtle borders and shadows\n- Mobile-responsive design\n- Easy-to-scan format with visual hierarchy\n\nRETURN JSON ONLY:\n{\n  \"email_subject\": \"string\",\n  \"html_report\": \"string\"\n}",
        "options": {
          "systemMessage": "You are a concise survey analysis system that generates brief, point-by-point personalized reports.\n\nYour role:\n1. Extract key facts from survey responses\n2. Identify 3-4 main insights specific to the respondent\n3. Generate 3-4 actionable recommendations\n4. Create a compact HTML email report (minimal design, quick read)\n\nGuidelines:\n- Be concise and direct - no lengthy explanations\n- Use bullet points and short statements\n- Focus on: demographics, consumption habits, spending, health, brand preference\n- Generate specific recommendations based on their answers\n- Maintain professional tone\n- Ensure HTML is compact and email-friendly\n\nOutput ONLY valid JSON with no additional text."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "dae0887f-fe3e-4967-a3fa-29878f03aa07",
      "name": "Response Ready - Pause",
      "type": "n8n-nodes-base.wait",
      "position": [
        8704,
        5072
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "a0c4f4ff-a078-46d3-844e-30bd662a383f",
      "name": "Gemini LLM (Personal)",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        8304,
        5264
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "3c885d88-083c-4a60-8ef0-1b73af282d6e",
      "name": "Parse Personal Report JSON",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        8528,
        5280
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"email_subject\": \"Your Fast Food Survey Analysis - Key Insights\",\n  \"html_report\": \"[Complete personalized HTML report with inline CSS]\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "03432b73-c45f-4431-94e4-6c1b050f36fc",
      "name": "Send Personal Report",
      "type": "n8n-nodes-base.gmail",
      "position": [
        8912,
        5072
      ],
      "parameters": {
        "sendTo": "={{ $('Form Submission Trigger').item.json['Please indicate your email so that we can reach you about the results.'] }}",
        "message": "={{ $json.output.html_report }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "={{ $json.output.email_subject }}"
      },
      "typeVersion": 2.1
    },
    {
      "id": "340a9911-23d4-4cd3-abc4-c4bfdf6a7f20",
      "name": "Gemini LLM",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        8880,
        5856
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "a0b2076e-742b-4e9f-be8f-a8b144b7ff7b",
      "name": "Weekly Report Scheduler",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        7696,
        5680
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtHour": 11
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "88f3cdd7-57c0-41e4-b04a-8d9ed0a40c77",
      "name": "Fetch Survey Submissions",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        7920,
        5680
      ],
      "parameters": {
        "url": "https://api.jotform.com/form/YOUR_JOTFORM_FORM_ID/submissions",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "apiKey",
              "value": "YOUR_JOTFORM_API_KEY"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "a03fc700-9c02-4bff-9e8a-1dc32d465acd",
      "name": "Unpack Response Objects",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        8128,
        5680
      ],
      "parameters": {
        "include": "selectedOtherFields",
        "options": {},
        "fieldToSplitOut": "content",
        "fieldsToInclude": "content.id, content.answers"
      },
      "typeVersion": 1
    },
    {
      "id": "e01bacda-db4d-42de-b069-e0f1757a7dd9",
      "name": "Normalize Response Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        8320,
        5680
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "f027e797-014e-47d9-ad55-0036bd06a453",
              "name": "content.id",
              "type": "string",
              "value": "={{ $json.content.id }}"
            },
            {
              "id": "43730158-8ed8-4abc-9a8a-cd62846a98bf",
              "name": "",
              "type": "string",
              "value": ""
            },
            {
              "id": "f5063b4f-ab7a-4007-9bb2-24fafbbdb78f",
              "name": "content.answers",
              "type": "object",
              "value": "={{ $json.content.answers }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "d56e17da-0499-4361-884d-875ca9d2822e",
      "name": "Extract Q&A Pairs",
      "type": "n8n-nodes-base.code",
      "position": [
        8528,
        5680
      ],
      "parameters": {
        "jsCode": "// Extract id, text, and answer from each submission\nconst results = [];\n\nfor (const item of $input.all()) {\n  const submission = item.json.content;\n  const id = submission.id;\n  const answers = submission.answers;\n  \n  // Extract only questions with answers (exclude headers, buttons, and empty answers)\n  const extractedAnswers = [];\n  \n  for (const key in answers) {\n    const field = answers[key];\n    \n    // Only include if it has text and answer, and is not a control element\n    if (field.text && field.answer && field.type !== 'control_head' && field.type !== 'control_button') {\n      extractedAnswers.push({\n        text: field.text,\n        answer: field.answer\n      });\n    }\n  }\n  \n  results.push({\n    id: id,\n    survey_responses: extractedAnswers\n  });\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "da49efb8-fbb7-4b0e-8d1f-359fa85601a4",
      "name": "Merge All Responses",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        8720,
        5680
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "157b8677-aa4d-4068-80f8-e2389073984a",
      "name": "Analyze & Report",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        8928,
        5680
      ],
      "parameters": {
        "text": "=Generate an aggregate report from these survey submissions.\n\nSURVEY DATA:\n{{ $json.data.toJsonString() }}\n\nReturn ONLY valid JSON with these exact two fields:\n{\n  \"email_subject\": \"Survey Aggregate Report - 4 Respondents - Fast Food Consumption Study\",\n  \"html_report\": \"[Complete HTML with inline styles, professional design, all statistics, demographics, insights, and findings embedded in the HTML string]\"\n}\n\nDo not include any text, markdown, or explanations outside the JSON.",
        "options": {
          "systemMessage": "=You are a survey aggregation and statistical analysis system that generates professional HTML reports from multiple survey submissions.\n\nYour ONLY job is to return a JSON object with exactly two fields:\n1. email_subject: A string with the report title\n2. html_report: A string containing complete, valid HTML with inline CSS\n\nDo NOT include any text before or after the JSON. Do NOT include markdown backticks. Do NOT include explanations.\n\nProcess:\n- Count total respondents\n- Analyze each question's responses\n- Calculate percentages and frequencies\n- Identify demographic patterns\n- Generate 5-7 key insights\n- Create comprehensive HTML report with statistics\n\nReturn ONLY this JSON structure:\n{\n  \"email_subject\": \"string\",\n  \"html_report\": \"string\"\n}"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "999ae35e-9a91-4a69-af48-8a4b52390eb9",
      "name": "Send Report to Admin",
      "type": "n8n-nodes-base.gmail",
      "position": [
        9264,
        5680
      ],
      "parameters": {
        "sendTo": "=YOUR_ADMIN_EMAIL@example.com",
        "message": "={{ $json.output.html_report }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "={{ $json.output.email_subject }}"
      },
      "typeVersion": 2.1
    },
    {
      "id": "f38a7b8f-ed90-417c-9956-c67787ff3cc7",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        9088,
        5872
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"email_subject\": \"Your Fast Food Survey Analysis - Key Insights\",\n  \"html_report\": \"[Complete personalized HTML report with inline CSS]\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "27544677-1438-444f-b90d-6b494daa02cd",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7168,
        4992
      ],
      "parameters": {
        "width": 2368,
        "height": 1040,
        "content": "# Automated Survey Reports via Jotform\n\n## What It Does\n\nThis workflow automatically processes Jotform survey responses and generates two types of reports:\n\n1. **Personal Reports** - Sent to each respondent immediately after they submit\n2. **Weekly Summaries** - Statistical overview sent to admin every week\n\n## [Get Jotform from here](https://www.jotform.com/?partner=roshanramanidev)\n---\n\n## How It Works\n\n### **When someone fills out the survey:**\n### \u2192 Personal report generated with their insights and recommendations\n### \u2192 HTML email sent to respondent (within seconds)\n\n### **Every week:**\n###  \u2192 Collects all responses\n###  \u2192 Analyzes trends and patterns\n###  \u2192 Generates aggregate report with statistics\n###  \u2192 Sends to admin email\n\n\n---\n\n## Quick Start\n\n1. Create your survey on [Jotform](https://www.jotform.com/?partner=roshanramanidev)\n2. Get your Jotform API key\n3. Setup Google Gemini API credentials\n4. Configure Gmail access\n5. Import workflow into n8n\n6. Test with sample response\n\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Gemini LLM": {
      "ai_languageModel": [
        [
          {
            "node": "Analyze & Report",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Analyze & Report": {
      "main": [
        [
          {
            "node": "Send Report to Admin",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Q&A Pairs": {
      "main": [
        [
          {
            "node": "Merge All Responses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge All Responses": {
      "main": [
        [
          {
            "node": "Analyze & Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini LLM (Personal)": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Personal Report",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Response Ready - Pause": {
      "main": [
        [
          {
            "node": "Send Personal Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Form Submission Trigger": {
      "main": [
        [
          {
            "node": "Collect Individual Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Unpack Response Objects": {
      "main": [
        [
          {
            "node": "Normalize Response Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Weekly Report Scheduler": {
      "main": [
        [
          {
            "node": "Fetch Survey Submissions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Survey Submissions": {
      "main": [
        [
          {
            "node": "Unpack Response Objects",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Personal Report": {
      "main": [
        [
          {
            "node": "Response Ready - Pause",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Analyze & Report",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Response Fields": {
      "main": [
        [
          {
            "node": "Extract Q&A Pairs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Personal Report JSON": {
      "ai_outputParser": [
        [
          {
            "node": "Generate Personal Report",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Collect Individual Response": {
      "main": [
        [
          {
            "node": "Generate Personal Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}