---
title: "评论 Webhook"
description: "启用和管理 Tiptap 中评论的 Webhook，以接收线程和评论活动的通知。更多内容请参阅文档！"
canonical_url: "https://tiptap.zhcndoc.com/comments/integrate/webhook"
---

# 评论 Webhook

启用和管理 Tiptap 中评论的 Webhook，以接收线程和评论活动的通知。更多内容请参阅文档！

设置和管理 Webhook，以改善您的评论集成。评论 Webhook 的常见用例包括：

- 在创建、解决、更新或删除线程时发送通知。
- 在添加、更新或删除评论时通知用户。
- 结合使用 [提及扩展](https://tiptap.zhcndoc.com/editor/extensions/nodes/mention.md)，在用户被提及时向用户发送电子邮件或通知。

* **1. Activate trial or subscribe**

  在您的账户中[开始免费试用](https://cloud.tiptap.dev/v2?trial=true)或[订阅团队计划](https://cloud.tiptap.dev/v2/billing)。
* **2. 启动文档服务器**

  在启动您的 [环境](https://cloud.tiptap.dev/v2/configuration/document-server) 后配置您的 [评论 Webhook](https://cloud.tiptap.dev/v2/configuration/document-server)。

## 启用评论事件

对于 2024 年 3 月 1 日后创建的账户，评论 Webhook 默认启用。否则，您可能仍在使用旧版本的 Webhook 系统，需要手动升级：

1. 如果您之前实现了协作 Webhook，请在处理传入 Webhook 时检查 `type` 和 `trigger` 字段。（[文档](https://tiptap.zhcndoc.com/collaboration/core-concepts/webhooks.md)）
2. 访问您的 [协作设置](https://cloud.tiptap.dev/v2/configuration/document-server)。
3. 在 Webhooks 部分，点击 **升级**。

该升级有必要以便适应多种新事件被路由到同一 Webhook 端点的引入，新的 `type` 和 `trigger` 字段作为区别。

## 配置 Webhook

要配置评论通知的 Webhook：

1. 访问您账户中的 [协作设置](https://cloud.tiptap.dev/v2/configuration/document-server)。
2. 在 Webhooks 部分，添加您希望的端点 URL。

添加 URL 后，Webhook 会立即生效。您将开始接收指定事件的通知，毫无延迟。

## Webhook 事件

评论 Webhook 触发与评论扩展内线程和评论相关的多种事件的通知。这些事件在其关联操作发生时立即触发。

- `comment.added`
- `comment.updated`
- `comment.deleted`
- `thread.created` (only triggered if the thread is created without a first comment, usually via our 'create thread' API. When using the official Tiptap extensions, you'll only see `comment.added`)
- `thread.resolved`
- `thread.updated`
- `thread.deleted`

## 示例有效载荷

以下是不同类型 Webhook 事件的示例有效载荷：

### 线程/评论创建

```json
{
  "trigger": "comment.added",
  "thread": {
    "id": "128ba3a9-c684-4956-8c9f-fe5dc147c7e5",
    "createdAt": "2024-03-02T22:17:51.304Z",
    "comments": [
      {
        "id": "0259e4cb-43ad-4eb2-a7e9-a7a7d5207a76",
        "createdAt": "2024-03-02T22:17:51.307Z",
        "updatedAt": "2024-03-02T22:17:51.307Z",
        "data": {
          "userName": "Cyndi Lauper",
          "userAvatar": "https://api.dicebear.com/7.x/lorelei/svg?seed=Cyndi Lauper"
        },
        "content": "线程创建评论"
      }
    ],
    "updatedAt": "2024-03-02T22:17:51.305Z"
  },
  "comment": {
    "id": "0259e4cb-43ad-4eb2-a7e9-a7a7d5207a76",
    "createdAt": "2024-03-02T22:17:51.307Z",
    "updatedAt": "2024-03-02T22:17:51.307Z",
    "data": {
      "userName": "Cyndi Lauper",
      "userAvatar": "https://api.dicebear.com/7.x/lorelei/svg?seed=Cyndi Lauper"
    },
    "content": "线程创建评论"
  },
  "selection": [
    {
      "type": "text",
      "text": "in my opinion",
      "marks": [
        {
          "type": "inlineThread",
          "attrs": {
            "data-thread-id": "128ba3a9-c684-4956-8c9f-fe5dc147c7e5"
          }
        }
      ]
    }
  ],
  "appName": "",
  "user": "",
  "name": "documentName",
  "type": "THREAD"
}
```

### 评论更新

```json
{
  "trigger": "comment.updated",
  "thread": [
    {
      "id": "0259e4cb-43ad-4eb2-a7e9-a7a7d5207a76",
      "createdAt": "2024-03-02T22:17:51.307Z",
      "updatedAt": "2024-03-02T22:18:04.246Z",
      "data": {
        "userName": "Cyndi Lauper",
        "userAvatar": "https://api.dicebear.com/7.x/lorelei/svg?seed=Cyndi Lauper"
      },
      "content": "线程创建评论（已编辑）"
    }
  ],
  "comment": {
    "id": "0259e4cb-43ad-4eb2-a7e9-a7a7d5207a76",
    "createdAt": "2024-03-02T22:17:51.307Z",
    "updatedAt": "2024-03-02T22:18:04.246Z",
    "data": {
      "userName": "Cyndi Lauper",
      "userAvatar": "https://api.dicebear.com/7.x/lorelei/svg?seed=Cyndi Lauper"
    },
    "content": "线程创建评论（已编辑）"
  },
  "selection": [
    {
      "type": "text",
      "text": "in my opinion",
      "marks": [
        {
          "type": "inlineThread",
          "attrs": {
            "data-thread-id": "0259e4cb-43ad-4eb2-a7e9-a7a7d5207a76"
          }
        }
      ]
    }
  ],
  "appName": "",
  "user": "",
  "name": "documentName",
  "type": "THREAD"
}
```

### 评论删除

```json
{
  "trigger": "comment.deleted",
  "thread": {
    "id": "128ba3a9-c684-4956-8c9f-fe5dc147c7e5",
    "createdAt": "2024-03-02T22:17:51.304Z",
    "comments": [
      {
        "id": "0259e4cb-43ad-4eb2-a7e9-a7a7d5207a76",
        "createdAt": "2024-03-02T22:17:51.307Z",
        "updatedAt": "2024-03-02T22:18:04.246Z",
        "data": {
          "userName": "Cyndi Lauper",
          "userAvatar": "https://api.dicebear.com/7.x/lorelei/svg?seed=Cyndi Lauper"
        },
        "content": "线程创建评论（已编辑）"
      }
    ],
    "updatedAt": "2024-03-02T22:17:51.305Z"
  },
  "comment": {
    "id": "1841e650-2202-42b6-a868-907fee42ccf7",
    "createdAt": "2024-03-02T22:18:20.974Z",
    "updatedAt": "2024-03-02T22:18:20.975Z",
    "data": {
      "userName": "Cyndi Lauper",
      "userAvatar": "https://api.dicebear.com/7.x/lorelei/svg?seed=Cyndi Lauper"
    },
    "content": "第二条评论，相同线程"
  },
  "selection": [], // selection is not sent for deleted comments
  "appName": "",
  "user": "",
  "name": "documentName",
  "type": "THREAD"
}
```

### 线程删除

```json
{
  "trigger": "thread.deleted",
  "thread": {
    "id": "128ba3a9-c684-4956-8c9f-fe5dc147c7e5",
    "createdAt": "2024-03-02T22:17:51.304Z",
    "comments": [
      {
        "id": "0259e4cb-43ad-4eb2-a7e9-a7a7d5207a76",
        "createdAt": "2024-03-02T22:17:51.307Z",
        "updatedAt": "2024-03-02T22:18:04.246Z",
        "data": {
          "userName": "Cyndi Lauper",
          "userAvatar": "https://api.dicebear.com/7.x/lorelei/svg?seed=Cyndi Lauper"
        },
        "content": "线程创建评论（已编辑）"
      }
    ],
    "updatedAt": "2024-03-02T22:18:52.050Z",
    "resolvedAt": null
  },
  "selection": [], // selection is not sent for deleted threads
  "appName": "",
  "user": "",
  "name": "documentName",
  "type": "THREAD"
}
```

### 线程解决

```json
{
  "trigger": "thread.resolved",
  "thread": {
    "id": "128ba3a9-c684-4956-8c9f-fe5dc147c7e5",
    "createdAt": "2024-03-02T22:17:51.304Z",
    "comments": [
      {
        "id": "0259e4cb-43ad-4eb2-a7e9-a7a7d5207a76",
        "createdAt": "2024-03-02T22:17:51.307Z",
        "updatedAt": "2024-03-02T22:18:04.246Z",
        "data": {
          "userName": "Cyndi Lauper",
          "userAvatar": "https://api.dicebear.com/7.x/lorelei/svg?seed=Cyndi Lauper"
        },
        "content": "线程创建评论（已编辑）"
      }
    ],
    "updatedAt": "2024-03-02T22:18:48.531Z",
    "resolvedAt": "2024-03-02T22:18:48.531Z"
  },
  "selection": [
    {
      "type": "text",
      "text": "in my opinion",
      "marks": [
        {
          "type": "inlineThread",
          "attrs": {
            "data-thread-id": "128ba3a9-c684-4956-8c9f-fe5dc147c7e5"
          }
        }
      ]
    }
  ],
  "appName": "",
  "user": "",
  "name": "documentName",
  "type": "THREAD"
}
```

### 线程更新（即未解决）

```json
{
  "trigger": "thread.updated",
  "thread": {
    "id": "128ba3a9-c684-4956-8c9f-fe5dc147c7e5",
    "createdAt": "2024-03-02T22:17:51.304Z",
    "comments": [
      {
        "id": "0259e4cb-43ad-4eb2-a7e9-a7a7d5207a76",
        "createdAt": "2024-03-02T22:17:51.307Z",
        "updatedAt": "2024-03-02T22:18:04.246Z",
        "data": {
          "userName": "Cyndi Lauper",
          "userAvatar": "https://api.dicebear.com/7.x/lorelei/svg?seed=Cyndi Lauper"
        },
        "content": "线程创建评论（已编辑）"
      }
    ],
    "updatedAt": "2024-03-02T22:18:52.050Z",
    "resolvedAt": null
  },
  "selection": [
    {
      "type": "text",
      "text": "in my opinion",
      "marks": [
        {
          "type": "inlineThread",
          "attrs": {
            "data-thread-id": "128ba3a9-c684-4956-8c9f-fe5dc147c7e5"
          }
        }
      ]
    }
  ],
  "appName": "",
  "user": "",
  "name": "documentName",
  "type": "THREAD"
}
```
