【n8n系列教程4】案例分享:为你的NotionNext博客添加AI总结功能

请先看完免费部署教程:

也可以使用官网的,但官网的仅14天试用,可以用临时邮箱薅

NotionNext 免费部署方法可论坛中搜索

效果展示


工作流展示

:wave:工作流JSON代码 (复制粘贴导入)

{
  "name": "Notion博客AI总结",
  "nodes": [
    {
      "parameters": {
        "modelName": "models/gemini-1.5-pro-002",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        800,
        660
      ],
      "id": "f753a85f-ea6d-4f2e-8d2d-827a97334089",
      "name": "Google Gemini Chat Model",
      "credentials": {
        "googlePalmApi": {
          "id": "vnGfDwgNjveLfGXc",
          "name": "Google Gemini(PaLM) Api account 2"
        }
      }
    },
    {
      "parameters": {
        "modelName": "models/gemini-1.5-flash-002",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        1300,
        680
      ],
      "id": "be219a41-a8eb-4b37-b036-cb11ea6c2f22",
      "name": "Google Gemini Chat Model1",
      "credentials": {
        "googlePalmApi": {
          "id": "YFFWuO7oyYsy3sPI",
          "name": "Google Gemini(PaLM) Api account"
        }
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": {
          "__rl": true,
          "value": "https://www.notion.so/9ab2636bcccc4d0da354a1a35abffa41?v=c41111a0d8ca49879d80c6266869566f",
          "mode": "url"
        },
        "returnAll": true,
        "options": {}
      },
      "id": "36fbfb70-1203-4837-9e02-aab9b1c0e725",
      "name": "获取Notion数据库内容",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        920,
        280
      ],
      "credentials": {
        "notionApi": {
          "id": "XVdzqw1H8HYyzjNp",
          "name": "Notion Blog"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "8b82adcf-c276-44a4-b0a8-12dd7a0ae0b6",
              "leftValue": "={{ $json.property_type }}",
              "rightValue": "Post",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            },
            {
              "id": "bb674557-bc9a-4451-b42c-03de2ece4526",
              "leftValue": "={{ $json.property_summary }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "empty",
                "singleValue": true
              }
            },
            {
              "id": "810e2d0c-8357-457e-8433-de2872a365ee",
              "leftValue": "={{ $json.property_status }}",
              "rightValue": "Published",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        1100,
        280
      ],
      "id": "48d53053-7d75-4638-9e74-36e20db74402",
      "name": "过滤"
    },
    {
      "parameters": {
        "resource": "block",
        "operation": "getAll",
        "blockId": {
          "__rl": true,
          "value": "={{ $json.url }}",
          "mode": "url"
        },
        "returnAll": true,
        "fetchNestedBlocks": true
      },
      "id": "a3fbe847-36ef-4970-9835-52b18fbbb430",
      "name": "获取博客文章内容",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        1300,
        280
      ],
      "executeOnce": true,
      "credentials": {
        "notionApi": {
          "id": "XVdzqw1H8HYyzjNp",
          "name": "Notion Blog"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// 获取前一个节点输出的所有items\nconst items = $input.all();\n\n// 创建一个数组用于存储所有含有content的内容\nconst contents = items\n    .map(item => item.json.content)  // 取出content字段\n    .filter(content => content !== undefined)  // 过滤掉没有content的item\n\n// 用转义换行符'\\n'拼接所有内容\nconst combinedText = contents.join(\"\\\\n\");\n\n// 返回结果\nreturn [\n    {\n        json: {\n            combinedText: combinedText\n        }\n    }\n];\n"
      },
      "id": "0351630b-adc1-41c2-a3fb-ef0b301a8ba5",
      "name": "拼接内容",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1480,
        280
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=根据以下提供的文本内容,生成仅一个具有概括性,吸引力的副标题。\n{{ $json.combinedText }}",
        "messages": {
          "messageValues": [
            {
              "message": "根据提供的文本内容,生成仅一个具有概括性,吸引力的副标题。"
            }
          ]
        }
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.4,
      "position": [
        720,
        540
      ],
      "id": "08a93b43-d544-414c-8aad-15f215b28398",
      "name": "生成副标题"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=根据以下提供的文本内容,生成仅简短全面的总结内容。\n{{ $('拼接内容').item.json.combinedText }}",
        "messages": {
          "messageValues": [
            {
              "message": "根据提供的文本内容,生成简短全面的总结内容"
            }
          ]
        }
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.4,
      "position": [
        1220,
        540
      ],
      "id": "c27e5979-2683-4ff5-9b57-c051597f53e5",
      "name": "AI总结"
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": {
          "__rl": true,
          "value": "={{ $('过滤').first().json.url }}",
          "mode": "url"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "summary|rich_text",
              "textContent": "={{ $json.text }}"
            }
          ]
        },
        "options": {}
      },
      "id": "3d9903ab-deb5-44bc-aad0-6f8ac69906e3",
      "name": "更新副标题",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        1040,
        540
      ],
      "credentials": {
        "notionApi": {
          "id": "XVdzqw1H8HYyzjNp",
          "name": "Notion Blog"
        }
      }
    },
    {
      "parameters": {
        "resource": "block",
        "blockId": {
          "__rl": true,
          "value": "={{ $('过滤').first().json.url }}",
          "mode": "url"
        },
        "blockUi": {
          "blockValues": [
            {
              "type": "toggle",
              "richText": true,
              "text": {
                "text": [
                  {
                    "text": "={{ $json.text }}",
                    "annotationUi": {
                      "bold": true,
                      "color": "blue"
                    }
                  }
                ]
              }
            }
          ]
        }
      },
      "id": "3679268f-35b4-448c-93f4-473a6aec6009",
      "name": "追加文章内容",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        1520,
        540
      ],
      "credentials": {
        "notionApi": {
          "id": "XVdzqw1H8HYyzjNp",
          "name": "Notion Blog"
        }
      }
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        740,
        280
      ],
      "id": "b25ba67a-b78d-49f3-b454-3994025ce705",
      "name": "每5分钟触发一次"
    }
  ],
  "pinData": {},
  "connections": {
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "生成副标题",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI总结",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "获取Notion数据库内容": {
      "main": [
        [
          {
            "node": "过滤",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "过滤": {
      "main": [
        [
          {
            "node": "获取博客文章内容",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "获取博客文章内容": {
      "main": [
        [
          {
            "node": "拼接内容",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "拼接内容": {
      "main": [
        [
          {
            "node": "生成副标题",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "生成副标题": {
      "main": [
        [
          {
            "node": "更新副标题",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI总结": {
      "main": [
        [
          {
            "node": "追加文章内容",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "更新副标题": {
      "main": [
        [
          {
            "node": "AI总结",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "每5分钟触发一次": {
      "main": [
        [
          {
            "node": "获取Notion数据库内容",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "eb1d1ff5-df8d-4220-9eba-7e2f809857f9",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "273cb072730a54351e245b85466131b67e03b4084264c10b9a2f40e05554ac84"
  },
  "id": "3UOXItnpeXmsd3IN",
  "tags": []
}

触发条件

AI模型用的免费的Gemini

Gemini APIKey和Notion Key获取方法见百度搜索

13 Likes

高产啊大佬,又可以跟着大佬C了

1 Like

感谢大佬分享 。

感谢大佬分享,希望多分享些agents