{
  "name": "03 - Daily Song (آهنگ روز)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 19 * * *"
            }
          ]
        }
      },
      "id": "a3000000-0000-4000-8000-000000000001",
      "name": "Schedule 19: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": "a3000000-0000-4000-8000-000000000002",
      "name": "Config",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [-60, 0],
      "notes": "فقط این نود را پر کنید."
    },
    {
      "parameters": {
        "url": "={{ $json.api_base }}/api/content/song",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [{ "name": "x-api-key", "value": "={{ $json.api_key }}" }]
        },
        "options": {}
      },
      "id": "a3000000-0000-4000-8000-000000000003",
      "name": "Get Song Of The Day",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [160, 0]
    },
    {
      "parameters": {
        "conditions": {
          "options": { "caseSensitive": true, "leftValue": "", "typeValidation": "loose", "version": 2 },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.has_audio }}",
              "rightValue": "",
              "operator": { "type": "boolean", "operation": "true", "singleValue": true }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "id": "a3000000-0000-4000-8000-000000000004",
      "name": "Has Audio?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [380, 0]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{ $('Config').item.json.bot_token }}/sendAudio",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ chat_id: $('Config').item.json.chat_id, audio: $json.file_id || $json.audio_url, title: $json.title, performer: $json.artist, caption: $json.caption, parse_mode: 'HTML' }) }}",
        "options": {}
      },
      "id": "a3000000-0000-4000-8000-000000000005",
      "name": "Send Audio",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [600, -120]
    },
    {
      "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.bot_token ? $('Config').item.json.chat_id : '', text: '⚠️ آهنگ امروز فایل صوتی ندارد:\\n' + $json.title + ' — ' + $json.artist + '\\nلطفاً در پنل مدیریت file_id یا لینک mp3 اضافه کنید.', parse_mode: 'HTML' }) }}",
        "options": {}
      },
      "id": "a3000000-0000-4000-8000-000000000006",
      "name": "Notify Missing File",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [600, 120],
      "notes": "این پیام هشدار است. بهتر است chat_id را روی آیدی شخصی خودتان بگذارید نه کانال."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{ $('Config').item.json.bot_token }}/pinChatMessage",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ chat_id: $('Config').item.json.chat_id, message_id: $json.result.message_id, disable_notification: true }) }}",
        "options": {}
      },
      "id": "a3000000-0000-4000-8000-000000000007",
      "name": "Pin Message",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [820, -120],
      "onError": "continueRegularOutput",
      "notes": "سنجاق کردن آهنگ روز = دیده‌شدن بیشتر. اگر بات ادمین با دسترسی pin نباشد، خطا نادیده گرفته می‌شود."
    },
    {
      "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: 'song', ref_id: $('Get Song Of The Day').item.json.song_id, message_id: $('Send Audio').item.json.result.message_id, chat_id: $('Config').item.json.chat_id, file_id: $('Send Audio').item.json.result.audio ? $('Send Audio').item.json.result.audio.file_id : null, caption: $('Get Song Of The Day').item.json.caption }) }}",
        "options": {}
      },
      "id": "a3000000-0000-4000-8000-000000000008",
      "name": "Log + Save file_id",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [1040, -120],
      "notes": "بار اول که آهنگ از لینک mp3 ارسال شود، تلگرام یک file_id می‌دهد و اینجا ذخیره می‌شود؛ دفعه‌های بعد بدون آپلود ارسال می‌شود."
    }
  ],
  "connections": {
    "Schedule 19:00": { "main": [[{ "node": "Config", "type": "main", "index": 0 }]] },
    "Config": { "main": [[{ "node": "Get Song Of The Day", "type": "main", "index": 0 }]] },
    "Get Song Of The Day": { "main": [[{ "node": "Has Audio?", "type": "main", "index": 0 }]] },
    "Has Audio?": {
      "main": [
        [{ "node": "Send Audio", "type": "main", "index": 0 }],
        [{ "node": "Notify Missing File", "type": "main", "index": 0 }]
      ]
    },
    "Send Audio": { "main": [[{ "node": "Pin Message", "type": "main", "index": 0 }]] },
    "Pin Message": { "main": [[{ "node": "Log + Save file_id", "type": "main", "index": 0 }]] }
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "Asia/Tehran",
    "saveExecutionProgress": true
  },
  "pinData": {}
}
