8
n8n 中文网amn8n.com

MS_E_DAHAB

中级

这是一个Crypto Trading领域的自动化工作流,包含 6 个节点。主要使用 If, Code, Html, Telegram, HttpRequest 等节点。 使用Telegram通知监控埃及黄金和货币价格

前置要求
  • Telegram Bot Token
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "U4Fwm0qoedJIRzw4",
  "meta": {
    "instanceId": "c92a0c76586da37fb3ac600956b62e842bfa4bd5f52acc7feb4e8a6e75ca1381",
    "templateCredsSetupCompleted": true
  },
  "name": "MS_E_DAHAB",
  "tags": [],
  "nodes": [
    {
      "id": "a361f253-cd88-4694-bd75-40a69a5acaa3",
      "name": "定时触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -16,
        16
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "596cc3db-a89b-4562-aec3-32cbff60c977",
      "name": "HTTP 请求",
      "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": "发送短信",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1040,
        0
      ],
      "webhookId": "73040087-38b1-420d-af03-1daf30e79342",
      "parameters": {
        "text": "={{ $json.telegram_message }}",
        "chatId": "={{ $env.telegram_chat_id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "OymlVCuTPYhVa2B9",
          "name": "Telegram account"
        }
      },
      "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": "代码",
      "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('دولار')) return '🇺🇸';\n  if (currencyName.includes('يورو')) return '🇪🇺';\n  if (currencyName.includes('ريال')) return '🇸🇦';\n  if (currencyName.includes('درهم')) return '🇦🇪';\n  if (currencyName.includes('استرليني')) return '🇬🇧';\n  return '💰'; // 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(\"🥇 *أسعار الذهب اليوم في مصر* 🥇\");\nmessageLines.push(\"〰️〰️〰️〰️〰️〰️〰️〰️〰️〰️〰️\");\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 = '⚖️';\n    if (type.includes('الجنيه الذهب')) emoji = '🪙';\n    if (type.includes('العالمي')) emoji = '🌍';\n\n    if (cells.length > 2) {\n      const sellPrice = cleanText(cells[1]).replace(' جنيه', '');\n      const buyPrice = cleanText(cells[2]).replace(' جنيه', '');\n      messageLines.push(`${emoji} *${type}:* شراء \\`${buyPrice}\\` / بيع \\`${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('دولار') ? 'دولار' : 'جنيه';\n      messageLines.push(`${emoji} *${type}:* \\`${price}\\` ${currency}`);\n    }\n  }\n}\n\n// --- 2. Process Currency Rates ---\nmessageLines.push(\"\\n-----------------------------------\\n\");\nmessageLines.push(\"💸 *أسعار العملات (السوق الرسمي)* 💸\");\nmessageLines.push(\"〰️〰️〰️〰️〰️〰️〰️〰️〰️〰️〰️\");\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(' جنيه', '');\n    const emoji = getCurrencyEmoji(currencyName);\n    messageLines.push(`${emoji} *${currencyName}:* \\`${currencyPrice}\\` جنيه`);\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`\" + `تحديث: ${timeString} بتوقيت القاهرة` + \"`\");\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": "条件判断",
      "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,
  "pinData": {},
  "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
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 加密货币交易

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量6
分类1
节点类型6
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流