{
  "id": "36Ag52lg9PbHbEC3",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Telegram to Email Newsletter Automation using Dumpling AI",
  "tags": [],
  "nodes": [
    {
      "id": "1b978cc3-984c-4964-a732-ade35e5087d1",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -3136,
        0
      ],
      "parameters": {
        "sessionKey": "={{ $json.message.from.id }}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "e3a409e6-2225-4ecc-8f19-3b2b9ef1b34e",
      "name": "Search_news",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -2944,
        0
      ],
      "parameters": {
        "url": "https://app.dumplingai.com/api/v1/search-news",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"query\": \"{{ $fromAI('suggestion', 'Autocomplete suggestion to search in Google News', 'string') }}\"\n}\n",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "toolDescription": "use this to Search Google News using the autocomplete suggestions as input. Use this after getting results from Google_autocomplete to find recent news articles on those suggested queries."
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "3f1bc79c-e630-4cda-b41a-28b54e26a71f",
      "name": "Google_autocomplete",
      "type": "n8n-nodes-base.httpRequestTool",
      "position": [
        -2704,
        -48
      ],
      "parameters": {
        "url": "https://app.dumplingai.com/api/v1/get-autocomplete",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"query\": \"{{ $fromAI('keyword', 'Keyword to get autocomplete suggestions', 'string') }}\"\n}\n",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "toolDescription": "use this to Fetche autocomplete suggestions from Google based on a keyword and returns the response data"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "b4501237-6712-4da9-a753-351aa6667d78",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        -1920,
        -240
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "74009d0d-f5a0-4d21-b2fe-6b12b9f8d2f2",
      "name": "Start: Receive Keyword from Telegram",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -3360,
        -256
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f7d45172-ebc9-410b-8da5-2aab5ad6edcd",
      "name": "AI Agent: Expand Keyword & Orchestrate Tools",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -2992,
        -256
      ],
      "parameters": {
        "text": "=Keyword: {{ $json.message.text }}",
        "options": {
          "systemMessage": "=You are a helpful assistant connected to multiple tools in n8n. Your main job is to take a keyword provided by the trigger, expand it into relevant search terms, and then find the most recent news related to those terms. Here is how you should use the tools:\n\nGoogle_autocomplete tool (Dumpling AI Autocomplete):\n\nAlways call this first when you receive a keyword from the trigger.\n\nInput: the keyword or phrase provided.\n\nOutput: a list of popular search suggestions related to that keyword.\n\nPurpose: to understand what people are actually searching for and generate multiple angles of interest on the keyword.\n\nGoogle_News tool (Dumpling AI Google News):\n\nAfter you receive autocomplete suggestions, pass those suggestions directly into the Google_News tool.\n\nInput: each autocomplete suggestion as a search term.\n\nOutput: recent articles, headlines, or updates from Google News related to those suggestions.\n\nPurpose: to gather fresh and relevant information tied to what people are searching for.\n\nFlow Logic:\n\nTrigger sends a keyword \u2192 Call Google_autocomplete \u2192 Take results \u2192 Feed results into Google_News \u2192 Return the final set of news articles.\n\nIf no autocomplete results are found, use the original keyword directly in Google_News.\n\nGuidelines:\n\nDo not skip the autocomplete step unless it returns no results.\n\nUse the autocomplete suggestions exactly as they are for Google News searches.\n\nAlways structure your output in a clean and easy-to-read format so results can be reused in later steps of the automation.\n\nReturn result in a structured JSON,here is the example JSON:\n{\n  \"articles\": [\n    {\n      \"category\": \"string\",\n      \"title\": \"string\",\n      \"url\": \"string\",\n      \"source\": \"string\",\n      \"summary\": \"string\",\n      \"published\": \"string\"\n    }\n  ]\n}\n"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "b8f6aae2-3c9b-4c04-9650-a7c206a24a22",
      "name": "LLM: Language Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -3344,
        -16
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "334cf258-1045-4e30-8d9e-9420d9ac6990",
      "name": "Parser: Format News JSON",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -2416,
        -48
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"articles\": [\n    {\n      \"category\": \"string\",\n      \"title\": \"string\",\n      \"url\": \"string\",\n      \"source\": \"string\",\n      \"summary\": \"string\",\n      \"published\": \"string\"\n    }\n  ]\n}\n"
      },
      "typeVersion": 1.2
    },
    {
      "id": "a9673a47-600f-4571-a2cc-605480741a4e",
      "name": "Split Articles",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -2464,
        -256
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "output.articles"
      },
      "typeVersion": 1
    },
    {
      "id": "beed3081-737a-4ca7-8a10-2fedfbaede46",
      "name": "Loop: Process Each Article",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -2240,
        -256
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "e2f661cc-c28c-454f-b202-f8ee60c92819",
      "name": "Scraper: Clean Article Content",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1648,
        -240
      ],
      "parameters": {
        "url": "https://app.dumplingai.com/api/v1/scrape",
        "method": "POST",
        "options": {},
        "jsonBody": "={\n  \"url\": \"{{ $json.url }}\",\n  \"cleaned\": true\n}\n",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "2605c6e3-b4ad-475e-9119-3c0da295470d",
      "name": "Aggregate: Combine Article Content",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -2016,
        -464
      ],
      "parameters": {
        "include": "specifiedFields",
        "options": {},
        "aggregate": "aggregateAllItemData",
        "fieldsToInclude": "content",
        "destinationFieldName": "content"
      },
      "typeVersion": 1
    },
    {
      "id": "f4e40d07-48b6-457e-a83d-48a3a6c3baf4",
      "name": "Generate Newsletter",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        -1808,
        -464
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "GPT-4.1-MINI"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "=You are an assistant that writes newsletters from provided source content. Use only the content I give you. Do not invent facts. If something is missing, omit it.\n\nGOAL:\nCreate a high quality newsletter in HTML and a strong email subject line.\n\nOUTPUT FORMAT:\nReturn only valid JSON with this exact schema and nothing else:\n{\n  \"newsletter\": \"html\",\n  \"subject\": \"string\"\n}\n\nSUBJECT RULES:\n\u2022 Write a clear subject under 60 characters.\n\u2022 Make it specific and benefit driven.\n\u2022 No clickbait. No emojis. Use simple grammar.\n\nNEWSLETTER HTML RULES:\n\u2022 Produce production ready HTML suitable for email.\n\u2022 Include a clear header title, a short intro paragraph, two to six story sections, and a closing call to action.\n\u2022 Use simple inline CSS only. No external styles, no scripts.\n\u2022 Use a single column layout with readable fonts, clear spacing, and mobile friendly widths.\n\u2022 For each story, include a headline, two to three sentence summary, and a source link if present in the input.\n\u2022 Group similar items together and remove duplicates.\n\u2022 Keep links as plain anchor tags. Open in same tab.\n\u2022 Add a brief footer with sources list using the available links from the input, and an unsubscribe placeholder.\n\nTONE AND STYLE:\n\u2022 Write in clear, friendly, professional language.\n\u2022 Keep sentences short and direct.\n\u2022 Avoid jargon and filler.\n\nCONSTRAINTS:\n\u2022 Use only information found in INPUT_CONTENT.\n\u2022 If there is conflicting info, pick the most recent or most credible item and note it briefly.\n\u2022 If there are no valid items, return an empty newsletter with a short note in the intro explaining that no recent updates were found.\n\nVALIDATION:\n\u2022 Ensure the JSON is valid.\n\u2022 Escape quotes inside the HTML as needed.\n\u2022 Do not include markdown. Do not include code fences. Output JSON only.\n"
            },
            {
              "content": "=INPUT_CONTENT:\n\"{{ JSON.stringify($json.content) }}\""
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "e2ea6b10-bcc3-4e28-bafc-ff5db1c874f3",
      "name": "Send Newsletter via Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1424,
        -464
      ],
      "parameters": {
        "sendTo": "=",
        "message": "={{ $json.message.content.newsletter }}",
        "options": {},
        "subject": "={{ $json.message.content.subject }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "41135b73-722e-4287-8a65-cd62e72777a8",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -3360,
        -480
      ],
      "parameters": {
        "width": 820,
        "height": 280,
        "content": "## Agent Branch\n\nThis branch begins when a keyword is received from **Telegram**.  \nThe keyword is expanded into search queries using **Dumpling AI Autocomplete**, then relevant articles are fetched via **Dumpling AI Google News**.  \n\nThe articles are parsed into structured JSON and passed into the **Split Out** node, which separates them for further processing.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "e08fdd8d-4864-4480-b9f0-7bbdcdf99720",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2096,
        -640
      ],
      "parameters": {
        "color": 3,
        "width": 780,
        "height": 300,
        "content": "## Newsletter Branch\n\nStarting from the **Loop Over Items** node, each article is scraped and cleaned using **Dumpling AI Scraper**.  \nThe cleaned articles are aggregated, then sent to **OpenAI** to generate a professional HTML newsletter and subject line.  \n\nFinally, the newsletter is delivered via **Gmail** to the specified inbox.\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "ef12c48d-5bdb-4348-b42d-f1ac5851a3e3",
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Scraper: Clean Article Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search_news": {
      "ai_tool": [
        [
          {
            "node": "AI Agent: Expand Keyword & Orchestrate Tools",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent: Expand Keyword & Orchestrate Tools",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Split Articles": {
      "main": [
        [
          {
            "node": "Loop: Process Each Article",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Newsletter": {
      "main": [
        [
          {
            "node": "Send Newsletter via Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google_autocomplete": {
      "ai_tool": [
        [
          {
            "node": "AI Agent: Expand Keyword & Orchestrate Tools",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "LLM: Language Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent: Expand Keyword & Orchestrate Tools",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Parser: Format News JSON": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent: Expand Keyword & Orchestrate Tools",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Send Newsletter via Email": {
      "main": [
        []
      ]
    },
    "Loop: Process Each Article": {
      "main": [
        [
          {
            "node": "Aggregate: Combine Article Content",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scraper: Clean Article Content": {
      "main": [
        [
          {
            "node": "Loop: Process Each Article",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate: Combine Article Content": {
      "main": [
        [
          {
            "node": "Generate Newsletter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Start: Receive Keyword from Telegram": {
      "main": [
        [
          {
            "node": "AI Agent: Expand Keyword & Orchestrate Tools",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent: Expand Keyword & Orchestrate Tools": {
      "main": [
        [
          {
            "node": "Split Articles",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}