mcpField
W
webhook-integration

webhook-integration

github.com/aj-geddes开发375458 次安装35 周前更新
代码仓库

关于 webhook-integration

面向开发者的 Webhook 实现指南,涵盖事件驱动集成中的发送、接收、队列和测试。内容强调签名校验、幂等处理与可靠交付。

主要功能

  1. 01TypeScript Webhook 发送指南
  2. 02Express 接收端实现
  3. 03Bull 队列处理
  4. 04Webhook 测试工具
  5. 05签名、重试与幂等实践

适用场景

  1. 01集成 Stripe、GitHub 或 Shopify
  2. 02构建事件通知与数据同步
  3. 03触发自动化工作流
  4. 04处理支付回调和 CI/CD 通知

安装

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

$npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill webhook-integration

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

包含的文件

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

references/
webhook-queue-with-bull.md
webhook-receiver-express.md
webhook-sender-typescript.md
webhook-testing-utilities.md
scripts/
validate-pipeline.sh
templates/
pipeline.yaml

详细介绍

Webhook 集成

目录

概述

为事件驱动架构实现可靠的 webhook 系统,实现服务与第三方集成之间的实时通信。

适用场景

  • 第三方服务集成(Stripe、GitHub、Shopify)
  • 事件通知系统
  • 实时数据同步
  • 自动化工作流触发
  • 支付处理回调
  • CI/CD 流水线通知
  • 用户活动跟踪
  • 微服务通信

快速开始

最小可运行示例:

import crypto from "crypto";
import axios from "axios";

interface WebhookEvent {
  id: string;
  type: string;
  timestamp: number;
  data: any;
}

interface WebhookEndpoint {
  url: string;
  secret: string;
  events: string[];
  active: boolean;
}

interface DeliveryAttempt {
  attemptNumber: number;
  timestamp: number;
  statusCode?: number;
  error?: string;
  duration: number;
}

// ... (see reference guides for full implementation)

参考指南

references/ 目录中的详细实现:

指南内容
Webhook Sender (TypeScript)Webhook Sender (TypeScript)
Webhook Receiver (Express)Webhook Receiver (Express)
Webhook Queue with BullWebhook Queue with Bull
Webhook Testing UtilitiesWebhook Testing Utilities

最佳实践

✅ 应该做
  • 使用 HMAC 签名进行验证
  • 使用事件 ID 实现幂等性
  • 快速返回 200 OK,异步处理
  • 为重试实现指数退避
  • 添加时间戳以防止重放攻击
  • 使用队列系统确保可靠交付
  • 记录所有交付尝试
  • 提供 webhook 测试工具
  • 记录 webhook 负载架构
  • 实现 webhook 管理界面
  • 允许按事件类型筛选
  • 支持 webhook 版本控制
❌ 不要做
  • 在 webhook 中发送敏感数据
  • 跳过签名验证
  • 因繁重处理而阻塞响应
  • 无限重试
  • 暴露内部错误详情
  • 将 webhook 发送到 localhost(生产环境中)
  • 忘记处理超时
  • 跳过速率限制

评论

支持 Markdown