> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ycloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 联系人及备注删除 Webhook 示例

> 处理联系人删除和独立备注删除事件。

> [!NOTE]
>
> 如需查看基于架构生成的完整目录，请参阅[所有示例](https://docs.ycloud.com/zh/api-reference/guides/examples/webhook-examples/webhook-payload-examples)。

## 概述

处理 `contact.deleted` 和 `contact.note.deleted` 事件。

## 准备工作

* 在您的应用程序中创建一个公开的 HTTPS 终端节点。
* 为您所需的事件类型配置 YCloud Webhook 终端节点。
* 安全存储终端节点签名密钥。
* 确保事件处理具备幂等性。

## 工作原理

事件发生时，YCloud 会发送 HTTP `POST` 请求。验证签名，持久化记录该事件，返回 `2xx` 响应，并异步处理耗时任务。

## 请求

以下场景展示了发送到您的 Webhook URL 的请求。将事件 `id` 视为投递标识符，并使用 `type` 来路由有效载荷。

## 响应

在接收事件后返回 `2xx` 状态。

```http theme={"theme":{"light":"github-light","dark":"github-dark"}}
HTTP/1.1 200 OK
```

> [!NOTE]
>
> 有关终端节点设置、签名验证和重试机制的详细信息，请参阅[配置 Webhook](https://docs.ycloud.com/zh/api-reference/guides/api-fundamentals/configure-webhooks.md)。

前提条件

* Webhook 终端节点 URL 应由您的服务器提供，而非 YCloud。 **请确保将该 URL 替换为您实际的 Webhook 终端节点 URL。**
* **请确保您的 Webhook 终端节点正在侦听相应的事件类型。** 另请参阅[配置 Webhook](https://docs.ycloud.com/zh/api-reference/guides/api-fundamentals/configure-webhooks.md)、[获取 Webhook 终端节点 API](https://docs.ycloud.com/api-reference/webhook-endpoints/retrieve-a-webhook-endpoint.md)。

在联系人被删除时触发。Webhook 有效载荷包含被删除的最小联系人信息。

## 基础联系人删除示例

### 请求

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "evt_3456789012",
  "type": "contact.deleted",
  "apiVersion": "v2",
  "createTime": "2024-01-01T12:00:00.000Z",
  "contactDeleted": {
    "id": "1824266594102064128",
    "nickName": "John Doe",
    "phoneNumber": "+16315551111",
    "updateTime": "2024-01-01T12:00:00.000Z"
  }
}
```

### 响应

在持久化接收事件后确认接收。

```http theme={"theme":{"light":"github-light","dark":"github-dark"}}
HTTP/1.1 200 OK
```

### 说明

* **最简信息**：`contactDeleted` 对象仅包含基本信息：`id`、`nickName`、`phoneNumber` 和 `updateTime`。
* **Null 值**：如果联系人未设置昵称，则 `nickName` 字段可能为 `null`。
* **更新时间**：`updateTime` 反映了联系人在删除前的最后修改时间。
* **联系人 ID**：`id` 字段包含已删除联系人的唯一标识符以供参考。
* **电话号码**：`phoneNumber` 始终存在并采用 E.164 格式。

## 联系人备注已删除

当联系人备注被删除时使用 `contact.note.deleted`。

### 请求

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "evt_3234567890abcdef12345678",
  "type": "contact.note.deleted",
  "apiVersion": "v2",
  "createTime": "2024-01-03T12:00:00.000Z",
  "contactNote": {
    "id": "6a3de646e18f344f743aaa4d",
    "contactId": "1824266594102064128",
    "username": "alice_01",
    "phoneNumber": "+16315551111",
    "content": "Customer now prefers afternoon follow-up.",
    "createTime": "2024-01-01T12:00:00.000Z",
    "updateTime": "2024-01-02T12:00:00.000Z"
  }
}
```

### 响应

在持久化接收事件后确认接收。

```http theme={"theme":{"light":"github-light","dark":"github-dark"}}
HTTP/1.1 200 OK
```

### 说明

使用 `contactNote.id` 标识备注，使用 `contactId` 标识其所属的联系人。`username` 和 `phoneNumber` 用于描述联系人，可以为 null。有效载荷包含面向客户的备注快照，包括 `content`，不含内部操作员标识符。该事件在独立删除备注时发出。删除联系人不会针对每个级联删除的备注发出此事件。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.