> ## 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.

# whatsapp.user.preferences

> 当 WhatsApp 用户停止接收营销消息或恢复接收营销消息时触发。

使用 `whatsapp.user.preferences` 在您的 Webhook 端点处理此事件。

## 触发条件

当 WhatsApp 用户停止接收营销消息或恢复接收营销消息时触发。

在您[配置 Webhook 端点](https://docs.ycloud.com/zh/api-reference/guides/api-fundamentals/configure-webhooks.md)时订阅 `whatsapp.user.preferences`。

## 语法

YCloud 向您配置的 Webhook URL 发送 HTTP `POST` 请求。以下结构展示了一种负载变体。尖括号中的值为占位符；其类型列于 **参数** 下。可选字段和其他变体在下文中有详细说明。

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "<ID>",
  "type": "whatsapp.user.preferences",
  "apiVersion": "<API_VERSION>",
  "createTime": "<CREATE_TIME>",
  "whatsappUserPreference": {
    "wabaId": "<WABA_ID>",
    "businessPhoneNumber": "<BUSINESS_PHONE_NUMBER>",
    "businessPhoneId": "<BUSINESS_PHONE_ID>",
    "contactName": "<CONTACT_NAME>",
    "contactPhoneNumber": "<CONTACT_PHONE_NUMBER>",
    "userId": "<USER_ID>",
    "parentUserId": "<PARENT_USER_ID>",
    "detail": "<DETAIL>",
    "category": "<CATEGORY>",
    "value": "<VALUE>",
    "timestamp": "<TIMESTAMP>"
  }
}
```

## 参数

在处理 JSON 请求体之前验证 `YCloud-Signature` HTTP 请求头。参见[签名验证](https://docs.ycloud.com/zh/api-reference/guides/api-fundamentals/configure-webhooks.md)。

### 事件信封

| 参数 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `id` | string | 是 | 事件的唯一 ID。最小长度：`6`。最大长度：`128`。 |
| `type` | string | 是 | 固定为 `whatsapp.user.preferences`。 |
| `apiVersion` | string | 是 | 用于呈现此事件的 API 版本。 |
| `createTime` | string (date-time) | 是 | 此事件创建的时间，格式采用 [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339)。例如：`2022-06-01T12:00:00.000Z`。 |

### 事件负载

| 参数 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `whatsappUserPreference` | object | 否 | 特定于事件的 `whatsappUserPreference` 负载。 |

四个通用信封字段为必填项。负载字段取决于事件变体。在每个对象表中， **必填** 在其父对象存在时适用。可选字段可以省略；示例中出现并不代表该字段为必填项。

#### whatsappUserPreference

| 参数 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `wabaId` | string | 否 | WhatsApp 商业账户 ID。 |
| `businessPhoneNumber` | string | 否 | 采用 [E.164](https://en.wikipedia.org/wiki/E.164) 格式的电话号码。 |
| `businessPhoneId` | string | 否 | 电话号码 ID。 |
| `contactName` | string | 否 | WhatsApp 用户名称。 |
| `contactPhoneNumber` | string | 否 | WhatsApp 用户电话号码。采用 [E.164](https://en.wikipedia.org/wiki/E.164) 格式的电话号码。 |
| `userId` | string | 否 | WhatsApp 用户的业务范围用户 ID（BSUID）。 |
| `parentUserId` | string | 否 | WhatsApp 用户的父级业务范围用户 ID。当未启用父级 BSUID 时省略。 |
| `detail` | string | 否 | 营销消息偏好描述。 |
| `category` | string | 否 | WhatsApp 报告的偏好类别，例如 `marketing_messages`。 |
| `value` | string | 否 | 营销消息偏好。 |
| `timestamp` | string | 否 | 表示 Webhook 触发时间的 Unix 时间戳。 |

## 示例

以下 JSON 是传递给您接收器的请求体。ID、电话号码和其他账户值仅供参考。

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "evt_example_whatsapp_user_preferences",
  "type": "whatsapp.user.preferences",
  "apiVersion": "v2",
  "createTime": "2026-05-26T12:00:00.000Z",
  "whatsappUserPreference": {
    "wabaId": "whatsapp-business-account-id",
    "businessPhoneNumber": "+12025550123",
    "businessPhoneId": "1234567890123456",
    "contactName": "Example customer",
    "contactPhoneNumber": "+12025550124",
    "userId": "US.13491208655302741918",
    "parentUserId": "US.ENT.11815799212886844830",
    "detail": "User requested to stop marketing messages",
    "category": "marketing_messages",
    "value": "stop",
    "timestamp": "1779796800000"
  }
}
```

验证签名并持久化接收事件后，返回 `2xx` 响应。耗时任务请异步处理。

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

有关场景演练，请参阅[带注释的示例](https://docs.ycloud.com/zh/api-reference/guides/examples/webhook-examples/whatsapp-inbound-message-webhook-examples)。


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