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

> 当呼入通话提供 SDP offer 或商家发起的通话提供 SDP answer 时触发。

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

## 触发条件

当呼入通话提供 SDP offer 或商家发起的通话提供 SDP answer 时触发。

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

使用 `sdpType` 区分 offer 与 answer。对于呼入 offer，接听通话前请先创建 SDP answer。

## 语法

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

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "<ID>",
  "type": "whatsapp.call.connect",
  "apiVersion": "<API_VERSION>",
  "createTime": "<CREATE_TIME>",
  "callingConnect": {
    "id": "<ID>",
    "wacid": "<WACID>",
    "phoneId": "<PHONE_ID>",
    "from": "<FROM>",
    "to": "<TO>",
    "direction": "<DIRECTION>",
    "dialTime": "<DIAL_TIME_VALUE>",
    "sdpType": "<SDP_TYPE>",
    "sdp": "<SDP>"
  }
}
```

## 参数

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

### 事件载荷

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

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

#### callingConnect

| 参数 | 类型 | 必填 | 说明 |
| - | - | - | - |
| `id` | string | 是 | 通话事件的唯一 ID。 |
| `wacid` | string | 是 | WhatsApp 通话 ID。此 ID 唯一标识该通话会话。 |
| `phoneId` | string | 否 | WhatsApp Business 电话号码 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> |
| `sdpType` | string | 否 | WebRTC 连接的 SDP 类型。可选值：`offer`、`answer`。 |
| `sdp` | string | 否 | 符合 [RFC 8866](https://datatracker.ietf.org/doc/html/rfc8866) 的会话描述协议（SDP）信息。包含 WebRTC 连接的媒体会话参数。 |
| `dialTime` | integer (int64) | 否 | 拨打电话的时间，以 Unix 时间戳毫秒为单位。 |

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

## 示例

以下 JSON 是发送到您的接收端的消息体。ID、电话号码和其他账户值仅供参考。

> [accordion] WhatsApp 通话连接事件
>
> WhatsApp 通话接通时的示例载荷
>
> ```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
> {
>   "id": "evt_call_connect_123",
>   "type": "whatsapp.call.connect",
>   "apiVersion": "v2",
>   "createTime": "2024-01-01T12:00:00.000Z",
>   "callingConnect": {
>     "id": "6757b723960b25543b9ecc66",
>     "wacid": "wacid.HBgNNjI4MTM2MTkwNTEzMxUCABIYIEF",
>     "phoneId": "461269257068832",
>     "from": "+12025550124",
>     "to": "+12025550123",
>     "direction": "USER_INITIATED",
>     "dialTime": 1733826430000,
>     "sdpType": "offer",
>     "sdp": "v=0\r\no=- 1732169627243 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE audio\r\na=msid-semantic: WMS af3b01e3-eb42-4244-812e-db903c062ae7\r\na=ice-lite\r\nm=audio 3480 UDP/TLS/RTP/SAVPF 111 126\r\nc=IN IP4 31.13.87.130\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=candidate:785588535 1 udp 2122260223 31.13.87.130 3480 typ host generation 0 network-cost 50\r\na=candidate:1906600321 1 udp 2122262783 2a03:2880:f217:d0:face:b00c:0:699c 3480 typ host generation 0 network-cost 50\r\na=ice-ufrag:CvRXRnInnWhQzLIE\r\na=ice-pwd:HGXUGAFI8wK6seuVknBT2Q==\r\na=fingerprint:sha-256 FB:56:A1:C5:37:35:6C:5C:1B:05:23:B0:DD:BB:2E:C9:5F:E4:70:61:7B:D9:1D:09:84:76:46:23:12:38:B7:01\r\na=setup:actpass\r\na=mid:audio\r\na=sendrecv\r\na=msid:af3b01e3-eb42-4244-812e-db903c062ae7 WhatsAppTrack1\r\na=rtcp-mux\r\na=rtpmap:111 opus/48000/2\r\na=rtcp-fb:111 transport-cc\r\na=fmtp:111 maxaveragebitrate=20000;maxplaybackrate=16000;minptime=20;sprop-maxcapturerate=16000;useinbandfec=1\r\na=rtpmap:126 telephone-event/8000\r\na=maxptime:20\r\na=ptime:20\r\na=ssrc:659928310 cname:WhatsAppAudioStream1\r\n"
>   }
> }
> ```

> [accordion] 用户发起的呼叫连接
>
> ```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": "+12025550124",
>     "fromUserId": "ID.13491208655302741918",
>     "fromParentUserId": "ID.11815799212886844830",
>     "to": "+12025550123",
>     "direction": "USER_INITIATED",
>     "sdpType": "offer",
>     "sdp": "<<RFC 4566 SDP>>"
>   }
> }
> ```

> [accordion] 商家发起的呼叫连接
>
> ```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": "+12025550124",
>     "to": "+12025550123",
>     "toUserId": "ID.13491208655302741918",
>     "toParentUserId": "ID.11815799212886844830",
>     "direction": "BUSINESS_INITIATED",
>     "sdpType": "answer",
>     "sdp": "<<RFC 4566 SDP>>",
>     "dialTime": 1735283452000
>   }
> }
> ```

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


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