{
  "id": "jn6Sgk2HcKiQKW0s",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Automate AI News Filtering with Keywords to Telegram",
  "tags": [],
  "nodes": [
    {
      "id": "c6e3a4a0-5ad5-4112-b31f-5fe4778e6166",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        416,
        64
      ],
      "parameters": {
        "unit": "minutes"
      },
      "typeVersion": 1.1
    },
    {
      "id": "18832f60-9fb3-4cec-ba87-781dd68bfcde",
      "name": "Wait1",
      "type": "n8n-nodes-base.wait",
      "position": [
        -128,
        64
      ],
      "parameters": {
        "unit": "minutes",
        "amount": 1
      },
      "typeVersion": 1.1
    },
    {
      "id": "fdc9f1cf-45ff-4264-885f-ccf84593244e",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        928,
        -32
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"Matched_News\": [\n    {\n      \"Headline\": \"<String>\",\n      \"Pic\": \"<String>\",\n      \"Url\": \"<String>\"\n    }\n  ]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "f5977d48-28d1-4fa5-adcb-d15a1d735a3e",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -624,
        -192
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7df1a8af-2829-41c8-9b5d-6b295a3be150",
      "name": "Sticky Note-Intro",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1232,
        -416
      ],
      "parameters": {
        "width": 592,
        "height": 424,
        "content": "## Try It Out!\n### This n8n template automates news content marketing by scraping news and sending relevant articles to Telegram using an AI Agent.\n\n### How it works\n* The workflow is triggered automatically on a schedule.\n* It uses an **HTTP Request** node to start a web scraping task with the **BrowserAct** API to collect the latest news.\n* A series of **If** and **Wait** nodes monitor the scraping job until it's finished.\n* An **AI Agent** node, powered by **Google Gemini**, processes the headlines and filters the news based on a list of keywords you define.\n* A **Code** node then formats the AI's output into a clean format.\n* The final news articles are sent as rich media messages to **Telegram**, including the headline, a picture, and a link.\n\n### Requirements\n* **BrowserAct** API account for web scraping\n* **Gemini** account for the AI Agent\n* **BrowserAct** **\u201cNews Content Marketing Automation\u201d** Template\n* **Telegram** credentials for sending messages\n\n### Need Help?\nJoin the **BrowserAct** [Discord](https://discord.com/invite/UpnCKd7GaU) or Visit Our [Blog](https://www.browseract.com/blog)!\n"
      },
      "typeVersion": 1
    },
    {
      "id": "254977ab-b357-46b9-b802-bd467faa3bf1",
      "name": "Sticky Note-Scraping",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -384,
        -416
      ],
      "parameters": {
        "color": 5,
        "width": 480,
        "height": 180,
        "content": "## 1. Trigger the News Scraper\n\nThis workflow runs on a set schedule to automatically trigger a web scraping task via the BrowserAct API. This allows you to continuously collect up-to-date news data.\n\n### Don't forget to add your BrowserAct Workflow ID. "
      },
      "typeVersion": 1
    },
    {
      "id": "cea82e48-0885-4791-b9ad-ba376541e4ca",
      "name": "Sticky Note-Wait",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        112,
        -416
      ],
      "parameters": {
        "color": 5,
        "width": 496,
        "height": 180,
        "content": "## 2. Wait for Scraping to Finish\n\nThese nodes check the status of the scraping task. The `If` node determines if the task is complete. If it's still running, the `Wait` node pauses the workflow for a set period before retrying to check the status."
      },
      "typeVersion": 1
    },
    {
      "id": "fedbec03-948e-44b5-b39b-919b85ba450b",
      "name": "Sticky Note-AI",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        624,
        -416
      ],
      "parameters": {
        "color": 4,
        "width": 496,
        "height": 176,
        "content": "## 3. Use AI to Filter News by Keywords\n\nThis node uses an AI Agent to filter the scraped news articles. It checks each article headline against your specified keywords to find the most relevant content. It's configured with a **Structured Output Parser** to ensure the results are always in the correct format.\n\n### Don't forget to Connect Your Gemini."
      },
      "typeVersion": 1
    },
    {
      "id": "c0ad9350-4281-48f7-adb0-0ae07bf9e733",
      "name": "Sticky Note-Notifications",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        624,
        288
      ],
      "parameters": {
        "color": 3,
        "width": 496,
        "height": 164,
        "content": "## 4. Send News to Telegram\n\nThe scraped data is sometimes hard to read. A **Code** node is used here to transform the AI's output into a more readable format. The **Telegram** node then sends the final, filtered news articles directly to you as a photo message with a caption and link.\n\n### Don't forget to Config your Telegram Api & Telegram Channel ID. "
      },
      "typeVersion": 1
    },
    {
      "id": "321d6bf9-303f-43a2-a559-4c1bbff5e543",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -384,
        -224
      ],
      "parameters": {
        "color": 5,
        "width": 480,
        "height": 496,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "85c6eae6-b867-41d0-9028-a5f5664b0956",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        624,
        -224
      ],
      "parameters": {
        "color": 4,
        "width": 496,
        "height": 304,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "bff1aca3-719f-4328-8d4d-2d95583fa413",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        624,
        96
      ],
      "parameters": {
        "color": 3,
        "width": 496,
        "height": 176,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "c27989d0-7f1b-4a42-8dc1-7ac56e6f0fbd",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        112,
        -224
      ],
      "parameters": {
        "color": 5,
        "width": 496,
        "height": 496,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "416d315c-0554-40ff-a7af-9a4e73f4fd05",
      "name": "Sticky Note-How to Use",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1232,
        16
      ],
      "parameters": {
        "width": 592,
        "height": 168,
        "content": "## How to use\n1- **Create BrowserAct Workflow:** Set up the **News Content Marketing Automation** template in your BrowserAct account.\n2- **Add BrowserAct Token:** Connect your BrowserAct account credentials to the **HTTP Request** inside **Run Node**.\n3- **Update Workflow ID:** Change the `workflow_id` value in the **HTTP Request** inside **Run Node** to match the one from your BrowserAct workflow.\n4- **Connect Gemini:** Add your Google Gemini credentials to the **AI Agent** node.\n5- **Configure Telegram:** Connect your Telegram account and add your Channel ID to the **Send Node** node."
      },
      "typeVersion": 1
    },
    {
      "id": "b51ef89a-024e-4e05-910e-6e6767341f08",
      "name": "Run WorkFlow",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        -320,
        -192
      ],
      "parameters": {
        "url": "https://api.browseract.com/v2/workflow/run-task",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "workflow_id",
              "value": "52940169781736034"
            }
          ]
        },
        "genericAuthType": "httpBearerAuth"
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.2,
      "alwaysOutputData": true
    },
    {
      "id": "2a231d11-d5cd-4407-8eed-ae5da29f784f",
      "name": "Check For Errors",
      "type": "n8n-nodes-base.if",
      "position": [
        -128,
        -192
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "d48ae258-78a0-4b26-923d-2643b6b774c6",
              "operator": {
                "type": "object",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.error }}",
              "rightValue": ""
            },
            {
              "id": "3967a169-8432-45bd-8f89-08795fd12679",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": "null"
            }
          ]
        }
      },
      "retryOnFail": false,
      "typeVersion": 2.2
    },
    {
      "id": "5a7f5fa2-c200-4083-b7f5-583fefac52b2",
      "name": "Get WorkFlow Data",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        160,
        -208
      ],
      "parameters": {
        "url": "https://api.browseract.com/v2/workflow/get-task",
        "options": {},
        "sendQuery": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBearerAuth",
        "queryParameters": {
          "parameters": [
            {
              "name": "=task_id",
              "value": "={{ $json.id }}"
            }
          ]
        }
      },
      "credentials": {
        "httpBearerAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "73aaf1e5-d195-456b-8f27-421d0341fde2",
      "name": "Check For \"Finished\" Status",
      "type": "n8n-nodes-base.if",
      "position": [
        432,
        -208
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "0347a2a2-eb32-414d-9494-4e648078cf40",
              "operator": {
                "type": "object",
                "operation": "notExists",
                "singleValue": true
              },
              "leftValue": "={{ $json.error }}",
              "rightValue": ""
            },
            {
              "id": "99f31959-6f27-40dd-97c3-6ff611da1e0b",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.status }}",
              "rightValue": "finished"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "95c5ddfe-713d-4aa1-8a8e-8ef3bbef9847",
      "name": "KeyWords filtering",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        784,
        -224
      ],
      "parameters": {
        "text": "=from input parameters {{ $json.input_parameters }} you can find \"Key_Words\" input parametres are spilted by \";\" and each keyWord Splited by \",\" Extract the Keywords From it\n\ninside the Output -> String {{ $json.output.string }} there is list of maps like thsi sample\n[\n{\n\"Headline\":<String>\n\"Pic\":<String>\n\"Url\":<String>\n}\n]\n\ni want you to check each items Headline and comapre it with teh keywords if it directly contains keywords or were about keywords send it to output in the Json like this \n\n{\n  \"Matched_News\": [\n    {\n      \"Headline\": \"<String>\",\n      \"Pic\": \"<String>\",\n      \"Url\": \"<String>\"\n    }\n  ]\n}",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "2bcfb58c-03ce-4b10-bdaa-1b2b349b1e25",
      "name": "Google Gemini",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        784,
        -32
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "20e496e0-d254-4bbf-b1fb-7a26c629dabf",
      "name": "Code - Clean Output",
      "type": "n8n-nodes-base.code",
      "position": [
        688,
        128
      ],
      "parameters": {
        "jsCode": "// Get the original list from the 'Request' key in the incoming data.\nconst originalList = $input.first().json.output.Matched_News;\n\n// Create a new array to store the formatted output.\nconst outputItems = [];\n\n// Loop through each item in the original list.\nfor (const item of originalList) {\n  // For each item, create a new object in the desired format.\n  outputItems.push({\n    json: {\n      \"text\": item\n    }\n  });\n}\n\n// Return the new list of formatted objects.\nreturn outputItems;"
      },
      "typeVersion": 2
    },
    {
      "id": "c6716be1-b60f-45f6-a4ed-0352fe5019a7",
      "name": "Send a News Photo To Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        896,
        128
      ],
      "parameters": {
        "file": "={{ $json.text.Url }}",
        "chatId": "@test",
        "operation": "sendPhoto",
        "additionalFields": {
          "caption": "={{ $json.text.Headline }}\n\n{{ $json.text.Url }}"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0dbf1ada-3cdb-4167-b024-672bb01f6f39",
      "name": "Sticky Note-How to Use1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1232,
        192
      ],
      "parameters": {
        "width": 592,
        "height": 96,
        "content": "## Need Help ?\n*  [How to Find Your BrowseAct API Key & Workflow ID](https://www.youtube.com/watch?v=pDjoZWEsZlE)\n* [How to Connect n8n to Browseract](https://www.youtube.com/watch?v=RoYMdJaRdcQ)\n* [How to Use & Customize BrowserAct Templates](https://www.youtube.com/watch?v=CPZHFUASncY)"
      },
      "typeVersion": 1
    },
    {
      "id": "409a0100-6535-45e9-8354-b0f148a2acb9",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -512
      ],
      "parameters": {
        "color": 5,
        "width": 182,
        "height": 80,
        "content": "## \n# Run Node"
      },
      "typeVersion": 1
    },
    {
      "id": "66583e9c-49db-4498-a42e-c0d5a2d5455b",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        -512
      ],
      "parameters": {
        "color": 5,
        "width": 182,
        "height": 80,
        "content": "## \n# Get Node"
      },
      "typeVersion": 1
    },
    {
      "id": "1ba5bc7c-7190-44a9-9bb4-92fb0261607e",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        784,
        -512
      ],
      "parameters": {
        "color": 4,
        "width": 262,
        "height": 80,
        "content": "## \n# AI Agent Node"
      },
      "typeVersion": 1
    },
    {
      "id": "33e672c8-e51c-4fc9-bbf6-adec63b3c27d",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        768,
        464
      ],
      "parameters": {
        "color": 3,
        "width": 214,
        "height": 80,
        "content": "## \n# Send Node"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d1c49fab-6556-4a49-81ba-7171954be2df",
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Get WorkFlow Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait1": {
      "main": [
        [
          {
            "node": "Run WorkFlow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run WorkFlow": {
      "main": [
        [
          {
            "node": "Check For Errors",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini": {
      "ai_languageModel": [
        [
          {
            "node": "KeyWords filtering",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Check For Errors": {
      "main": [
        [
          {
            "node": "Get WorkFlow Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Run WorkFlow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get WorkFlow Data": {
      "main": [
        [
          {
            "node": "Check For \"Finished\" Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "KeyWords filtering": {
      "main": [
        [
          {
            "node": "Code - Clean Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code - Clean Output": {
      "main": [
        [
          {
            "node": "Send a News Photo To Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "KeyWords filtering",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Check For \"Finished\" Status": {
      "main": [
        [
          {
            "node": "KeyWords filtering",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}