{
  "name": "HR Daily Digest",
  "nodes": [
    {
      "id": "b1b2c3d4-1111-4111-8111-111111111101",
      "name": "Daily 8PM Cairo",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 18 * * *"
            }
          ]
        }
      }
    },
    {
      "id": "b1b2c3d4-2222-4222-8222-222222222202",
      "name": "Read Organized Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        240,
        0
      ],
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "YOUR_SPREADSHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "\u0627\u0644\u0648\u0638\u0627\u064a\u0641 \u0627\u0644\u0645\u0646\u0638\u0645\u0629",
          "mode": "name"
        },
        "filtersUI": {},
        "options": {}
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "id": "b1b2c3d4-3333-4333-8333-333333333303",
      "name": "Filter Today + Group",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        480,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const today = DateTime.now().setZone('Africa/Cairo').toFormat('yyyy-MM-dd');\n\nconst allRows = $input.all();\n\n// Filter rows added today\nconst todayRows = allRows.filter(row => {\n  const rowDate = (row.json['\u0627\u0644\u062a\u0627\u0631\u064a\u062e'] || '').toString().trim();\n  return rowDate === today;\n});\n\n// Group by field in fixed display order\nconst fieldOrder = [\n  'IT/\u062a\u0642\u0646\u064a\u0629',\n  '\u0645\u062d\u0627\u0633\u0628\u0629 \u0648\u0645\u0627\u0644\u064a\u0629',\n  '\u0645\u0628\u064a\u0639\u0627\u062a',\n  '\u0647\u0646\u062f\u0633\u0629',\n  '\u062a\u0633\u0648\u064a\u0642',\n  '\u0645\u0648\u0627\u0631\u062f \u0628\u0634\u0631\u064a\u0629',\n  '\u0637\u0628 \u0648\u0635\u062d\u0629',\n  '\u062a\u0639\u0644\u064a\u0645',\n  '\u0623\u062e\u0631\u0649'\n];\n\nconst groups = {};\nfor (const row of todayRows) {\n  const field = (row.json['\u0627\u0644\u0645\u062c\u0627\u0644'] || '\u0623\u062e\u0631\u0649').toString().trim();\n  if (!groups[field]) groups[field] = [];\n  groups[field].push(row.json);\n}\n\nreturn [{\n  json: {\n    today,\n    totalCount: todayRows.length,\n    groups,\n    fieldOrder,\n    hasJobs: todayRows.length > 0\n  }\n}];"
      }
    },
    {
      "id": "b1b2c3d4-4444-4444-8444-444444444404",
      "name": "Has Jobs Today?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        720,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "cond-0002-4002-8002-000000000002",
              "leftValue": "={{ $json.hasJobs }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "b1b2c3d4-5555-4555-8555-555555555505",
      "name": "Skip - No Jobs",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        960,
        80
      ],
      "parameters": {}
    },
    {
      "id": "b1b2c3d4-6666-4666-8666-666666666606",
      "name": "Format Arabic Message",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        960,
        -80
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const { today, groups, fieldOrder, totalCount } = $json;\n\n// Format date as DD/MM/YYYY\nconst parts = today.split('-');\nconst displayDate = `${parts[2]}/${parts[1]}/${parts[0]}`;\n\nconst lines = [];\nlines.push(`\u0648\u0638\u0627\u064a\u0641 \u0627\u0644\u0646\u0647\u0627\u0631\u062f\u0647 - ${displayDate}`);\nlines.push('');\n\nfor (const field of fieldOrder) {\n  const jobs = groups[field];\n  if (!jobs || jobs.length === 0) continue;\n\n  lines.push(`${field}:`);\n  for (const job of jobs) {\n    let line = `- ${job['\u0627\u0633\u0645 \u0627\u0644\u0634\u0631\u0643\u0629']} | ${job['\u0627\u0644\u0645\u0633\u0645\u0649 \u0627\u0644\u0648\u0638\u064a\u0641\u064a']} | ${job['\u0627\u0644\u0645\u062f\u064a\u0646\u0629']} | ${job['\u0646\u0648\u0639 \u0627\u0644\u0634\u063a\u0644']}`;\n    const salary = (job['\u0627\u0644\u0631\u0627\u062a\u0628'] || '').toString().trim();\n    if (salary) {\n      line += ` | \u0631\u0627\u062a\u0628: ${salary}`;\n    }\n    lines.push(line);\n  }\n  lines.push('');\n}\n\nlines.push(`\u0627\u0644\u0645\u062c\u0645\u0648\u0639: ${totalCount} \u0648\u0638\u064a\u0641\u0629 \u062c\u062f\u064a\u062f\u0629`);\n\nreturn [{ json: { message: lines.join('\\n') } }];"
      }
    },
    {
      "id": "b1b2c3d4-7777-4777-8777-777777777707",
      "name": "Send Daily Digest",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1200,
        -80
      ],
      "parameters": {
        "chatId": "YOUR_ADMIN_CHAT_ID",
        "text": "={{ $json.message }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Daily 8PM Cairo": {
      "main": [
        [
          {
            "node": "Read Organized Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read Organized Sheet": {
      "main": [
        [
          {
            "node": "Filter Today + Group",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Today + Group": {
      "main": [
        [
          {
            "node": "Has Jobs Today?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Jobs Today?": {
      "main": [
        [
          {
            "node": "Format Arabic Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Skip - No Jobs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Arabic Message": {
      "main": [
        [
          {
            "node": "Send Daily Digest",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": [
    {
      "name": "hr-service",
      "id": ""
    }
  ]
}