{
  "name": "Wekala — أتمتة التقارير",
  "nodes": [
    {
      "parameters": {
        "content": "## 📊 Wekala — أتمتة التقارير\n\nبيشتغل تلقائياً (شهرياً/أسبوعياً):\n1) **Schedule** بيشغّل الفلو في ميعاد ثابت.\n2) **Meta Insights (HTTP)** بيسحب أرقام الحملات.\n3) **تجهيز الملخص** بيرتّبها.\n4) بتتسجّل في **Google Sheet** + بيتبعت **إيميل** بالملخص.\n\n⚠️ اظبط: Ad Account ID + Access Token (استخدم Credentials مش hardcode)، والـ Sheet ID والإيميل.\n\n➕ Google Ads و TikTok: كرّر نود HTTP بنفس الطريقة بالـ endpoint الخاص بكل منصة.",
        "height": 300,
        "width": 440,
        "color": 5
      },
      "id": "05f66ff6-d752-4ab4-8493-20238b95d221",
      "name": "تعليمات",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -60,
        -40
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 9 1 * *"
            }
          ]
        }
      },
      "id": "1ba6a063-8460-46cc-bbab-2eca5e6572c8",
      "name": "جدولة (أول كل شهر 9 ص)",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        220,
        240
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://graph.facebook.com/v21.0/act_YOUR_AD_ACCOUNT_ID/insights",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "fields",
              "value": "spend,impressions,clicks,ctr,cpc,actions"
            },
            {
              "name": "date_preset",
              "value": "last_30d"
            },
            {
              "name": "access_token",
              "value": "YOUR_META_ACCESS_TOKEN"
            }
          ]
        },
        "options": {}
      },
      "id": "f4334753-56a9-499c-9d53-27a942a7f7c7",
      "name": "Meta Insights (HTTP)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        240
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "88318925-5304-4764-816f-e321eff94c1b",
              "name": "الفترة",
              "type": "string",
              "value": "=آخر 30 يوم"
            },
            {
              "id": "ac5a80dd-dc9c-4f1e-b146-9a52a740235e",
              "name": "الإنفاق",
              "type": "string",
              "value": "={{ $json.data[0].spend }}"
            },
            {
              "id": "07715470-bf8a-438e-8444-4a47ed7e984a",
              "name": "الظهور",
              "type": "string",
              "value": "={{ $json.data[0].impressions }}"
            },
            {
              "id": "02205a8e-f4db-413d-90a6-cbf76025a1e3",
              "name": "النقرات",
              "type": "string",
              "value": "={{ $json.data[0].clicks }}"
            },
            {
              "id": "c0837f09-e724-463b-ba80-47265c1ed5db",
              "name": "CTR",
              "type": "string",
              "value": "={{ $json.data[0].ctr }}"
            }
          ]
        },
        "options": {}
      },
      "id": "18289cb8-0514-4238-bf0a-c470234ae115",
      "name": "تجهيز الملخص",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        680,
        240
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "YOUR_GOOGLE_SHEET_ID",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "Reports",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": []
        },
        "options": {}
      },
      "id": "6933a9ef-9ad7-458a-91e6-20c4a99dc5e7",
      "name": "حفظ التقرير في Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        920,
        140
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "send",
        "sendTo": "team@wekalaaa.com",
        "subject": "=تقرير أداء الحملات — {{ $json['الفترة'] }}",
        "message": "=📊 ملخص الأداء:\n\nالإنفاق: {{ $json['الإنفاق'] }}\nالظهور: {{ $json['الظهور'] }}\nالنقرات: {{ $json['النقرات'] }}\nCTR: {{ $json['CTR'] }}\n\n— Wekala",
        "options": {}
      },
      "id": "ea276925-26db-4563-8fe6-0de15b2dd21c",
      "name": "إرسال إيميل الملخص",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        920,
        340
      ]
    }
  ],
  "connections": {
    "جدولة (أول كل شهر 9 ص)": {
      "main": [
        [
          {
            "node": "Meta Insights (HTTP)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Meta Insights (HTTP)": {
      "main": [
        [
          {
            "node": "تجهيز الملخص",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "تجهيز الملخص": {
      "main": [
        [
          {
            "node": "حفظ التقرير في Sheet",
            "type": "main",
            "index": 0
          },
          {
            "node": "إرسال إيميل الملخص",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}