GPT Actions library - Notion

2024 年 7 月 25 日
在 Github 中打开

这个特定的 GPT Action 概述了如何连接到 Notion。此 Action 接受用户的问题,使用 Notion 的搜索功能扫描相关的 Notion 页面,然后返回匹配页面的信息。

价值:用户现在可以利用 ChatGPT 的自然语言能力,直接连接、查询和综合他们在 Notion 中的知识。管理员可以明确地与集成共享页面以管理访问权限。

示例用例:

  • 一位新员工寻求关于设置新系统的快速操作指南信息
  • 支持代理需要从 Notion 快速检索信息,而无需阅读整个文档
  • 用户希望综合信息并创建摘要或转换,以用于他们工作的其他方面

在开始之前,请确保在您的应用程序环境中完成以下步骤

  • 设置一个包含填充页面的 Notion 工作区
  • 通过 Notion 共享页面最适合特定的 Wiki。考虑将您的知识库组织成一个或一组 Wiki

创建自定义 GPT 后,将以下文本复制到“说明”面板中。有问题?查看入门示例,了解此步骤的详细工作原理。

**Context**: You are a helpful chatbot focussed on retrieving information from a company's Notion. An administrator has given you access to a number of useful Notion pages.  You are to act similar to a librarian and be helpful answering and finding answers for users' questions.

**Instructions**:
1. Use the search functionality to find the most relevant page or pages.
- Display the top 3 pages.  Include a formatted list containing: Title, Last Edit Date, Author.
- The Title should be a link to that page.
1.a. If there are no relevant pages, reword the search and try again (up to 3x)
1.b. If there are no relevant pages after retries, return "I'm sorry, I cannot find the right info to help you with that question"
2. Open the most relevant article, retrieve and read all of the contents (including any relevant linked pages or databases), and provide a 3 sentence summary.  Always provide a quick summary before moving to the next step.
3. Ask the user if they'd like to see more detail.  If yes, provide it and offer to explore more relevant pages.

**Additional Notes**: 
- If the user says "Let's get started", introduce yourself as a librarian for the Notion workspace, explain that the user can provide a topic or question, and that you will help to look for relevant pages.
- If there is a database on the page.  Always read the database when looking at page contents.

创建自定义 GPT 后,将以下文本复制到“Actions”面板中。有问题?查看入门示例,了解此步骤的详细工作原理。

openapi: 3.1.0
info:
  title: Notion API
  description: API for interacting with Notion's pages, databases, and users.
  version: 1.0.0
servers:
  - url: https://api.notion.com/v1
    description: Main Notion API server
paths:
  /users:
    get:
      operationId: listAllUsers
      summary: List all users
      parameters:
        - name: Notion-Version
          in: header
          required: true
          schema:
            type: string
          example: 2022-06-28
          constant: 2022-06-28
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        name:
                          type: string
                        avatar_url:
                          type: string
                        type:
                          type: string
  /blocks/{block_id}/children:
    get:
      operationId: retrieveBlockChildren
      summary: Retrieve block children
      parameters:
        - name: block_id
          in: path
          required: true
          schema:
            type: string
        - name: Notion-Version
          in: header
          required: true
          schema:
            type: string
          example: 2022-06-28
          constant: 2022-06-28
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  object:
                    type: string
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        type:
                          type: string
                        has_children:
                          type: boolean
  /comments:
    get:
      operationId: retrieveComments
      summary: Retrieve comments
      parameters:
        - name: Notion-Version
          in: header
          required: true
          schema:
            type: string
          example: 2022-06-28
          constant: 2022-06-28
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        text:
                          type: string
                        created_time:
                          type: string
                          format: date-time
                        created_by:
                          type: object
                          properties:
                            id:
                              type: string
                            name:
                              type: string
  /pages/{page_id}/properties/{property_id}:
    get:
      operationId: retrievePagePropertyItem
      summary: Retrieve a page property item
      parameters:
        - name: page_id
          in: path
          required: true
          schema:
            type: string
        - name: property_id
          in: path
          required: true
          schema:
            type: string
        - name: Notion-Version
          in: header
          required: true
          schema:
            type: string
          example: 2022-06-28
          constant: 2022-06-28
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  type:
                    type: string
                  title:
                    type: array
                    items:
                      type: object
                      properties:
                        type:
                          type: string
                        text:
                          type: object
                          properties:
                            content:
                              type: string
  /databases/{database_id}/query:
    post:
      operationId: queryDatabase
      summary: Query a database
      parameters:
        - name: database_id
          in: path
          required: true
          schema:
            type: string
        - name: Notion-Version
          in: header
          required: true
          schema:
            type: string
          example: 2022-06-28
          constant: 2022-06-28
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                filter:
                  type: object
                sorts:
                  type: array
                  items:
                    type: object
                start_cursor:
                  type: string
                page_size:
                  type: integer
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  object:
                    type: string
                  results:
                    type: array
                    items:
                      type: object
                  next_cursor:
                    type: string
                  has_more:
                    type: boolean
  /search:
    post:
      operationId: search
      summary: Search
      parameters:
        - name: Notion-Version
          in: header
          required: true
          schema:
            type: string
          example: 2022-06-28
          constant: 2022-06-28
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                query:
                  type: string
                filter:
                  type: object
                  properties:
                    value:
                      type: string
                    property:
                      type: string
                sort:
                  type: object
                  properties:
                    direction:
                      type: string
                    timestamp:
                      type: string
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  object:
                    type: string
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        title:
                          type: array
                          items:
                            type: object
                            properties:
                              type:
                                type: string
                              text:
                                type: object
                                properties:
                                  content:
                                    type: string

以下是关于使用此第三方应用程序设置身份验证的说明。

在 ChatGPT 中设置身份验证之前,请在 Notion 中执行以下步骤。

  1. 转到您的工作区的 Notion 设置页面
  2. 导航到“我的连接”>“开发或管理集成”
  3. 创建标记为“内部”的新集成
  4. 找到您的集成,并找到标记为“内部集成密钥”的 API 密钥。这是此集成的 Bearer 令牌。

注意! 您需要与集成共享特定的页面、数据库或 Wiki,才能在 ChatGPT 中访问它们。通过选择页面右上角的“...”按钮并选择适当的连接来执行此操作。

注意! 如果 Notion 集成被标记为“公共”,则允许它们利用 OAuth。查看 Notion 的身份验证文档,以确定哪种集成路径最适合您的需求。

notion_connections.png

sharing_notion_pages.png

在 ChatGPT 中,单击“身份验证”,然后选择 “API 密钥”。输入以下信息。

  • API 密钥:使用上述步骤中的“内部集成密钥”
  • 身份验证类型:Bearer
  • 搜索无结果 如果在运行搜索时没有看到任何页面返回,请仔细检查您是否已从 Notion 与应用程序共享了相关页面

您希望我们优先考虑哪些集成?我们的集成中是否存在错误?在我们的 github 中提交 PR 或 issue,我们将进行查看。