Calendar_scheduling

工作流概述

这是一个包含21个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "slP122GjD9meGkS6",
  "meta": {
    "instanceId": "178ef8a5109fc76c716d40bcadb720c455319f7b7a3fd5a39e4f336a091f524a"
  },
  "name": "Calendar_scheduling",
  "tags": [],
  "nodes": [
    {
      "id": "bd1dae81-daea-4539-bf1d-38eb9a2bd2f0",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        500,
        560
      ],
      "parameters": {
        "filters": {
          "readStatus": "unread",
          "includeSpamTrash": false
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "kLFedNEM8Zwkergv",
          "name": "Gmail account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a97c3ab1-6fbc-441e-af11-3c746936013b",
      "name": "Chat OpenAI",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        720,
        740
      ],
      "parameters": {
        "model": "gpt-4",
        "options": {
          "temperature": 0.1
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "wJtZwsVKW5v6R2Iy",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a1205598-7cd4-4278-ad53-0cfc7c7947ff",
      "name": "Workflow Tool",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        1580,
        759
      ],
      "parameters": {
        "name": "Calendar_Availability",
        "workflowId": "={{ $workflow.id }}",
        "description": "Call this tool to get my calendar availability as stringified JSON array."
      },
      "typeVersion": 1
    },
    {
      "id": "5ba2c2b0-2218-45d2-a417-f86c80643397",
      "name": "Chat OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1420,
        759
      ],
      "parameters": {
        "model": "gpt-4",
        "options": {
          "temperature": 0
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "wJtZwsVKW5v6R2Iy",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "012835ec-c20a-4b84-bed8-67f6aac30698",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        460,
        460
      ],
      "parameters": {
        "width": 616.8060552874073,
        "height": 410.24791575252334,
        "content": "## Check if incoming email is about appointment
We use LLM to check subject and body of the email and determine if it's an appointment request. "
      },
      "typeVersion": 1
    },
    {
      "id": "ceaa4f77-acc8-437e-9d61-16cf344a7748",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1340,
        460
      ],
      "parameters": {
        "width": 676.1951194231482,
        "height": 241.70645019745504,
        "content": "## Get calendar availability and compose a response
Make sure to update the Workflow ID if you are running this as 2 workflows"
      },
      "typeVersion": 1
    },
    {
      "id": "499def23-7dec-4131-91fd-326b1b824762",
      "name": "Google Calendar",
      "type": "n8n-nodes-base.googleCalendar",
      "position": [
        680,
        1120
      ],
      "parameters": {
        "options": {
          "timeMax": "={{ $now.plus(1, 'month').toISO() }}",
          "timeMin": "={{ $now.minus(1, 'day').toISO() }}",
          "singleEvents": true
        },
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "your_email@gmail.com",
          "cachedResultName": "your_email@gmail.com"
        },
        "operation": "getAll",
        "returnAll": true
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "id": "s95HsHIMB7oK0dAH",
          "name": "Google Calendar account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0f5f43fa-3386-4682-b620-21db35651d3b",
      "name": "Execute Workflow Trigger",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        460,
        1120
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "8b2b82b9-c11f-4e7f-ab23-16ea5e395e11",
      "name": "Format response",
      "type": "n8n-nodes-base.itemLists",
      "position": [
        1560,
        1120
      ],
      "parameters": {
        "include": "allFieldsExcept",
        "options": {},
        "aggregate": "aggregateAllItemData",
        "operation": "concatenateItems",
        "fieldsToExclude": "sort",
        "destinationFieldName": "response"
      },
      "typeVersion": 3
    },
    {
      "id": "ac363d85-5c6e-4a9f-9cfc-ecc15a325b01",
      "name": "Stringify Response",
      "type": "n8n-nodes-base.set",
      "position": [
        1780,
        1120
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "response",
              "value": "={{ JSON.stringify($json.response) }}"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 2
    },
    {
      "id": "399c5bc4-c8bd-4d0b-942a-9889447880a9",
      "name": "Extract start, end and name",
      "type": "n8n-nodes-base.set",
      "position": [
        1100,
        1120
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "start",
              "value": "={{ DateTime.fromISO($json.start.dateTime).toLocaleString(DateTime.DATE_HUGE) }}, {{ DateTime.fromISO($json.start.dateTime).toLocaleString(DateTime.TIME_24_WITH_SHORT_OFFSET) }}"
            },
            {
              "name": "end",
              "value": "={{ DateTime.fromISO($json.end.dateTime).toLocaleString(DateTime.DATE_HUGE) }}, {{ DateTime.fromISO($json.end.dateTime).toLocaleString(DateTime.TIME_24_WITH_SHORT_OFFSET) }}"
            },
            {
              "name": "name",
              "value": "={{ $json.summary }}"
            },
            {
              "name": "sort",
              "value": "={{ $json.start.dateTime }}"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 2
    },
    {
      "id": "a39b6c7d-fdcc-452d-9ef5-50b038153330",
      "name": "Filter only confirmed and with set time",
      "type": "n8n-nodes-base.filter",
      "position": [
        880,
        1120
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.status }}",
              "value2": "confirmed"
            }
          ],
          "boolean": [
            {
              "value1": "={{ $json.start.dateTime }}",
              "value2": "={{ undefined }}",
              "operation": "notEqual"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0e0a2be9-cde7-497d-94c5-180128382bb7",
      "name": "Is appointment request",
      "type": "n8n-nodes-base.if",
      "position": [
        1100,
        560
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.is_appointment }}",
              "value2": "true"
            }
          ],
          "boolean": [
            {
              "value1": "={{ $json.is_appointment }}",
              "value2": true
            }
          ]
        },
        "combineOperation": "any"
      },
      "typeVersion": 1
    },
    {
      "id": "a6e11f63-a56a-4fe0-91c8-0dde2720e905",
      "name": "Classify appointment",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        720,
        560
      ],
      "parameters": {
        "prompt": "=Please evaluate the following email to determine if it suggests scheduling a meeting or a call:
Subject: {{ encodeURI($json.Subject) }}
Snippet: {{ encodeURI($json.snippet) }}
Indicate your assessment by responding with \"true\" if it suggests a meeting or call, or \"false\" otherwise. Use lowercase for your response.
"
      },
      "typeVersion": 1
    },
    {
      "id": "b6411b14-67f6-4195-a834-60a4dc5e4851",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        880,
        740
      ],
      "parameters": {
        "jsonSchema": "{
 \"type\": \"object\",
 \"properties\": {
 \"is_appointment\": {
 \"type\": \"boolean\"
 }
 }
}"
      },
      "typeVersion": 1
    },
    {
      "id": "96248431-290b-4fb1-94a3-714e7c0008d4",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        1058.6115582634225
      ],
      "parameters": {
        "width": 810.4923211935056,
        "height": 224.60561166142082,
        "content": "### Get all query google events for the next month and extract relevant data"
      },
      "typeVersion": 1
    },
    {
      "id": "48bc7c0c-0b74-418e-8c5c-6a6faf24722c",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1513,
        1060
      ],
      "parameters": {
        "width": 444.4130232558142,
        "height": 220.42397542781927,
        "content": "### Wrap the result in `response` object and return "
      },
      "typeVersion": 1
    },
    {
      "id": "a68f7b27-1891-46c7-92b2-650cc17f94d6",
      "name": "Sort",
      "type": "n8n-nodes-base.itemLists",
      "position": [
        1320,
        1120
      ],
      "parameters": {
        "options": {},
        "operation": "sort",
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "sort"
            }
          ]
        }
      },
      "typeVersion": 3
    },
    {
      "id": "2b5b5855-6d3f-4405-9f48-5d6c4ee2475b",
      "name": "Mark as read",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1840,
        739
      ],
      "parameters": {
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "operation": "markAsRead"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "kLFedNEM8Zwkergv",
          "name": "Gmail account"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "accbe2df-367a-4bd3-a383-12ee79062e12",
      "name": "Send Reply",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1840,
        539
      ],
      "parameters": {
        "message": "={{ $json.output }}",
        "options": {
          "replyToSenderOnly": true
        },
        "messageId": "={{ $('Gmail Trigger').item.json.id }}",
        "operation": "reply"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "kLFedNEM8Zwkergv",
          "name": "Gmail account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "66d62337-d0c1-4744-b169-8e95c1d1492a",
      "name": "Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1400,
        539
      ],
      "parameters": {
        "text": "=Sender: {{ $('Gmail Trigger').item.json.From }}\nSubject: {{ $('Gmail Trigger').item.json.Subject }}\nEmail Text: {{ $('Gmail Trigger').item.json.snippet }}",
        "options": {
          "systemMessage": "=You are an email scheduling assistant. Based on the received email, check my availability and propose an appropriate response. 
Aim to get a specific time, rather than just a day. When checking my availability, make sure that there's enough time in between meetings.
If I'm not available, ALWAYS propose a new time based on my availability. When proposing a new time, always leave 15 minutes buffer from previous meeting.
Today date and time is: {{ $now.toISO() }}."
        }
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "0cf0768b-ddc0-42a3-9c84-f93d43c66dc7",
  "connections": {
    "Sort": {
      "main": [
        [
          {
            "node": "Format response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agent": {
      "main": [
        [
          {
            "node": "Send Reply",
            "type": "main",
            "index": 0
          },
          {
            "node": "Mark as read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat OpenAI": {
      "ai_languageModel": [
        [
          {
            "node": "Classify appointment",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Chat OpenAI1": {
      "ai_languageModel": [
        [
          {
            "node": "Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Classify appointment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Tool": {
      "ai_tool": [
        [
          {
            "node": "Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Format response": {
      "main": [
        [
          {
            "node": "Stringify Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Calendar": {
      "main": [
        [
          {
            "node": "Filter only confirmed and with set time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify appointment": {
      "main": [
        [
          {
            "node": "Is appointment request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is appointment request": {
      "main": [
        [
          {
            "node": "Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Workflow Trigger": {
      "main": [
        [
          {
            "node": "Google Calendar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Classify appointment",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Extract start, end and name": {
      "main": [
        [
          {
            "node": "Sort",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter only confirmed and with set time": {
      "main": [
        [
          {
            "node": "Extract start, end and name",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Gmailtrigger
  • @N8N/N8N Nodes Langchain.Lmchatopenai
  • @N8N/N8N Nodes Langchain.Toolworkflow
  • Stickynote
  • Googlecalendar

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作