8
n8n 中文网amn8n.com

Telegram上的Gmail AI搜索助手(Gemini驱动)

高级

这是一个Other, AI领域的自动化工作流,包含 19 个节点。主要使用 Set, Gmail, Telegram, Agent, TelegramTrigger 等节点,结合人工智能技术实现智能自动化。 Telegram上的Gmail AI搜索助手(Gemini驱动)

前置要求
  • Google 账号和 Gmail API 凭证
  • Telegram Bot Token
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "d04643ba872bb0fb252ed2c8197858d58cc47dd3c15ff6d08b19addd679e927b",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "78a9a2ba-dfbd-4b29-abb0-0d8e50fca199",
      "name": "Basic LLM Chain",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "maxTries": 2,
      "position": [
        60,
        260
      ],
      "parameters": {
        "text": "=Convert this email search request into a valid Gmail search query. Output ONLY JSON with:\n1. \"search\": The complete Gmail query using operators (from:, subject:, after:, etc.)\n2. \"metadata\": Extracted components for reference\n\nRules:\n- Use exact Gmail search syntax\n- Convert dates to YYYY/MM/DD or newer_than/older_than\n- Group related terms with (parentheses)\n- Prioritize exact matches with \"quotes\"\n- Include multiple variations of keywords (e.g., invoice/invoices)\n\nExample Output:\n```json\n{\n  \"search\": \"from:amazon AND (invoice OR invoices) AND after:2024/06/01\",\n  \"metadata\": {\n    \"senders\": [\"amazon\"],\n    \"keywords\": [\"invoice\", \"invoices\"],\n    \"timeFilters\": {\"after\": \"2024/06/01\"}\n  }\n}\n\nUser Input: {{ $('User Request - Telegram Trigger').item.json.message.text }}",
        "promptType": "define",
        "hasOutputParser": true
      },
      "executeOnce": false,
      "retryOnFail": true,
      "typeVersion": 1.6,
      "alwaysOutputData": false
    },
    {
      "id": "967d4a5f-f911-4c1d-b9ee-36f7edddac96",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        160,
        600
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "LnJ23V279k2RRO8R",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e5b584a1-c153-46bc-adb3-00a6e355ba99",
      "name": "Google Gemini Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        980,
        480
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "LnJ23V279k2RRO8R",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "7cd5d1d5-a75f-43d6-9e68-2212396394df",
      "name": "Basic LLM Chain1",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1020,
        260
      ],
      "parameters": {
        "text": "=Convert this email data into a well-formatted Telegram message with these sections:\n1. 📅 Date (DD/MM/YYYY format)\n2. 👤 Sender (extract name & email)\n3. 📌 Subject\n4. ✂️ Preview (full snippet)\n\nRules:\n- Use emojis for visual separation\n- Keep entire message under 400 characters\n- Format dates as \"09/06/2025\"\n- Extract names from \"From\" field (remove quotes/email)\n- Full snippets that conveys the full summarised email (max 4 lines)\n\nExample Output:\n📅Date:  09/06/2025  \n👤Sender: elad malka (example@gmail.com)\n📌Subject Line: Share request for \"Acuity to Sheets\"  \n✂️Snippet: Requesting access to spreadsheet: Acuity to Sheets \n\nEmail Data: \ndate: {{ $json.Date }}\nfrom: {{ $json.From }}\nsubject: {{ $json.Subject }}\nsender: {{ $json.snippet }}",
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.6
    },
    {
      "id": "30113c5d-07b9-4015-ab26-9a69fc874038",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -500,
        260
      ],
      "parameters": {
        "text": "=Analyze the user's request (User request:{{ $json.message.text }} )  about fetching Gmail emails and output a JSON with:\n1. `sender` (name or email, if specified).\n2. `keywords` (list of words/phrases to search for).\n3. `afterDate` (ISO format: YYYY-MM-DD, ONLY if user specifies \"after [date]\" or \"since [date]\").\n4. `beforeDate` (ISO format: YYYY-MM-DD, ONLY if user specifies \"before [date]\" or \"until [date]\").\n\nRules:\n- Convert relative dates (e.g., \"since Monday\") to ISO format using TODAY as reference.\n- For ambiguous dates (e.g., \"last week\"), use the afterDate (calculated from present date to last 7 days).\n- Strictly return ONLY valid JSON.\n\nExamples:\n\nUser Input: \"Get emails from Amazon after 2024-06-10 about returns\"\nOutput:\n```json\n{\n  \"sender\": \"Amazon\",\n  \"keywords\": [\"returns\"],\n  \"afterDate\": \"2024-06-10\"\n} ",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "ed601ecc-c4c0-4de1-9e3a-cb398ffe35c8",
      "name": "Google Gemini Chat Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -460,
        600
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.0-flash"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "LnJ23V279k2RRO8R",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5c577624-52e0-4a17-8604-80e2cd4b77de",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        -200,
        600
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"sender\": \"Amazon\",\n  \"keywords\": [\"returns\"],\n  \"afterDate\": \"2024-06-10\",\n  \"beforeDate\": \"2024-06-30\"\n} "
      },
      "typeVersion": 1.2
    },
    {
      "id": "371362b5-44c3-490a-bea9-a5e1d0246fd9",
      "name": "Structured Output Parser1",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        420,
        600
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"search\": \"from:amazon AND (invoice OR invoices) AND after:2024/06/01\",\n  \"metadata\": {\n    \"senders\": [\"amazon\"],\n    \"keywords\": [\"invoice\", \"invoices\"],\n    \"timeFilters\": {\"after\": \"2024/06/01\"}\n  }\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "2e2dc24c-f458-4339-86bf-6501e84c4ea3",
      "name": "Structured Output Parser2",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1220,
        500
      ],
      "parameters": {
        "jsonSchemaExample": "{\n\t\"text\": \"📅Date: 09/06/2025\\n👤Sender: elad malka (drive-shares-dm-noreply@google.com)\\n📌Subject: Share request for \"\n}"
      },
      "typeVersion": 1.2
    },
    {
      "id": "c2aa8043-0df7-48fe-87eb-f6bcdc09a6f9",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -960,
        -20
      ],
      "parameters": {
        "width": 360,
        "height": 480,
        "content": "## 1. Telegram Bot (API)\n1. Create a bot using Bot_Father on telegram by sending a message to @BotFather.\n\n2. Send a command /newbot in the message.\n\n3. Choose username and then copy the api.\n\n4. Create Telegram credential here in n8n. By inputting the api token in access token and base url (https://api.telegram.org).\n\n5. Hit Save.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "eb75fe77-953b-4c81-8d42-79b70171b947",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -580,
        500
      ],
      "parameters": {
        "width": 340,
        "height": 260,
        "content": "Replace the API with your own API of Gemini or choose an OpenAi node if you want to use openai model. (depends on your choice)."
      },
      "typeVersion": 1
    },
    {
      "id": "faca346a-8a08-49d2-902d-a29cfb366228",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        40,
        500
      ],
      "parameters": {
        "width": 340,
        "height": 260,
        "content": "Replace the API with your own API of Gemini or choose an OpenAi node if you want to use openai model. (depends on your choice)."
      },
      "typeVersion": 1
    },
    {
      "id": "4067630a-3888-42f9-ad7e-e01f87d6430e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        440,
        -80
      ],
      "parameters": {
        "width": 320,
        "height": 520,
        "content": "## 2. Connecting Your Gmail Account.\n\n1. Connect your Gmail account – Choose the account you want to retrieve emails from.\n\n2. Set the email limit – Enter the number of emails you want to fetch, or check \"Return all\" to retrieve every email matching your request.\n\n3. Select read status – Choose whether to fetch unread or read emails."
      },
      "typeVersion": 1
    },
    {
      "id": "be41decd-60dc-4055-acc7-9ffc8201c7a3",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1400,
        20
      ],
      "parameters": {
        "width": 340,
        "height": 420,
        "content": "## 3. Chat ID.\n\n1. Get the Chat ID – Copy the output from the first Telegram trigger node, then pass it to an AI model to extract the Chat ID.\n\n2. Use the Chat ID – Once identified, simply drag and drop the Chat ID value into the field.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "d3371952-c3aa-4cd9-ab08-594b4760ad48",
      "name": "User Request - Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -800,
        260
      ],
      "webhookId": "6eae6ee1-b07e-4b7b-af8f-a79a6755fd93",
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "id": "m3VuvOq8aZdBV0My",
          "name": "Telegram account (AigmailAssitant)"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "683f78bd-1ac4-4b51-90ed-17f0675bc1cb",
      "name": "Set Parameters From User Request (for fetching emails)",
      "type": "n8n-nodes-base.set",
      "position": [
        -140,
        260
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "93d9bf21-89b5-4544-80db-ed0cc875cb5c",
              "name": "Sender",
              "type": "string",
              "value": "={{ $json.output.sender }}"
            },
            {
              "id": "933fae65-1251-4995-be9a-03691e30d1c7",
              "name": "Keywords/Prompt/Criteria",
              "type": "string",
              "value": "={{ $json.output.keywords }}"
            },
            {
              "id": "bf4c646a-5b8e-49a3-a1a2-68836c731404",
              "name": "afterDate",
              "type": "string",
              "value": "={{ $json.output.afterDate }}"
            },
            {
              "id": "2a91fd77-77e9-4c3f-8f30-17a97fb9871d",
              "name": "beforeDate",
              "type": "string",
              "value": "={{ $json.output.beforeDate }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "fb2cb2c8-59e9-40e6-abe0-447335e499fb",
      "name": "Gets Requested Email(s)",
      "type": "n8n-nodes-base.gmail",
      "position": [
        540,
        260
      ],
      "webhookId": "ac0ae124-5b2e-473c-9716-473110d3c121",
      "parameters": {
        "limit": 10,
        "filters": {
          "q": "={{ $json.output.search }}",
          "sender": "={{ $('Set Parameters From User Request (for fetching emails)').item.json.Sender }}",
          "readStatus": "unread",
          "receivedAfter": "={{ $('Set Parameters From User Request (for fetching emails)').item.json.afterDate }}",
          "receivedBefore": "={{ $('Set Parameters From User Request (for fetching emails)').item.json.beforeDate }}"
        },
        "operation": "getAll"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "tuAn4zK9wTO9JZvR",
          "name": "Gmail account"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "4b229ce7-c941-4d6c-a999-26054468490c",
      "name": "Sets Parameters For Response",
      "type": "n8n-nodes-base.set",
      "position": [
        840,
        260
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7e8b9cac-da96-4568-b520-8f64bed8b35b",
              "name": "Date",
              "type": "string",
              "value": "={{ new Date(Number($json.internalDate)).toISOString() }}"
            },
            {
              "id": "6a422a1c-395c-4759-b642-40b33295b8d1",
              "name": "From",
              "type": "string",
              "value": "={{ $json.From }}"
            },
            {
              "id": "85b67fb6-f4ed-4672-becd-43aa682c5cdf",
              "name": "Subject",
              "type": "string",
              "value": "={{ $json.Subject }}"
            },
            {
              "id": "9b4fa0e0-da5a-4c3a-a049-ec1c2ac9c600",
              "name": "snippet",
              "type": "string",
              "value": "={{ $json.snippet }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "e7501362-37d8-4a05-919a-72ad419ee59a",
      "name": "Sends (requested emails) via Telegram back",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1500,
        260
      ],
      "webhookId": "aad6a23e-6d2a-4a74-b1ec-addc668033e1",
      "parameters": {
        "text": "={{ $json.output.text }}",
        "chatId": "={{ $('User Request - Telegram Trigger').item.json.message.chat.id }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "id": "m3VuvOq8aZdBV0My",
          "name": "Telegram account (AigmailAssitant)"
        }
      },
      "typeVersion": 1.2
    }
  ],
  "pinData": {
    "User Request - Telegram Trigger": [
      {
        "message": {
          "chat": {
            "id": 6305257849,
            "type": "private",
            "username": "ToooooopGG",
            "last_name": "Tate",
            "first_name": "Andrew"
          },
          "date": 1750328451,
          "from": {
            "id": 6305257849,
            "is_bot": false,
            "username": "ToooooopGG",
            "last_name": "Tate",
            "first_name": "Andrew",
            "language_code": "en"
          },
          "text": "Hey get me summary of all the emails by elevenlabs",
          "message_id": 15
        },
        "update_id": 216173590
      }
    ]
  },
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Set Parameters From User Request (for fetching emails)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "Gets Requested Email(s)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain1": {
      "main": [
        [
          {
            "node": "Sends (requested emails) via Telegram back",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gets Requested Email(s)": {
      "main": [
        [
          {
            "node": "Sets Parameters For Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model2": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser1": {
      "ai_outputParser": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser2": {
      "ai_outputParser": [
        [
          {
            "node": "Basic LLM Chain1",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Sets Parameters For Response": {
      "main": [
        [
          {
            "node": "Basic LLM Chain1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "User Request - Telegram Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Parameters From User Request (for fetching emails)": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 其他, 人工智能

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量19
分类2
节点类型9
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

外部链接
在 n8n.io 查看

分享此工作流