TwimlInterceptor
Defined in: lib/twiml/twiml.interceptor.ts:198
Serializes Twilio TwiML builder responses (VoiceResponse,
MessagingResponse, FaxResponse) returned from a controller handler
into their XML string representation, and sets the matching
Content-Type header on the underlying HTTP response.
Non-TwiML return values are passed through unchanged, so the interceptor
is safe to register globally alongside handlers that return plain JSON.
It works identically on the Express and Fastify platform adapters, since
it only relies on the response.header() method both implement, and it
never touches the response status code or any other header.
Examples
Section titled “Examples”Registered globally, using the default content type
app.useGlobalInterceptors(new TwimlInterceptor());Registered per-route, overriding the default content type
@Post('incoming')@UseInterceptors(new TwimlInterceptor({ contentType: 'application/xml' }))handleIncomingCall(): MessagingResponse { const response = new MessagingResponse(); response.message('Thanks for texting us!'); return response;}Registered as a provider, with a per-route override
providers: [{ provide: APP_INTERCEPTOR, useClass: TwimlInterceptor }];Implements
Section titled “Implements”NestInterceptor
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TwimlInterceptor(options?): TwimlInterceptor;Defined in: lib/twiml/twiml.interceptor.ts:209
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
TwimlInterceptorOptions |
Returns
Section titled “Returns”TwimlInterceptor
Methods
Section titled “Methods”intercept()
Section titled “intercept()”intercept(context, next): Observable<unknown>;Defined in: lib/twiml/twiml.interceptor.ts:217
Method to implement a custom interceptor.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
context |
ExecutionContext |
an ExecutionContext object providing methods to access the route handler and class about to be invoked. |
next |
CallHandler |
a reference to the CallHandler, which provides access to an Observable representing the response stream from the route handler. |
Returns
Section titled “Returns”Observable<unknown>
Implementation of
Section titled “Implementation of”NestInterceptor.intercept