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

> 在 WhatsApp 通话终止时触发。

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

## 触发条件

在 WhatsApp 通话终止时触发。

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

## 语法

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

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "<ID>",
  "type": "whatsapp.call.terminate",
  "apiVersion": "<API_VERSION>",
  "createTime": "<CREATE_TIME>",
  "callingTerminate": {
    "id": "<ID>",
    "wacid": "<WACID>",
    "phoneId": "<PHONE_ID>",
    "from": "<FROM>",
    "to": "<TO>",
    "direction": "<DIRECTION>",
    "startTime": "<START_TIME_VALUE>",
    "endTime": "<END_TIME_VALUE>",
    "duration": "<DURATION_VALUE>",
    "status": "<STATUS>"
  }
}
```

## 参数

在处理 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.call.terminate`。 |
| `apiVersion` | string | 是 | 用于渲染此事件的 API 版本。 |
| `createTime` | string (date-time) | 是 | 此事件的创建时间，格式为 [RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339)。例如 `2022-06-01T12:00:00.000Z`。 |

### 事件有效载荷

| 参数 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `callingTerminate` | object | 否 | 特定于事件的 `callingTerminate` 有效载荷。 |

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

#### callingTerminate

| 参数 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `id` | string | 是 | 通话事件的唯一 ID。 |
| `wacid` | string | 是 | WhatsApp 通话 ID。此 ID 唯一标识该通话会话。 |
| `phoneId` | string | 否 | WhatsApp 商业电话号码 ID。 |
| `from` | string | 否 | 主叫方的电话号码，采用 [E.164](https://en.wikipedia.org/wiki/E.164) 格式。 |
| `fromUserId` | string | 否 | 针对客户发起的通话，主叫方的 WhatsApp 商业范围用户 ID（BSUID）。 |
| `fromParentUserId` | string | 否 | 针对客户发起的通话，主叫方的父级 WhatsApp 商业范围用户 ID。 |
| `to` | string | 否 | 被叫方的电话号码，采用 [E.164](https://en.wikipedia.org/wiki/E.164) 格式。 |
| `toUserId` | string | 否 | 针对商家发起的通话，被叫方的 WhatsApp 商业范围用户 ID（BSUID）。 |
| `toParentUserId` | string | 否 | 针对商家发起的通话，被叫方的父级 WhatsApp 商业范围用户 ID。 |
| `customerProfile` | object | 否 | 客户的个人资料信息，包括 WhatsApp 用户名（如果可用）。 |
| `direction` | string | 否 | 通话方向。<ul><li>`USER_INITIATED`：客户向商家发起的通话。</li><li>`BUSINESS_INITIATED`：商家向客户发起的通话。</li></ul> |
| `startTime` | integer (int64) | 否 | 通话开始时间，采用 Unix 时间戳毫秒数表示。 |
| `endTime` | integer (int64) | 否 | 通话结束时间，采用 Unix 时间戳毫秒数表示。 |
| `duration` | integer (int64) | 否 | 通话时长（秒）。 |
| `status` | string | 否 | 通话的最终状态。<ul><li>`COMPLETED`：通话已成功完成。</li><li>`FAILED`：通话因错误失败。</li></ul> |
| `errorCode` | string | 否 | 通话状态为 `FAILED` 时的错误代码。表示错误的数字字符串。 |

> [accordion] callingTerminate.customerProfile
>
> | 参数 | 类型 | 必填 | 说明 |
> | - | - | - | - |
> | `name` | string | 否 | WhatsApp 账户的名称。 |
> | `username` | string | 否 | WhatsApp 用户名。 |

## 示例

以下 JSON 是发送至接收方的请求体。其中的 ID、电话号码以及其他账户数值仅供参考。

> [accordion] WhatsApp 通话终止事件
>
> WhatsApp 通话终止时的示例有效载荷
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "id": "evt_6757b889a5a42d369ef48481",
>   "type": "whatsapp.call.terminate",
>   "apiVersion": "v2",
>   "createTime": "2024-12-10T03:42:01.822Z",
>   "callingTerminate": {
>     "id": "6757b889960b25543b9ecc67",
>     "wacid": "wacid.HBgNNjI4MTM2MTkwNTEzMxUCABIYIEFENjB",
>     "phoneId": "461269257068832",
>     "from": "+12025550124",
>     "to": "+12025550123",
>     "direction": "USER_INITIATED",
>     "startTime": 1733734738000,
>     "endTime": 1733734771000,
>     "duration": 33,
>     "status": "COMPLETED"
>   }
> }
> ```

> [accordion] 通话已完成
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "id": "evt_6757b889a5a42d369ef48481",
>   "type": "whatsapp.call.terminate",
>   "apiVersion": "v2",
>   "createTime": "2024-12-10T03:42:01.822Z",
>   "callingTerminate": {
>     "id": "6757b889960b25543b9ecc67",
>     "wacid": "wacid.HBgNNjI4MTM2MTkwNTE",
>     "phoneId": "461269257068832",
>     "from": "+12025550124",
>     "fromUserId": "ID.13491208655302741918",
>     "fromParentUserId": "ID.11815799212886844830",
>     "to": "+12025550123",
>     "direction": "USER_INITIATED",
>     "startTime": 1733734738000,
>     "endTime": 1733734771000,
>     "duration": 33,
>     "status": "COMPLETED"
>   }
> }
> ```

> [accordion] 通话失败
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "id": "evt_675907f431c55113a751d0e7",
>   "type": "whatsapp.call.terminate",
>   "apiVersion": "v2",
>   "createTime": "2024-12-11T03:33:08.679Z",
>   "callingTerminate": {
>     "id": "675907a13ae4a901f05fee95",
>     "wacid": "wacid.HBgNODYxNTE1NzEzNzYyM",
>     "phoneId": "461269257068832",
>     "from": "+12025550124",
>     "fromUserId": "ID.13491208655302741918",
>     "fromParentUserId": "ID.11815799212886844830",
>     "to": "+12025550123",
>     "direction": "USER_INITIATED",
>     "startTime": 1733826484000,
>     "endTime": 1733826637000,
>     "duration": 30,
>     "status": "FAILED",
>     "errorCode": "131000"
>   }
> }
> ```

在验证签名并持久化接收事件后，返回 `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-calling-terminate-webhook-examples)。


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