Stop fightingwebhooks.
The local-first toolkit for capturing, replaying, and shipping type-safe webhook handlers in TypeScript.
Quick Install
1import { github } from "@better-webhook/github";2import { push, pull_request } from "@better-webhook/github/events";3import { toNextJS } from "@better-webhook/nextjs";45const webhook = github()6 .event(push, async (payload) => {7 console.log(payload.repository.name);8 console.log(payload.commits.length);9 })10 .event(pull_request, async (payload) => {11 if (payload.action === "opened") {12 await notifyTeam(payload.pull_request);13 }14 });1516export const POST = toNextJS(webhook);Get started in 60s
Build type-safe webhook handlers with automatic signature verification in your framework of choice.
Install packages
$ npm install @better-webhook/github @better-webhook/nextjsCreate webhook handler
import { github } from "@better-webhook/github";
import { push, pull_request } from "@better-webhook/github/events";
import { toNextJS } from "@better-webhook/nextjs";
const webhook = github()
.event(push, async (payload) => {
console.log(`Push to ${payload.repository.name}`);
})
.event(pull_request, async (payload) => {
if (payload.action === "opened") {
console.log(`New PR: ${payload.pull_request.title}`);
}
});
export const POST = toNextJS(webhook);Set webhook secret
# .env
GITHUB_WEBHOOK_SECRET=your_webhook_secretDone! Your webhook endpoint has automatic signature verification and full TypeScript support.
Everything you need for webhook dev
A focused SDK for production webhook handlers, provider events, and framework adapters.
Type-Safe Handlers
Full TypeScript support with Zod schemas. Get autocomplete for every event payload property.
Signature Verification
Automatic signature verification for GitHub, Stripe, Ragie, Recall.ai, and Resend with timing-safe comparison.
Framework Adapters
First-class integrations for Next.js, Hono, Express, NestJS, and GCP Cloud Functions.
Replay Protection
Optional duplicate detection with provider replay keys and configurable duplicate handling.
Typed Event Catalogs
Provider packages expose curated event definitions so handlers stay precise and discoverable.
Custom Providers
Define your own providers with schemas, signature verification, and event matching.
Type-safe. Verified. Simple.
Build webhook handlers with full TypeScript support, automatic signature verification, and Zod schema validation.
Signature Verification
Automatic HMAC verification for all providers. Timing-safe comparison prevents attacks.
Type-Safe Handlers
Full TypeScript support with Zod schemas. Autocomplete for every payload property.
Framework Adapters
First-class support for Next.js, Hono, Express, NestJS, and GCP Functions.
import { github } from "@better-webhook/github";
import { push, pull_request } from "@better-webhook/github/events";
import { toNextJS } from "@better-webhook/nextjs";
const webhook = github()
.event(push, async (payload) => {
console.log(`Push to ${payload.repository.name}`);
console.log(`${payload.commits.length} commits`);
})
.event(pull_request, async (payload) => {
if (payload.action === "opened") {
console.log(`New PR: ${payload.pull_request.title}`);
}
})
.onError((error, context) => {
console.error(`Error in ${context.eventType}`, error);
});
export const POST = toNextJS(webhook);Available Providers
GitHub
@better-webhook/githubRagie
@better-webhook/ragieStripe
@better-webhook/stripeRecall.ai
@better-webhook/recallResend
@better-webhook/resendSee the difference
Compare traditional webhook handling with better-webhook. Less boilerplate, more safety.
1// The better-webhook way - type-safe and secure23import { github } from "@better-webhook/github";4import { push } from "@better-webhook/github/events";5import { toExpress } from "@better-webhook/express";67const webhook = github()8 .event(push, async (payload) => {9 // Full autocomplete and type safety!10 console.log(payload.repository.name);11 console.log(payload.commits.length);12 13 for (const commit of payload.commits) {14 console.log(commit.message);15 }16 })17 .onError((error, context) => {18 logger.error(`Failed: ${context.eventType}`, error);19 });2021app.post('/webhooks/github',22 express.raw({ type: 'application/json' }),23 toExpress(webhook)24);What changes
Webhook Providers
Pre-built providers with automatic signature verification and fully typed payloads. Create custom providers for any webhook source.
GitHub
Ragie
Stripe
Recall.ai
Resend
Custom
GitHub
@better-webhook/githubExample Events
Ragie
@better-webhook/ragieExample Events
Stripe
@better-webhook/stripeExample Events
Recall.ai
@better-webhook/recallExample Events
Resend
@better-webhook/resendExample Events
Need a different provider? Create custom webhooks with the core package.