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

# 示例 1：AI 自动回复

本示例演示了如何使用 n8n、大语言模型和 YCloud 节点实现基本的自动回复工作流：<br />当 YCloud 平台收到入站消息时，会通过 Webhook 触发 n8n 工作流。工作流调用大语言模型生成回复，然后通过 YCloud 节点将消息发送回用户。

> YCloud AI Agent 为您构建了全面的 AI 工作流，提供端到端、通俗易懂的 AI 知识库、语料库和自动化流程。点击此处查看更多详情。

### 整体流程

<img src="https://mintcdn.com/lchnan/7IqVC2giQEcOq6-5/product-assets/31a5e257bb-image-835.webp?fit=max&auto=format&n=7IqVC2giQEcOq6-5&q=85&s=45da1a8b4fd560222e1adc5d9e57bd47" alt="YCloud 产品截图" width="1739" height="787" data-path="product-assets/31a5e257bb-image-835.webp" />

### Webhook 事件

1. 创建 Webhook 端点
   1. 使用 n8n Webhook 节点创建新的监听器
   2. 选择 POST 作为 HTTP 方法
   3. 在 Options 中，将 Response Code 设置为 200，并确保选中“Immediately”

<img src="https://mintcdn.com/lchnan/PCdfO4VGvgYoGyQM/product-assets/fc7f38f8c3-ishot-2026-04-30-10-25-09.webp?fit=max&auto=format&n=PCdfO4VGvgYoGyQM&q=85&s=68fa46fe890c8b71626e7b2e4afb6860" alt="YCloud 产品截图" width="1920" height="993" data-path="product-assets/fc7f38f8c3-ishot-2026-04-30-10-25-09.webp" />

将端点详细信息添加到 YCloud 平台，并选择要监听的 Webhook 事件

<Frame caption="Use Search event to find the webhook events your n8n workflow needs before confirming.">
  <img src="https://mintcdn.com/lchnan/gXEJIQXV2JH2VUQJ/product-assets/english-help-2026-09-22/developer-webhook-events-annotated.svg?fit=max&auto=format&n=gXEJIQXV2JH2VUQJ&q=85&s=81cb1ab6ab3e979bb8ad6fdd9c4d4122" alt="带有 Search 事件高亮显示的 YCloud Webhook 事件选择器。" width="3024" height="1656" data-path="product-assets/english-help-2026-09-22/developer-webhook-events-annotated.svg" />
</Frame>

### 解析返回值并验证签名

#### 解析返回值

使用 n8n 内置的“code”节点解析 Webhook 响应中的请求头

<img src="https://mintcdn.com/lchnan/7IqVC2giQEcOq6-5/product-assets/2c273275ba-ishot-2026-04-30-10-50-04.webp?fit=max&auto=format&n=7IqVC2giQEcOq6-5&q=85&s=2ce32f2b7a9148f5c19f291ff87fb4ad" alt="YCloud 产品截图" width="1920" height="993" data-path="product-assets/2c273275ba-ishot-2026-04-30-10-50-04.webp" />

选择 JavaScript 进行解析

```javascript theme={"theme":{"light":"github-light","dark":"github-dark"}}
function parseSignatureHeader(signatureHeader) {
  const result = {};
  for (const part of (signatureHeader || '').split(',')) {
    const [key, value] = part.split('=');
    if (key && value) {
      result[key.trim()] = value.trim();
    }
  }
  return result;
}

const input = $input.first().json;
const headers = input.headers || {};
const body = input.body;

const signatureHeader = headers['ycloud-signature'] ;
const parsed = parseSignatureHeader(signatureHeader);

const timestamp = parsed.t;
const receivedSignature = parsed.s;

const payload =
  body === undefined || body === null
    ? ''
    : typeof body === 'string'
      ? body
      : JSON.stringify(body);

const signedPayload = `${timestamp}.${payload}`;

return [
  {
    json: {
      ...input,
      timestamp,
      receivedSignature,
      payload,
      signedPayload,
      signatureHeader,

    }
  }
];
```

该节点的返回值包括：

* 原始值，
* 时间戳，
* 接收到的签名、有效负载 (payload)、已签名负载 (signed payload) 以及请求头中的签名信息

#### 加密数据

在上一步中，数据已被完全拆分。在此节点中，我们将使用 SignedPayload 和 Secret。我们将使用 Crypto 节点对数据进行加密。

<img src="https://mintcdn.com/lchnan/7IqVC2giQEcOq6-5/product-assets/304e08d482-ishot-2026-04-30-10-52-06.webp?fit=max&auto=format&n=7IqVC2giQEcOq6-5&q=85&s=ef80f4acfb29d1a6ac4db24fbcb9d958" alt="YCloud 产品截图" width="1920" height="993" data-path="product-assets/304e08d482-ishot-2026-04-30-10-52-06.webp" />

从 YCloud 平台获取 Secret。

