8
n8n 中文网amn8n.com

Notion知识库AI助手

中级

这是一个HR, AI, IT Ops领域的自动化工作流,包含 10 个节点。主要使用 Set, Notion, Agent, ChatTrigger, LmChatOpenAi 等节点,结合人工智能技术实现智能自动化。 Notion知识库AI助手

前置要求
  • Notion API Key
  • OpenAI API Key
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "205b3bc06c96f2dc835b4f00e1cbf9a937a74eeb3b47c99d0c30b0586dbf85aa"
  },
  "nodes": [
    {
      "id": "d1d4291e-fa37-43d0-81e0-f0a594371426",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        680,
        620
      ],
      "parameters": {
        "model": "gpt-4o",
        "options": {
          "timeout": 25000,
          "temperature": 0.7
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "AzPPV759YPBxJj3o",
          "name": "Max's DevRel OpenAI account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "68e6805b-9c19-4c9e-a300-8983f2b7c28a",
      "name": "搜索 Notion 数据库",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "position": [
        980,
        620
      ],
      "parameters": {
        "url": "=https://api.notion.com/v1/databases/{{ $json.notionID }}/query",
        "method": "POST",
        "jsonBody": "{\n  \"filter\": {\n    \"or\": [\n      {\n        \"property\": \"question\",\n        \"rich_text\": {\n          \"contains\": \"{keyword}\"\n        }\n      },\n      {\n        \"property\": \"tags\",\n        \"multi_select\": {\n          \"contains\": \"{tag}\"\n        }\n      }\n    ]\n  },\n  \"sorts\": [\n    {\n      \"property\": \"updated_at\",\n      \"direction\": \"ascending\"\n    }\n  ]\n}",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "predefinedCredentialType",
        "toolDescription": "=Use this tool to search the \"\" Notion app database.\n\nIt is structured with question and answer format. \nYou can filter query result by:\n- By keyword\n- filter by tag.\n\nKeyword and Tag have an OR relationship not AND.\n\n",
        "nodeCredentialType": "notionApi",
        "placeholderDefinitions": {
          "values": [
            {
              "name": "keyword",
              "description": "Searches question of the record. Use one keyword at a time."
            },
            {
              "name": "tag",
              "description": "=Options: {{ $json.tagsOptions }}"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "id": "gfNp6Jup8rsmFLRr",
          "name": "max-bot"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "c3164d38-a9fb-4ee3-b6bd-fccb4aa5a1a4",
      "name": "获取数据库详情",
      "type": "n8n-nodes-base.notion",
      "position": [
        420,
        380
      ],
      "parameters": {
        "simple": false,
        "resource": "database",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "7ea9697d-4875-441e-b262-1105337d232e",
          "cachedResultUrl": "https://www.notion.so/7ea9697d4875441eb2621105337d232e",
          "cachedResultName": "StarLens Company Knowledge Base"
        }
      },
      "credentials": {
        "notionApi": {
          "id": "gfNp6Jup8rsmFLRr",
          "name": "max-bot"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "98300243-efcc-4427-88da-c1af8a91ddae",
      "name": "窗口缓冲内存",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        820,
        620
      ],
      "parameters": {
        "contextWindowLength": 4
      },
      "typeVersion": 1.2
    },
    {
      "id": "a8473f48-1343-4eb2-8e48-ec89377a2a00",
      "name": "在数据库记录内搜索",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "notes": " ",
      "position": [
        1140,
        620
      ],
      "parameters": {
        "url": "https://api.notion.com/v1/blocks/{page_id}/children",
        "fields": "id, type, paragraph.text, heading_1.text, heading_2.text, heading_3.text, bulleted_list_item.text, numbered_list_item.text, to_do.text, children",
        "dataField": "results",
        "authentication": "predefinedCredentialType",
        "fieldsToInclude": "selected",
        "toolDescription": "=Use this tool to retrieve Notion page content using the page ID. \n\nIt is structured with question and answer format. \nYou can filter query result by:\n- By keyword\n- filter by tag.\n\nKeyword and Tag have an OR relationship not AND.\n\n",
        "optimizeResponse": true,
        "nodeCredentialType": "notionApi",
        "placeholderDefinitions": {
          "values": [
            {
              "name": "page_id",
              "description": "Notion page id from 'Search notion database' tool results"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "id": "gfNp6Jup8rsmFLRr",
          "name": "max-bot"
        }
      },
      "notesInFlow": true,
      "typeVersion": 1.1
    },
    {
      "id": "115c328e-84b0-43d2-8df7-8b3f74cbb2fb",
      "name": "格式化架构",
      "type": "n8n-nodes-base.set",
      "position": [
        620,
        380
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a8e58791-ba51-46a2-8645-386dd1a0ff6e",
              "name": "sessionId",
              "type": "string",
              "value": "={{ $('When chat message received').item.json.sessionId }}"
            },
            {
              "id": "434209de-39d5-43d8-a964-0fcb7396306c",
              "name": "action",
              "type": "string",
              "value": "={{ $('When chat message received').item.json.action }}"
            },
            {
              "id": "cad4c972-51a9-4e16-a627-b00eea77eb30",
              "name": "chatInput",
              "type": "string",
              "value": "={{ $('When chat message received').item.json.chatInput }}"
            },
            {
              "id": "8e88876c-2714-494d-bd5e-5e80c99f83e3",
              "name": "notionID",
              "type": "string",
              "value": "={{ $('Get database details').item.json.id }}"
            },
            {
              "id": "a88a15f6-317c-4d2e-9d64-26f5ccaf7a97",
              "name": "databaseName",
              "type": "string",
              "value": "={{ $json.title[0].text.content }}"
            },
            {
              "id": "7c3bf758-8ed3-469a-8695-6777f4af4fb9",
              "name": "tagsOptions",
              "type": "string",
              "value": "={{ $json.properties.tags.multi_select.options.map(item => item.name).join(',') }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "3b82f4fe-6c0c-4e6e-a387-27de31fec758",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -340,
        240
      ],
      "parameters": {
        "color": 6,
        "width": 462.3561535890252,
        "height": 95.12709218477178,
        "content": "## Notion 知识库助手 [v1]"
      },
      "typeVersion": 1
    },
    {
      "id": "31debc55-6608-4e64-be18-1bc0fc0fbf16",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -340,
        1060
      ],
      "parameters": {
        "color": 7,
        "width": 462.3561535890252,
        "height": 172.4760209818479,
        "content": "### 常见问题"
      },
      "typeVersion": 1
    },
    {
      "id": "9f48e548-f032-477c-960d-9c99d61443df",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        820,
        380
      ],
      "parameters": {
        "text": "={{ $json.chatInput }}",
        "options": {
          "systemMessage": "=# Role:\nYou are a helpful agent. Query the \"{{ $json.databaseName }}\" Notion database to find relevant records or summarize insights based on multiple records.\n\n# Behavior:\n\nBe clear, very concise, efficient, and accurate in responses. Do not hallucinate.\nIf the request is ambiguous, ask for clarification. Do not embellish, only use facts from the Notion records. Do not offer general advice.\n\n# Error Handling:\n\nIf no matching records are found, try alternative search criteria. Example 1: Laptop, then Computer, then Equipment. Example 2: meetings, then meeting.\nClearly explain any issues with queries (e.g., missing fields or unsupported filters).\n\n# Output:\n\nReturn concise, user-friendly results or summaries.\nFor large sets, show top results by default and offer more if needed. Output URLs in markdown format. \n\nWhen a record has the answer to user question, always output the URL to that page. Do not output links twice."
        },
        "promptType": "define"
      },
      "typeVersion": 1.6
    },
    {
      "id": "f1274a12-128c-4549-a19b-6bfc3beccd89",
      "name": "当收到聊天消息时",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        220,
        380
      ],
      "webhookId": "b76d02c0-b406-4d21-b6bf-8ad2c623def3",
      "parameters": {
        "public": true,
        "options": {
          "title": "Notion Knowledge Base",
          "subtitle": ""
        },
        "initialMessages": "=Happy {{ $today.weekdayLong }}!\nKnowledge source assistant at your service. How can I help you?"
      },
      "typeVersion": 1.1
    },
    {
      "id": "2e25e4bc-7970-4d00-a757-ba1e418873aa",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -340,
        360
      ],
      "parameters": {
        "color": 7,
        "width": 463.90418399676537,
        "height": 318.2958135288425,
        "content": "### 模板设置快速入门视频 👇"
      },
      "typeVersion": 1
    },
    {
      "id": "ba6fe953-fd5c-497f-ac2a-7afa04b7e6cc",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -340,
        700
      ],
      "parameters": {
        "color": 7,
        "width": 461.5634274842711,
        "height": 332.14098134070576,
        "content": "### 书面设置步骤"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Format schema": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get database details": {
      "main": [
        [
          {
            "node": "Format schema",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Window Buffer Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Search notion database": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Get database details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search inside database record": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 人力资源, 人工智能, IT 运维

需要付费吗?

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

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

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Max Tkacz

Max Tkacz

@max-n8n

Principal Product Designer @ n8n

外部链接
在 n8n.io 查看

分享此工作流