> This is a page from the ElevenLabs documentation. For an index of the documentation, fetch https://elevenlabs.io/docs/llms.txt.

# 触发器

每个例程都有一个触发器。触发器会启动每次运行，并提供运行输入。只有在例程已启用时，触发器才会触发，且始终运行已发布的版本。

> **Info**
>
> 例程目前处于 Beta 阶段，尚未在所有工作区开放。若要申请访问权限，请联系客户经理。

例程发布后，编辑器标题栏中的**立即运行**可使用任意触发器和你填写的输入，启动已发布版本的一次运行。

## 手动运行

手动运行触发器不会自行启动运行。在触发器中定义运行输入字段，**立即运行**会要求填写相应值。

![“立即运行”对话框，要求输入手动运行触发器的输入
字段](/docs/_fern-files/_img/59f7519bd680a89c855cbc074e5ecb274e5d5201db60442a6d0ec0eb84ea8c2d.webp)

## 计划

计划触发器会按你选择的时区重复运行例程：可按小时、每天、工作日、每周或每月在设定时间运行；其他需求可使用 **自定义（cron）** 表达式。编辑时，触发器会显示下次运行时间。

![计划触发器设为每周一伦敦时间 09:00
运行](/docs/_fern-files/_img/aff65483575de07bf85779fe2db1d4c87cae04ecc1dce75afeefa41a533630c6.webp)

每次运行的输入都是其计划运行时间：

```json
{
  "scheduled_time": "2026-12-08T09:00:00+00:00"
}
```

## 传入 webhook

传入 webhook 触发器可让其他系统（如 CRM 或帮助台）通过发送包含自身数据的请求来启动运行。

#### 生成密钥

在触发器设置中，选择**生成密钥**。

#### 配置发送方

将触发器显示的 webhook URL 和密钥复制到发送请求的系统中。

#### 捕获示例（可选）

关闭例程后，选择**监听示例请求**并发送请求。编辑器会根据请求正文填充触发器输入字段。编辑器
正在监听时发送的请求会被捕获，而不会启动运行。

![传入的 webhook 触发器及其 webhook URL、密钥和输入
参数](/docs/_fern-files/_img/82589b4923aeac7ad6eb5fb0102e3d413da9ca9d2a2738e0c8e9b16a84bdb93f.webp)

在 `X-Webhook-Secret` 请求头中发送密钥，并将运行输入作为 JSON 请求体发送。例程暂不支持 SDK，因此请直接调用 webhook URL：

```python
import os

import requests
from dotenv import load_dotenv

load_dotenv()

response = requests.post(
    "https://api.elevenlabs.io/v1/convai/routines/routine_6801m6ngj6hafeftf8shk12jzfzd/webhook",
    headers={"X-Webhook-Secret": os.getenv("ROUTINE_WEBHOOK_SECRET")},
    json={"customer_id": "cus_8Hk2pQ", "appointment_time": "2026-12-03T15:00:00Z"},
)
response.raise_for_status()
print(response.json()["routine_run_id"])
```

```typescript
import "dotenv/config";

const response = await fetch(
  "https://api.elevenlabs.io/v1/convai/routines/routine_6801m6ngj6hafeftf8shk12jzfzd/webhook",
  {
    method: "POST",
    headers: {
      "X-Webhook-Secret": process.env.ROUTINE_WEBHOOK_SECRET,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ customer_id: "cus_8Hk2pQ", appointment_time: "2026-12-03T15:00:00Z" }),
  }
);
if (!response.ok) {
  throw new Error(`Failed to start the run: ${response.statusText}`);
}
const { routine_run_id } = await response.json();
console.log(routine_run_id);
```

**`cURL`**

```bash title="cURL"
curl -X POST "https://api.elevenlabs.io/v1/convai/routines/routine_6801m6ngj6hafeftf8shk12jzfzd/webhook" \
  -H "X-Webhook-Secret: $ROUTINE_WEBHOOK_SECRET" \
  -H "Content-Type: application/json" \
  -d '{"customer_id": "cus_8Hk2pQ", "appointment_time": "2026-12-03T15:00:00Z"}'
```

请求正文必须是最大不超过 256 KB 的 JSON 对象，并将成为运行输入。端点会返回以下状态之一：

| 状态    | 含义                                         |
| ----- | ------------------------------------------ |
| `202` | 运行已启动。响应包含 `routine_run_id`。               |
| `400` | 请求正文不是 JSON 对象，或缺少必填输入字段。不会启动运行，错误会指出字段名称。 |
| `401` | 密钥缺失或错误。                                   |
| `403` | 例程无法以发布它的成员身份运行。                           |
| `409` | 例程未使用此触发器启用。                               |
| `413` | 请求正文大于 256 KB。                             |
| `429` | 请求过多：超过例程每分钟 60 次的限制，或工作区每小时 1,000 次运行的限制。 |

> **Warning**
>
> 任何拥有密钥的人都可以使用任意输入启动运行，包括步骤所用的值，例如要拨打的
> 电话号码。如果密钥泄露，请从触发器中重新生成。重新生成会直接替换该值，因此请同时更新发送方。

## 对话结束

当与所选任一智能体的对话结束且分析完成后，“对话结束”触发器会启动一次运行。运行输入为该对话及其[数据收集](/docs/zh/eleven-agents/customization/agent-analysis/data-collection)和[成功评估](/docs/zh/eleven-agents/customization/agent-analysis/success-evaluation)结果：

```json
{
  "conversation_id": "conv_0501k6qxbw7fe6v9z3h0r2m8ct4d",
  "agent_id": "agent_7101k5zvyjhmfg983brhmhkd98n6",
  "agent_name": "Support agent",
  "status": "done",
  "metadata": {
    "start_time_unix_secs": 1764836400,
    "call_duration_secs": 184
  },
  "analysis": {
    "call_successful": "success",
    "transcript_summary": "The customer asked to move their delivery to Friday. The agent confirmed the new date.",
    "call_summary_title": "Delivery moved to Friday",
    "evaluation_criteria_results": {
      "resolved": {
        "criteria_id": "resolved",
        "result": "success",
        "rationale": "The agent changed the delivery date as requested."
      }
    },
    "data_collection_results": {
      "email": {
        "data_collection_id": "email",
        "value": "jane.doe@example.com",
        "rationale": "The customer gave their email address to receive the confirmation."
      }
    }
  },
  "transcript": [
    { "role": "agent", "message": "Hi, how can I help you today?", "time_in_call_secs": 0 },
    { "role": "user", "message": "I'd like to move my delivery to Friday.", "time_in_call_secs": 4 }
  ]
}
```

例如，要发送跟进邮件，可将该步骤的收件人设为触发器的 `analysis.data_collection_results.email.value`。

![“对话结束”触发器，已选择一个智能体，并将对话字段保存为
变量](/docs/_fern-files/_img/05d86bf55fd6456dde34cbbc6c7688f324ea48af9a6a07760950f19d9d23a919.webp)

## 触发器未启动运行的情况

* 例程已关闭，或尚未发布。
* 工作区超过每小时 1,000 次运行限制。计划运行会记录为**已停止**，webhook 请求会收到 `429`。
* 计划的上一次运行仍在进行，或其时间已错过超过 1 分钟。
* 编辑器正在监听示例时收到 webhook 请求。
* 对话已加密、处于零保留模式，或已启动此例程。
* 发布例程的成员失去了对其所用内容的访问权限。例程也会被关闭。