> ## Documentation Index
> Fetch the complete documentation index at: https://docs.twenty.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 将 Typeform 提交导入 Twenty

> 处理 Typeform 的 webhook 负载，以从表单提交创建潜在客户。

关于标准 webhook 设置，请参见 [设置 Webhook 触发器](/zh/user-guide/workflows/how-tos/connect-to-other-tools/set-up-a-webhook-trigger)。 本文介绍针对 Typeform 自定义负载结构所需的特定处理。

### 步骤 1：创建 Webhook 工作流

1. 进入 **设置 → 工作流**
2. 点击 **+ 新建工作流**
3. 选择 **Webhook** 作为触发器
4. 复制 webhook URL

### 步骤 2：配置 Typeform

1. 在 Typeform 中，打开您的表单
2. 前往 **Connect → Webhooks**
3. 粘贴您的 Twenty webhook URL
4. 保存

### 步骤 3：了解 Typeform 负载

Typeform 会发送嵌套的 JSON 结构。 以下是一个简化示例：

```json theme={null}
{
  "event_type": "form_response",
  "form_response": {
    "form_id": "abc123",
    "submitted_at": "2025-01-15T10:30:00Z",
    "answers": [
      {
        "text": "Jane",
        "type": "text",
        "field": { "id": "field1", "type": "short_text", "title": "First Name" }
      },
      {
        "text": "Smith",
        "type": "text",
        "field": { "id": "field2", "type": "short_text", "title": "Last Name" }
      },
      {
        "text": "Acme Corp",
        "type": "text",
        "field": { "id": "field3", "type": "short_text", "title": "Company" }
      },
      {
        "email": "jane@acme.com",
        "type": "email",
        "field": { "id": "field4", "type": "email", "title": "Email" }
      },
      {
        "type": "choice",
        "field": { "id": "field5", "type": "dropdown", "title": "Team Size" },
        "choice": { "label": "10-50" }
      }
    ]
  }
}
```

关键注意事项：

* 表单数据嵌套在 `form_response` 下
* **答案以数组形式返回**，而不是按命名字段返回
* 每个答案都包含字段类型和标题以供参考

### 步骤 4：从 answers 数组中提取字段

由于 `answers` 是一个数组，在后续步骤中，您只能选择整个数组，而不能选择单独的字段。 添加一个 **Code** 操作来提取您需要的字段：

```javascript theme={null}
export const main = async (params: {
  answers: any;
}): Promise<object> => {
  const { answers } = params;

  // Handle input that may come as a string or an array
  const answersFormatted = typeof answers === "string"
    ? JSON.parse(answers)
    : answers;

  // Extract fields by position or by finding the field type
  const firstName = answersFormatted[0]?.text || "";
  const lastName = answersFormatted[1]?.text || "";
  const company = answersFormatted[2]?.text || "";
  const email = answersFormatted.find(a => a.type === "email")?.email || "";
  const teamSize = answersFormatted.find(a => a.type === "choice")?.choice?.label || "";

  return {
    contact: {
      firstName,
      lastName,
      company,
      email,
      teamSize
    }
  };
};
```

现在在后续步骤中，您可以在变量选择器中选择 `contact.firstName`、`contact.email` 等。

<Tip>
  关于在 Code 操作中处理数组的更多详情，请参见[在 Code 操作中处理数组](/zh/user-guide/workflows/how-tos/advanced-configurations/handle-arrays-in-code-actions)。
</Tip>

### 步骤 5：创建记录

添加 **创建记录** 操作：

| 字段       | 值                                   |
| -------- | ----------------------------------- |
| **对象**   | 人员                                  |
| **名字**   | `{{code.contact.firstName}}`        |
| **姓氏**   | `{{code.contact.lastName}}`         |
| **电子邮件** | `{{code.contact.email}}`            |
| **公司**   | 基于 `{{code.contact.company}}` 搜索或创建 |

### 步骤 6：测试并启用

1. 在 Typeform 中提交测试响应
2. 检查工作流运行以验证已捕获数据
3. 激活工作流

## 相关内容

* [设置 Webhook 触发器](/zh/user-guide/workflows/how-tos/connect-to-other-tools/set-up-a-webhook-trigger)
* [在 Code 操作中处理数组](/zh/user-guide/workflows/how-tos/advanced-configurations/handle-arrays-in-code-actions)
