{
  "name": "Config Form Workflow",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "7951ec37-23f7-418d-adb2-23714ba6a723",
        "options": {
          "responseMode": "responseNode"
        }
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        320,
        240
      ],
      "id": "config-webhook-main",
      "name": "Config Webhook"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "condition-check-employee",
              "leftValue": "={{ $json.body.employeeName }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        540,
        240
      ],
      "id": "check-employee-exists",
      "name": "Check Employee Exists"
    },
    {
      "parameters": {
        "jsCode": "for (const item of $input.all()) {\n  const configDate = item.json.body.configDate || \"\";\n  // Format date for display\n  const dateObj = new Date(configDate);\n  item.json.formattedDate = dateObj.toLocaleDateString('ar-EG');\n  item.json.formattedTime = dateObj.toLocaleTimeString('ar-EG', { hour: '2-digit', minute: '2-digit' });\n  item.json.dateOnly = configDate.substring(0, 10);\n}\nreturn $input.all();"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        760,
        140
      ],
      "id": "format-date",
      "name": "Format Date"
    },
    {
      "parameters": {
        "mode": "raw",
        "jsonOutput": "={\n  \"message\": \"\u062a\u0648\u062c\u064a\u0647 \u062c\u062f\u064a\u062f \u2705    \u0627\u0644\u0637\u0627\u0644\u0628: {{ $('Config Webhook').item.json.body.studentName }}    \u0627\u0644\u0645\u0648\u0638\u0641: {{ $('Config Webhook').item.json.body.employeeName }}    \u0627\u0644\u062a\u0627\u0631\u064a\u062e: {{ $json.formattedDate }}    \u0627\u0644\u0648\u0642\u062a: {{ $json.formattedTime }}\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        980,
        140
      ],
      "id": "prepare-message",
      "name": "Prepare WhatsApp Message"
    },
    {
      "parameters": {
        "jsCode": "for (const item of $input.all()) {\n  let val = item.json.message || \"\";\n  // Replace 4 spaces with newline for WhatsApp formatting\n  val = val.replace(/ {4}/g, \"\\n\");\n  item.json.formattedMessage = val;\n}\nreturn $input.all();"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1200,
        140
      ],
      "id": "format-message",
      "name": "Format Message"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.WASSENGER_API_URL }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            },
            {
              "name": "Token",
              "value": "={{ $env.WASSENGER_API_TOKEN }}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "group",
              "value": "={{ $env.WASSENGER_GROUP_ID }}"
            },
            {
              "name": "message",
              "value": "={{ $json.formattedMessage }}"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1420,
        140
      ],
      "id": "send-whatsapp",
      "name": "Send WhatsApp to Group"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"sendmessage\": \"true\", \"textdata\": \"\u062a\u0645 \u0625\u0631\u0633\u0627\u0644 \u0627\u0644\u062a\u0648\u062c\u064a\u0647 \u0628\u0646\u062c\u0627\u062d\" }",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1640,
        140
      ],
      "id": "respond-success",
      "name": "Respond Success"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"sendmessage\": \"errorvalue\", \"textdata\": \"\u064a\u0631\u062c\u0649 \u0625\u062f\u062e\u0627\u0644 \u0631\u0642\u0645 \u0627\u0644\u0647\u0627\u062a\u0641\" }",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        760,
        340
      ],
      "id": "respond-need-phone",
      "name": "Respond Need Phone"
    }
  ],
  "connections": {
    "Config Webhook": {
      "main": [
        [
          {
            "node": "Check Employee Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Employee Exists": {
      "main": [
        [
          {
            "node": "Format Date",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond Need Phone",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Date": {
      "main": [
        [
          {
            "node": "Prepare WhatsApp Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare WhatsApp Message": {
      "main": [
        [
          {
            "node": "Format Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Message": {
      "main": [
        [
          {
            "node": "Send WhatsApp to Group",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send WhatsApp to Group": {
      "main": [
        [
          {
            "node": "Respond Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true
  }
}