> ## 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 呼叫连接 Webhook 示例

> 处理 WhatsApp 呼叫连接事件。

<Note>如需查看完整的基于 Schema 生成的目录，请参阅[所有示例](/zh/api-reference/guides/examples/webhook-examples/webhook-payload-examples)。</Note>

## 功能简介

处理 WhatsApp 呼叫连接事件。

## 准备工作

* 在您的应用程序中创建一个公开的 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](/zh/api-reference/guides/api-fundamentals/configure-webhooks)。</Note>

## 用户发起的呼叫连接

当 WhatsApp 用户呼叫您的商家时，将触发包含 SDP Offer 的呼叫连接 Webhook：

### 请求

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "evt_6757b723a5a42d369ef48480",
  "type": "whatsapp.call.connect",
  "apiVersion": "v2",
  "createTime": "2024-12-10T03:36:03.749Z",
  "callingConnect": {
    "id": "6757b723960b25543b9ecc66",
    "wacid": "wacid.HBgNNjI4MTM2MTkwNTEzMxrtLopSdPMwd",
    "phoneId": "461269257068832",
    "from": "+6281361905133",
    "fromUserId": "ID.13491208655302741918",
    "fromParentUserId": "ID.11815799212886844830",
    "to": "+6283138205150",
    "direction": "USER_INITIATED",
    "sdpType": "offer",
    "sdp": "<<RFC 4566 SDP>>"
  }
}
```

### 响应

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

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

<br />

### 说明

按 `type` 路由事件，通过 `id` 进行去重，并将耗时或容易失败的任务移至异步处理器。

## 商家发起的呼叫连接

当商家向 WhatsApp 用户发起新呼叫时，将触发包含 SDP Answer 的呼叫连接 Webhook：

### 请求

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "evt_676e5a0d7a9cb742d02d7645",
  "type": "whatsapp.call.connect",
  "apiVersion": "v2",
  "createTime": "2024-12-27T07:41:01.554Z",
  "callingConnect": {
    "id": "676e5a0d94c533526d3c5ad5",
    "wacid": "wacid.HBgNNjI4MTM2MTkwNTEzMxUCABE",
    "phoneId": "461269257068832",
    "from": "+6283138205150",
    "to": "+6281361905133",
    "toUserId": "ID.13491208655302741918",
    "toParentUserId": "ID.11815799212886844830",
    "direction": "BUSINESS_INITIATED",
    "sdpType": "answer",
    "sdp": "<<RFC 4566 SDP>>",
    "dialTime": 1735283452000
  }
}
```

### 响应

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

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

<br />

### 说明

按 `type` 路由事件，通过 `id` 进行去重，并将耗时或容易失败的任务移至异步处理器。


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