TwilioWebhook
function TwilioWebhook(options?): MethodDecorator & ClassDecorator;Defined in: lib/webhook/twilio-webhook.decorator.ts:45
Validates that a request was signed by Twilio, and configures how.
Binds TwilioWebhookGuard to the decorated route or controller and
records the supplied options for it to read, so the decorator alone is
sufficient. There is no separate @UseGuards() to remember, and therefore
no way to record webhook options while leaving the route unprotected.
Applying it to a controller class protects every handler in that controller. Applying it again on a method overrides the class-level options for that handler only.
Options precedence, highest first: this decorator, then any per-request context, then the module-level default provided under TWILIO_WEBHOOK_OPTIONS.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
options |
TwilioWebhookOptions |
Per-route webhook validation overrides. |
Returns
Section titled “Returns”MethodDecorator & ClassDecorator
Examples
Section titled “Examples”Protect a single route
@Post('webhooks/sms')@TwilioWebhook()handleIncomingSms(@Body() body: Record<string, string>) { // Reached only if the Twilio signature verified.}Validate against a subaccount token, behind a proxy
@Post('webhooks/billing')@TwilioWebhook({ authToken: process.env.TWILIO_BILLING_AUTH_TOKEN, url: 'https://api.example.com/webhooks/billing',})handleBilling() {}