{
  "name": "04 - Weekly Report + Poll (رشد کانال)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 21 * * 5"
            }
          ]
        }
      },
      "id": "a4000000-0000-4000-8000-000000000001",
      "name": "Schedule Friday 21:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [-260, 0]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            { "id": "f1", "name": "api_base", "value": "https://YOUR-PROJECT.pages.dev", "type": "string" },
            { "id": "f2", "name": "api_key", "value": "PASTE_YOUR_API_KEY", "type": "string" },
            { "id": "f3", "name": "bot_token", "value": "PASTE_YOUR_BOT_TOKEN", "type": "string" },
            { "id": "f4", "name": "chat_id", "value": "@your_channel", "type": "string" }
          ]
        },
        "options": {}
      },
      "id": "a4000000-0000-4000-8000-000000000002",
      "name": "Config",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-60, 0]
    },
    {
      "parameters": {
        "url": "=https://api.telegram.org/bot{{ $json.bot_token }}/getChatMemberCount?chat_id={{ encodeURIComponent($json.chat_id) }}",
        "options": {}
      },
      "id": "a4000000-0000-4000-8000-000000000003",
      "name": "Get Member Count",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [160, 0],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('Config').item.json.api_base }}/api/log",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [{ "name": "x-api-key", "value": "={{ $('Config').item.json.api_key }}" }]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ kind: 'members', members_count: $json.result || 0 }) }}",
        "options": {}
      },
      "id": "a4000000-0000-4000-8000-000000000004",
      "name": "Save Member Count",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [380, 0]
    },
    {
      "parameters": {
        "url": "={{ $('Config').item.json.api_base }}/api/content/weekly",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [{ "name": "x-api-key", "value": "={{ $('Config').item.json.api_key }}" }]
        },
        "options": {}
      },
      "id": "a4000000-0000-4000-8000-000000000005",
      "name": "Get Weekly Report",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [600, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{ $('Config').item.json.bot_token }}/sendMessage",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ chat_id: $('Config').item.json.chat_id, text: $json.text, parse_mode: 'HTML', disable_web_page_preview: true }) }}",
        "options": {}
      },
      "id": "a4000000-0000-4000-8000-000000000006",
      "name": "Send Report",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [820, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{ $('Config').item.json.bot_token }}/sendPoll",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ chat_id: $('Config').item.json.chat_id, question: $('Get Weekly Report').item.json.poll.question, options: $('Get Weekly Report').item.json.poll.options, is_anonymous: true, allows_multiple_answers: false }) }}",
        "options": {}
      },
      "id": "a4000000-0000-4000-8000-000000000007",
      "name": "Send Poll",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1040, 0],
      "notes": "نظرسنجی = بالاترین نرخ تعامل در تلگرام و باعث دیده‌شدن کانال در Explore می‌شود."
    }
  ],
  "connections": {
    "Schedule Friday 21:00": { "main": [[{ "node": "Config", "type": "main", "index": 0 }]] },
    "Config": { "main": [[{ "node": "Get Member Count", "type": "main", "index": 0 }]] },
    "Get Member Count": { "main": [[{ "node": "Save Member Count", "type": "main", "index": 0 }]] },
    "Save Member Count": { "main": [[{ "node": "Get Weekly Report", "type": "main", "index": 0 }]] },
    "Get Weekly Report": { "main": [[{ "node": "Send Report", "type": "main", "index": 0 }]] },
    "Send Report": { "main": [[{ "node": "Send Poll", "type": "main", "index": 0 }]] }
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "Asia/Tehran",
    "saveExecutionProgress": true
  },
  "pinData": {}
}
