{
  "name": "Vernacular AI Skilling - Enrollment Workflow",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "vernacular-ai-skilling/enrollment",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "enrollment-webhook",
      "name": "Enrollment Event Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        240,
        320
      ]
    },
    {
      "parameters": {
        "language": "JavaScript",
        "jsCode": "const body = $json.body ?? $json;\nreturn [{\n  json: {\n    eventType: body.eventType ?? 'worker.interested',\n    phoneNumber: body.phoneNumber ?? body.from,\n    studentName: body.studentName ?? body.profileName ?? 'Learner',\n    preferredLanguage: body.preferredLanguage ?? 'ta-IN',\n    paymentLink: body.paymentLink ?? $env.UPI_PAYMENT_LINK ?? 'upi://pay?pa=apexarcglobal@upi&pn=Apex%20Arc%20Global&am=500&cu=INR',\n    groupInviteLink: body.groupInviteLink ?? $env.WHATSAPP_GROUP_INVITE_LINK ?? 'https://chat.whatsapp.com/example-vernacular-ai-skilling-group',\n    courseName: body.courseName ?? 'EV Technician Foundation',\n    amountInInr: body.amountInInr ?? 500\n  }\n}];"
      },
      "id": "normalize-event",
      "name": "Normalize Enrollment Event",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        500,
        320
      ]
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{$json.eventType}}",
        "rules": [
          {
            "operation": "equal",
            "value2": "lead.created"
          },
          {
            "operation": "equal",
            "value2": "worker.interested"
          },
          {
            "operation": "equal",
            "value2": "payment.confirmed"
          }
        ]
      },
      "id": "switch-event",
      "name": "Switch Event Type",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        760,
        320
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://graph.facebook.com/v20.0/{{$env.WHATSAPP_PHONE_NUMBER_ID}}/messages",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{$env.WHATSAPP_ACCESS_TOKEN}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"messaging_product\":\"whatsapp\",\"to\":\"{{$json.phoneNumber}}\",\"type\":\"text\",\"text\":{\"preview_url\":false,\"body\":\"Vanakkam {{$json.studentName}}. EV Technician training is now live on WhatsApp in Tamil. Reply INTERESTED to receive the \u20b9500 UPI enrollment link.\"}}"
      },
      "id": "send-lead-outreach",
      "name": "Send Lead Outreach",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1040,
        180
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://graph.facebook.com/v20.0/{{$env.WHATSAPP_PHONE_NUMBER_ID}}/messages",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{$env.WHATSAPP_ACCESS_TOKEN}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"messaging_product\":\"whatsapp\",\"to\":\"{{$json.phoneNumber}}\",\"type\":\"text\",\"text\":{\"preview_url\":true,\"body\":\"Vanakkam {{$json.studentName}}. Your {{$json.courseName}} seat is ready. Pay \u20b9{{$json.amountInInr}} here: {{$json.paymentLink}} and reply with your UTR to activate the learning group.\"}}"
      },
      "id": "send-upi-link",
      "name": "Send UPI Link",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1040,
        320
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://graph.facebook.com/v20.0/{{$env.WHATSAPP_PHONE_NUMBER_ID}}/messages",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{$env.WHATSAPP_ACCESS_TOKEN}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"messaging_product\":\"whatsapp\",\"to\":\"{{$json.phoneNumber}}\",\"type\":\"text\",\"text\":{\"preview_url\":true,\"body\":\"Payment confirmed for {{$json.studentName}}. Join the EV learning group here: {{$json.groupInviteLink}}. Daily Tamil lessons and evening quizzes start immediately.\"}}"
      },
      "id": "send-group-invite",
      "name": "Send Group Invite",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1040,
        460
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{$env.TELEGRAM_BOT_TOKEN}}/sendMessage",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"chat_id\":\"{{$env.TELEGRAM_CHAT_ID}}\",\"text\":\"Lead Finder: outreach sent to {{$json.studentName}} ({{$json.phoneNumber}}).\"}"
      },
      "id": "notify-telegram-lead",
      "name": "Notify Telegram Lead",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1320,
        180
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{$env.TELEGRAM_BOT_TOKEN}}/sendMessage",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"chat_id\":\"{{$env.TELEGRAM_CHAT_ID}}\",\"text\":\"Enrollment Agent: UPI link sent to {{$json.studentName}} ({{$json.phoneNumber}}).\"}"
      },
      "id": "notify-telegram-interest",
      "name": "Notify Telegram Interest",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1320,
        320
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{$env.TELEGRAM_BOT_TOKEN}}/sendMessage",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"chat_id\":\"{{$env.TELEGRAM_CHAT_ID}}\",\"text\":\"Enrollment Agent: payment confirmed and group invite sent to {{$json.studentName}} ({{$json.phoneNumber}}).\"}"
      },
      "id": "notify-telegram-payment",
      "name": "Notify Telegram Payment",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1320,
        460
      ]
    }
  ],
  "connections": {
    "Enrollment Event Webhook": {
      "main": [
        [
          {
            "node": "Normalize Enrollment Event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Enrollment Event": {
      "main": [
        [
          {
            "node": "Switch Event Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch Event Type": {
      "main": [
        [
          {
            "node": "Send Lead Outreach",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send UPI Link",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send Group Invite",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Lead Outreach": {
      "main": [
        [
          {
            "node": "Notify Telegram Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send UPI Link": {
      "main": [
        [
          {
            "node": "Notify Telegram Interest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Group Invite": {
      "main": [
        [
          {
            "node": "Notify Telegram Payment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1"
}