Official integration of Rewrite with Express to receive Webhooks in a simple, secure and fully typed way.
@rewritetoday/express is a framework-first package, designed to work natively with Express, focused on DX, TypeScript first and good security practices.
You can find the full Webhooks documentation here.
Use with your favorite package manager:
npm install @rewritetoday/express express
# ou
pnpm add @rewritetoday/express express
# ou
bun add @rewritetoday/express expressNo extra dependencies are needed. The package already handles the raw body middleware required by Express for webhook verification.
import express from 'express';
import { Webhooks } from '@rewritetoday/express';
const app = express();
app.post(
'/webhooks/rewrite',
...Webhooks({
secret: '...',
onPayload({ id, type, data }) {
console.log('Hey, a new webhook event:', type);
},
}),
);- Automatic webhook signature verification
- Secure webhook secret comparison
- Payload validated before reaching your handler
- No direct access to API key
Never expose your API key in webhooks.
Always use environment variables.
app.post(
'/webhooks/rewrite',
...Webhooks({
secret: '...',
onSMSOTP({ data }) {
console.log({ data });
},
onMessageSent({ data }) {
console.log({ data });
},
onMessageBatch({ data }) {
console.log({ data });
},
onMessageQueued({ data }) {
console.log({ data });
},
onMessageDelivered({ data }) {
console.log({ data });
},
onMessageScheduled({ data }) {
console.log({ data });
},
onMessageFailed({ data }) {
console.error({ error: data.error });
},
onMessageCanceled({ data }) {
console.log({ data });
},
}),
);Or treat everything generically:
app.post(
'/webhooks/rewrite',
...Webhooks({
secret: '...',
onPayload({ id, type, data }) {
console.log({ id, type, data });
},
}),
);Made by the Rewrite team.
SMS the way it should be.