{
  "id": "CPeiiO2EfYX53YbE",
  "name": "Monitor competitor ad activity via Telegram using BrowserAct & Gemini",
  "tags": [],
  "nodes": [
    {
      "id": "03a69bc4-91c0-4a96-9f34-16b89d6a4559",
      "name": "Validate inputs",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -400,
        512
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "57d4a1fa-20d4-4029-91b3-7da67840900a",
      "name": "Structured Output",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        704,
        512
      ],
      "parameters": {
        "autoFix": true,
        "jsonSchemaExample": "{ \"TelegramText\": \"TelegramText\" }"
      },
      "typeVersion": 1.3
    },
    {
      "id": "e2c42ca2-3e22-4cf0-b706-f3a3b17e2aa5",
      "name": "Analyze user Input",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -400,
        304
      ],
      "parameters": {
        "text": "={{ $json.message.text }}",
        "options": {
          "systemMessage": "You are a precise data extraction engine.\n\nYour Task:\n1. Receive a user's natural language input (e.g., \"check ads for Higgsfield\" or \"spy on nike\").\n2. Extract the specific Company Name or Brand Name.\n3. Output the result in a strict JSON format.\n\nConstraints:\n- Do NOT output any conversational text, markdown, or explanations.\n- Do NOT output code blocks (like ```json). Just the raw JSON string.\n- If no company name is found, set \"company_name\" to null.\n\nOutput Structure:\nYou must output a single JSON object with this exact schema:\n{\n  \"company_name\": \"String\"\n}\n\nExamples:\nInput: \"check if higgsfield is running ads\"\nOutput: { \"company_name\": \"Higgsfield\" }\n\nInput: \"i want to see ads for Coca Cola\"\nOutput: { \"company_name\": \"Coca Cola\" }\n\nInput: \"hello\"\nOutput: { \"company_name\": null }"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "9d5af975-f526-4e0a-a76d-1dfd3a336bd6",
      "name": "Structured Output1",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -288,
        512
      ],
      "parameters": {
        "autoFix": true,
        "jsonSchemaExample": "{ \"company_name\": \"company_name\" }"
      },
      "typeVersion": 1.3
    },
    {
      "id": "dca8a02c-405c-4c7d-82da-556a7531a6e2",
      "name": "Send Message to User Chat",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1088,
        304
      ],
      "parameters": {
        "text": "={{ $json.output.TelegramText }}",
        "chatId": "=parameters.chatId=={{ $('User Sends Message to Bot').first().json.message.chat.id }} (Use Channel ID or Chat ID from the Telegram Trigger node)",
        "additionalFields": {
          "parse_mode": "HTML"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "2ed2ac7b-1a76-4214-9af5-cf250bb6e957",
      "name": "User Sends Message to Bot",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -576,
        304
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0bf6563c-1614-4fae-a96c-a6930d58ffc3",
      "name": "Scrape Ads from Meta and Google",
      "type": "n8n-nodes-browseract.browserAct",
      "position": [
        32,
        304
      ],
      "parameters": {
        "type": "WORKFLOW",
        "workflowId": "70626184596326140",
        "workflowConfig": {
          "value": {
            "input-Company": "={{ $json.output.company_name }}"
          },
          "schema": [
            {
              "id": "input-Facebook_Ads",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "description": "If left blank, the default value defined in BrowserAct will be used.",
              "displayName": "Facebook_Ads",
              "defaultMatch": true
            },
            {
              "id": "input-Company",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "description": "If left blank, the default value defined in BrowserAct will be used.",
              "displayName": "Company",
              "defaultMatch": true
            },
            {
              "id": "input-Google_ads",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "description": "If left blank, the default value defined in BrowserAct will be used.",
              "displayName": "Google_ads",
              "defaultMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "input-Company"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "open_incognito_mode": false
      },
      "credentials": {
        "browserActApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "16ed7f61-49a2-4339-92cf-97b99997c70c",
      "name": "Process Ad Data",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        576,
        304
      ],
      "parameters": {
        "text": "={{ $json.output.string }}",
        "options": {
          "systemMessage": "You are a Senior Marketing Analyst Bot.\n\nYour Task:\n1. Analyze the provided JSON data of competitor advertisements.\n2. Determine if the user should advertise now based on the activity volume and recency.\n3. Generate a formatted HTML message strictly following the template below.\n\nConstraints:\n- Output ONLY the HTML string. Do not use Markdown (no ** or ##).\n- Do not wrap the output in code blocks (no ```html).\n- Use ONLY these Telegram-supported tags: <b>, <i>, <code>, <a href=\"...\">.\n- Keep the total length under 3000 characters.\n\nAnalysis Logic:\n- Count the total number of ad objects in the input list.\n- Check \"total_active_time\". If multiple ads say \"hrs\" (e.g. 14 hrs), the status is \"Active & Scaling\".\n- If the list is empty, the status is \"Inactive\".\n- Identify the strongest \"Call to Action\" or \"Hook\" from the descriptions.\n\nVerdict Logic:\n- If ads are recent (< 24h) and high volume (> 3): Verdict is \"ADVERTISE NOW\".\n- If ads are old or low volume: Verdict is \"WAIT / MONITOR\".\n\nOutput Structure:\nYou must strictly follow this HTML template. Replace [Bracketed Info] with your analysis:\n\n<b>\ud83d\udea8 Competitor Intelligence: [Insert Company Name]</b>\n\n<b>\ud83d\udcca Activity Report</b>\n\u2022 <b>Ads Found:</b> <code>[Insert Count]</code>\n\u2022 <b>Status:</b> [Insert Status]\n\u2022 <b>Key Hook:</b> [Insert Main Topic, e.g., Black Friday]\n\n<b>\ud83d\udd25 Best Ad Copy Detected</b>\n<i>\"[Insert a short 1-sentence quote from the best ad]\"</i>\n\n<b>\ud83d\udca1 STRATEGIC VERDICT: [ADVERTISE NOW / WAIT]</b>\n[Insert 2 sentences explaining why. Example: They are spending heavily right now. You must compete.]\n\n---\n<i>Generated by Your AdSpy Bot</i>\n\nsend it to output using this JSON :\n{ \"TelegramText\": \"TelegramText\" }"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3
    },
    {
      "id": "080b7ff9-e6b8-4212-9006-e0a3f3656067",
      "name": "Gemini",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        576,
        528
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ceaeb7bf-e207-41a8-bc65-1596c3f1a59f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -592,
        -416
      ],
      "parameters": {
        "color": 6,
        "width": 624,
        "height": 368,
        "content": "@[youtube](ZV8ERteG_04)"
      },
      "typeVersion": 1
    },
    {
      "id": "5449d0fe-d629-4f3a-a4e1-910c9b425851",
      "name": "Documentation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -992,
        -416
      ],
      "parameters": {
        "width": 380,
        "height": 520,
        "content": "## \u26a1 Workflow Overview & Setup\n\n**Summary:** This automation allows users to monitor competitor ad activity on Meta and Google via Telegram, providing an AI-driven strategic verdict on whether to launch competing ads.\n\n### Requirements\n* **Credentials:** Telegram, BrowserAct, Google Gemini (PaLM).\n* **Mandatory:** BrowserAct API (Template: **Competitor Ad Activity Monitor**)\n\n### How to Use\n1. **Credentials:** Set up your Telegram Bot, BrowserAct, and Google Gemini credentials.\n2. **BrowserAct Template:** Ensure you have the **Competitor Ad Activity Monitor** template saved in your BrowserAct account.\n3. **Interaction:** Send a message to your bot like \"Check ads for [Company Name]\" to start the report generation.\n\n### Need Help?\n[How to Find Your BrowserAct API Key & Workflow ID](https://docs.browseract.com)\n[How to Connect n8n to BrowserAct](https://docs.browseract.com)\n[How to Use & Customize BrowserAct Templates](https://docs.browseract.com)"
      },
      "typeVersion": 1
    },
    {
      "id": "7e04c1d5-b08d-4242-9662-b63073d75149",
      "name": "Step 1 Explanation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -576,
        0
      ],
      "parameters": {
        "color": 7,
        "width": 796,
        "height": 124,
        "content": "### \ud83d\udd0d Step 1: Input & Extraction\n\nThe workflow triggers when a user sends a brand name via Telegram. An AI agent extracts the clean company name from natural language.BrowserAct  scrapes active ad counts, copy, and run durations."
      },
      "typeVersion": 1
    },
    {
      "id": "b6835f1c-d8b4-46ae-815a-67f39cd64386",
      "name": "Step 3 Explanation",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        480,
        144
      ],
      "parameters": {
        "color": 7,
        "width": 812,
        "height": 124,
        "content": "### \ud83d\udcca Step 3: Analysis & Report Delivery\n\nAI processes the raw data. It counts active ads, identifies the best creative hooks, and issues a final strategic verdict (ADVERTISE NOW vs. WAIT) based on competitor spending trends. The final intelligence report is formatted into clean HTML and sent directly back to the user's Telegram chat for immediate review."
      },
      "typeVersion": 1
    },
    {
      "id": "a2c75ac5-c271-4806-a03a-50c77ea78e82",
      "name": "Process Initialization Alert",
      "type": "n8n-nodes-base.telegram",
      "position": [
        32,
        160
      ],
      "parameters": {
        "text": "=Hello, ok i will look for {{ $json.output.company_name }} ads. i will be rigth back.",
        "chatId": "={{ $('User Sends Message to Bot').first().json.message.chat.id }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "27d0cf77-5ed2-4b8d-a48e-a9b0fa9d7e2e",
  "connections": {
    "Gemini": {
      "ai_languageModel": [
        [
          {
            "node": "Process Ad Data",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Structured Output",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Process Ad Data": {
      "main": [
        [
          {
            "node": "Send Message to User Chat",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate inputs": {
      "ai_languageModel": [
        [
          {
            "node": "Analyze user Input",
            "type": "ai_languageModel",
            "index": 0
          },
          {
            "node": "Structured Output1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output": {
      "ai_outputParser": [
        [
          {
            "node": "Process Ad Data",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Analyze user Input": {
      "main": [
        [
          {
            "node": "Scrape Ads from Meta and Google",
            "type": "main",
            "index": 0
          },
          {
            "node": "Process Initialization Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output1": {
      "ai_outputParser": [
        [
          {
            "node": "Analyze user Input",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "User Sends Message to Bot": {
      "main": [
        [
          {
            "node": "Analyze user Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scrape Ads from Meta and Google": {
      "main": [
        [
          {
            "node": "Process Ad Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}