{
  "id": "k2FvKOkV5UgBEnCu",
  "name": "Financial Insight Automation: Market Cap to Telegram via Bright Data",
  "tags": [],
  "nodes": [
    {
      "id": "7cebf294-ed28-4cce-935f-8182c953aa5d",
      "name": "\ud83d\udfe9 Form Trigger",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -1440,
        16
      ],
      "parameters": {
        "options": {},
        "formTitle": "Yahoo",
        "formFields": {
          "values": [
            {
              "fieldLabel": "keyword"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "21b115c8-d3a7-4c6e-b3af-aab2e2c7f7d1",
      "name": "\ud83d\ude80 Trigger Scraping1 (HTTP Request to Bright Data)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1184,
        16
      ],
      "parameters": {
        "url": "https://api.brightdata.com/datasets/v3/trigger",
        "method": "POST",
        "options": {},
        "jsonBody": "=[\n  {\n    \"keyword\": \"{{ $json.keyword }}\"\n  } \n]",
        "sendBody": true,
        "sendQuery": true,
        "sendHeaders": true,
        "specifyBody": "json",
        "queryParameters": {
          "parameters": [
            {
              "name": "dataset_id",
              "value": "gd_lmrpz3vxmz972ghd7"
            },
            {
              "name": "include_errors",
              "value": "true"
            },
            {
              "name": "type",
              "value": "discover_new"
            },
            {
              "name": "discover_by",
              "value": "keyword"
            },
            {
              "name": "limit_per_input",
              "value": "2"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2,
      "alwaysOutputData": true
    },
    {
      "id": "75b8a695-9ad8-4d55-8cee-e6ebfda0defd",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1488,
        -144
      ],
      "parameters": {
        "color": 7,
        "width": 448,
        "height": 368,
        "content": "\ud83d\udfe9 Form Trigger (On form submission1)\n\u27a4 User form se keyword deta hai (e.g. \"AI\", \"Crypto\", \"MSFT\")\n\n\ud83d\ude80 Trigger Scraping1 (HTTP Request to Bright Data)\n\u27a4 Bright Data API ko call karta hai:\n\u27a4 discover_by: keyword, type: discover_new\n\u27a4 Dataset ID: gd_lmrpz3vxmz972ghd7"
      },
      "typeVersion": 1
    },
    {
      "id": "db304f8b-91e1-4d33-acc9-0ba8351160da",
      "name": "\ud83d\udd50 Wait 1 minute1",
      "type": "n8n-nodes-base.wait",
      "position": [
        -720,
        16
      ],
      "parameters": {
        "unit": "minutes",
        "amount": 1
      },
      "typeVersion": 1.1
    },
    {
      "id": "c0a0422f-a712-4be9-b46d-c35e6b5956ce",
      "name": "\ud83d\udfe1 Check Delivery Status of Snap ID1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -960,
        16
      ],
      "parameters": {
        "url": "=https://api.brightdata.com/datasets/v3/progress/{{ $json.snapshot_id }}",
        "options": {},
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2,
      "alwaysOutputData": true
    },
    {
      "id": "a23cf845-6bff-4a40-a87f-5d0bac918acc",
      "name": "\ud83d\udfe2 Check Final Status",
      "type": "n8n-nodes-base.if",
      "position": [
        -480,
        16
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "35ed620d-b5d5-4e97-bcc5-52b283d85616",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "ready"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "4d719ca5-ae7f-44b2-8b63-ed8a729ebbbb",
      "name": "\ud83d\udd3d final data given (Snapshot Fetch)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -240,
        0
      ],
      "parameters": {
        "url": "=https://api.brightdata.com/datasets/v3/snapshot/{{ $json.snapshot_id }}",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "format",
              "value": "json"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer YOUR_TOKEN_HERE"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "6efc936b-cfa4-431f-81a0-fd6536bd3072",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1008,
        -240
      ],
      "parameters": {
        "color": 3,
        "width": 688,
        "height": 464,
        "content": "\u23f3 Zone 2: Monitor & Fetch Results\n(Sticky Name: \u23f1\ufe0f Scraping Monitor & Result Pull)\n\nIncludes:\n\nWait Node \u2013 1 minute delay for job completion\n\nStatus Check Node \u2013 Check if status == \"ready\"\n\nIF Node \u2013 Loop or continue\n\nSnapshot API \u2013 Pull final result"
      },
      "typeVersion": 1
    },
    {
      "id": "438a38f6-c401-4b75-94c6-e15992a97e76",
      "name": "\ud83d\udcca Filtered Output & Save to Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -16,
        0
      ],
      "parameters": {
        "columns": {
          "value": {
            "ask": "={{ $json.ask }}",
            "bid": "={{ $json.bid }}",
            "eps": "={{ $json.eps }}",
            "url": "={{ $json.url }}",
            "beta": "={{ $json.pe_ratio }}",
            "name": "={{ $json.name }}",
            "open": "={{ $json.open }}",
            "input": "={{ $json.input }}",
            "volume": "={{ $json.volume }}",
            "similar": "={{ $json.similar }}",
            "summary": "={{ $json.summary }}",
            "currency": "={{ $json.currency }}",
            "exchange": "={{ $json.exchange }}",
            "day_range": "={{ $json.day_range }}",
            "eps_trend": "={{ $json.eps_trend }}",
            "timestamp": "={{ $json.timestamp }}",
            "avg_volume": "={{ $json.avg_volume }}",
            "company_id": "={{ $json.company_id }}",
            "financials": "={{ $json.financials }}",
            "market_cap": "={{ $json.market_cap }}",
            "target_est": "={{ $json.target_est }}",
            "week_range": "={{ $json.week_range }}",
            "entity_type": "={{ $json.entity_type }}",
            "recent_news": "={{ $json.recent_news }}",
            "stock_ticker": "={{ $json.stock_ticker }}",
            "top_analysts": "={{ $json.top_analysts }}",
            "closing_price": "={{ $json.closing_price }}",
            "earnings_date": "={{ $json.earnings_date }}",
            "eps_revisions": "={{ $json.eps_revisions }}",
            "dividend_yield": "={{ $json.dividend_yield }}",
            "previous_close": "={{ $json.previous_close }}",
            "discovery_input": "={{ $json.discovery_input }}",
            "earnings_history": "={{ $json.earnings_history }}",
            "growth_estimates": "={{ $json.growth_estimates }}",
            "revenue_estimate": "={{ $json.revenue_estimate }}",
            "earnings_estimate": "={{ $json.earnings_estimate }}",
            "people_also_watch": "={{ $json.people_also_watch }}",
            "fanacials_currency": "={{ $json.fanacials_currency }}",
            "stock_market_index": "={{ $json.stock_market_index }}",
            "analyst_price_target": "={{ $json.analyst_price_target }}",
            "financials_quarterly": "={{ $json.financials_quarterly }}",
            "company_profile_phone": "={{ $json.company_profile_phone }}",
            "company_profile_sector": "={{ $json.company_profile_sector }}",
            "company_profile_address": "={{ $json.company_profile_address }}",
            "company_profile_website": "={{ $json.company_profile_website }}",
            "upgrades_and_downgrades": "={{ $json.upgrades_and_downgrades }}",
            "company_profile_industry": "={{ $json.company_profile_industry }}",
            "company_profile_employees": "={{ $json.company_profile_key_executives }}",
            "company_profile_description": "={{ $json.company_profile_description }}",
            "company_profile_key_executives": "={{ $json.company_profile_key_executives }}"
          },
          "schema": [
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": []
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": "=https://docs.google.com/spreadsheets/d/YOUR_SHEET_ID/edit?gid=0#gid=0"
        }
      },
      "credentials": {},
      "typeVersion": 4.6
    },
    {
      "id": "eb1997f3-3a09-417b-9ea6-86861ec5c1df",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -288,
        -256
      ],
      "parameters": {
        "color": 4,
        "width": 432,
        "height": 480,
        "content": "\ud83d\udcca Zone 3: Filter & Output\n(Sticky Name: \ud83d\udcca Filtered Output & Save to Sheet)\n\nIncludes:\n\nOptional IF Node \u2013 Market Cap > $1B\n\nCode Node \u2013 Format complex arrays to human readable\n\nGoogle Sheets Node \u2013 Append data to final sheet\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "87619346-06ed-4311-a7e0-bcb82f554aca",
      "name": "\ud83e\uddee Generate Chart Payload",
      "type": "n8n-nodes-base.code",
      "position": [
        240,
        0
      ],
      "parameters": {
        "jsCode": "const itemsOut = [];\n\nconst labels = [];\nconst data = [];\n\nfor (const item of items) {\n  const name = item.json.name;\n  let cap = item.json.market_cap;\n  if (cap === undefined || cap === null) cap = \"0\";\n  cap = String(cap);\n\n  let value = 0;\n  if (cap.includes(\"T\")) value = parseFloat(cap) * 1e12;\n  else if (cap.includes(\"B\")) value = parseFloat(cap) * 1e9;\n  else if (cap.includes(\"M\")) value = parseFloat(cap) * 1e6;\n  else value = parseFloat(cap);\n\n  labels.push(name);\n  data.push(Math.round(value / 1e9));\n}\n\nconst chartPayload = {\n  type: 'bar',\n  data: {\n    labels,\n    datasets: [{\n      label: 'Market Cap (in Billion $)',\n      data,\n      backgroundColor: [\n        'rgba(75, 192, 192, 0.8)',\n        'rgba(153, 102, 255, 0.8)',\n        'rgba(255, 159, 64, 0.8)',\n        'rgba(255, 99, 132, 0.8)',\n        'rgba(54, 162, 235, 0.8)',\n        'rgba(201, 203, 207, 0.8)'\n      ],\n      borderColor: 'rgba(0,0,0,0.1)',\n      borderWidth: 1\n    }]\n  },\n  options: {\n    indexAxis: 'y',\n    responsive: true,\n    plugins: {\n      legend: {\n        display: false\n      },\n      title: {\n        display: true,\n        text: '\ud83d\udcca Company Market Cap Overview',\n        font: {\n          size: 20\n        },\n        padding: {\n          top: 10,\n          bottom: 20\n        }\n      },\n      tooltip: {\n        callbacks: {\n          label: function(context) {\n            return context.dataset.label + ': $' + context.raw + 'B';\n          }\n        }\n      }\n    },\n    scales: {\n      x: {\n        title: {\n          display: true,\n          text: 'Market Cap (in Billions $)'\n        },\n        grid: {\n          display: true\n        }\n      },\n      y: {\n        ticks: {\n          font: {\n            size: 12\n          }\n        }\n      }\n    }\n  }\n};\n\nitemsOut.push({ json: { chart: chartPayload } });\nreturn itemsOut;"
      },
      "typeVersion": 2
    },
    {
      "id": "a4c79ae7-ef35-4509-91f5-71107fcfee20",
      "name": "\ud83c\udf10 Generate PNG from Chart",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        448,
        0
      ],
      "parameters": {
        "url": "=https://quickchart.io/chart?c={{ JSON.stringify($json.chart) }}",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "405f8c35-7747-442b-a14f-898a2b366d0e",
      "name": "\ud83d\udce4 Send Chart on Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        656,
        0
      ],
      "parameters": {
        "chatId": "YOUR_TELEGRAM_CHAT_ID",
        "operation": "sendPhoto",
        "binaryData": true,
        "additionalFields": {}
      },
      "credentials": {},
      "typeVersion": 1.2
    },
    {
      "id": "01b96865-6ae1-43d8-962d-2a7141f9254f",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        208,
        -256
      ],
      "parameters": {
        "width": 624,
        "height": 480,
        "content": "1.\ud83e\uddee Generate Chart Payload (Code Node)\nPrepare chart data (labels + values) for market cap in billions using QuickChart format.\n\n2.\ud83c\udf10 Generate PNG from Chart (HTTP Request Node)\nPurpose: Use QuickChart.io API to generate PNG image from chart JSON.\n\n3.\ud83d\udce4 Send Chart on Telegram (Telegram Node)\nPurpose: Send chart image with caption to client/group."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "514d9f62-1953-40f2-bf5d-9b00b95ded68",
  "connections": {
    "\ud83d\udfe9 Form Trigger": {
      "main": [
        [
          {
            "node": "\ud83d\ude80 Trigger Scraping1 (HTTP Request to Bright Data)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udd50 Wait 1 minute1": {
      "main": [
        [
          {
            "node": "\ud83d\udfe2 Check Final Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udfe2 Check Final Status": {
      "main": [
        [
          {
            "node": "\ud83d\udd3d final data given (Snapshot Fetch)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "\ud83d\udfe1 Check Delivery Status of Snap ID1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83e\uddee Generate Chart Payload": {
      "main": [
        [
          {
            "node": "\ud83c\udf10 Generate PNG from Chart",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83c\udf10 Generate PNG from Chart": {
      "main": [
        [
          {
            "node": "\ud83d\udce4 Send Chart on Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udcca Filtered Output & Save to Sheet": {
      "main": [
        [
          {
            "node": "\ud83e\uddee Generate Chart Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udd3d final data given (Snapshot Fetch)": {
      "main": [
        [
          {
            "node": "\ud83d\udcca Filtered Output & Save to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\udfe1 Check Delivery Status of Snap ID1": {
      "main": [
        [
          {
            "node": "\ud83d\udd50 Wait 1 minute1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\ud83d\ude80 Trigger Scraping1 (HTTP Request to Bright Data)": {
      "main": [
        [
          {
            "node": "\ud83d\udfe1 Check Delivery Status of Snap ID1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}