<img src="https://mintcdn.com/lchnan/PCdfO4VGvgYoGyQM/product-assets/f3c6c5acc3-ishot-2026-04-30-11-24-02.webp?fit=max&auto=format&n=PCdfO4VGvgYoGyQM&q=85&s=1217648ce39e95778e3a1079aec84c13" alt="YCloud 产品截图" width="2940" height="604" data-path="product-assets/f3c6c5acc3-ishot-2026-04-30-11-24-02.webp" />

#### 对比签名

使用 if 语句验证签名信息；如果匹配，则视为验证成功。

<img src="https://mintcdn.com/lchnan/AlSk34JesCiO_ZYy/product-assets/e3c383a5bb-ishot-2026-04-30-10-54-22.webp?fit=max&auto=format&n=AlSk34JesCiO_ZYy&q=85&s=2ee80efbbc283a3fe1390d3e82ff4c95" alt="YCloud 产品截图" width="1920" height="993" data-path="product-assets/e3c383a5bb-ishot-2026-04-30-10-54-22.webp" />

#### 使用 AI 回复消息

订阅 `whatsapp.inbound_message.received` 和 `whatsapp.message.updated` 事件后，您将在收到消息时收到推送通知，或在发送消息后收到后续状态更新。

1. 使用 `switch` 节点配置多种 Webhook 通知类型。

<img src="https://mintcdn.com/lchnan/RN4tXfXENVvDu0Te/product-assets/b3c1737815-ishot-2026-04-30-16-25-41.webp?fit=max&auto=format&n=RN4tXfXENVvDu0Te&q=85&s=9e974b4c366f72c61bfae9bfbd37ce00" alt="YCloud 产品截图" width="1920" height="993" data-path="product-assets/b3c1737815-ishot-2026-04-30-16-25-41.webp" />

2. 当收到 `inbound_message_received` 事件时，可以通过调用 AI API 生成回复

<img src="https://mintcdn.com/lchnan/WD-ixrYVrqB7b7aQ/product-assets/50e1d1e086-ishot-2026-04-30-16-28-07.webp?fit=max&auto=format&n=WD-ixrYVrqB7b7aQ&q=85&s=ded17a4e52f2fbc1a0ca65475b14424d" alt="YCloud 产品截图" width="1920" height="993" data-path="product-assets/50e1d1e086-ishot-2026-04-30-16-28-07.webp" />

3. 使用 merge 节点保留上一部分中的 Webhook 推送数据集合

<img src="https://mintcdn.com/lchnan/9zlgZMZStxEKrVPM/product-assets/09afdc4376-ishot-2026-04-30-16-28-24.webp?fit=max&auto=format&n=9zlgZMZStxEKrVPM&q=85&s=aff24c2139549e797167523c027732d1" alt="YCloud 产品截图" width="571" height="517" data-path="product-assets/09afdc4376-ishot-2026-04-30-16-28-24.webp" />

4. 使用 YCloud 节点发送消息

<img src="https://mintcdn.com/lchnan/WD-ixrYVrqB7b7aQ/product-assets/4c8c3181d3-ishot-2026-04-30-16-34-48.webp?fit=max&auto=format&n=WD-ixrYVrqB7b7aQ&q=85&s=0a5b33d46797eead0c71665dadf4b640" alt="YCloud 产品截图" width="1047" height="862" data-path="product-assets/4c8c3181d3-ishot-2026-04-30-16-34-48.webp" />

填写相关详情，将 AI 生成的文本放入 Body 字段中并发送。

<Warning>
  请注意，这里的发送者和接收者是 **相反的** ；这是一条回复消息。
</Warning>

至此，完整的 n8n 工作流（Webhook → 大语言模型 → 自动回复）现已配置完成。

### 保存到数据表（可选）

<img src="https://mintcdn.com/lchnan/PCdfO4VGvgYoGyQM/product-assets/facf991e02-ishot-2026-04-30-17-17-34.webp?fit=max&auto=format&n=PCdfO4VGvgYoGyQM&q=85&s=c31f86a044a3198ac01f4df4bb1c61fb" alt="YCloud 产品截图" width="710" height="916" data-path="product-assets/facf991e02-ishot-2026-04-30-17-17-34.webp" />

### 监听已发送消息的后续更新（可选）

完成步骤 5 后，数据将通过 `whatsapp.message.update` 事件推送。

收到此推送后，您可以使用 `datatable - update rows` 节点更新数据表，从而跟踪整个消息发送过程。

<img src="https://mintcdn.com/lchnan/RN4tXfXENVvDu0Te/product-assets/d71c29cf5b-image-20260430172030545.webp?fit=max&auto=format&n=RN4tXfXENVvDu0Te&q=85&s=6e9c7f56be24cde01e3a56489add9c9c" alt="YCloud 产品截图" width="652" height="574" data-path="product-assets/d71c29cf5b-image-20260430172030545.webp" />

<img src="https://mintcdn.com/lchnan/6CxA7mK2t7klNAOL/product-assets/a35824b7cb-image-20260430172039734.webp?fit=max&auto=format&n=6CxA7mK2t7klNAOL&q=85&s=831e5308b4b34776bb5416220faa1878" alt="YCloud 产品截图" width="644" height="652" data-path="product-assets/a35824b7cb-image-20260430172039734.webp" />


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