mcpField
W
webflow-webhooks

webflow-webhooks

github.com/hookdeck开发95190 次安装今天更新
代码仓库

关于 webflow-webhooks

webflow-webhooks 是一项指导实现 Webflow Webhook 接收、签名验证和事件处理的技能,面向处理 Webflow 表单、电商、发布和 CMS 事件的开发者。它还说明签名验证的前提及本地测试方法。

主要功能

  1. 01Webhook 签名验证指南
  2. 02防重放的时间戳校验
  3. 03常见 Webflow 事件参考
  4. 04原始请求体处理示例
  5. 05使用 Hookdeck CLI 本地测试

适用场景

  1. 01验证带签名的 Webflow Webhook 请求
  2. 02处理表单提交和订单
  3. 03在 CMS 条目变更时更新系统
  4. 04在本地开发中测试 Webhook 投递

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/hookdeck/webhook-skills --skill webflow-webhooks

安装后在 Claude Code 中输入/webflow-webhooks确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

examples/express/
.env.example
package.json
README.md
examples/express/src/
index.js
examples/express/test/
webhook.test.js
examples/fastapi/
.env.example
main.py
README.md
requirements.txt
test_webhook.py
examples/nextjs/
.env.example
package.json
README.md
vitest.config.ts
examples/nextjs/app/webhooks/webflow/
route.ts
examples/nextjs/test/
webhook.test.ts
references/
overview.md
setup.md
verification.md

详细介绍

Webflow Webhooks

何时使用此技能

  • 如何接收 Webflow Webhooks?
  • 如何验证 Webflow Webhook 签名?
  • 如何处理来自 Webflow 的 form_submission 事件?
  • 如何处理 Webflow 电商订单事件?
  • 为什么我的 Webflow Webhook 签名验证失败?
  • 设置 Webflow CMS 集合项 Webhooks

核心代码

手动验证签名
const crypto = require('crypto');

function verifyWebflowSignature(rawBody, signature, timestamp, secret) {
  // Check timestamp to prevent replay attacks (5 minute window - 300000 milliseconds)
  const currentTime = Date.now();
  if (Math.abs(currentTime - parseInt(timestamp)) > 300000) {
    return false;
  }

  // Generate HMAC signature
  const signedContent = `${timestamp}:${rawBody}`;
  const expectedSignature = crypto
    .createHmac('sha256', secret)
    .update(signedContent)
    .digest('hex');

  // Timing-safe comparison
  try {
    return crypto.timingSafeEqual(
      Buffer.from(signature),
      Buffer.from(expectedSignature)
    );
  } catch {
    return false; // Different lengths = invalid
  }
}
处理事件
app.post('/webhooks/webflow', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = req.headers['x-webflow-signature'];
  const timestamp = req.headers['x-webflow-timestamp'];

  if (!signature || !timestamp) {
    return res.status(400).send('Missing required headers');
  }

  // Verify signature (use OAuth client secret or webhook-specific secret)
  const isValid = verifyWebflowSignature(
    req.body.toString(),
    signature,
    timestamp,
    process.env.WEBFLOW_WEBHOOK_SECRET
  );

  if (!isValid) {
    return res.status(400).send('Invalid signature');
  }

  // Parse the verified payload
  const event = JSON.parse(req.body);

  // Handle different event types
  switch (event.triggerType) {
    case 'form_submission':
      console.log('New form submission:', event.payload.data);
      break;
    case 'ecomm_new_order':
      console.log('New order:', event.payload);
      break;
    case 'collection_item_created':
      console.log('New CMS item:', event.payload);
      break;
    // Add more event handlers as needed
  }

  // Always return 200 to acknowledge receipt
  res.status(200).send('OK');
});

常见事件类型

事件触发时机用例
form_submission网站上的表单提交时联系表单、潜在客户获取
site_publish网站发布时清除缓存、触发构建
ecomm_new_order新电商订单创建时订单处理、库存管理
ecomm_order_changed订单状态变更时更新履约系统
collection_item_createdCMS 项目创建时内容分发
collection_item_changedCMS 项目更新时更新外部系统
collection_item_deletedCMS 项目删除时从外部系统中移除
collection_item_publishedCMS 项目发布时使缓存失效、发布到下游系统

Webflow 在 All Events中记录了 13 种事件类型;其官方 webflow-api SDK 的 TriggerType 枚举包含这些类型以及 collection_item_published。user_account_* 事件已弃用——请参阅 references/overview.md。

环境变量

# For webhooks created via OAuth App
WEBFLOW_WEBHOOK_SECRET=your_oauth_client_secret

# For webhooks created via API (after April 2025)
WEBFLOW_WEBHOOK_SECRET=whsec_xxxxx  # Returned when creating webhook

本地开发

如需在本地测试 Webhook,请安装 Hookdeck CLI:

然后启动隧道:

npx hookdeck-cli listen 3000 webflow --path /webhooks/webflow

无需账户。提供本地隧道和 Web 界面,用于检查请求。

资源

重要说明

  • 通过 Webflow 控制面板创建的 Webhooks 不包含签名标头
  • 只有通过 OAuth 应用或 API 创建的 Webhooks 才包含 x-webflow-signature 和 x-webflow-timestamp
  • 验证签名时务必使用原始请求体,而不是解析后的 JSON
  • 时间戳验证(5 分钟窗口,即 300000 毫秒)对于防止重放攻击至关重要
  • 返回 200 状态码以确认收到;其他状态码会触发重试(最多 3 次)

推荐:webhook-handler-patterns

此技能与 webhook-handler-patterns 搭配使用,有助于实现可用于生产环境的方案:

相关技能

来源:

评论

支持 Markdown