{
  "name": "EduPrime - Inquiry Follow-up Automation",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "inquiry-webhook",
        "options": {}
      },
      "id": "webhook-trigger",
      "name": "New Inquiry Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1.1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const inquiry = $input.item.json;\n\n// Validate required fields\nif (!inquiry.student_name || !inquiry.phone) {\n  throw new Error('Missing required fields: student_name and phone are required');\n}\n\n// Prepare inquiry data\nconst data = {\n  student_name: inquiry.student_name,\n  phone: inquiry.phone,\n  email: inquiry.email || null,\n  parent_name: inquiry.parent_name || null,\n  parent_phone: inquiry.parent_phone || null,\n  class_interested: inquiry.class_interested || 'Not specified',\n  course_interest: inquiry.course_interest || 'General',\n  source: inquiry.source || 'website',\n  notes: inquiry.notes || '',\n  follow_up_date: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString().split('T')[0], // Tomorrow\n  status: 'new'\n};\n\nreturn data;"
      },
      "id": "validate-inquiry",
      "name": "Validate & Prepare",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO inquiries (\n  student_name, phone, email, parent_name, parent_phone,\n  class_interested, course_interest, source, notes,\n  follow_up_date, status, created_at\n) VALUES (\n  '={{ $json.student_name }}',\n  '={{ $json.phone }}',\n  '={{ $json.email }}',\n  '={{ $json.parent_name }}',\n  '={{ $json.parent_phone }}',\n  '={{ $json.class_interested }}',\n  '={{ $json.course_interest }}',\n  '={{ $json.source }}',\n  '={{ $json.notes }}',\n  '={{ $json.follow_up_date }}',\n  'new',\n  NOW()\n) RETURNING id",
        "additionalFields": {}
      },
      "id": "save-inquiry",
      "name": "Save to Database",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.3,
      "position": [
        650,
        300
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const inquiry = $input.item.json;\n\nconst welcomeMessage = `Hello ${inquiry.student_name}! \ud83d\udc4b\n\nThank you for your interest in EduPrime Institute! \ud83c\udf93\n\nWe received your inquiry for ${inquiry.course_interest} (${inquiry.class_interested}).\n\nOur academic counselor will contact you within 24 hours to discuss:\n\u2705 Course curriculum & schedule\n\u2705 Faculty expertise\n\u2705 Fee structure & payment options\n\u2705 Demo class opportunity\n\nIn the meantime, visit our website to learn more about our programs.\n\nFor immediate assistance:\n\ud83d\udcde Call: +91-XXXXXXXXXX\n\ud83d\udce7 Email: info@eduprime.edu\n\nBest regards,\nEduPrime Team`;\n\nreturn {\n  ...inquiry,\n  welcome_message: welcomeMessage\n};"
      },
      "id": "prepare-welcome",
      "name": "Prepare Welcome Message",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "send",
        "phoneNumberId": "={{ $env.WHATSAPP_PHONE_NUMBER_ID }}",
        "recipientPhoneNumber": "={{ $json.phone }}",
        "textBody": "={{ $json.welcome_message }}"
      },
      "id": "send-welcome-whatsapp",
      "name": "Send Welcome WhatsApp",
      "type": "n8n-nodes-base.whatsApp",
      "typeVersion": 1,
      "position": [
        1050,
        200
      ],
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "fromEmail": "={{ $env.SMTP_FROM_EMAIL }}",
        "toEmail": "={{ $json.email }}",
        "subject": "Welcome to EduPrime - Your Inquiry Received!",
        "emailType": "html",
        "html": "<!DOCTYPE html>\n<html>\n<head>\n  <style>\n    body { font-family: Arial, sans-serif; line-height: 1.6; }\n    .header { background: #4e73df; color: white; padding: 20px; text-align: center; }\n    .content { padding: 20px; }\n    .footer { background: #f8f9fc; padding: 15px; text-align: center; font-size: 12px; }\n    .btn { background: #4e73df; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px; }\n  </style>\n</head>\n<body>\n  <div class=\"header\">\n    <h1>\ud83c\udf93 Welcome to EduPrime!</h1>\n  </div>\n  <div class=\"content\">\n    <h2>Hello {{ $json.student_name }},</h2>\n    <p>Thank you for your interest in <strong>EduPrime Institute</strong>!</p>\n    <p>We have received your inquiry for:</p>\n    <ul>\n      <li><strong>Course:</strong> {{ $json.course_interest }}</li>\n      <li><strong>Class:</strong> {{ $json.class_interested }}</li>\n    </ul>\n    <p>Our academic counselor will reach out to you within 24 hours to discuss your educational goals and how we can help you achieve them.</p>\n    <p><a href=\"#\" class=\"btn\">Book a Demo Class</a></p>\n    <h3>Why Choose EduPrime?</h3>\n    <ul>\n      <li>\u2705 Expert Faculty with IIT/AIIMS background</li>\n      <li>\u2705 Proven Track Record - 500+ selections</li>\n      <li>\u2705 Personalized Attention - Small batch sizes</li>\n      <li>\u2705 Regular Tests & Performance Analysis</li>\n    </ul>\n  </div>\n  <div class=\"footer\">\n    <p>EduPrime Institute | +91-XXXXXXXXXX | info@eduprime.edu</p>\n  </div>\n</body>\n</html>"
      },
      "id": "send-welcome-email",
      "name": "Send Welcome Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1050,
        400
      ],
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "channel": "#admissions",
        "text": "\ud83c\udd95 *New Inquiry Received!*\n\n*Name:* {{ $json.student_name }}\n*Phone:* {{ $json.phone }}\n*Course:* {{ $json.course_interest }}\n*Class:* {{ $json.class_interested }}\n*Source:* {{ $json.source }}\n\n_Follow-up scheduled for tomorrow_",
        "otherOptions": {}
      },
      "id": "notify-team-slack",
      "name": "Notify Team (Slack)",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.1,
      "position": [
        1250,
        300
      ],
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={\n  \"success\": true,\n  \"message\": \"Inquiry received successfully\",\n  \"inquiry_id\": {{ $json.id }}\n}",
        "options": {}
      },
      "id": "respond-webhook",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1450,
        300
      ]
    }
  ],
  "connections": {
    "New Inquiry Webhook": {
      "main": [
        [
          {
            "node": "Validate & Prepare",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate & Prepare": {
      "main": [
        [
          {
            "node": "Save to Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to Database": {
      "main": [
        [
          {
            "node": "Prepare Welcome Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Welcome Message": {
      "main": [
        [
          {
            "node": "Send Welcome WhatsApp",
            "type": "main",
            "index": 0
          },
          {
            "node": "Send Welcome Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Welcome WhatsApp": {
      "main": [
        [
          {
            "node": "Notify Team (Slack)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Welcome Email": {
      "main": [
        [
          {
            "node": "Notify Team (Slack)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify Team (Slack)": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "tags": [
    "automation",
    "inquiries",
    "admissions"
  ]
}