{
  "id": "gXutAybKcZqblZjF",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "My workflow",
  "tags": [],
  "nodes": [
    {
      "id": "a47db6e0-7861-4c0e-9628-1cab45cce413",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        160,
        540
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "5b19646e-e002-4ad0-9422-70d95fa09f79",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1120,
        -100
      ],
      "parameters": {
        "width": 2020,
        "height": 1140,
        "content": "## \ud83d\udccc Email Summary to Telegram\n\n## \ud83d\udd04 What this workflow does\nThis automation checks your Gmail inbox every minute, detects important emails based on keyword filters, and sends a short, Telegram-style summary using GPT-4o-mini.\n\n---\n\n#### \ud83e\udde9 Node-by-node Breakdown\n\n1. **\ud83d\udce5 Email Received**\n   - Gmail Trigger node\n   - Polls inbox every minute for new emails (subject + text)\n\n2. **\ud83e\uddea Is Important**\n   - Checks if the email is important using keyword filters.\n   - If email subject or body **contains keywords** like `\"Sales\"`, it continues.\n   - Otherwise, it stops.\n\n   **\ud83d\udca1 Examples of keywords you can use:**\n   - `\"invoice\"`\n   - `\"payment due\"`\n   - `\"security alert\"`\n   - `\"job offer\"`\n   - `\"delivery\"`  \n   \ud83d\udc49 Add anything **important to you** in the condition list.\n\n3. **\ud83e\udde0 AI Agent**\n   - Sends email content to OpenAI with a pre-written system prompt.\n   - Returns a short, human-style summary (max 300 characters) using emojis and plain language.\n\n4. **\ud83d\udce4 Send a text message**\n   - Sends the AI-generated summary to your Telegram chat.\n\n---\n\n#### \u2705 Sample Telegram Message\n> \ud83d\udce6 Your Flipkart order \u201cBluetooth Speaker\u201d was delivered today. Enjoy!\n\n---\n\n#### \ud83d\udee0 Notes\n- You can modify keyword filters in the **Is Important** node.\n- Make sure your **Telegram chat ID and bot** are set correctly.\n- This workflow works well for:\n  - Billing alerts \ud83d\udcb0\n  - Delivery updates \ud83d\udce6\n  - Job or HR emails \ud83e\uddd1\u200d\ud83d\udcbc\n  - OTP/security messages \ud83d\udd10\n\n---\n"
      },
      "typeVersion": 1
    },
    {
      "id": "38ec8af8-000a-4c81-ac84-3f57b13653ff",
      "name": "Check for New Emails",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -300,
        570
      ],
      "parameters": {
        "simple": false,
        "filters": {},
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "e9ca1183-73c2-40ae-8911-dc293c76d3af",
      "name": "Important Email Filter",
      "type": "n8n-nodes-base.if",
      "position": [
        -80,
        570
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "f300ae2b-5de4-4efc-88ae-130a957588cb",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.subject }}",
              "rightValue": "sales"
            },
            {
              "id": "30e5cc92-886b-4a5b-bc36-6cefc443c66b",
              "operator": {
                "type": "string",
                "operation": "contains"
              },
              "leftValue": "={{ $json.text }}",
              "rightValue": "jobs"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "d646dfa9-28f3-4466-9bbe-154397d1c7af",
      "name": " Ignore Unimportant Email",
      "type": "n8n-nodes-base.noOp",
      "position": [
        210,
        720
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "c5b0111c-f1ee-4d9c-94bc-e64e83c5ba6f",
      "name": "Summarize Email with GPT-4o",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        140,
        340
      ],
      "parameters": {
        "text": "=Email Subject:  {{ $json.subject }}\nEmail Body:  {{ $json.text }}",
        "options": {
          "systemMessage": "=# \ud83e\udde0 Multi-Purpose Email Summarizer\n\nYou are an intelligent assistant that reads all kinds of emails \u2014 work-related, personal, financial, promotional, alerts, and more.\n\nYour job is to:\n- Understand the core message and intent of the email\n- Write a short, clear **summary (max 300 characters)** as if you're notifying the user on Telegram\n- Use **plain English** with light emojis where helpful (\ud83d\udccc, \u26a0\ufe0f, \u2705, \ud83d\udcb0, \ud83d\udd14, etc.)\n- Highlight any important info: payment due, meeting, offer, delivery, confirmation, alert, etc.\n- Make sure it sounds natural and relevant \u2014 like a smart assistant updating someone quickly\n\n## \u270d\ufe0f Output Format:\nOnly give the **summary text**. No intro, no explanation, no formatting tags.\n\n---\n\n### \ud83d\udce8 Examples:\n\n**Email about invoice:**  \n\ud83d\udccc Invoice from AWS for $23.50 is due by July 20. Check your billing portal to avoid service disruption.\n\n**Email from HR:**  \n\u2705 HR shared your July payslip. No action needed unless there's an error.\n\n**Amazon delivery email:**  \n\ud83d\udce6 Your Amazon order \"AirPods Pro\" has been delivered today. Enjoy!\n\n**Newsletter:**  \n\ud83d\udcf0 New issue of \"FinTech Weekly\" is out \u2014 AI trends, market insights & more.\n\n\n---\n\nOnly return a short, smart Telegram-style summary like above \u2014 no headers, no extra context.\n"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.8
    },
    {
      "id": "7937a159-cb46-445b-87fc-3751297e269c",
      "name": "Send Summary to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        500,
        340
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "123456789",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "30db915b-a020-48cf-9b69-b43c0e3b9fbe",
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Summarize Email with GPT-4o",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Check for New Emails": {
      "main": [
        [
          {
            "node": "Important Email Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Important Email Filter": {
      "main": [
        [
          {
            "node": "Summarize Email with GPT-4o",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": " Ignore Unimportant Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Summarize Email with GPT-4o": {
      "main": [
        [
          {
            "node": "Send Summary to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}