> ## 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.created` 和 `contact.note.created` 事件。

## 准备工作

* 在您的应用程序中创建一个公开的 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 有效载荷包含所创建联系人的完整信息。

## 联系人创建示例

### 请求

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "evt_2345678901",
  "type": "contact.created",
  "apiVersion": "v2",
  "createTime": "2024-01-01T12:00:00.000Z",
  "contactCreated": {
    "id": "1824266594102064128",
    "nickName": "John Doe",
    "realName": "John Smith",
    "phoneNumber": "+16315551111",
    "countryCode": "US",
    "countryName": "United States",
    "email": "john.doe@example.com",
    "sourceType": "api",
    "sourceId": "import_batch_123",
    "sourceUrl": "https://example.com/signup",
    "lastSeen": "2024-01-01T11:59:00.000Z",
    "lastConnectedNumber": "+16315552222",
    "ownerEmail": "owner@example.com",
    "tags": [
      "premium",
      "newsletter"
    ],
    "createTime": "2024-01-01T12:00:00.000Z",
    "updateTime": "2024-01-01T12:00:00.000Z",
    "blocked": false,
    "customAttributes": {
      "company": "YCloud Inc",
      "age": 25
    }
  }
}
```

### 响应

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

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

### 说明

* **完整联系人信息**：`contactCreated` 对象包含创建时所有可用的联系人信息。
* **自定义属性**：`customAttributes` 字段包含与联系人关联的所有自定义数据。
* **标签**：`tags` 数组包含创建期间分配给联系人的所有标签。

## 联系人备注已创建

在创建联系人备注时使用 `contact.note.created`。

### 请求

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "evt_1234567890abcdef12345678",
  "type": "contact.note.created",
  "apiVersion": "v2",
  "createTime": "2024-01-01T12:00:00.000Z",
  "contactNote": {
    "id": "6a3de646e18f344f743aaa4d",
    "contactId": "1824266594102064128",
    "username": "alice_01",
    "phoneNumber": "+16315551111",
    "content": "Customer prefers follow-up in the morning.",
    "createTime": "2024-01-01T12:00:00.000Z",
    "updateTime": "2024-01-01T12: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.