8
n8n 中文网amn8n.com

聊天机器人Webhook

高级

这是一个Miscellaneous, AI Chatbot, Multimodal AI领域的自动化工作流,包含 19 个节点。主要使用 Set, Webhook, GmailTool, DateTimeTool, Agent 等节点。 基于AI的Gmail和日历助手,集成Gemini聊天界面

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • Google 账号和 Gmail API 凭证
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移

无法加载工作流预览

导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Chatbot webhook",
  "tags": [],
  "nodes": [
    {
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        320,
        176
      ],
      "parameters": {
        "text": "={{ $json.input }}",
        "options": {
          "systemMessage": "\nYou are an advanced AI Personal Assistant operating within an n8n workflow. Your primary function is to serve as a cognitive engine that translates user requests into specific, executable tool calls. You are precise, methodical, and you do not act without sufficient information.\n\n---\n\n## Core Operating Principles\n\n1.  **Tool-Centric Operation:** You can only perform actions for which you have been explicitly provided a tool. Before acting, you will review the `Tool Manifest` to confirm you have the required capability. If a user's request does not map to any available tool, you **MUST** clearly state that you cannot perform the action and why. For example: \"I am sorry, but I cannot set a reminder as I do not have a tool for that function.\"\n2.  **Clarification Mandate:** If a user's request is ambiguous or is missing a required parameter for a tool, you **MUST** ask clarifying questions before proceeding. Never guess or assume details like email recipients or event durations.\n3.  **Single-Focus Execution:** Handle one primary task at a time. If a user asks to schedule a meeting and check emails, process the meeting first unless the user specifies otherwise.\n4.  **User Confirmation:** Before executing actions that create data or notify others (e.g., creating an event, sending an email), briefly state your plan of action for the user to confirm. Example: \"I will schedule an event titled 'Project Sync' for 3 PM tomorrow and invite 'bob@example.com'. Is that correct?\"\n\n---\n\n## Tool Manifest & Usage Protocols\n\nYou have access to the following tools. Adhere strictly to their parameters and usage triggers.\n\n#### Tool: `system_getCurrentTime`\n\n* **Description:** Retrieves the current date and time. This is often a dependency for other tools.\n* **When to Use:** When the user asks for the current time, date, or uses relative terms like \"today\", \"tomorrow\", \"this week\".\n* **Parameters:**\n    * `timezone` (string, optional): The IANA timezone identifier (e.g., 'America/New_York', 'Asia/Kolkata').\n* **Protocol:** If the `timezone` is not provided, you **MUST** ask the user for their location to infer it. For example: \"Certainly. To give you the correct time, could you let me know where you are located?\" If the user provides a location (e.g., \"India\", \"New York\"), use the corresponding IANA timezone. You will output the time in `HH:MM` format as requested.\n\n#### Tool: `googleCalendar_getEvents`\n\n* **Description:** Fetches a list of events from the user's Google Calendar within a specified date range.\n* **When to Use:** When the user asks \"What's on my schedule?\", \"Am I busy?\", or asks about events for a specific day, week, or month.\n* **Parameters:**\n    * `startDate` (string, ISO 8601 format, required): The start of the time period.\n    * `endDate` (string, ISO 8601 format, required): The end of the time period.\n* **Protocol:** Use `system_getCurrentTime` to establish the date for relative queries.\n    * **\"Today\"** means the last 24 hours from the current time.\n    * **\"This week\"** means from today's date for the next 7 days.\n    * **\"This month\"** means from today's date for the next 30 days.\n\n#### Tool: `googleCalendar_createEvent`\n\n* **Description:** Creates a new event on the user's Google Calendar.\n* **When to Use:** When the user asks to \"schedule\", \"book\", \"create\", or \"add\" an event, meeting, or appointment.\n* **Parameters:**\n    * `summary` (string, required): The title of the event.\n    * `startTime` (string, ISO 8601 format, required): The start time of the event.\n    * `endTime` (string, ISO 8601 format, required): The end time of the event.\n    * `attendees` (array of strings, optional): A list of attendee email addresses.\n* **Protocol:** If the user mentions other people in the scheduling request, automatically include their names/emails in the `attendees` parameter. You must have all required parameters before calling this tool.\n\n#### Tool: `gmail_sendMessage`\n\n* **Description:** Composes and sends an email via Gmail.\n* **When to Use:** When the user asks to \"email\", \"send a message\", or \"contact\" someone.\n* **Parameters:**\n    * `recipient` (string, required): The primary recipient's email address.\n    * `subject` (string, required): The email subject line.\n    * `body` (string, required): The content of the email.\n* **Protocol:** The `subject` must be detailed and relevant to the body's content. The `body` should be professionally written and clearly articulate the user's message without unnecessary embellishment.\n\n#### Tool: `gmail_getMessages`\n\n* **Description:** Retrieves a list of emails from the user's Gmail account.\n* **When to Use:** When the user asks to \"check my email\", \"see recent emails\", or \"find an email from someone\".\n* **Parameters:**\n    * `startDate` (string, ISO 8601 format, optional): The start date to filter emails from.\n    * `endDate` (string, ISO 8601 format, optional): The end date to filter emails to.\n    * `from` (string, optional): Filter emails from a specific sender.\n* **Protocol:** Use `system_getCurrentTime` to define date ranges for requests. For example, \"retrieve emails sent today\" means fetching emails from the last 24 hours.\n\n---\n\n## Defined Workflow: \"Schedule a Meeting and Send Invite\"\n\nWhen a user's request involves both scheduling a meeting and notifying the attendees, you **MUST** follow this exact sequence of tool calls:\n\n1.  **Acknowledge and Gather:** Acknowledge the request. Check if you have all the necessary information (`topic/summary`, `attendees`, `proposed time/date`, `duration`). If not, ask for the missing details.\n2.  **Step 1: Check Availability (`googleCalendar_getEvents`)**: Use the `googleCalendar_getEvents` tool to check the user's schedule for the proposed `startTime` and `endTime`.\n3.  **Step 2: Report & Decide**:\n    * **If Conflict Exists:** Report the scheduling conflict to the user, mentioning the existing event. State: \"You already have '[Existing Event Title]' scheduled at that time. Would you like to find a different time?\" Await further instructions.\n    * **If No Conflict:** Proceed to the next step.\n4.  **Step 3: Create Event (`googleCalendar_createEvent`)**: Once the time is confirmed to be free, call this tool with the gathered `summary`, `startTime`, `endTime`, and `attendees`.\n5.  **Step 4: Notify Attendees (`gmail_sendMessage`)**: After the event is successfully created, immediately call this tool to send an invitation email.\n    * `recipient`: The `attendees` from the event.\n    * `subject`: \"Meeting Invitation: [Event Summary]\".\n    * `body`: \"Hello,\\n\\nThis is an invitation to schedule '[Event Summary]' on [Date] at [Time]. Please check your calendar for the official Google Calendar invite.\\n\\nBest regards,\"\n6.  **Step 5: Final Confirmation**: Report to the user that the event has been scheduled and the invitation email has been sent."
        },
        "promptType": "define"
      },
      "retryOnFail": true,
      "typeVersion": 2.2
    },
    {
      "name": "Google Gemini 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -112,
        368
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "Google Gemini API Credentials [REDACTED]"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1
    },
    {
      "name": "在 Gmail 中发送消息",
      "type": "n8n-nodes-base.gmailTool",
      "position": [
        144,
        400
      ],
      "parameters": {
        "sendTo": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('To', ``, 'string') }}",
        "message": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', ``, 'string') }}",
        "options": {
          "appendAttribution": true
        },
        "subject": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Subject', ``, 'string') }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "Gmail Credentials [REDACTED]"
        }
      },
      "notesInFlow": true,
      "typeVersion": 2.1
    },
    {
      "name": "在 Gmail 中获取多条消息",
      "type": "n8n-nodes-base.gmailTool",
      "notes": "You Get Details Of the Mail of the User, You are able to Read through them and if the user says a time frame you only give for the specific time frame",
      "position": [
        272,
        400
      ],
      "parameters": {
        "limit": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Limit', `If the User Specifies a certain time frame, lets make it so that it returns it from that specific time frame and not from other than that time frame. ALSO IF IT ASKS FOR A CERTAIN TIME FRAME GIVE ALL IN THAT TIME FRAME `, 'number') }}",
        "simple": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Simplify', `Dont give a very short summary, give a more detailed Summary than a breif summary`, 'boolean') }}",
        "filters": {
          "q": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Search', ``, 'string') }}"
        },
        "options": {},
        "operation": "getAll"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "Gmail Credentials [REDACTED]"
        }
      },
      "notesInFlow": true,
      "typeVersion": 2.1
    },
    {
      "name": "在 Google Calendar 中获取多个事件",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        400,
        400
      ],
      "parameters": {
        "options": {},
        "timeMax": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Before', ``, 'string') }}",
        "timeMin": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('After', ``, 'string') }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "[REDACTED_EMAIL]",
          "cachedResultName": "[REDACTED_EMAIL]"
        },
        "operation": "getAll"
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "Google Calendar Credentials [REDACTED]"
        }
      },
      "typeVersion": 1.3
    },
    {
      "name": "日期与时间",
      "type": "n8n-nodes-base.dateTimeTool",
      "position": [
        528,
        400
      ],
      "parameters": {
        "options": {
          "timezone": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Timezone', ``, 'string') }}"
        },
        "outputFieldName": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Output_Field_Name', ``, 'string') }}"
      },
      "typeVersion": 2
    },
    {
      "name": "在 Google Calendar 中获取日历可用性",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        656,
        400
      ],
      "parameters": {
        "options": {},
        "timeMax": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('End_Time', ``, 'string') }}",
        "timeMin": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Start_Time', ``, 'string') }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "[REDACTED_EMAIL]",
          "cachedResultName": "[REDACTED_EMAIL]"
        },
        "resource": "calendar"
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "Google Calendar Credentials [REDACTED]"
        }
      },
      "typeVersion": 1.3
    },
    {
      "name": "在 Google Calendar 中创建事件",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        784,
        400
      ],
      "parameters": {
        "end": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('End', ``, 'string') }}",
        "start": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Start', ``, 'string') }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "[REDACTED_EMAIL]",
          "cachedResultName": "[REDACTED_EMAIL]"
        },
        "additionalFields": {
          "attendees": [
            "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('attendees0_Attendees', `you add attendees here, add there email here`, 'string') }}"
          ],
          "description": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Description', ``, 'string') }}",
          "conferenceDataUi": {
            "conferenceDataValues": {
              "conferenceSolution": "hangoutsMeet"
            }
          }
        },
        "useDefaultReminders": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Use_Default_Reminders', ``, 'boolean') }}"
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "Google Calendar Credentials [REDACTED]"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1.3
    },
    {
      "name": "在 Google Calendar 中更新事件",
      "type": "n8n-nodes-base.googleCalendarTool",
      "position": [
        912,
        400
      ],
      "parameters": {
        "eventId": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Event_ID', ``, 'string') }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "[REDACTED_EMAIL]",
          "cachedResultName": "[REDACTED_EMAIL]"
        },
        "operation": "update",
        "updateFields": {}
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "Google Calendar Credentials [REDACTED]"
        }
      },
      "typeVersion": 1.3
    },
    {
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -688,
        144
      ],
      "parameters": {
        "color": 4,
        "content": "### 🗣️ 聊天节点"
      },
      "typeVersion": 1
    },
    {
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        320,
        0
      ],
      "parameters": {
        "width": 320,
        "height": 144,
        "content": "### 🤖 AI 智能体"
      },
      "typeVersion": 1
    },
    {
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        352
      ],
      "parameters": {
        "color": 5,
        "width": 272,
        "height": 192,
        "content": "### 🧠 Google Gemini 聊天模型(或任意 LLM)"
      },
      "typeVersion": 1
    },
    {
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -128,
        560
      ],
      "parameters": {
        "color": 6,
        "width": 272,
        "height": 128,
        "content": "### 📌 简易记忆"
      },
      "typeVersion": 1
    },
    {
      "name": "便签说明4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        608
      ],
      "parameters": {
        "color": 7,
        "width": 1024,
        "height": 624,
        "content": "## 工具集"
      },
      "typeVersion": 1
    },
    {
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -288,
        176
      ],
      "parameters": {
        "path": "chat",
        "options": {
          "allowedOrigins": "*"
        },
        "httpMethod": "POST",
        "responseMode": "responseNode"
      },
      "typeVersion": 2.1
    },
    {
      "name": "Prepare Reply",
      "type": "n8n-nodes-base.set",
      "position": [
        832,
        176
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "name": "reply",
              "type": "string",
              "value": "={{ $json.output }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "position": [
        16,
        176
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "name": "input",
              "type": "string",
              "value": "= {{$json[\"body\"]?.text || $json[\"text\"] || $json[\"body\"]?.input || $json[\"text\"]}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "name": "响应 Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1104,
        176
      ],
      "parameters": {
        "options": {
          "responseCode": 200
        }
      },
      "typeVersion": 1.4
    },
    {
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        16,
        400
      ],
      "parameters": {
        "sessionKey": "=\"parameters\": {\n  \"memoryKey\": \"history\",\n  \"inputKey\": \"input\",\n  \"outputKey\": \"reply\"\n}\n",
        "sessionIdType": "customKey",
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "Set": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Prepare Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Date & Time": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Reply": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Send a message in Gmail": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get many messages in Gmail": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Create an event in Google Calendar": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get many events in Google Calendar": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Update an event in Google Calendar": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get availability in a calendar in Google Calendar": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 杂项, AI 聊天机器人, 多模态 AI

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流