{
  "id": "U4Fwm0qoedJIRzw4",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "MS_E_DAHAB",
  "tags": [],
  "nodes": [
    {
      "id": "a361f253-cd88-4694-bd75-40a69a5acaa3",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -16,
        16
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "596cc3db-a89b-4562-aec3-32cbff60c977",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        416,
        0
      ],
      "parameters": {
        "url": "https://edahabapp.com/",
        "options": {}
      },
      "retryOnFail": true,
      "typeVersion": 4.2
    },
    {
      "id": "7a2d2504-4e40-4996-8a70-abfa6994cefb",
      "name": "Send a text message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1040,
        0
      ],
      "parameters": {
        "text": "={{ $json.telegram_message }}",
        "chatId": "={{ $env.telegram_chat_id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "52200b7f-2e76-4907-9ed8-50cb921d8ce6",
      "name": "HTML",
      "type": "n8n-nodes-base.html",
      "position": [
        624,
        0
      ],
      "parameters": {
        "options": {},
        "operation": "extractHtmlContent",
        "extractionValues": {
          "values": [
            {
              "key": "gold_prices",
              "cssSelector": "section:first-of-type .grid div:first-child table",
              "returnValue": "html"
            },
            {
              "key": "currency_rates",
              "cssSelector": "section:first-of-type .grid div:nth-child(2) table",
              "returnValue": "html"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e2f5a0fd-d422-42ff-a393-74b553f408db",
      "name": "Code",
      "type": "n8n-nodes-base.code",
      "position": [
        832,
        0
      ],
      "parameters": {
        "jsCode": "// This code uses Regular Expressions and adds emojis and better formatting.\n\n// Helper function to get an emoji for a currency name\nfunction getCurrencyEmoji(currencyName) {\n  if (currencyName.includes('\u062f\u0648\u0644\u0627\u0631')) return '\ud83c\uddfa\ud83c\uddf8';\n  if (currencyName.includes('\u064a\u0648\u0631\u0648')) return '\ud83c\uddea\ud83c\uddfa';\n  if (currencyName.includes('\u0631\u064a\u0627\u0644')) return '\ud83c\uddf8\ud83c\udde6';\n  if (currencyName.includes('\u062f\u0631\u0647\u0645')) return '\ud83c\udde6\ud83c\uddea';\n  if (currencyName.includes('\u0627\u0633\u062a\u0631\u0644\u064a\u0646\u064a')) return '\ud83c\uddec\ud83c\udde7';\n  return '\ud83d\udcb0'; // A default emoji\n}\n\n// Helper function to remove all HTML tags from a string\nfunction cleanText(htmlString) {\n  if (!htmlString) return '';\n  return htmlString.replace(/<[^>]*>/g, '').trim();\n}\n\n\n// --- Main Script ---\nconst goldHtml = items[0].json.gold_prices;\nconst currencyHtml = items[0].json.currency_rates;\nlet messageLines = [];\n\n// --- 1. Process Gold Prices ---\nmessageLines.push(\"\ud83e\udd47 *\u0623\u0633\u0639\u0627\u0631 \u0627\u0644\u0630\u0647\u0628 \u0627\u0644\u064a\u0648\u0645 \u0641\u064a \u0645\u0635\u0631* \ud83e\udd47\");\nmessageLines.push(\"\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\");\n\nconst goldRows = goldHtml.match(/<tr.*?>.*?<\\/tr>/gs) || [];\n\nfor (const row of goldRows) {\n  const cells = row.match(/<td.*?>.*?<\\/td>/gs) || [];\n  \n  if (cells.length > 0) {\n    const type = cleanText(cells[0]);\n    let emoji = '\u2696\ufe0f';\n    if (type.includes('\u0627\u0644\u062c\u0646\u064a\u0647 \u0627\u0644\u0630\u0647\u0628')) emoji = '\ud83e\ude99';\n    if (type.includes('\u0627\u0644\u0639\u0627\u0644\u0645\u064a')) emoji = '\ud83c\udf0d';\n\n    if (cells.length > 2) {\n      const sellPrice = cleanText(cells[1]).replace(' \u062c\u0646\u064a\u0647', '');\n      const buyPrice = cleanText(cells[2]).replace(' \u062c\u0646\u064a\u0647', '');\n      messageLines.push(`${emoji} *${type}:* \u0634\u0631\u0627\u0621 \\`${buyPrice}\\` / \u0628\u064a\u0639 \\`${sellPrice}\\``);\n    } else if (cells.length === 2) {\n      const priceText = cleanText(cells[1]);\n      const price = priceText.replace(/[^0-9.]/g, ''); // Extract only numbers\n      const currency = priceText.includes('\u062f\u0648\u0644\u0627\u0631') ? '\u062f\u0648\u0644\u0627\u0631' : '\u062c\u0646\u064a\u0647';\n      messageLines.push(`${emoji} *${type}:* \\`${price}\\` ${currency}`);\n    }\n  }\n}\n\n// --- 2. Process Currency Rates ---\nmessageLines.push(\"\\n-----------------------------------\\n\");\nmessageLines.push(\"\ud83d\udcb8 *\u0623\u0633\u0639\u0627\u0631 \u0627\u0644\u0639\u0645\u0644\u0627\u062a (\u0627\u0644\u0633\u0648\u0642 \u0627\u0644\u0631\u0633\u0645\u064a)* \ud83d\udcb8\");\nmessageLines.push(\"\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\u3030\ufe0f\");\n\nconst currencyRows = currencyHtml.match(/<tr.*?>.*?<\\/tr>/gs) || [];\n\nfor (const row of currencyRows) {\n  const cells = row.match(/<td.*?>.*?<\\/td>/gs) || [];\n  \n  if (cells.length === 2) {\n    const currencyName = cleanText(cells[0]);\n    const currencyPrice = cleanText(cells[1]).replace(' \u062c\u0646\u064a\u0647', '');\n    const emoji = getCurrencyEmoji(currencyName);\n    messageLines.push(`${emoji} *${currencyName}:* \\`${currencyPrice}\\` \u062c\u0646\u064a\u0647`);\n  }\n}\n\n// --- 3. Add a Timestamp ---\nconst now = new Date();\nconst timeString = now.toLocaleTimeString('ar-EG', { timeZone: 'Africa/Cairo', hour: '2-digit', minute:'2-digit' });\nmessageLines.push(\"\\n`\" + `\u062a\u062d\u062f\u064a\u062b: ${timeString} \u0628\u062a\u0648\u0642\u064a\u062a \u0627\u0644\u0642\u0627\u0647\u0631\u0629` + \"`\");\n\nconst finalMessage = messageLines.join('\\n');\n\nreturn [{\n  json: {\n    telegram_message: finalMessage\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "7d09a941-bd9d-4202-941f-29bb239ea03f",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        192,
        16
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "91dddd01-0a73-4294-8dce-73b805499b12",
              "operator": {
                "type": "number",
                "operation": "gte"
              },
              "leftValue": "={{ $now.hour }}",
              "rightValue": 10
            },
            {
              "id": "1e107caf-af95-4750-ae8e-879d0706b4f0",
              "operator": {
                "type": "number",
                "operation": "lte"
              },
              "leftValue": "={{ $now.hour }}",
              "rightValue": 22
            }
          ]
        }
      },
      "typeVersion": 2.2
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "84f5a6ec-9ded-4f31-bb68-0fa8b75a8eb5",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "HTML",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}