Skip to content
This repository was archived by the owner on Jun 10, 2026. It is now read-only.

Latest commit

 

History

History
126 lines (95 loc) · 2.51 KB

File metadata and controls

126 lines (95 loc) · 2.51 KB

Rewrite Express

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.

Rewrite Banner

Instalação

Use with your favorite package manager:

npm install @rewritetoday/express express
# ou
pnpm add @rewritetoday/express express
# ou
bun add @rewritetoday/express express

No extra dependencies are needed. The package already handles the raw body middleware required by Express for webhook verification.

Basic usage

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);
		},
	}),
);

Security by default

  • 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.

Event processing

You can handle specific events without boilerplate:

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.